snappymail/dev/Stores/User/Quota.js

35 lines
601 B
JavaScript
Raw Normal View History

import window from 'window';
import ko from 'ko';
2016-08-24 06:17:50 +08:00
import {Magics} from 'Common/Enums';
class QuotaUserStore
2016-06-30 08:02:45 +08:00
{
constructor() {
this.quota = ko.observable(0);
this.usage = ko.observable(0);
2016-06-30 08:02:45 +08:00
this.percentage = ko.computed(() => {
2016-06-30 08:02:45 +08:00
const
quota = this.quota(),
usage = this.usage();
2016-06-30 08:02:45 +08:00
return 0 < quota ? window.Math.ceil((usage / quota) * 100) : 0;
2016-06-30 08:02:45 +08:00
});
}
2016-06-30 08:02:45 +08:00
/**
* @param {number} quota
* @param {number} usage
*/
populateData(quota, usage) {
2016-08-24 06:17:50 +08:00
this.quota(quota * Magics.BitLength1024);
this.usage(usage * Magics.BitLength1024);
}
}
2016-06-30 08:02:45 +08:00
export default new QuotaUserStore();