adminReports.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import { AttachmentStorage } from '/models/attachments';
  4. import { CardSearchPagedComponent } from '/client/lib/cardSearch';
  5. import SessionData from '/models/usersessiondata';
  6. import { QueryParams } from '/config/query-classes';
  7. import { OPERATOR_LIMIT } from '/config/search-const';
  8. const filesize = require('filesize');
  9. BlazeComponent.extendComponent({
  10. subscription: null,
  11. showFilesReport: new ReactiveVar(false),
  12. showBrokenCardsReport: new ReactiveVar(false),
  13. showOrphanedFilesReport: new ReactiveVar(false),
  14. showRulesReport: new ReactiveVar(false),
  15. showCardsReport: new ReactiveVar(false),
  16. showBoardsReport: new ReactiveVar(false),
  17. sessionId: null,
  18. onCreated() {
  19. this.error = new ReactiveVar('');
  20. this.loading = new ReactiveVar(false);
  21. this.sessionId = SessionData.getSessionId();
  22. },
  23. events() {
  24. return [
  25. {
  26. 'click a.js-report-broken': this.switchMenu,
  27. 'click a.js-report-files': this.switchMenu,
  28. 'click a.js-report-rules': this.switchMenu,
  29. 'click a.js-report-cards': this.switchMenu,
  30. 'click a.js-report-boards': this.switchMenu,
  31. },
  32. ];
  33. },
  34. switchMenu(event) {
  35. const target = $(event.target);
  36. if (!target.hasClass('active')) {
  37. this.loading.set(true);
  38. this.showFilesReport.set(false);
  39. this.showBrokenCardsReport.set(false);
  40. this.showOrphanedFilesReport.set(false);
  41. this.showRulesReport.set(false)
  42. this.showBoardsReport.set(false);
  43. this.showCardsReport.set(false);
  44. if (this.subscription) {
  45. this.subscription.stop();
  46. }
  47. $('.side-menu li.active').removeClass('active');
  48. target.parent().addClass('active');
  49. const targetID = target.data('id');
  50. if ('report-broken' === targetID) {
  51. this.showBrokenCardsReport.set(true);
  52. this.subscription = Meteor.subscribe(
  53. 'brokenCards',
  54. SessionData.getSessionId(),
  55. () => {
  56. this.loading.set(false);
  57. },
  58. );
  59. } else if ('report-files' === targetID) {
  60. this.showFilesReport.set(true);
  61. this.subscription = Meteor.subscribe('attachmentsList', () => {
  62. this.loading.set(false);
  63. });
  64. } else if ('report-rules' === targetID) {
  65. this.subscription = Meteor.subscribe('rulesReport', () => {
  66. this.showRulesReport.set(true);
  67. this.loading.set(false);
  68. });
  69. } else if ('report-boards' === targetID) {
  70. this.subscription = Meteor.subscribe('boardsReport', () => {
  71. this.showBoardsReport.set(true);
  72. this.loading.set(false);
  73. });
  74. } else if ('report-cards' === targetID) {
  75. const qp = new QueryParams();
  76. qp.addPredicate(OPERATOR_LIMIT, 300);
  77. this.subscription = Meteor.subscribe(
  78. 'globalSearch',
  79. this.sessionId,
  80. qp.getParams(),
  81. qp.text,
  82. () => {
  83. this.showCardsReport.set(true);
  84. this.loading.set(false);
  85. },
  86. );
  87. }
  88. }
  89. },
  90. }).register('adminReports');
  91. class AdminReport extends BlazeComponent {
  92. collection;
  93. results() {
  94. // eslint-disable-next-line no-console
  95. return this.collection.find();
  96. }
  97. yesOrNo(value) {
  98. if (value) {
  99. return TAPi18n.__('yes');
  100. } else {
  101. return TAPi18n.__('no');
  102. }
  103. }
  104. resultsCount() {
  105. return this.collection.find().count();
  106. }
  107. fileSize(size) {
  108. let ret = "";
  109. if (_.isNumber(size)) {
  110. ret = filesize(size);
  111. }
  112. return ret;
  113. }
  114. abbreviate(text) {
  115. if (text.length > 30) {
  116. return `${text.substr(0, 29)}...`;
  117. }
  118. return text;
  119. }
  120. }
  121. (class extends AdminReport {
  122. collection = Attachments;
  123. }.register('filesReport'));
  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 = ReactiveCache.getUser(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 = ReactiveCache.getUser(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');