boardHeader.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. import { ReactiveCache } from '/imports/reactiveCache';
  2. import { TAPi18n } from '/imports/i18n';
  3. import dragscroll from '@wekanteam/dragscroll';
  4. /*
  5. const DOWNCLS = 'fa-sort-down';
  6. const UPCLS = 'fa-sort-up';
  7. */
  8. const sortCardsBy = new ReactiveVar('');
  9. Template.boardChangeTitlePopup.events({
  10. submit(event, templateInstance) {
  11. const newTitle = templateInstance
  12. .$('.js-board-name')
  13. .val()
  14. .trim();
  15. const newDesc = templateInstance
  16. .$('.js-board-desc')
  17. .val()
  18. .trim();
  19. if (newTitle) {
  20. this.rename(newTitle);
  21. this.setDescription(newDesc);
  22. Popup.back();
  23. }
  24. event.preventDefault();
  25. },
  26. });
  27. BlazeComponent.extendComponent({
  28. watchLevel() {
  29. const currentBoard = Utils.getCurrentBoard();
  30. return currentBoard && currentBoard.getWatchLevel(Meteor.userId());
  31. },
  32. isStarred() {
  33. const boardId = Session.get('currentBoard');
  34. const user = ReactiveCache.getCurrentUser();
  35. return user && user.hasStarred(boardId);
  36. },
  37. // Only show the star counter if the number of star is greater than 2
  38. showStarCounter() {
  39. const currentBoard = Utils.getCurrentBoard();
  40. return currentBoard && currentBoard.stars >= 2;
  41. },
  42. /*
  43. showSort() {
  44. return ReactiveCache.getCurrentUser().hasSortBy();
  45. },
  46. directionClass() {
  47. return this.currentDirection() === -1 ? DOWNCLS : UPCLS;
  48. },
  49. changeDirection() {
  50. const direction = 0 - this.currentDirection() === -1 ? '-' : '';
  51. Meteor.call('setListSortBy', direction + this.currentListSortBy());
  52. },
  53. currentDirection() {
  54. return ReactiveCache.getCurrentUser().getListSortByDirection();
  55. },
  56. currentListSortBy() {
  57. return ReactiveCache.getCurrentUser().getListSortBy();
  58. },
  59. listSortShortDesc() {
  60. return `list-label-short-${this.currentListSortBy()}`;
  61. },
  62. */
  63. events() {
  64. return [
  65. {
  66. 'click .js-edit-board-title': Popup.open('boardChangeTitle'),
  67. 'click .js-star-board'() {
  68. ReactiveCache.getCurrentUser().toggleBoardStar(Session.get('currentBoard'));
  69. },
  70. 'click .js-open-board-menu': Popup.open('boardMenu'),
  71. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  72. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  73. 'click .js-open-archived-board'() {
  74. Modal.open('archivedBoards');
  75. },
  76. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  77. // Sidebar toggle is handled by the sidebar component itself
  78. // 'click .js-toggle-sidebar'() {
  79. // if (Sidebar) {
  80. // Sidebar.toggle();
  81. // } else {
  82. // console.warn('Sidebar not available for toggle');
  83. // }
  84. // },
  85. 'click .js-open-filter-view'() {
  86. if (Sidebar) {
  87. Sidebar.setView('filter');
  88. } else {
  89. console.warn('Sidebar not available for setView');
  90. }
  91. },
  92. 'click .js-sort-cards': Popup.open('cardsSort'),
  93. /*
  94. 'click .js-open-sort-view'(evt) {
  95. const target = evt.target;
  96. if (target.tagName === 'I') {
  97. // click on the text, popup choices
  98. this.changeDirection();
  99. } else {
  100. // change the sort order
  101. Popup.open('listsort')(evt);
  102. }
  103. },
  104. */
  105. 'click .js-filter-reset'(event) {
  106. event.stopPropagation();
  107. if (Sidebar) {
  108. Sidebar.setView();
  109. } else {
  110. console.warn('Sidebar not available for setView');
  111. }
  112. Filter.reset();
  113. },
  114. 'click .js-sort-reset'() {
  115. Session.set('sortBy', '');
  116. },
  117. 'click .js-open-search-view'() {
  118. if (Sidebar) {
  119. Sidebar.setView('search');
  120. } else {
  121. console.warn('Sidebar not available for setView');
  122. }
  123. },
  124. 'click .js-multiselection-activate'() {
  125. const currentCard = Utils.getCurrentCardId();
  126. MultiSelection.activate();
  127. if (currentCard) {
  128. MultiSelection.add(currentCard);
  129. }
  130. },
  131. 'click .js-multiselection-reset'(event) {
  132. event.stopPropagation();
  133. MultiSelection.disable();
  134. },
  135. 'click .js-log-in'() {
  136. FlowRouter.go('atSignIn');
  137. },
  138. },
  139. ];
  140. },
  141. }).register('boardHeaderBar');
  142. Template.boardHeaderBar.helpers({
  143. boardView() {
  144. return Utils.boardView();
  145. },
  146. isSortActive() {
  147. return Session.get('sortBy') ? true : false;
  148. },
  149. });
  150. Template.boardChangeViewPopup.events({
  151. 'click .js-open-lists-view'() {
  152. Utils.setBoardView('board-view-lists');
  153. Popup.back();
  154. },
  155. 'click .js-open-swimlanes-view'() {
  156. Utils.setBoardView('board-view-swimlanes');
  157. Popup.back();
  158. },
  159. 'click .js-open-cal-view'() {
  160. Utils.setBoardView('board-view-cal');
  161. Popup.back();
  162. },
  163. });
  164. const CreateBoard = BlazeComponent.extendComponent({
  165. template() {
  166. return 'createBoard';
  167. },
  168. onCreated() {
  169. this.visibilityMenuIsOpen = new ReactiveVar(false);
  170. this.visibility = new ReactiveVar('private');
  171. this.boardId = new ReactiveVar('');
  172. Meteor.subscribe('tableVisibilityModeSettings');
  173. },
  174. notAllowPrivateVisibilityOnly(){
  175. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  176. },
  177. visibilityCheck() {
  178. return this.currentData() === this.visibility.get();
  179. },
  180. setVisibility(visibility) {
  181. this.visibility.set(visibility);
  182. this.visibilityMenuIsOpen.set(false);
  183. },
  184. toggleVisibilityMenu() {
  185. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  186. },
  187. toggleAddTemplateContainer() {
  188. $('#add-template-container').toggleClass('is-checked');
  189. },
  190. onSubmit(event) {
  191. event.preventDefault();
  192. const title = this.find('.js-new-board-title').value;
  193. const addTemplateContainer = $('#add-template-container.is-checked').length > 0;
  194. if (addTemplateContainer) {
  195. //const templateContainerId = Meteor.call('setCreateTemplateContainer');
  196. //Utils.goBoardId(templateContainerId);
  197. //alert('niinku template ' + Meteor.call('setCreateTemplateContainer'));
  198. this.boardId.set(
  199. Boards.insert({
  200. // title: TAPi18n.__('templates'),
  201. title: title,
  202. permission: 'private',
  203. type: 'template-container',
  204. migrationVersion: 1, // Latest version - no migration needed
  205. }),
  206. );
  207. // Insert the card templates swimlane
  208. Swimlanes.insert({
  209. // title: TAPi18n.__('card-templates-swimlane'),
  210. title: 'Card Templates',
  211. boardId: this.boardId.get(),
  212. sort: 1,
  213. type: 'template-container',
  214. }),
  215. // Insert the list templates swimlane
  216. Swimlanes.insert(
  217. {
  218. // title: TAPi18n.__('list-templates-swimlane'),
  219. title: 'List Templates',
  220. boardId: this.boardId.get(),
  221. sort: 2,
  222. type: 'template-container',
  223. },
  224. );
  225. // Insert the board templates swimlane
  226. Swimlanes.insert(
  227. {
  228. //title: TAPi18n.__('board-templates-swimlane'),
  229. title: 'Board Templates',
  230. boardId: this.boardId.get(),
  231. sort: 3,
  232. type: 'template-container',
  233. },
  234. );
  235. Utils.goBoardId(this.boardId.get());
  236. } else {
  237. const visibility = this.visibility.get();
  238. this.boardId.set(
  239. Boards.insert({
  240. title,
  241. permission: visibility,
  242. migrationVersion: 1, // Latest version - no migration needed
  243. }),
  244. );
  245. Swimlanes.insert({
  246. title: 'Default',
  247. boardId: this.boardId.get(),
  248. });
  249. Utils.goBoardId(this.boardId.get());
  250. }
  251. },
  252. events() {
  253. return [
  254. {
  255. 'click .js-select-visibility'() {
  256. this.setVisibility(this.currentData());
  257. },
  258. 'click .js-change-visibility': this.toggleVisibilityMenu,
  259. 'click .js-import': Popup.open('boardImportBoard'),
  260. submit: this.onSubmit,
  261. 'click .js-import-board': Popup.open('chooseBoardSource'),
  262. 'click .js-board-template': Popup.open('searchElement'),
  263. 'click .js-toggle-add-template-container': this.toggleAddTemplateContainer,
  264. },
  265. ];
  266. },
  267. }).register('createBoardPopup');
  268. (class HeaderBarCreateBoard extends CreateBoard {
  269. onSubmit(event) {
  270. super.onSubmit(event);
  271. // Immediately star boards crated with the headerbar popup.
  272. ReactiveCache.getCurrentUser().toggleBoardStar(this.boardId.get());
  273. }
  274. }.register('headerBarCreateBoardPopup'));
  275. BlazeComponent.extendComponent({
  276. notAllowPrivateVisibilityOnly(){
  277. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  278. },
  279. visibilityCheck() {
  280. const currentBoard = Utils.getCurrentBoard();
  281. return this.currentData() === currentBoard.permission;
  282. },
  283. selectBoardVisibility() {
  284. const currentBoard = Utils.getCurrentBoard();
  285. const visibility = this.currentData();
  286. currentBoard.setVisibility(visibility);
  287. Popup.back();
  288. },
  289. events() {
  290. return [
  291. {
  292. 'click .js-select-visibility': this.selectBoardVisibility,
  293. },
  294. ];
  295. },
  296. }).register('boardChangeVisibilityPopup');
  297. BlazeComponent.extendComponent({
  298. watchLevel() {
  299. const currentBoard = Utils.getCurrentBoard();
  300. return currentBoard.getWatchLevel(Meteor.userId());
  301. },
  302. watchCheck() {
  303. return this.currentData() === this.watchLevel();
  304. },
  305. events() {
  306. return [
  307. {
  308. 'click .js-select-watch'() {
  309. const level = this.currentData();
  310. Meteor.call(
  311. 'watch',
  312. 'board',
  313. Session.get('currentBoard'),
  314. level,
  315. (err, ret) => {
  316. if (!err && ret) Popup.back();
  317. },
  318. );
  319. },
  320. },
  321. ];
  322. },
  323. }).register('boardChangeWatchPopup');
  324. /*
  325. BlazeComponent.extendComponent({
  326. onCreated() {
  327. //this.sortBy = new ReactiveVar();
  328. ////this.sortDirection = new ReactiveVar();
  329. //this.setSortBy();
  330. this.downClass = DOWNCLS;
  331. this.upClass = UPCLS;
  332. },
  333. allowedSortValues() {
  334. const types = [];
  335. const pushed = {};
  336. ReactiveCache.getCurrentUser()
  337. .getListSortTypes()
  338. .forEach(type => {
  339. const key = type.replace(/^-/, '');
  340. if (pushed[key] === undefined) {
  341. types.push({
  342. name: key,
  343. label: `list-label-${key}`,
  344. shortLabel: `list-label-short-${key}`,
  345. });
  346. pushed[key] = 1;
  347. }
  348. });
  349. return types;
  350. },
  351. Direction() {
  352. return ReactiveCache.getCurrentUser().getListSortByDirection() === -1
  353. ? this.downClass
  354. : this.upClass;
  355. },
  356. sortby() {
  357. return ReactiveCache.getCurrentUser().getListSortBy();
  358. },
  359. setSortBy(type = null) {
  360. const user = ReactiveCache.getCurrentUser();
  361. if (type === null) {
  362. type = user._getListSortBy();
  363. } else {
  364. let value = '';
  365. if (type.map) {
  366. // is an array
  367. value = (type[1] === -1 ? '-' : '') + type[0];
  368. }
  369. Meteor.call('setListSortBy', value);
  370. }
  371. //this.sortBy.set(type[0]);
  372. //this.sortDirection.set(type[1]);
  373. },
  374. events() {
  375. return [
  376. {
  377. 'click .js-sort-by'(evt) {
  378. evt.preventDefault();
  379. const target = evt.target;
  380. const sortby = target.getAttribute('name');
  381. const down = !!target.querySelector(`.${this.upClass}`);
  382. const direction = down ? -1 : 1;
  383. this.setSortBy([sortby, direction]);
  384. if (Utils.isMiniScreen) {
  385. Popup.back();
  386. }
  387. },
  388. },
  389. ];
  390. },
  391. }).register('listsortPopup');
  392. */
  393. BlazeComponent.extendComponent({
  394. events() {
  395. return [
  396. {
  397. 'click .js-sort-due'() {
  398. const sortBy = {
  399. dueAt: 1,
  400. };
  401. Session.set('sortBy', sortBy);
  402. sortCardsBy.set(TAPi18n.__('due-date'));
  403. Popup.back();
  404. },
  405. 'click .js-sort-title'() {
  406. const sortBy = {
  407. title: 1,
  408. };
  409. Session.set('sortBy', sortBy);
  410. sortCardsBy.set(TAPi18n.__('title'));
  411. Popup.back();
  412. },
  413. 'click .js-sort-created-asc'() {
  414. const sortBy = {
  415. createdAt: 1,
  416. };
  417. Session.set('sortBy', sortBy);
  418. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  419. Popup.back();
  420. },
  421. 'click .js-sort-created-desc'() {
  422. const sortBy = {
  423. createdAt: -1,
  424. };
  425. Session.set('sortBy', sortBy);
  426. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  427. Popup.back();
  428. },
  429. },
  430. ];
  431. },
  432. }).register('cardsSortPopup');