boardHeader.js 12 KB

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