informationBody.js 1.3 KB

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