adminReports.js 5.3 KB

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