listBody.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. const subManager = new SubsManager();
  2. const InfiniteScrollIter = 10;
  3. BlazeComponent.extendComponent({
  4. onCreated() {
  5. // for infinite scrolling
  6. this.cardlimit = new ReactiveVar(InfiniteScrollIter);
  7. },
  8. mixins() {
  9. return [Mixins.PerfectScrollbar];
  10. },
  11. openForm(options) {
  12. options = options || {};
  13. options.position = options.position || 'top';
  14. const forms = this.childComponents('inlinedForm');
  15. let form = forms.find(component => {
  16. return component.data().position === options.position;
  17. });
  18. if (!form && forms.length > 0) {
  19. form = forms[0];
  20. }
  21. form.open();
  22. },
  23. addCard(evt) {
  24. evt.preventDefault();
  25. const firstCardDom = this.find('.js-minicard:first');
  26. const lastCardDom = this.find('.js-minicard:last');
  27. const textarea = $(evt.currentTarget).find('textarea');
  28. const position = this.currentData().position;
  29. const title = textarea.val().trim();
  30. const formComponent = this.childComponents('addCardForm')[0];
  31. let sortIndex;
  32. if (position === 'top') {
  33. sortIndex = Utils.calculateIndex(null, firstCardDom).base;
  34. } else if (position === 'bottom') {
  35. sortIndex = Utils.calculateIndex(lastCardDom, null).base;
  36. }
  37. const members = formComponent.members.get();
  38. const labelIds = formComponent.labels.get();
  39. const customFields = formComponent.customFields.get();
  40. const board = this.data().board();
  41. let linkedId = '';
  42. let swimlaneId = '';
  43. const boardView = (Meteor.user().profile || {}).boardView;
  44. let cardType = 'cardType-card';
  45. if (title) {
  46. if (board.isTemplatesBoard()) {
  47. swimlaneId = this.parentComponent()
  48. .parentComponent()
  49. .data()._id; // Always swimlanes view
  50. const swimlane = Swimlanes.findOne(swimlaneId);
  51. // If this is the card templates swimlane, insert a card template
  52. if (swimlane.isCardTemplatesSwimlane()) cardType = 'template-card';
  53. // If this is the board templates swimlane, insert a board template and a linked card
  54. else if (swimlane.isBoardTemplatesSwimlane()) {
  55. linkedId = Boards.insert({
  56. title,
  57. permission: 'private',
  58. type: 'template-board',
  59. });
  60. Swimlanes.insert({
  61. title: TAPi18n.__('default'),
  62. boardId: linkedId,
  63. });
  64. cardType = 'cardType-linkedBoard';
  65. }
  66. } else if (boardView === 'board-view-swimlanes')
  67. swimlaneId = this.parentComponent()
  68. .parentComponent()
  69. .data()._id;
  70. else if (
  71. boardView === 'board-view-lists' ||
  72. boardView === 'board-view-cal' ||
  73. !boardView
  74. )
  75. swimlaneId = board.getDefaultSwimline()._id;
  76. const _id = Cards.insert({
  77. title,
  78. members,
  79. labelIds,
  80. customFields,
  81. listId: this.data()._id,
  82. boardId: board._id,
  83. sort: sortIndex,
  84. swimlaneId,
  85. type: cardType,
  86. linkedId,
  87. });
  88. // if the displayed card count is less than the total cards in the list,
  89. // we need to increment the displayed card count to prevent the spinner
  90. // to appear
  91. const cardCount = this.data()
  92. .cards(this.idOrNull(swimlaneId))
  93. .count();
  94. if (this.cardlimit.get() < cardCount) {
  95. this.cardlimit.set(this.cardlimit.get() + InfiniteScrollIter);
  96. }
  97. // In case the filter is active we need to add the newly inserted card in
  98. // the list of exceptions -- cards that are not filtered. Otherwise the
  99. // card will disappear instantly.
  100. // See https://github.com/wekan/wekan/issues/80
  101. Filter.addException(_id);
  102. // We keep the form opened, empty it, and scroll to it.
  103. textarea.val('').focus();
  104. autosize.update(textarea);
  105. if (position === 'bottom') {
  106. this.scrollToBottom();
  107. }
  108. formComponent.reset();
  109. }
  110. },
  111. scrollToBottom() {
  112. const container = this.firstNode();
  113. $(container).animate({
  114. scrollTop: container.scrollHeight,
  115. });
  116. },
  117. clickOnMiniCard(evt) {
  118. if (MultiSelection.isActive() || evt.shiftKey) {
  119. evt.stopImmediatePropagation();
  120. evt.preventDefault();
  121. const methodName = evt.shiftKey ? 'toggleRange' : 'toggle';
  122. MultiSelection[methodName](this.currentData()._id);
  123. // If the card is already selected, we want to de-select it.
  124. // XXX We should probably modify the minicard href attribute instead of
  125. // overwriting the event in case the card is already selected.
  126. } else if (Session.equals('currentCard', this.currentData()._id)) {
  127. evt.stopImmediatePropagation();
  128. evt.preventDefault();
  129. Utils.goBoardId(Session.get('currentBoard'));
  130. }
  131. },
  132. cardIsSelected() {
  133. return Session.equals('currentCard', this.currentData()._id);
  134. },
  135. toggleMultiSelection(evt) {
  136. evt.stopPropagation();
  137. evt.preventDefault();
  138. MultiSelection.toggle(this.currentData()._id);
  139. },
  140. idOrNull(swimlaneId) {
  141. const currentUser = Meteor.user();
  142. if (
  143. (currentUser.profile || {}).boardView === 'board-view-swimlanes' ||
  144. this.data()
  145. .board()
  146. .isTemplatesBoard()
  147. )
  148. return swimlaneId;
  149. return undefined;
  150. },
  151. cardsWithLimit(swimlaneId) {
  152. const limit = this.cardlimit.get();
  153. const selector = {
  154. listId: this.currentData()._id,
  155. archived: false,
  156. };
  157. if (swimlaneId) selector.swimlaneId = swimlaneId;
  158. return Cards.find(Filter.mongoSelector(selector), {
  159. sort: ['sort'],
  160. limit,
  161. });
  162. },
  163. showSpinner(swimlaneId) {
  164. const list = Template.currentData();
  165. return list.cards(swimlaneId).count() > this.cardlimit.get();
  166. },
  167. canSeeAddCard() {
  168. return (
  169. !this.reachedWipLimit() &&
  170. Meteor.user() &&
  171. Meteor.user().isBoardMember() &&
  172. !Meteor.user().isCommentOnly()
  173. );
  174. },
  175. reachedWipLimit() {
  176. const list = Template.currentData();
  177. return (
  178. !list.getWipLimit('soft') &&
  179. list.getWipLimit('enabled') &&
  180. list.getWipLimit('value') <= list.cards().count()
  181. );
  182. },
  183. events() {
  184. return [
  185. {
  186. 'click .js-minicard': this.clickOnMiniCard,
  187. 'click .js-toggle-multi-selection': this.toggleMultiSelection,
  188. 'click .open-minicard-composer': this.scrollToBottom,
  189. submit: this.addCard,
  190. },
  191. ];
  192. },
  193. }).register('listBody');
  194. function toggleValueInReactiveArray(reactiveValue, value) {
  195. const array = reactiveValue.get();
  196. const valueIndex = array.indexOf(value);
  197. if (valueIndex === -1) {
  198. array.push(value);
  199. } else {
  200. array.splice(valueIndex, 1);
  201. }
  202. reactiveValue.set(array);
  203. }
  204. BlazeComponent.extendComponent({
  205. onCreated() {
  206. this.labels = new ReactiveVar([]);
  207. this.members = new ReactiveVar([]);
  208. this.customFields = new ReactiveVar([]);
  209. const currentBoardId = Session.get('currentBoard');
  210. arr = [];
  211. _.forEach(
  212. Boards.findOne(currentBoardId)
  213. .customFields()
  214. .fetch(),
  215. function(field) {
  216. if (field.automaticallyOnCard)
  217. arr.push({ _id: field._id, value: null });
  218. },
  219. );
  220. this.customFields.set(arr);
  221. },
  222. reset() {
  223. this.labels.set([]);
  224. this.members.set([]);
  225. this.customFields.set([]);
  226. },
  227. getLabels() {
  228. const currentBoardId = Session.get('currentBoard');
  229. return Boards.findOne(currentBoardId).labels.filter(label => {
  230. return this.labels.get().indexOf(label._id) > -1;
  231. });
  232. },
  233. pressKey(evt) {
  234. // Pressing Enter should submit the card
  235. if (evt.keyCode === 13 && !evt.shiftKey) {
  236. evt.preventDefault();
  237. const $form = $(evt.currentTarget).closest('form');
  238. // XXX For some reason $form.submit() does not work (it's probably a bug
  239. // of blaze-component related to the fact that the submit event is non-
  240. // bubbling). This is why we click on the submit button instead -- which
  241. // work.
  242. $form.find('button[type=submit]').click();
  243. // Pressing Tab should open the form of the next column, and Maj+Tab go
  244. // in the reverse order
  245. } else if (evt.keyCode === 9) {
  246. evt.preventDefault();
  247. const isReverse = evt.shiftKey;
  248. const list = $(`#js-list-${this.data().listId}`);
  249. const listSelector = '.js-list:not(.js-list-composer)';
  250. let nextList = list[isReverse ? 'prev' : 'next'](listSelector).get(0);
  251. // If there is no next list, loop back to the beginning.
  252. if (!nextList) {
  253. nextList = $(listSelector + (isReverse ? ':last' : ':first')).get(0);
  254. }
  255. BlazeComponent.getComponentForElement(nextList).openForm({
  256. position: this.data().position,
  257. });
  258. }
  259. },
  260. events() {
  261. return [
  262. {
  263. keydown: this.pressKey,
  264. 'click .js-link': Popup.open('linkCard'),
  265. 'click .js-search': Popup.open('searchElement'),
  266. 'click .js-card-template': Popup.open('searchElement'),
  267. },
  268. ];
  269. },
  270. onRendered() {
  271. const editor = this;
  272. const $textarea = this.$('textarea');
  273. autosize($textarea);
  274. $textarea.escapeableTextComplete(
  275. [
  276. // User mentions
  277. {
  278. match: /\B@([\w.]*)$/,
  279. search(term, callback) {
  280. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  281. callback(
  282. $.map(currentBoard.activeMembers(), member => {
  283. const user = Users.findOne(member.userId);
  284. return user.username.indexOf(term) === 0 ? user : null;
  285. }),
  286. );
  287. },
  288. template(user) {
  289. return user.username;
  290. },
  291. replace(user) {
  292. toggleValueInReactiveArray(editor.members, user._id);
  293. return '';
  294. },
  295. index: 1,
  296. },
  297. // Labels
  298. {
  299. match: /\B#(\w*)$/,
  300. search(term, callback) {
  301. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  302. callback(
  303. $.map(currentBoard.labels, label => {
  304. if (
  305. label.name.indexOf(term) > -1 ||
  306. label.color.indexOf(term) > -1
  307. ) {
  308. return label;
  309. }
  310. return null;
  311. }),
  312. );
  313. },
  314. template(label) {
  315. return Blaze.toHTMLWithData(Template.autocompleteLabelLine, {
  316. hasNoName: !label.name,
  317. colorName: label.color,
  318. labelName: label.name || label.color,
  319. });
  320. },
  321. replace(label) {
  322. toggleValueInReactiveArray(editor.labels, label._id);
  323. return '';
  324. },
  325. index: 1,
  326. },
  327. ],
  328. {
  329. // When the autocomplete menu is shown we want both a press of both `Tab`
  330. // or `Enter` to validation the auto-completion. We also need to stop the
  331. // event propagation to prevent the card from submitting (on `Enter`) or
  332. // going on the next column (on `Tab`).
  333. onKeydown(evt, commands) {
  334. if (evt.keyCode === 9 || evt.keyCode === 13) {
  335. evt.stopPropagation();
  336. return commands.KEY_ENTER;
  337. }
  338. return null;
  339. },
  340. },
  341. );
  342. },
  343. }).register('addCardForm');
  344. BlazeComponent.extendComponent({
  345. onCreated() {
  346. this.selectedBoardId = new ReactiveVar('');
  347. this.selectedSwimlaneId = new ReactiveVar('');
  348. this.selectedListId = new ReactiveVar('');
  349. this.boardId = Session.get('currentBoard');
  350. // In order to get current board info
  351. subManager.subscribe('board', this.boardId, false);
  352. this.board = Boards.findOne(this.boardId);
  353. // List where to insert card
  354. const list = $(Popup._getTopStack().openerElement).closest('.js-list');
  355. this.listId = Blaze.getData(list[0])._id;
  356. // Swimlane where to insert card
  357. const swimlane = $(Popup._getTopStack().openerElement).closest(
  358. '.js-swimlane',
  359. );
  360. this.swimlaneId = '';
  361. const boardView = (Meteor.user().profile || {}).boardView;
  362. if (boardView === 'board-view-swimlanes')
  363. this.swimlaneId = Blaze.getData(swimlane[0])._id;
  364. else if (boardView === 'board-view-lists' || !boardView)
  365. this.swimlaneId = Swimlanes.findOne({ boardId: this.boardId })._id;
  366. },
  367. boards() {
  368. const boards = Boards.find(
  369. {
  370. archived: false,
  371. 'members.userId': Meteor.userId(),
  372. _id: { $ne: Session.get('currentBoard') },
  373. type: 'board',
  374. },
  375. {
  376. sort: ['title'],
  377. },
  378. );
  379. return boards;
  380. },
  381. swimlanes() {
  382. if (!this.selectedBoardId.get()) {
  383. return [];
  384. }
  385. const swimlanes = Swimlanes.find({ boardId: this.selectedBoardId.get() });
  386. if (swimlanes.count())
  387. this.selectedSwimlaneId.set(swimlanes.fetch()[0]._id);
  388. return swimlanes;
  389. },
  390. lists() {
  391. if (!this.selectedBoardId.get()) {
  392. return [];
  393. }
  394. const lists = Lists.find({ boardId: this.selectedBoardId.get() });
  395. if (lists.count()) this.selectedListId.set(lists.fetch()[0]._id);
  396. return lists;
  397. },
  398. cards() {
  399. if (!this.board) {
  400. return [];
  401. }
  402. const ownCardsIds = this.board.cards().map(card => {
  403. return card.linkedId || card._id;
  404. });
  405. return Cards.find({
  406. boardId: this.selectedBoardId.get(),
  407. swimlaneId: this.selectedSwimlaneId.get(),
  408. listId: this.selectedListId.get(),
  409. archived: false,
  410. linkedId: { $nin: ownCardsIds },
  411. _id: { $nin: ownCardsIds },
  412. type: { $nin: ['template-card'] },
  413. });
  414. },
  415. events() {
  416. return [
  417. {
  418. 'change .js-select-boards'(evt) {
  419. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  420. this.selectedBoardId.set($(evt.currentTarget).val());
  421. },
  422. 'change .js-select-swimlanes'(evt) {
  423. this.selectedSwimlaneId.set($(evt.currentTarget).val());
  424. },
  425. 'change .js-select-lists'(evt) {
  426. this.selectedListId.set($(evt.currentTarget).val());
  427. },
  428. 'click .js-done'(evt) {
  429. // LINK CARD
  430. evt.stopPropagation();
  431. evt.preventDefault();
  432. const linkedId = $('.js-select-cards option:selected').val();
  433. if (!linkedId) {
  434. Popup.close();
  435. return;
  436. }
  437. const _id = Cards.insert({
  438. title: $('.js-select-cards option:selected').text(), //dummy
  439. listId: this.listId,
  440. swimlaneId: this.swimlaneId,
  441. boardId: this.boardId,
  442. sort: Lists.findOne(this.listId)
  443. .cards()
  444. .count(),
  445. type: 'cardType-linkedCard',
  446. linkedId,
  447. });
  448. Filter.addException(_id);
  449. Popup.close();
  450. },
  451. 'click .js-link-board'(evt) {
  452. //LINK BOARD
  453. evt.stopPropagation();
  454. evt.preventDefault();
  455. const impBoardId = $('.js-select-boards option:selected').val();
  456. if (
  457. !impBoardId ||
  458. Cards.findOne({ linkedId: impBoardId, archived: false })
  459. ) {
  460. Popup.close();
  461. return;
  462. }
  463. const _id = Cards.insert({
  464. title: $('.js-select-boards option:selected').text(), //dummy
  465. listId: this.listId,
  466. swimlaneId: this.swimlaneId,
  467. boardId: this.boardId,
  468. sort: Lists.findOne(this.listId)
  469. .cards()
  470. .count(),
  471. type: 'cardType-linkedBoard',
  472. linkedId: impBoardId,
  473. });
  474. Filter.addException(_id);
  475. Popup.close();
  476. },
  477. },
  478. ];
  479. },
  480. }).register('linkCardPopup');
  481. BlazeComponent.extendComponent({
  482. mixins() {
  483. return [Mixins.PerfectScrollbar];
  484. },
  485. onCreated() {
  486. this.isCardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  487. 'js-card-template',
  488. );
  489. this.isListTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  490. 'js-list-template',
  491. );
  492. this.isSwimlaneTemplateSearch = $(
  493. Popup._getTopStack().openerElement,
  494. ).hasClass('js-open-add-swimlane-menu');
  495. this.isBoardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  496. 'js-add-board',
  497. );
  498. this.isTemplateSearch =
  499. this.isCardTemplateSearch ||
  500. this.isListTemplateSearch ||
  501. this.isSwimlaneTemplateSearch ||
  502. this.isBoardTemplateSearch;
  503. let board = {};
  504. if (this.isTemplateSearch) {
  505. board = Boards.findOne((Meteor.user().profile || {}).templatesBoardId);
  506. } else {
  507. // Prefetch first non-current board id
  508. board = Boards.findOne({
  509. archived: false,
  510. 'members.userId': Meteor.userId(),
  511. _id: {
  512. $nin: [
  513. Session.get('currentBoard'),
  514. (Meteor.user().profile || {}).templatesBoardId,
  515. ],
  516. },
  517. });
  518. }
  519. if (!board) {
  520. Popup.close();
  521. return;
  522. }
  523. const boardId = board._id;
  524. // Subscribe to this board
  525. subManager.subscribe('board', boardId, false);
  526. this.selectedBoardId = new ReactiveVar(boardId);
  527. if (!this.isBoardTemplateSearch) {
  528. this.boardId = Session.get('currentBoard');
  529. // In order to get current board info
  530. subManager.subscribe('board', this.boardId, false);
  531. this.swimlaneId = '';
  532. // Swimlane where to insert card
  533. const swimlane = $(Popup._getTopStack().openerElement).parents(
  534. '.js-swimlane',
  535. );
  536. if ((Meteor.user().profile || {}).boardView === 'board-view-swimlanes')
  537. this.swimlaneId = Blaze.getData(swimlane[0])._id;
  538. else this.swimlaneId = Swimlanes.findOne({ boardId: this.boardId })._id;
  539. // List where to insert card
  540. const list = $(Popup._getTopStack().openerElement).closest('.js-list');
  541. this.listId = Blaze.getData(list[0])._id;
  542. }
  543. this.term = new ReactiveVar('');
  544. },
  545. boards() {
  546. const boards = Boards.find(
  547. {
  548. archived: false,
  549. 'members.userId': Meteor.userId(),
  550. _id: { $ne: Session.get('currentBoard') },
  551. type: 'board',
  552. },
  553. {
  554. sort: ['title'],
  555. },
  556. );
  557. return boards;
  558. },
  559. results() {
  560. if (!this.selectedBoardId) {
  561. return [];
  562. }
  563. const board = Boards.findOne(this.selectedBoardId.get());
  564. if (!this.isTemplateSearch || this.isCardTemplateSearch) {
  565. return board.searchCards(this.term.get(), false);
  566. } else if (this.isListTemplateSearch) {
  567. return board.searchLists(this.term.get());
  568. } else if (this.isSwimlaneTemplateSearch) {
  569. return board.searchSwimlanes(this.term.get());
  570. } else if (this.isBoardTemplateSearch) {
  571. const boards = board.searchBoards(this.term.get());
  572. boards.forEach(board => {
  573. subManager.subscribe('board', board.linkedId, false);
  574. });
  575. return boards;
  576. } else {
  577. return [];
  578. }
  579. },
  580. events() {
  581. return [
  582. {
  583. 'change .js-select-boards'(evt) {
  584. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  585. this.selectedBoardId.set($(evt.currentTarget).val());
  586. },
  587. 'submit .js-search-term-form'(evt) {
  588. evt.preventDefault();
  589. this.term.set(evt.target.searchTerm.value);
  590. },
  591. 'click .js-minicard'(evt) {
  592. // 0. Common
  593. const title = $('.js-element-title')
  594. .val()
  595. .trim();
  596. if (!title) return;
  597. const element = Blaze.getData(evt.currentTarget);
  598. element.title = title;
  599. let _id = '';
  600. if (!this.isTemplateSearch || this.isCardTemplateSearch) {
  601. // Card insertion
  602. // 1. Common
  603. element.sort = Lists.findOne(this.listId)
  604. .cards()
  605. .count();
  606. // 1.A From template
  607. if (this.isTemplateSearch) {
  608. element.type = 'cardType-card';
  609. element.linkedId = '';
  610. _id = element.copy(this.boardId, this.swimlaneId, this.listId);
  611. // 1.B Linked card
  612. } else {
  613. delete element._id;
  614. element.type = 'cardType-linkedCard';
  615. element.linkedId = element.linkedId || element._id;
  616. _id = Cards.insert(element);
  617. }
  618. Filter.addException(_id);
  619. // List insertion
  620. } else if (this.isListTemplateSearch) {
  621. element.sort = Swimlanes.findOne(this.swimlaneId)
  622. .lists()
  623. .count();
  624. element.type = 'list';
  625. _id = element.copy(this.boardId, this.swimlaneId);
  626. } else if (this.isSwimlaneTemplateSearch) {
  627. element.sort = Boards.findOne(this.boardId)
  628. .swimlanes()
  629. .count();
  630. element.type = 'swimlalne';
  631. _id = element.copy(this.boardId);
  632. } else if (this.isBoardTemplateSearch) {
  633. board = Boards.findOne(element.linkedId);
  634. board.sort = Boards.find({ archived: false }).count();
  635. board.type = 'board';
  636. board.title = element.title;
  637. delete board.slug;
  638. _id = board.copy();
  639. }
  640. Popup.close();
  641. },
  642. },
  643. ];
  644. },
  645. }).register('searchElementPopup');
  646. BlazeComponent.extendComponent({
  647. onCreated() {
  648. this.cardlimit = this.parentComponent().cardlimit;
  649. this.listId = this.parentComponent().data()._id;
  650. this.swimlaneId = '';
  651. let user = Meteor.user();
  652. if (user) {
  653. const boardView = (Meteor.user().profile || {}).boardView;
  654. if (boardView === 'board-view-swimlanes') {
  655. this.swimlaneId = this.parentComponent()
  656. .parentComponent()
  657. .parentComponent()
  658. .data()._id;
  659. }
  660. }
  661. },
  662. onRendered() {
  663. this.spinner = this.find('.sk-spinner-list');
  664. this.container = this.$(this.spinner).parents('.js-perfect-scrollbar')[0];
  665. $(this.container).on(
  666. `scroll.spinner_${this.swimlaneId}_${this.listId}`,
  667. () => this.updateList(),
  668. );
  669. $(window).on(`resize.spinner_${this.swimlaneId}_${this.listId}`, () =>
  670. this.updateList(),
  671. );
  672. this.updateList();
  673. },
  674. onDestroyed() {
  675. $(this.container).off(`scroll.spinner_${this.swimlaneId}_${this.listId}`);
  676. $(window).off(`resize.spinner_${this.swimlaneId}_${this.listId}`);
  677. },
  678. updateList() {
  679. if (this.spinnerInView()) {
  680. this.cardlimit.set(this.cardlimit.get() + InfiniteScrollIter);
  681. window.requestIdleCallback(() => this.updateList());
  682. }
  683. },
  684. spinnerInView() {
  685. const parentViewHeight = this.container.clientHeight;
  686. const bottomViewPosition = this.container.scrollTop + parentViewHeight;
  687. const threshold = this.spinner.offsetTop;
  688. // spinner deleted
  689. if (!this.spinner.offsetTop) {
  690. return false;
  691. }
  692. return bottomViewPosition > threshold;
  693. },
  694. }).register('spinnerList');