listHeader.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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.listActionPopup.helpers({
  74. isWipLimitEnabled() {
  75. return Template.currentData().getWipLimit('enabled');
  76. },
  77. isWatching() {
  78. return this.findWatcher(Meteor.userId());
  79. },
  80. });
  81. Template.listActionPopup.events({
  82. 'click .js-list-subscribe'() {},
  83. 'click .js-set-color-list': Popup.open('setListColor'),
  84. 'click .js-select-cards'() {
  85. const cardIds = this.allCards().map(card => card._id);
  86. MultiSelection.add(cardIds);
  87. Popup.close();
  88. },
  89. 'click .js-toggle-watch-list'() {
  90. const currentList = this;
  91. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  92. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  93. if (!err && ret) Popup.close();
  94. });
  95. },
  96. 'click .js-close-list'(event) {
  97. event.preventDefault();
  98. this.archive();
  99. Popup.close();
  100. },
  101. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  102. 'click .js-more': Popup.open('listMore'),
  103. });
  104. BlazeComponent.extendComponent({
  105. applyWipLimit() {
  106. const list = Template.currentData();
  107. const limit = parseInt(
  108. Template.instance()
  109. .$('.wip-limit-value')
  110. .val(),
  111. 10,
  112. );
  113. if (limit < list.cards().count() && !list.getWipLimit('soft')) {
  114. Template.instance()
  115. .$('.wip-limit-error')
  116. .click();
  117. } else {
  118. Meteor.call('applyWipLimit', list._id, limit);
  119. Popup.back();
  120. }
  121. },
  122. enableSoftLimit() {
  123. const list = Template.currentData();
  124. if (
  125. list.getWipLimit('soft') &&
  126. list.getWipLimit('value') < list.cards().count()
  127. ) {
  128. list.setWipLimit(list.cards().count());
  129. }
  130. Meteor.call('enableSoftLimit', Template.currentData()._id);
  131. },
  132. enableWipLimit() {
  133. const list = Template.currentData();
  134. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  135. if (
  136. !list.getWipLimit('enabled') &&
  137. list.getWipLimit('value') < list.cards().count()
  138. ) {
  139. list.setWipLimit(list.cards().count());
  140. }
  141. Meteor.call('enableWipLimit', list._id);
  142. },
  143. isWipLimitSoft() {
  144. return Template.currentData().getWipLimit('soft');
  145. },
  146. isWipLimitEnabled() {
  147. return Template.currentData().getWipLimit('enabled');
  148. },
  149. wipLimitValue() {
  150. return Template.currentData().getWipLimit('value');
  151. },
  152. events() {
  153. return [
  154. {
  155. 'click .js-enable-wip-limit': this.enableWipLimit,
  156. 'click .wip-limit-apply': this.applyWipLimit,
  157. 'click .wip-limit-error': Popup.open('wipLimitError'),
  158. 'click .materialCheckBox': this.enableSoftLimit,
  159. },
  160. ];
  161. },
  162. }).register('setWipLimitPopup');
  163. Template.listMorePopup.events({
  164. 'click .js-delete': Popup.afterConfirm('listDelete', function() {
  165. Popup.close();
  166. this.allCards().map(card => Cards.remove(card._id));
  167. Lists.remove(this._id);
  168. Utils.goBoardId(this.boardId);
  169. }),
  170. });
  171. BlazeComponent.extendComponent({
  172. onCreated() {
  173. this.currentList = this.currentData();
  174. this.currentColor = new ReactiveVar(this.currentList.color);
  175. },
  176. colors() {
  177. return listsColors.map(color => ({ color, name: '' }));
  178. },
  179. isSelected(color) {
  180. return this.currentColor.get() === color;
  181. },
  182. events() {
  183. return [
  184. {
  185. 'click .js-palette-color'() {
  186. this.currentColor.set(this.currentData().color);
  187. },
  188. 'click .js-submit'() {
  189. this.currentList.setColor(this.currentColor.get());
  190. Popup.close();
  191. },
  192. 'click .js-remove-color'() {
  193. this.currentList.setColor(null);
  194. Popup.close();
  195. },
  196. },
  197. ];
  198. },
  199. }).register('setListColorPopup');