listHeader.js 6.4 KB

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