listBody.js 22 KB

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