listHeader.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. let listsColors;
  2. Meteor.startup(() => {
  3. listsColors = Lists.simpleSchema()._schema.color.allowedValues;
  4. });
  5. BlazeComponent.extendComponent({
  6. canSeeAddCard() {
  7. const list = Template.currentData();
  8. return (
  9. !list.getWipLimit('enabled') ||
  10. list.getWipLimit('soft') ||
  11. !this.reachedWipLimit()
  12. );
  13. },
  14. editTitle(event) {
  15. event.preventDefault();
  16. const newTitle = this.childComponents('inlinedForm')[0]
  17. .getValue()
  18. .trim();
  19. const list = this.currentData();
  20. if (newTitle) {
  21. list.rename(newTitle.trim());
  22. }
  23. },
  24. isWatching() {
  25. const list = this.currentData();
  26. return list.findWatcher(Meteor.userId());
  27. },
  28. limitToShowCardsCount() {
  29. return Meteor.user().getLimitToShowCardsCount();
  30. },
  31. cardsCount() {
  32. const list = Template.currentData();
  33. let swimlaneId = '';
  34. const boardView = (Meteor.user().profile || {}).boardView;
  35. if (boardView === 'board-view-swimlanes')
  36. swimlaneId = this.parentComponent()
  37. .parentComponent()
  38. .data()._id;
  39. return list.cards(swimlaneId).count();
  40. },
  41. reachedWipLimit() {
  42. const list = Template.currentData();
  43. return (
  44. list.getWipLimit('enabled') &&
  45. list.getWipLimit('value') <= list.cards().count()
  46. );
  47. },
  48. showCardsCountForList(count) {
  49. const limit = this.limitToShowCardsCount();
  50. return limit > 0 && count > limit;
  51. },
  52. events() {
  53. return [
  54. {
  55. 'click .js-open-list-menu': Popup.open('listAction'),
  56. 'click .js-add-card'(event) {
  57. const listDom = $(event.target).parents(
  58. `#js-list-${this.currentData()._id}`,
  59. )[0];
  60. const listComponent = BlazeComponent.getComponentForElement(listDom);
  61. listComponent.openForm({
  62. position: 'top',
  63. });
  64. },
  65. 'click .js-unselect-list'() {
  66. Session.set('currentList', null);
  67. },
  68. submit: this.editTitle,
  69. },
  70. ];
  71. },
  72. }).register('listHeader');
  73. Template.listHeader.helpers({
  74. showDesktopDragHandles() {
  75. return Meteor.user().hasShowDesktopDragHandles();
  76. },
  77. });
  78. Template.listActionPopup.helpers({
  79. isWipLimitEnabled() {
  80. return Template.currentData().getWipLimit('enabled');
  81. },
  82. isWatching() {
  83. return this.findWatcher(Meteor.userId());
  84. },
  85. });
  86. Template.listActionPopup.events({
  87. 'click .js-list-subscribe'() {},
  88. 'click .js-set-color-list': Popup.open('setListColor'),
  89. 'click .js-select-cards'() {
  90. const cardIds = this.allCards().map(card => card._id);
  91. MultiSelection.add(cardIds);
  92. Popup.close();
  93. },
  94. 'click .js-toggle-watch-list'() {
  95. const currentList = this;
  96. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  97. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  98. if (!err && ret) Popup.close();
  99. });
  100. },
  101. 'click .js-close-list'(event) {
  102. event.preventDefault();
  103. this.archive();
  104. Popup.close();
  105. },
  106. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  107. 'click .js-more': Popup.open('listMore'),
  108. });
  109. BlazeComponent.extendComponent({
  110. applyWipLimit() {
  111. const list = Template.currentData();
  112. const limit = parseInt(
  113. Template.instance()
  114. .$('.wip-limit-value')
  115. .val(),
  116. 10,
  117. );
  118. if (limit < list.cards().count() && !list.getWipLimit('soft')) {
  119. Template.instance()
  120. .$('.wip-limit-error')
  121. .click();
  122. } else {
  123. Meteor.call('applyWipLimit', list._id, limit);
  124. Popup.back();
  125. }
  126. },
  127. enableSoftLimit() {
  128. const list = Template.currentData();
  129. if (
  130. list.getWipLimit('soft') &&
  131. list.getWipLimit('value') < list.cards().count()
  132. ) {
  133. list.setWipLimit(list.cards().count());
  134. }
  135. Meteor.call('enableSoftLimit', Template.currentData()._id);
  136. },
  137. enableWipLimit() {
  138. const list = Template.currentData();
  139. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  140. if (
  141. !list.getWipLimit('enabled') &&
  142. list.getWipLimit('value') < list.cards().count()
  143. ) {
  144. list.setWipLimit(list.cards().count());
  145. }
  146. Meteor.call('enableWipLimit', list._id);
  147. },
  148. isWipLimitSoft() {
  149. return Template.currentData().getWipLimit('soft');
  150. },
  151. isWipLimitEnabled() {
  152. return Template.currentData().getWipLimit('enabled');
  153. },
  154. wipLimitValue() {
  155. return Template.currentData().getWipLimit('value');
  156. },
  157. events() {
  158. return [
  159. {
  160. 'click .js-enable-wip-limit': this.enableWipLimit,
  161. 'click .wip-limit-apply': this.applyWipLimit,
  162. 'click .wip-limit-error': Popup.open('wipLimitError'),
  163. 'click .materialCheckBox': this.enableSoftLimit,
  164. },
  165. ];
  166. },
  167. }).register('setWipLimitPopup');
  168. Template.listMorePopup.events({
  169. 'click .js-delete': Popup.afterConfirm('listDelete', function() {
  170. Popup.close();
  171. this.allCards().map(card => Cards.remove(card._id));
  172. Lists.remove(this._id);
  173. Utils.goBoardId(this.boardId);
  174. }),
  175. });
  176. BlazeComponent.extendComponent({
  177. onCreated() {
  178. this.currentList = this.currentData();
  179. this.currentColor = new ReactiveVar(this.currentList.color);
  180. },
  181. colors() {
  182. return listsColors.map(color => ({ color, name: '' }));
  183. },
  184. isSelected(color) {
  185. return this.currentColor.get() === color;
  186. },
  187. events() {
  188. return [
  189. {
  190. 'click .js-palette-color'() {
  191. this.currentColor.set(this.currentData().color);
  192. },
  193. 'click .js-submit'() {
  194. this.currentList.setColor(this.currentColor.get());
  195. Popup.close();
  196. },
  197. 'click .js-remove-color'() {
  198. this.currentList.setColor(null);
  199. Popup.close();
  200. },
  201. },
  202. ];
  203. },
  204. }).register('setListColorPopup');