adminReports.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. BlazeComponent.extendComponent({
  8. subscription: null,
  9. showFilesReport: new ReactiveVar(false),
  10. showBrokenCardsReport: new ReactiveVar(false),
  11. showOrphanedFilesReport: new ReactiveVar(false),
  12. showRulesReport: new ReactiveVar(false),
  13. showCardsReport: new ReactiveVar(false),
  14. showBoardsReport: new ReactiveVar(false),
  15. sessionId: null,
  16. onCreated() {
  17. this.error = new ReactiveVar('');
  18. this.loading = new ReactiveVar(false);
  19. this.sessionId = SessionData.getSessionId();
  20. },
  21. events() {
  22. return [
  23. {
  24. 'click a.js-report-broken': this.switchMenu,
  25. 'click a.js-report-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-rules' === targetID) {
  63. this.subscription = Meteor.subscribe('rulesReport', () => {
  64. this.showRulesReport.set(true);
  65. this.loading.set(false);
  66. });
  67. } else if ('report-boards' === targetID) {
  68. this.subscription = Meteor.subscribe('boardsReport', () => {
  69. this.showBoardsReport.set(true);
  70. this.loading.set(false);
  71. });
  72. } else if ('report-cards' === targetID) {
  73. const qp = new QueryParams();
  74. qp.addPredicate(OPERATOR_LIMIT, 300);
  75. this.subscription = Meteor.subscribe(
  76. 'globalSearch',
  77. this.sessionId,
  78. qp.getParams(),
  79. qp.text,
  80. () => {
  81. this.showCardsReport.set(true);
  82. this.loading.set(false);
  83. },
  84. );
  85. }
  86. }
  87. },
  88. }).register('adminReports');
  89. class AdminReport extends BlazeComponent {
  90. collection;
  91. results() {
  92. // eslint-disable-next-line no-console
  93. return this.collection.find();
  94. }
  95. yesOrNo(value) {
  96. if (value) {
  97. return TAPi18n.__('yes');
  98. } else {
  99. return TAPi18n.__('no');
  100. }
  101. }
  102. resultsCount() {
  103. return this.collection.find().count();
  104. }
  105. fileSize(size) {
  106. return Math.round(size / 1024);
  107. }
  108. abbreviate(text) {
  109. if (text.length > 30) {
  110. return `${text.substr(0, 29)}...`;
  111. }
  112. return text;
  113. }
  114. }
  115. (class extends AdminReport {
  116. collection = Attachments;
  117. }.register('filesReport'));
  118. (class extends AdminReport {
  119. collection = Rules;
  120. results() {
  121. const rules = [];
  122. Rules.find().forEach(rule => {
  123. rules.push({
  124. _id: rule._id,
  125. title: rule.title,
  126. boardId: rule.boardId,
  127. boardTitle: rule.board().title,
  128. action: rule.action(),
  129. trigger: rule.trigger(),
  130. });
  131. });
  132. // eslint-disable-next-line no-console
  133. console.log('rows:', rules);
  134. return rules;
  135. }
  136. }.register('rulesReport'));
  137. (class extends AdminReport {
  138. collection = Boards;
  139. userNames(members) {
  140. let text = '';
  141. members.forEach(member => {
  142. const user = Users.findOne(member.userId);
  143. text += text ? ', ' : '';
  144. if (user) {
  145. text += user.username;
  146. } else {
  147. text += member.userId
  148. }
  149. });
  150. return text;
  151. }
  152. }.register('boardsReport'));
  153. (class extends AdminReport {
  154. collection = Cards;
  155. userNames(userIds) {
  156. let text = '';
  157. userIds.forEach(userId => {
  158. const user = Users.findOne(userId);
  159. text += text ? ', ' : '';
  160. text += user.username;
  161. });
  162. return text;
  163. }
  164. }.register('cardsReport'));
  165. class BrokenCardsComponent extends CardSearchPagedComponent {
  166. onCreated() {
  167. super.onCreated();
  168. }
  169. }
  170. BrokenCardsComponent.register('brokenCardsReport');