informationBody.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. BlazeComponent.extendComponent({
  2. onCreated() {
  3. this.info = new ReactiveVar({});
  4. Meteor.call('getStatistics', (error, ret) => {
  5. if (!error && ret) {
  6. this.info.set(ret);
  7. }
  8. });
  9. },
  10. statistics() {
  11. return this.info.get();
  12. },
  13. humanReadableTime(time) {
  14. const days = Math.floor(time / 86400);
  15. const hours = Math.floor((time % 86400) / 3600);
  16. const minutes = Math.floor(((time % 86400) % 3600) / 60);
  17. const seconds = Math.floor(((time % 86400) % 3600) % 60);
  18. let out = '';
  19. if (days > 0) {
  20. out += `${days} ${TAPi18n.__('days')}, `;
  21. }
  22. if (hours > 0) {
  23. out += `${hours} ${TAPi18n.__('hours')}, `;
  24. }
  25. if (minutes > 0) {
  26. out += `${minutes} ${TAPi18n.__('minutes')}, `;
  27. }
  28. if (seconds > 0) {
  29. out += `${seconds} ${TAPi18n.__('seconds')}`;
  30. }
  31. return out;
  32. },
  33. numFormat(number) {
  34. return parseFloat(number).toFixed(2);
  35. },
  36. bytesToSize(bytes) {
  37. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  38. if (bytes === 0) {
  39. return '0 Byte';
  40. }
  41. const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10);
  42. return `${Math.round(bytes / Math.pow(1024, i), 2)} ${sizes[i]}`;
  43. },
  44. }).register('statistics');