adminReports.js 4.9 KB

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