adminReports.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { AttachmentStorage } from '/models/attachments';
  2. import { CardSearchPagedComponent } from '/client/lib/cardSearch';
  3. import SessionData from '/models/usersessiondata';
  4. BlazeComponent.extendComponent({
  5. subscription: null,
  6. showFilesReport: new ReactiveVar(false),
  7. showBrokenCardsReport: new ReactiveVar(false),
  8. showOrphanedFilesReport: new ReactiveVar(false),
  9. onCreated() {
  10. this.error = new ReactiveVar('');
  11. this.loading = new ReactiveVar(false);
  12. },
  13. events() {
  14. return [
  15. {
  16. 'click a.js-report-broken': this.switchMenu,
  17. 'click a.js-report-files': this.switchMenu,
  18. 'click a.js-report-orphaned-files': this.switchMenu,
  19. },
  20. ];
  21. },
  22. switchMenu(event) {
  23. const target = $(event.target);
  24. if (!target.hasClass('active')) {
  25. this.loading.set(true);
  26. this.showFilesReport.set(false);
  27. this.showBrokenCardsReport.set(false);
  28. this.showOrphanedFilesReport.set(false);
  29. if (this.subscription) {
  30. this.subscription.stop();
  31. }
  32. $('.side-menu li.active').removeClass('active');
  33. target.parent().addClass('active');
  34. const targetID = target.data('id');
  35. if ('report-broken' === targetID) {
  36. this.showBrokenCardsReport.set(true);
  37. this.subscription = Meteor.subscribe(
  38. 'brokenCards',
  39. SessionData.getSessionId(),
  40. () => {
  41. this.loading.set(false);
  42. },
  43. );
  44. } else if ('report-files' === targetID) {
  45. this.showFilesReport.set(true);
  46. this.subscription = Meteor.subscribe('attachmentsList', () => {
  47. this.loading.set(false);
  48. });
  49. } else if ('report-orphaned-files' === targetID) {
  50. this.showOrphanedFilesReport.set(true);
  51. this.subscription = Meteor.subscribe('orphanedAttachments', () => {
  52. this.loading.set(false);
  53. });
  54. }
  55. }
  56. },
  57. }).register('adminReports');
  58. Template.filesReport.helpers({
  59. attachmentFiles() {
  60. // eslint-disable-next-line no-console
  61. // console.log('attachments:', AttachmentStorage.find());
  62. // console.log('attachments.count:', AttachmentStorage.find().count());
  63. return AttachmentStorage.find();
  64. },
  65. resultsCount() {
  66. return AttachmentStorage.find().count();
  67. },
  68. fileSize(size) {
  69. return Math.round(size / 1024);
  70. },
  71. usageCount(key) {
  72. return Attachments.find({ 'copies.attachments.key': key }).count();
  73. },
  74. });
  75. Template.orphanedFilesReport.helpers({
  76. attachmentFiles() {
  77. // eslint-disable-next-line no-console
  78. // console.log('attachments:', AttachmentStorage.find());
  79. // console.log('attachments.count:', AttachmentStorage.find().count());
  80. return AttachmentStorage.find();
  81. },
  82. resultsCount() {
  83. return AttachmentStorage.find().count();
  84. },
  85. fileSize(size) {
  86. return Math.round(size / 1024);
  87. },
  88. });
  89. class BrokenCardsComponent extends CardSearchPagedComponent {
  90. onCreated() {
  91. super.onCreated();
  92. }
  93. }
  94. BrokenCardsComponent.register('brokenCardsReport');