2
0

adminReports.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. showRulesReport: new ReactiveVar(false),
  10. onCreated() {
  11. this.error = new ReactiveVar('');
  12. this.loading = new ReactiveVar(false);
  13. },
  14. events() {
  15. return [
  16. {
  17. 'click a.js-report-broken': this.switchMenu,
  18. 'click a.js-report-files': this.switchMenu,
  19. 'click a.js-report-orphaned-files': this.switchMenu,
  20. 'click a.js-report-rules': this.switchMenu,
  21. },
  22. ];
  23. },
  24. switchMenu(event) {
  25. const target = $(event.target);
  26. if (!target.hasClass('active')) {
  27. this.loading.set(true);
  28. this.showFilesReport.set(false);
  29. this.showBrokenCardsReport.set(false);
  30. this.showOrphanedFilesReport.set(false);
  31. if (this.subscription) {
  32. this.subscription.stop();
  33. }
  34. $('.side-menu li.active').removeClass('active');
  35. target.parent().addClass('active');
  36. const targetID = target.data('id');
  37. if ('report-broken' === targetID) {
  38. this.showBrokenCardsReport.set(true);
  39. this.subscription = Meteor.subscribe(
  40. 'brokenCards',
  41. SessionData.getSessionId(),
  42. () => {
  43. this.loading.set(false);
  44. },
  45. );
  46. } else if ('report-files' === targetID) {
  47. this.showFilesReport.set(true);
  48. this.subscription = Meteor.subscribe('attachmentsList', () => {
  49. this.loading.set(false);
  50. });
  51. } else if ('report-orphaned-files' === targetID) {
  52. this.showOrphanedFilesReport.set(true);
  53. this.subscription = Meteor.subscribe('orphanedAttachments', () => {
  54. this.loading.set(false);
  55. });
  56. } else if ('report-rules' === targetID) {
  57. this.subscription = Meteor.subscribe('rulesReport', () => {
  58. this.showRulesReport.set(true);
  59. this.loading.set(false);
  60. });
  61. }
  62. }
  63. },
  64. }).register('adminReports');
  65. Template.filesReport.helpers({
  66. attachmentFiles() {
  67. // eslint-disable-next-line no-console
  68. // console.log('attachments:', AttachmentStorage.find());
  69. // console.log('attachments.count:', AttachmentStorage.find().count());
  70. return AttachmentStorage.find();
  71. },
  72. rulesReport() {
  73. const rules = [];
  74. Rules.find().forEach(rule => {
  75. rules.push({
  76. _id: rule._id,
  77. title: rule.title,
  78. boardId: rule.boardId,
  79. boardTitle: rule.board().title,
  80. action: rule.action().fetch(),
  81. trigger: rule.trigger().fetch(),
  82. });
  83. });
  84. return rules;
  85. },
  86. resultsCount() {
  87. return AttachmentStorage.find().count();
  88. },
  89. fileSize(size) {
  90. return Math.round(size / 1024);
  91. },
  92. usageCount(key) {
  93. return Attachments.find({ 'copies.attachments.key': key }).count();
  94. },
  95. });
  96. Template.orphanedFilesReport.helpers({
  97. attachmentFiles() {
  98. // eslint-disable-next-line no-console
  99. // console.log('attachments:', AttachmentStorage.find());
  100. // console.log('attachments.count:', AttachmentStorage.find().count());
  101. return AttachmentStorage.find();
  102. },
  103. resultsCount() {
  104. return AttachmentStorage.find().count();
  105. },
  106. fileSize(size) {
  107. return Math.round(size / 1024);
  108. },
  109. });
  110. Template.rulesReport.helpers({
  111. rows() {
  112. const rules = [];
  113. Rules.find().forEach(rule => {
  114. rules.push({
  115. _id: rule._id,
  116. title: rule.title,
  117. boardId: rule.boardId,
  118. boardTitle: rule.board().title,
  119. action: rule.action(),
  120. trigger: rule.trigger(),
  121. });
  122. });
  123. console.log('rows:', rules);
  124. return rules;
  125. },
  126. resultsCount() {
  127. return Rules.find().count();
  128. },
  129. });
  130. class BrokenCardsComponent extends CardSearchPagedComponent {
  131. onCreated() {
  132. super.onCreated();
  133. }
  134. }
  135. BrokenCardsComponent.register('brokenCardsReport');