adminReports.js 4.8 KB

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