swimlanes.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. const { calculateIndex, enableClickOnTouch } = Utils;
  2. function currentListIsInThisSwimlane(swimlaneId) {
  3. const currentList = Lists.findOne(Session.get('currentList'));
  4. return (
  5. currentList &&
  6. (currentList.swimlaneId === swimlaneId || currentList.swimlaneId === '')
  7. );
  8. }
  9. function currentCardIsInThisList(listId, swimlaneId) {
  10. const currentCard = Cards.findOne(Session.get('currentCard'));
  11. const currentUser = Meteor.user();
  12. if (
  13. currentUser &&
  14. currentUser.profile &&
  15. currentUser.profile.boardView === 'board-view-swimlanes'
  16. )
  17. return (
  18. currentCard &&
  19. currentCard.listId === listId &&
  20. currentCard.swimlaneId === swimlaneId
  21. );
  22. // Default view: board-view-lists
  23. else return currentCard && currentCard.listId === listId;
  24. // https://github.com/wekan/wekan/issues/1623
  25. // https://github.com/ChronikEwok/wekan/commit/cad9b20451bb6149bfb527a99b5001873b06c3de
  26. // TODO: In public board, if you would like to switch between List/Swimlane view, you could
  27. // 1) If there is no view cookie, save to cookie board-view-lists
  28. // board-view-lists / board-view-swimlanes / board-view-cal
  29. // 2) If public user changes clicks board-view-lists then change view and
  30. // then change view and save cookie with view value
  31. // without using currentuser above, because currentuser is null.
  32. }
  33. function initSortable(boardComponent, $listsDom) {
  34. // We want to animate the card details window closing. We rely on CSS
  35. // transition for the actual animation.
  36. $listsDom._uihooks = {
  37. removeElement(node) {
  38. const removeNode = _.once(() => {
  39. node.parentNode.removeChild(node);
  40. });
  41. if ($(node).hasClass('js-card-details')) {
  42. $(node).css({
  43. flexBasis: 0,
  44. padding: 0,
  45. });
  46. $listsDom.one(CSSEvents.transitionend, removeNode);
  47. } else {
  48. removeNode();
  49. }
  50. },
  51. };
  52. if (Utils.isMiniScreen) {
  53. $listsDom.sortable({
  54. handle: '.js-list-handle',
  55. });
  56. }
  57. if (!Utils.isMiniScreen && showDesktopDragHandles) {
  58. $listsDom.sortable({
  59. handle: '.js-list-header',
  60. });
  61. }
  62. $listsDom.sortable({
  63. tolerance: 'pointer',
  64. helper: 'clone',
  65. items: '.js-list:not(.js-list-composer)',
  66. placeholder: 'list placeholder',
  67. distance: 7,
  68. start(evt, ui) {
  69. ui.placeholder.height(ui.helper.height());
  70. EscapeActions.executeUpTo('popup-close');
  71. boardComponent.setIsDragging(true);
  72. },
  73. stop(evt, ui) {
  74. // To attribute the new index number, we need to get the DOM element
  75. // of the previous and the following card -- if any.
  76. const prevListDom = ui.item.prev('.js-list').get(0);
  77. const nextListDom = ui.item.next('.js-list').get(0);
  78. const sortIndex = calculateIndex(prevListDom, nextListDom, 1);
  79. $listsDom.sortable('cancel');
  80. const listDomElement = ui.item.get(0);
  81. const list = Blaze.getData(listDomElement);
  82. Lists.update(list._id, {
  83. $set: {
  84. sort: sortIndex.base,
  85. },
  86. });
  87. boardComponent.setIsDragging(false);
  88. },
  89. });
  90. // ugly touch event hotfix
  91. enableClickOnTouch('.js-list:not(.js-list-composer)');
  92. function userIsMember() {
  93. return (
  94. Meteor.user() &&
  95. Meteor.user().isBoardMember() &&
  96. !Meteor.user().isCommentOnly()
  97. );
  98. }
  99. // Disable drag-dropping while in multi-selection mode, or if the current user
  100. // is not a board member
  101. boardComponent.autorun(() => {
  102. const $listDom = $listsDom;
  103. if ($listDom.data('sortable')) {
  104. $listsDom.sortable(
  105. 'option',
  106. 'disabled',
  107. MultiSelection.isActive() || !userIsMember(),
  108. );
  109. }
  110. });
  111. }
  112. BlazeComponent.extendComponent({
  113. onRendered() {
  114. const boardComponent = this.parentComponent();
  115. const $listsDom = this.$('.js-lists');
  116. if (!Session.get('currentCard')) {
  117. boardComponent.scrollLeft();
  118. }
  119. initSortable(boardComponent, $listsDom);
  120. },
  121. onCreated() {
  122. this.draggingActive = new ReactiveVar(false);
  123. this._isDragging = false;
  124. this._lastDragPositionX = 0;
  125. },
  126. id() {
  127. return this._id;
  128. },
  129. currentCardIsInThisList(listId, swimlaneId) {
  130. return currentCardIsInThisList(listId, swimlaneId);
  131. },
  132. currentListIsInThisSwimlane(swimlaneId) {
  133. return currentListIsInThisSwimlane(swimlaneId);
  134. },
  135. events() {
  136. return [
  137. {
  138. // Click-and-drag action
  139. 'mousedown .board-canvas'(evt) {
  140. // Translating the board canvas using the click-and-drag action can
  141. // conflict with the build-in browser mechanism to select text. We
  142. // define a list of elements in which we disable the dragging because
  143. // the user will legitimately expect to be able to select some text with
  144. // his mouse.
  145. const noDragInside = ['a', 'input', 'textarea', 'p'].concat(
  146. Util.isMiniScreen || (!Util.isMiniScreen && showDesktopDragHandles)
  147. ? ['.js-list-handle', '.js-swimlane-header-handle']
  148. : ['.js-list-header'],
  149. );
  150. if (
  151. $(evt.target).closest(noDragInside.join(',')).length === 0 &&
  152. this.$('.swimlane').prop('clientHeight') > evt.offsetY
  153. ) {
  154. this._isDragging = true;
  155. this._lastDragPositionX = evt.clientX;
  156. }
  157. },
  158. mouseup() {
  159. if (this._isDragging) {
  160. this._isDragging = false;
  161. }
  162. },
  163. mousemove(evt) {
  164. if (this._isDragging) {
  165. // Update the canvas position
  166. this.listsDom.scrollLeft -= evt.clientX - this._lastDragPositionX;
  167. this._lastDragPositionX = evt.clientX;
  168. // Disable browser text selection while dragging
  169. evt.stopPropagation();
  170. evt.preventDefault();
  171. // Don't close opened card or inlined form at the end of the
  172. // click-and-drag.
  173. EscapeActions.executeUpTo('popup-close');
  174. EscapeActions.preventNextClick();
  175. }
  176. },
  177. },
  178. ];
  179. },
  180. }).register('swimlane');
  181. BlazeComponent.extendComponent({
  182. onCreated() {
  183. this.currentBoard = Boards.findOne(Session.get('currentBoard'));
  184. this.isListTemplatesSwimlane =
  185. this.currentBoard.isTemplatesBoard() &&
  186. this.currentData().isListTemplatesSwimlane();
  187. this.currentSwimlane = this.currentData();
  188. },
  189. // Proxy
  190. open() {
  191. this.childComponents('inlinedForm')[0].open();
  192. },
  193. events() {
  194. return [
  195. {
  196. submit(evt) {
  197. evt.preventDefault();
  198. const titleInput = this.find('.list-name-input');
  199. const title = titleInput.value.trim();
  200. if (title) {
  201. Lists.insert({
  202. title,
  203. boardId: Session.get('currentBoard'),
  204. sort: $('.list').length,
  205. type: this.isListTemplatesSwimlane ? 'template-list' : 'list',
  206. swimlaneId: this.currentBoard.isTemplatesBoard()
  207. ? this.currentSwimlane._id
  208. : '',
  209. });
  210. titleInput.value = '';
  211. titleInput.focus();
  212. }
  213. },
  214. 'click .js-list-template': Popup.open('searchElement'),
  215. },
  216. ];
  217. },
  218. }).register('addListForm');
  219. Template.swimlane.helpers({
  220. showDesktopDragHandles() {
  221. return Meteor.user().hasShowDesktopDragHandles();
  222. },
  223. canSeeAddList() {
  224. return (
  225. Meteor.user() &&
  226. Meteor.user().isBoardMember() &&
  227. !Meteor.user().isCommentOnly()
  228. );
  229. },
  230. });
  231. BlazeComponent.extendComponent({
  232. currentCardIsInThisList(listId, swimlaneId) {
  233. return currentCardIsInThisList(listId, swimlaneId);
  234. },
  235. visible(list) {
  236. if (list.archived) {
  237. // Show archived list only when filter archive is on or archive is selected
  238. if (!(Filter.archive.isSelected() || archivedRequested)) {
  239. return false;
  240. }
  241. }
  242. if (Filter.lists._isActive()) {
  243. if (!list.title.match(Filter.lists.getRegexSelector())) {
  244. return false;
  245. }
  246. }
  247. if (Filter.hideEmpty.isSelected()) {
  248. const swimlaneId = this.parentComponent()
  249. .parentComponent()
  250. .data()._id;
  251. const cards = list.cards(swimlaneId);
  252. if (cards.count() === 0) {
  253. return false;
  254. }
  255. }
  256. return true;
  257. },
  258. onRendered() {
  259. const boardComponent = this.parentComponent();
  260. const $listsDom = this.$('.js-lists');
  261. if (!Session.get('currentCard')) {
  262. boardComponent.scrollLeft();
  263. }
  264. initSortable(boardComponent, $listsDom);
  265. },
  266. }).register('listsGroup');