attachments.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import Attachments, { fileStoreStrategyFactory } from '/models/attachments';
  2. BlazeComponent.extendComponent({
  3. subscription: null,
  4. showMoveAttachments: new ReactiveVar(false),
  5. sessionId: null,
  6. onCreated() {
  7. this.error = new ReactiveVar('');
  8. this.loading = new ReactiveVar(false);
  9. },
  10. events() {
  11. return [
  12. {
  13. 'click a.js-move-attachments': this.switchMenu,
  14. },
  15. ];
  16. },
  17. switchMenu(event) {
  18. const target = $(event.target);
  19. if (!target.hasClass('active')) {
  20. this.loading.set(true);
  21. this.showMoveAttachments.set(false);
  22. if (this.subscription) {
  23. this.subscription.stop();
  24. }
  25. $('.side-menu li.active').removeClass('active');
  26. target.parent().addClass('active');
  27. const targetID = target.data('id');
  28. if ('move-attachments' === targetID) {
  29. this.showMoveAttachments.set(true);
  30. this.subscription = Meteor.subscribe('attachmentsList', () => {
  31. this.loading.set(false);
  32. });
  33. }
  34. }
  35. },
  36. }).register('attachments');
  37. BlazeComponent.extendComponent({
  38. getBoardsWithAttachments() {
  39. this.attachments = Attachments.find().get();
  40. this.attachmentsByBoardId = _.chain(this.attachments)
  41. .groupBy(fileObj => fileObj.meta.boardId)
  42. .value();
  43. const ret = Object.keys(this.attachmentsByBoardId)
  44. .map(boardId => {
  45. const boardAttachments = this.attachmentsByBoardId[boardId];
  46. _.each(boardAttachments, _attachment => {
  47. _attachment.flatVersion = Object.keys(_attachment.versions)
  48. .map(_versionName => {
  49. const _version = Object.assign(_attachment.versions[_versionName], {"versionName": _versionName});
  50. _version.storageName = fileStoreStrategyFactory.getFileStrategy(_attachment, _versionName).getStorageName();
  51. return _version;
  52. });
  53. });
  54. const board = Boards.findOne(boardId);
  55. board.attachments = boardAttachments;
  56. return board;
  57. })
  58. return ret;
  59. },
  60. getBoardData(boardid) {
  61. const ret = Boards.findOne(boardId);
  62. return ret;
  63. },
  64. events() {
  65. return [
  66. {
  67. 'click button.js-move-all-attachments-to-fs'(event) {
  68. this.attachments.forEach(_attachment => {
  69. Meteor.call('moveAttachmentToStorage', _attachment._id, "fs");
  70. });
  71. },
  72. 'click button.js-move-all-attachments-to-gridfs'(event) {
  73. this.attachments.forEach(_attachment => {
  74. Meteor.call('moveAttachmentToStorage', _attachment._id, "gridfs");
  75. });
  76. },
  77. }
  78. ]
  79. }
  80. }).register('moveAttachments');
  81. BlazeComponent.extendComponent({
  82. events() {
  83. return [
  84. {
  85. 'click button.js-move-all-attachments-of-board-to-fs'(event) {
  86. this.data().attachments.forEach(_attachment => {
  87. Meteor.call('moveAttachmentToStorage', _attachment._id, "fs");
  88. });
  89. },
  90. 'click button.js-move-all-attachments-of-board-to-gridfs'(event) {
  91. this.data().attachments.forEach(_attachment => {
  92. Meteor.call('moveAttachmentToStorage', _attachment._id, "gridfs");
  93. });
  94. },
  95. }
  96. ]
  97. },
  98. }).register('moveBoardAttachments');
  99. BlazeComponent.extendComponent({
  100. events() {
  101. return [
  102. {
  103. 'click button.js-move-storage-fs'(event) {
  104. Meteor.call('moveAttachmentToStorage', this.data()._id, "fs");
  105. },
  106. 'click button.js-move-storage-gridfs'(event) {
  107. Meteor.call('moveAttachmentToStorage', this.data()._id, "gridfs");
  108. },
  109. }
  110. ]
  111. },
  112. }).register('moveAttachment');