adminReports.js 5.4 KB

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