2015-01-26 07:09:22 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
import window from 'window';
|
|
|
|
import ko from 'ko';
|
|
|
|
|
|
|
|
class QuotaUserStore
|
2016-06-30 08:02:45 +08:00
|
|
|
{
|
2016-08-17 06:01:20 +08:00
|
|
|
constructor() {
|
|
|
|
this.quota = ko.observable(0);
|
|
|
|
this.usage = ko.observable(0);
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
this.percentage = ko.computed(() => {
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
const
|
|
|
|
quota = this.quota(),
|
|
|
|
usage = this.usage();
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
return 0 < quota ? window.Math.ceil((usage / quota) * 100) : 0;
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
});
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
2016-08-17 06:01:20 +08:00
|
|
|
/**
|
|
|
|
* @param {number} quota
|
|
|
|
* @param {number} usage
|
|
|
|
*/
|
|
|
|
populateData(quota, usage) {
|
|
|
|
this.quota(quota * 1024);
|
|
|
|
this.usage(usage * 1024);
|
|
|
|
}
|
|
|
|
}
|
2016-06-30 08:02:45 +08:00
|
|
|
|
|
|
|
module.exports = new QuotaUserStore();
|