adminReports.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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-orphaned-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-orphaned-files' === targetID) {
  64. this.showOrphanedFilesReport.set(true);
  65. this.subscription = Meteor.subscribe('orphanedAttachments', () => {
  66. this.loading.set(false);
  67. });
  68. } else if ('report-rules' === targetID) {
  69. this.subscription = Meteor.subscribe('rulesReport', () => {
  70. this.showRulesReport.set(true);
  71. this.loading.set(false);
  72. });
  73. } else if ('report-boards' === targetID) {
  74. this.subscription = Meteor.subscribe('boardsReport', () => {
  75. this.showBoardsReport.set(true);
  76. this.loading.set(false);
  77. });
  78. } else if ('report-cards' === targetID) {
  79. const qp = new QueryParams();
  80. qp.addPredicate(OPERATOR_LIMIT, 300);
  81. this.subscription = Meteor.subscribe(
  82. 'globalSearch',
  83. this.sessionId,
  84. qp.getParams(),
  85. qp.text,
  86. () => {
  87. this.showCardsReport.set(true);
  88. this.loading.set(false);
  89. },
  90. );
  91. }
  92. }
  93. },
  94. }).register('adminReports');
  95. class AdminReport extends BlazeComponent {
  96. collection;
  97. results() {
  98. // eslint-disable-next-line no-console
  99. // console.log('attachments:', AttachmentStorage.find());
  100. // console.log('attachments.count:', AttachmentStorage.find().count());
  101. return this.collection.find();
  102. }
  103. yesOrNo(value) {
  104. if (value) {
  105. return TAPi18n.__('yes');
  106. } else {
  107. return TAPi18n.__('no');
  108. }
  109. }
  110. resultsCount() {
  111. return this.collection.find().count();
  112. }
  113. fileSize(size) {
  114. return Math.round(size / 1024);
  115. }
  116. usageCount(key) {
  117. return Attachments.find({ 'copies.attachments.key': key }).count();
  118. }
  119. abbreviate(text) {
  120. if (text.length > 30) {
  121. return `${text.substr(0, 29)}...`;
  122. }
  123. return text;
  124. }
  125. }
  126. (class extends AdminReport {
  127. collection = AttachmentStorage;
  128. }.register('filesReport'));
  129. (class extends AdminReport {
  130. collection = AttachmentStorage;
  131. }.register('orphanedFilesReport'));
  132. (class extends AdminReport {
  133. collection = Rules;
  134. results() {
  135. const rules = [];
  136. Rules.find().forEach(rule => {
  137. rules.push({
  138. _id: rule._id,
  139. title: rule.title,
  140. boardId: rule.boardId,
  141. boardTitle: rule.board().title,
  142. action: rule.action(),
  143. trigger: rule.trigger(),
  144. });
  145. });
  146. // eslint-disable-next-line no-console
  147. console.log('rows:', rules);
  148. return rules;
  149. }
  150. }.register('rulesReport'));
  151. (class extends AdminReport {
  152. collection = Boards;
  153. userNames(members) {
  154. let text = '';
  155. members.forEach(member => {
  156. const user = Users.findOne(member.userId);
  157. text += text ? ', ' : '';
  158. if (user) {
  159. text += user.username;
  160. } else {
  161. text += member.userId
  162. }
  163. });
  164. return text;
  165. }
  166. }.register('boardsReport'));
  167. (class extends AdminReport {
  168. collection = Cards;
  169. userNames(userIds) {
  170. let text = '';
  171. userIds.forEach(userId => {
  172. const user = Users.findOne(userId);
  173. text += text ? ', ' : '';
  174. text += user.username;
  175. });
  176. return text;
  177. }
  178. }.register('cardsReport'));
  179. class BrokenCardsComponent extends CardSearchPagedComponent {
  180. onCreated() {
  181. super.onCreated();
  182. }
  183. }
  184. BrokenCardsComponent.register('brokenCardsReport');