informationBody.js 1.1 KB

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