adminReports.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { AttachmentStorage } from '/models/attachments';
  2. import { CardSearchPagedComponent } from '/client/lib/cardSearch';
  3. import SessionData from '/models/usersessiondata';
  4. import { QueryParams } from '/config/query-classes';
  5. import { OPERATOR_LIMIT } from '/config/search-const';
  6. BlazeComponent.extendComponent({
  7. subscription: null,
  8. showFilesReport: new ReactiveVar(false),
  9. showBrokenCardsReport: new ReactiveVar(false),
  10. showOrphanedFilesReport: new ReactiveVar(false),
  11. showRulesReport: new ReactiveVar(false),
  12. showCardsReport: new ReactiveVar(false),
  13. sessionId: null,
  14. onCreated() {
  15. this.error = new ReactiveVar('');
  16. this.loading = new ReactiveVar(false);
  17. this.sessionId = SessionData.getSessionId();
  18. },
  19. events() {
  20. return [
  21. {
  22. 'click a.js-report-broken': this.switchMenu,
  23. 'click a.js-report-files': this.switchMenu,
  24. 'click a.js-report-orphaned-files': this.switchMenu,
  25. 'click a.js-report-rules': this.switchMenu,
  26. 'click a.js-report-cards': this.switchMenu,
  27. },
  28. ];
  29. },
  30. switchMenu(event) {
  31. const target = $(event.target);
  32. if (!target.hasClass('active')) {
  33. this.loading.set(true);
  34. this.showFilesReport.set(false);
  35. this.showBrokenCardsReport.set(false);
  36. this.showOrphanedFilesReport.set(false);
  37. if (this.subscription) {
  38. this.subscription.stop();
  39. }
  40. $('.side-menu li.active').removeClass('active');
  41. target.parent().addClass('active');
  42. const targetID = target.data('id');
  43. if ('report-broken' === targetID) {
  44. this.showBrokenCardsReport.set(true);
  45. this.subscription = Meteor.subscribe(
  46. 'brokenCards',
  47. SessionData.getSessionId(),
  48. () => {
  49. this.loading.set(false);
  50. },
  51. );
  52. } else if ('report-files' === targetID) {
  53. this.showFilesReport.set(true);
  54. this.subscription = Meteor.subscribe('attachmentsList', () => {
  55. this.loading.set(false);
  56. });
  57. } else if ('report-orphaned-files' === targetID) {
  58. this.showOrphanedFilesReport.set(true);
  59. this.subscription = Meteor.subscribe('orphanedAttachments', () => {
  60. this.loading.set(false);
  61. });
  62. } else if ('report-rules' === targetID) {
  63. this.subscription = Meteor.subscribe('rulesReport', () => {
  64. this.showRulesReport.set(true);
  65. this.loading.set(false);
  66. });
  67. } else if ('report-cards' === targetID) {
  68. const qp = new QueryParams();
  69. qp.addPredicate(OPERATOR_LIMIT, 300);
  70. this.subscription = Meteor.subscribe(
  71. 'globalSearch',
  72. this.sessionId,
  73. qp.getParams(),
  74. qp.text,
  75. () => {
  76. this.showCardsReport.set(true);
  77. this.loading.set(false);
  78. },
  79. );
  80. }
  81. }
  82. },
  83. }).register('adminReports');
  84. class AdminReport extends BlazeComponent {
  85. collection;
  86. results() {
  87. // eslint-disable-next-line no-console
  88. // console.log('attachments:', AttachmentStorage.find());
  89. // console.log('attachments.count:', AttachmentStorage.find().count());
  90. return this.collection.find();
  91. }
  92. resultsCount() {
  93. return this.collection.find().count();
  94. }
  95. fileSize(size) {
  96. return Math.round(size / 1024);
  97. }
  98. usageCount(key) {
  99. return Attachments.find({ 'copies.attachments.key': key }).count();
  100. }
  101. abbreviate(text) {
  102. if (text.length > 30) {
  103. return `${text.substr(0, 29)}...`;
  104. }
  105. return text;
  106. }
  107. }
  108. (class extends AdminReport {
  109. collection = AttachmentStorage;
  110. }.register('filesReport'));
  111. (class extends AdminReport {
  112. collection = AttachmentStorage;
  113. }.register('orphanedFilesReport'));
  114. (class extends AdminReport {
  115. collection = Rules;
  116. results() {
  117. const rules = [];
  118. Rules.find().forEach(rule => {
  119. rules.push({
  120. _id: rule._id,
  121. title: rule.title,
  122. boardId: rule.boardId,
  123. boardTitle: rule.board().title,
  124. action: rule.action(),
  125. trigger: rule.trigger(),
  126. });
  127. });
  128. // eslint-disable-next-line no-console
  129. console.log('rows:', rules);
  130. return rules;
  131. }
  132. }.register('rulesReport'));
  133. (class extends AdminReport {
  134. collection = Cards;
  135. userNames(userIds) {
  136. let text = '';
  137. userIds.forEach(userId => {
  138. const user = Users.findOne(userId);
  139. text += text ? ', ' : '';
  140. text += user.username;
  141. });
  142. return text;
  143. }
  144. }.register('cardsReport'));
  145. class BrokenCardsComponent extends CardSearchPagedComponent {
  146. onCreated() {
  147. super.onCreated();
  148. }
  149. }
  150. BrokenCardsComponent.register('brokenCardsReport');