listHeader.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 {
  103. if (cookies.has('showDesktopDragHandles')) {
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. }
  109. },
  110. });
  111. Template.listActionPopup.helpers({
  112. isWipLimitEnabled() {
  113. return Template.currentData().getWipLimit('enabled');
  114. },
  115. isWatching() {
  116. return this.findWatcher(Meteor.userId());
  117. },
  118. });
  119. Template.listActionPopup.events({
  120. 'click .js-list-subscribe'() {},
  121. 'click .js-set-color-list': Popup.open('setListColor'),
  122. 'click .js-select-cards'() {
  123. const cardIds = this.allCards().map(card => card._id);
  124. MultiSelection.add(cardIds);
  125. Popup.close();
  126. },
  127. 'click .js-toggle-watch-list'() {
  128. const currentList = this;
  129. const level = currentList.findWatcher(Meteor.userId()) ? null : 'watching';
  130. Meteor.call('watch', 'list', currentList._id, level, (err, ret) => {
  131. if (!err && ret) Popup.close();
  132. });
  133. },
  134. 'click .js-close-list'(event) {
  135. event.preventDefault();
  136. this.archive();
  137. Popup.close();
  138. },
  139. 'click .js-set-wip-limit': Popup.open('setWipLimit'),
  140. 'click .js-more': Popup.open('listMore'),
  141. });
  142. BlazeComponent.extendComponent({
  143. applyWipLimit() {
  144. const list = Template.currentData();
  145. const limit = parseInt(
  146. Template.instance()
  147. .$('.wip-limit-value')
  148. .val(),
  149. 10,
  150. );
  151. if (limit < list.cards().count() && !list.getWipLimit('soft')) {
  152. Template.instance()
  153. .$('.wip-limit-error')
  154. .click();
  155. } else {
  156. Meteor.call('applyWipLimit', list._id, limit);
  157. Popup.back();
  158. }
  159. },
  160. enableSoftLimit() {
  161. const list = Template.currentData();
  162. if (
  163. list.getWipLimit('soft') &&
  164. list.getWipLimit('value') < list.cards().count()
  165. ) {
  166. list.setWipLimit(list.cards().count());
  167. }
  168. Meteor.call('enableSoftLimit', Template.currentData()._id);
  169. },
  170. enableWipLimit() {
  171. const list = Template.currentData();
  172. // Prevent user from using previously stored wipLimit.value if it is less than the current number of cards in the list
  173. if (
  174. !list.getWipLimit('enabled') &&
  175. list.getWipLimit('value') < list.cards().count()
  176. ) {
  177. list.setWipLimit(list.cards().count());
  178. }
  179. Meteor.call('enableWipLimit', list._id);
  180. },
  181. isWipLimitSoft() {
  182. return Template.currentData().getWipLimit('soft');
  183. },
  184. isWipLimitEnabled() {
  185. return Template.currentData().getWipLimit('enabled');
  186. },
  187. wipLimitValue() {
  188. return Template.currentData().getWipLimit('value');
  189. },
  190. events() {
  191. return [
  192. {
  193. 'click .js-enable-wip-limit': this.enableWipLimit,
  194. 'click .wip-limit-apply': this.applyWipLimit,
  195. 'click .wip-limit-error': Popup.open('wipLimitError'),
  196. 'click .materialCheckBox': this.enableSoftLimit,
  197. },
  198. ];
  199. },
  200. }).register('setWipLimitPopup');
  201. Template.listMorePopup.events({
  202. 'click .js-delete': Popup.afterConfirm('listDelete', function() {
  203. Popup.close();
  204. this.allCards().map(card => Cards.remove(card._id));
  205. Lists.remove(this._id);
  206. Utils.goBoardId(this.boardId);
  207. }),
  208. });
  209. BlazeComponent.extendComponent({
  210. onCreated() {
  211. this.currentList = this.currentData();
  212. this.currentColor = new ReactiveVar(this.currentList.color);
  213. },
  214. colors() {
  215. return listsColors.map(color => ({ color, name: '' }));
  216. },
  217. isSelected(color) {
  218. return this.currentColor.get() === color;
  219. },
  220. events() {
  221. return [
  222. {
  223. 'click .js-palette-color'() {
  224. this.currentColor.set(this.currentData().color);
  225. },
  226. 'click .js-submit'() {
  227. this.currentList.setColor(this.currentColor.get());
  228. Popup.close();
  229. },
  230. 'click .js-remove-color'() {
  231. this.currentList.setColor(null);
  232. Popup.close();
  233. },
  234. },
  235. ];
  236. },
  237. }).register('setListColorPopup');