listBody.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 [];
  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. !Meteor.user().isWorker()
  172. );
  173. },
  174. reachedWipLimit() {
  175. const list = Template.currentData();
  176. return (
  177. !list.getWipLimit('soft') &&
  178. list.getWipLimit('enabled') &&
  179. list.getWipLimit('value') <= list.cards().count()
  180. );
  181. },
  182. events() {
  183. return [
  184. {
  185. 'click .js-minicard': this.clickOnMiniCard,
  186. 'click .js-toggle-multi-selection': this.toggleMultiSelection,
  187. 'click .open-minicard-composer': this.scrollToBottom,
  188. submit: this.addCard,
  189. },
  190. ];
  191. },
  192. }).register('listBody');
  193. function toggleValueInReactiveArray(reactiveValue, value) {
  194. const array = reactiveValue.get();
  195. const valueIndex = array.indexOf(value);
  196. if (valueIndex === -1) {
  197. array.push(value);
  198. } else {
  199. array.splice(valueIndex, 1);
  200. }
  201. reactiveValue.set(array);
  202. }
  203. BlazeComponent.extendComponent({
  204. onCreated() {
  205. this.labels = new ReactiveVar([]);
  206. this.members = new ReactiveVar([]);
  207. this.customFields = new ReactiveVar([]);
  208. const currentBoardId = Session.get('currentBoard');
  209. arr = [];
  210. _.forEach(
  211. Boards.findOne(currentBoardId)
  212. .customFields()
  213. .fetch(),
  214. function(field) {
  215. if (field.automaticallyOnCard || field.alwaysOnCard)
  216. arr.push({ _id: field._id, value: null });
  217. },
  218. );
  219. this.customFields.set(arr);
  220. },
  221. reset() {
  222. this.labels.set([]);
  223. this.members.set([]);
  224. this.customFields.set([]);
  225. },
  226. getLabels() {
  227. const currentBoardId = Session.get('currentBoard');
  228. return Boards.findOne(currentBoardId).labels.filter(label => {
  229. return this.labels.get().indexOf(label._id) > -1;
  230. });
  231. },
  232. pressKey(evt) {
  233. // Pressing Enter should submit the card
  234. if (evt.keyCode === 13 && !evt.shiftKey) {
  235. evt.preventDefault();
  236. const $form = $(evt.currentTarget).closest('form');
  237. // XXX For some reason $form.submit() does not work (it's probably a bug
  238. // of blaze-component related to the fact that the submit event is non-
  239. // bubbling). This is why we click on the submit button instead -- which
  240. // work.
  241. $form.find('button[type=submit]').click();
  242. // Pressing Tab should open the form of the next column, and Maj+Tab go
  243. // in the reverse order
  244. } else if (evt.keyCode === 9) {
  245. evt.preventDefault();
  246. const isReverse = evt.shiftKey;
  247. const list = $(`#js-list-${this.data().listId}`);
  248. const listSelector = '.js-list:not(.js-list-composer)';
  249. let nextList = list[isReverse ? 'prev' : 'next'](listSelector).get(0);
  250. // If there is no next list, loop back to the beginning.
  251. if (!nextList) {
  252. nextList = $(listSelector + (isReverse ? ':last' : ':first')).get(0);
  253. }
  254. BlazeComponent.getComponentForElement(nextList).openForm({
  255. position: this.data().position,
  256. });
  257. }
  258. },
  259. events() {
  260. return [
  261. {
  262. keydown: this.pressKey,
  263. 'click .js-link': Popup.open('linkCard'),
  264. 'click .js-search': Popup.open('searchElement'),
  265. 'click .js-card-template': Popup.open('searchElement'),
  266. },
  267. ];
  268. },
  269. onRendered() {
  270. const editor = this;
  271. const $textarea = this.$('textarea');
  272. autosize($textarea);
  273. $textarea.escapeableTextComplete(
  274. [
  275. // User mentions
  276. {
  277. match: /\B@([\w.]*)$/,
  278. search(term, callback) {
  279. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  280. callback(
  281. $.map(currentBoard.activeMembers(), member => {
  282. const user = Users.findOne(member.userId);
  283. return user.username.indexOf(term) === 0 ? user : null;
  284. }),
  285. );
  286. },
  287. template(user) {
  288. return user.username;
  289. },
  290. replace(user) {
  291. toggleValueInReactiveArray(editor.members, user._id);
  292. return '';
  293. },
  294. index: 1,
  295. },
  296. // Labels
  297. {
  298. match: /\B#(\w*)$/,
  299. search(term, callback) {
  300. const currentBoard = Boards.findOne(Session.get('currentBoard'));
  301. callback(
  302. $.map(currentBoard.labels, label => {
  303. if (
  304. label.name.indexOf(term) > -1 ||
  305. label.color.indexOf(term) > -1
  306. ) {
  307. return label;
  308. }
  309. return null;
  310. }),
  311. );
  312. },
  313. template(label) {
  314. return Blaze.toHTMLWithData(Template.autocompleteLabelLine, {
  315. hasNoName: !label.name,
  316. colorName: label.color,
  317. labelName: label.name || label.color,
  318. });
  319. },
  320. replace(label) {
  321. toggleValueInReactiveArray(editor.labels, label._id);
  322. return '';
  323. },
  324. index: 1,
  325. },
  326. ],
  327. {
  328. // When the autocomplete menu is shown we want both a press of both `Tab`
  329. // or `Enter` to validation the auto-completion. We also need to stop the
  330. // event propagation to prevent the card from submitting (on `Enter`) or
  331. // going on the next column (on `Tab`).
  332. onKeydown(evt, commands) {
  333. if (evt.keyCode === 9 || evt.keyCode === 13) {
  334. evt.stopPropagation();
  335. return commands.KEY_ENTER;
  336. }
  337. return null;
  338. },
  339. },
  340. );
  341. },
  342. }).register('addCardForm');
  343. BlazeComponent.extendComponent({
  344. onCreated() {
  345. this.selectedBoardId = new ReactiveVar('');
  346. this.selectedSwimlaneId = new ReactiveVar('');
  347. this.selectedListId = new ReactiveVar('');
  348. this.boardId = Session.get('currentBoard');
  349. // In order to get current board info
  350. subManager.subscribe('board', this.boardId, false);
  351. this.board = Boards.findOne(this.boardId);
  352. // List where to insert card
  353. const list = $(Popup._getTopStack().openerElement).closest('.js-list');
  354. this.listId = Blaze.getData(list[0])._id;
  355. // Swimlane where to insert card
  356. const swimlane = $(Popup._getTopStack().openerElement).closest(
  357. '.js-swimlane',
  358. );
  359. this.swimlaneId = '';
  360. if (Utils.boardView() === 'board-view-swimlanes')
  361. this.swimlaneId = Blaze.getData(swimlane[0])._id;
  362. else if (Utils.boardView() === 'board-view-lists' || !Utils.boardView)
  363. this.swimlaneId = Swimlanes.findOne({ boardId: this.boardId })._id;
  364. },
  365. boards() {
  366. const boards = Boards.find(
  367. {
  368. archived: false,
  369. 'members.userId': Meteor.userId(),
  370. _id: { $ne: Session.get('currentBoard') },
  371. type: 'board',
  372. },
  373. {
  374. sort: { sort: 1 /* boards default sorting */ },
  375. },
  376. );
  377. return boards;
  378. },
  379. swimlanes() {
  380. if (!this.selectedBoardId.get()) {
  381. return [];
  382. }
  383. const swimlanes = Swimlanes.find({ boardId: this.selectedBoardId.get() });
  384. if (swimlanes.count())
  385. this.selectedSwimlaneId.set(swimlanes.fetch()[0]._id);
  386. return swimlanes;
  387. },
  388. lists() {
  389. if (!this.selectedBoardId.get()) {
  390. return [];
  391. }
  392. const lists = Lists.find({ boardId: this.selectedBoardId.get() });
  393. if (lists.count()) this.selectedListId.set(lists.fetch()[0]._id);
  394. return lists;
  395. },
  396. cards() {
  397. if (!this.board) {
  398. return [];
  399. }
  400. const ownCardsIds = this.board.cards().map(card => {
  401. return card.linkedId || card._id;
  402. });
  403. return Cards.find({
  404. boardId: this.selectedBoardId.get(),
  405. swimlaneId: this.selectedSwimlaneId.get(),
  406. listId: this.selectedListId.get(),
  407. archived: false,
  408. linkedId: { $nin: ownCardsIds },
  409. _id: { $nin: ownCardsIds },
  410. type: { $nin: ['template-card'] },
  411. });
  412. },
  413. events() {
  414. return [
  415. {
  416. 'change .js-select-boards'(evt) {
  417. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  418. this.selectedBoardId.set($(evt.currentTarget).val());
  419. },
  420. 'change .js-select-swimlanes'(evt) {
  421. this.selectedSwimlaneId.set($(evt.currentTarget).val());
  422. },
  423. 'change .js-select-lists'(evt) {
  424. this.selectedListId.set($(evt.currentTarget).val());
  425. },
  426. 'click .js-done'(evt) {
  427. // LINK CARD
  428. evt.stopPropagation();
  429. evt.preventDefault();
  430. const linkedId = $('.js-select-cards option:selected').val();
  431. if (!linkedId) {
  432. Popup.close();
  433. return;
  434. }
  435. const _id = Cards.insert({
  436. title: $('.js-select-cards option:selected').text(), //dummy
  437. listId: this.listId,
  438. swimlaneId: this.swimlaneId,
  439. boardId: this.boardId,
  440. sort: Lists.findOne(this.listId)
  441. .cards()
  442. .count(),
  443. type: 'cardType-linkedCard',
  444. linkedId,
  445. });
  446. Filter.addException(_id);
  447. Popup.close();
  448. },
  449. 'click .js-link-board'(evt) {
  450. //LINK BOARD
  451. evt.stopPropagation();
  452. evt.preventDefault();
  453. const impBoardId = $('.js-select-boards option:selected').val();
  454. if (
  455. !impBoardId ||
  456. Cards.findOne({ linkedId: impBoardId, archived: false })
  457. ) {
  458. Popup.close();
  459. return;
  460. }
  461. const _id = Cards.insert({
  462. title: $('.js-select-boards option:selected').text(), //dummy
  463. listId: this.listId,
  464. swimlaneId: this.swimlaneId,
  465. boardId: this.boardId,
  466. sort: Lists.findOne(this.listId)
  467. .cards()
  468. .count(),
  469. type: 'cardType-linkedBoard',
  470. linkedId: impBoardId,
  471. });
  472. Filter.addException(_id);
  473. Popup.close();
  474. },
  475. },
  476. ];
  477. },
  478. }).register('linkCardPopup');
  479. BlazeComponent.extendComponent({
  480. mixins() {
  481. return [];
  482. },
  483. onCreated() {
  484. this.isCardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  485. 'js-card-template',
  486. );
  487. this.isListTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  488. 'js-list-template',
  489. );
  490. this.isSwimlaneTemplateSearch = $(
  491. Popup._getTopStack().openerElement,
  492. ).hasClass('js-open-add-swimlane-menu');
  493. this.isBoardTemplateSearch = $(Popup._getTopStack().openerElement).hasClass(
  494. 'js-add-board',
  495. );
  496. this.isTemplateSearch =
  497. this.isCardTemplateSearch ||
  498. this.isListTemplateSearch ||
  499. this.isSwimlaneTemplateSearch ||
  500. this.isBoardTemplateSearch;
  501. let board = {};
  502. if (this.isTemplateSearch) {
  503. board = Boards.findOne((Meteor.user().profile || {}).templatesBoardId);
  504. } else {
  505. // Prefetch first non-current board id
  506. board = Boards.findOne({
  507. archived: false,
  508. 'members.userId': Meteor.userId(),
  509. _id: {
  510. $nin: [
  511. Session.get('currentBoard'),
  512. (Meteor.user().profile || {}).templatesBoardId,
  513. ],
  514. },
  515. });
  516. }
  517. if (!board) {
  518. Popup.close();
  519. return;
  520. }
  521. const boardId = board._id;
  522. // Subscribe to this board
  523. subManager.subscribe('board', boardId, false);
  524. this.selectedBoardId = new ReactiveVar(boardId);
  525. if (!this.isBoardTemplateSearch) {
  526. this.boardId = Session.get('currentBoard');
  527. // In order to get current board info
  528. subManager.subscribe('board', this.boardId, false);
  529. this.swimlaneId = '';
  530. // Swimlane where to insert card
  531. const swimlane = $(Popup._getTopStack().openerElement).parents(
  532. '.js-swimlane',
  533. );
  534. if (Utils.boardView() === 'board-view-swimlanes')
  535. this.swimlaneId = Blaze.getData(swimlane[0])._id;
  536. else this.swimlaneId = Swimlanes.findOne({ boardId: this.boardId })._id;
  537. // List where to insert card
  538. const list = $(Popup._getTopStack().openerElement).closest('.js-list');
  539. this.listId = Blaze.getData(list[0])._id;
  540. }
  541. this.term = new ReactiveVar('');
  542. },
  543. boards() {
  544. const boards = Boards.find(
  545. {
  546. archived: false,
  547. 'members.userId': Meteor.userId(),
  548. _id: { $ne: Session.get('currentBoard') },
  549. type: 'board',
  550. },
  551. {
  552. sort: { sort: 1 /* boards default sorting */ },
  553. },
  554. );
  555. return boards;
  556. },
  557. results() {
  558. if (!this.selectedBoardId) {
  559. return [];
  560. }
  561. const board = Boards.findOne(this.selectedBoardId.get());
  562. if (!this.isTemplateSearch || this.isCardTemplateSearch) {
  563. return board.searchCards(this.term.get(), false);
  564. } else if (this.isListTemplateSearch) {
  565. return board.searchLists(this.term.get());
  566. } else if (this.isSwimlaneTemplateSearch) {
  567. return board.searchSwimlanes(this.term.get());
  568. } else if (this.isBoardTemplateSearch) {
  569. const boards = board.searchBoards(this.term.get());
  570. boards.forEach(board => {
  571. subManager.subscribe('board', board.linkedId, false);
  572. });
  573. return boards;
  574. } else {
  575. return [];
  576. }
  577. },
  578. events() {
  579. return [
  580. {
  581. 'change .js-select-boards'(evt) {
  582. subManager.subscribe('board', $(evt.currentTarget).val(), false);
  583. this.selectedBoardId.set($(evt.currentTarget).val());
  584. },
  585. 'submit .js-search-term-form'(evt) {
  586. evt.preventDefault();
  587. this.term.set(evt.target.searchTerm.value);
  588. },
  589. 'click .js-minicard'(evt) {
  590. // 0. Common
  591. const title = $('.js-element-title')
  592. .val()
  593. .trim();
  594. if (!title) return;
  595. const element = Blaze.getData(evt.currentTarget);
  596. element.title = title;
  597. let _id = '';
  598. if (!this.isTemplateSearch || this.isCardTemplateSearch) {
  599. // Card insertion
  600. // 1. Common
  601. element.sort = Lists.findOne(this.listId)
  602. .cards()
  603. .count();
  604. // 1.A From template
  605. if (this.isTemplateSearch) {
  606. element.type = 'cardType-card';
  607. element.linkedId = '';
  608. _id = element.copy(this.boardId, this.swimlaneId, this.listId);
  609. // 1.B Linked card
  610. } else {
  611. _id = element.link(this.boardId, this.swimlaneId, this.listId);
  612. }
  613. Filter.addException(_id);
  614. // List insertion
  615. } else if (this.isListTemplateSearch) {
  616. element.sort = Swimlanes.findOne(this.swimlaneId)
  617. .lists()
  618. .count();
  619. element.type = 'list';
  620. _id = element.copy(this.boardId, this.swimlaneId);
  621. } else if (this.isSwimlaneTemplateSearch) {
  622. element.sort = Boards.findOne(this.boardId)
  623. .swimlanes()
  624. .count();
  625. element.type = 'swimlane';
  626. _id = element.copy(this.boardId);
  627. } else if (this.isBoardTemplateSearch) {
  628. Meteor.call(
  629. 'copyBoard',
  630. element.linkedId,
  631. {
  632. sort: Boards.find({ archived: false }).count(),
  633. type: 'board',
  634. title: element.title,
  635. },
  636. (err, data) => {
  637. _id = data;
  638. },
  639. );
  640. }
  641. Popup.close();
  642. },
  643. },
  644. ];
  645. },
  646. }).register('searchElementPopup');
  647. BlazeComponent.extendComponent({
  648. onCreated() {
  649. this.cardlimit = this.parentComponent().cardlimit;
  650. this.listId = this.parentComponent().data()._id;
  651. this.swimlaneId = '';
  652. const isSandstorm =
  653. Meteor.settings &&
  654. Meteor.settings.public &&
  655. Meteor.settings.public.sandstorm;
  656. if (isSandstorm) {
  657. const user = Meteor.user();
  658. if (user) {
  659. if (Utils.boardView() === 'board-view-swimlanes') {
  660. this.swimlaneId = this.parentComponent()
  661. .parentComponent()
  662. .parentComponent()
  663. .data()._id;
  664. }
  665. }
  666. } else if (Utils.boardView() === 'board-view-swimlanes') {
  667. this.swimlaneId = this.parentComponent()
  668. .parentComponent()
  669. .parentComponent()
  670. .data()._id;
  671. }
  672. },
  673. onRendered() {
  674. this.spinner = this.find('.sk-spinner-list');
  675. this.container = this.$(this.spinner).parents('.list-body')[0];
  676. $(this.container).on(
  677. `scroll.spinner_${this.swimlaneId}_${this.listId}`,
  678. () => this.updateList(),
  679. );
  680. $(window).on(`resize.spinner_${this.swimlaneId}_${this.listId}`, () =>
  681. this.updateList(),
  682. );
  683. this.updateList();
  684. },
  685. onDestroyed() {
  686. $(this.container).off(`scroll.spinner_${this.swimlaneId}_${this.listId}`);
  687. $(window).off(`resize.spinner_${this.swimlaneId}_${this.listId}`);
  688. },
  689. updateList() {
  690. // Use fallback when requestIdleCallback is not available on iOS and Safari
  691. // https://www.afasterweb.com/2017/11/20/utilizing-idle-moments/
  692. checkIdleTime =
  693. window.requestIdleCallback ||
  694. function(handler) {
  695. const startTime = Date.now();
  696. return setTimeout(function() {
  697. handler({
  698. didTimeout: false,
  699. timeRemaining() {
  700. return Math.max(0, 50.0 - (Date.now() - startTime));
  701. },
  702. });
  703. }, 1);
  704. };
  705. if (this.spinnerInView()) {
  706. this.cardlimit.set(this.cardlimit.get() + InfiniteScrollIter);
  707. checkIdleTime(() => this.updateList());
  708. }
  709. },
  710. spinnerInView() {
  711. const parentViewHeight = this.container.clientHeight;
  712. const bottomViewPosition = this.container.scrollTop + parentViewHeight;
  713. const threshold = this.spinner.offsetTop;
  714. // spinner deleted
  715. if (!this.spinner.offsetTop) {
  716. return false;
  717. }
  718. return bottomViewPosition > threshold;
  719. },
  720. }).register('spinnerList');