2
0

swimlanes.js 9.6 KB

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