boardHeader.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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. const boardId = Session.get('currentBoard');
  69. if (boardId) {
  70. Meteor.call('toggleBoardStar', boardId);
  71. }
  72. },
  73. 'click .js-open-board-menu': Popup.open('boardMenu'),
  74. 'click .js-change-visibility': Popup.open('boardChangeVisibility'),
  75. 'click .js-watch-board': Popup.open('boardChangeWatch'),
  76. 'click .js-open-archived-board'() {
  77. Modal.open('archivedBoards');
  78. },
  79. 'click .js-toggle-board-view': Popup.open('boardChangeView'),
  80. 'click .js-toggle-sidebar'() {
  81. if (process.env.DEBUG === 'true') {
  82. console.log('Hamburger menu clicked');
  83. }
  84. // Use the same approach as keyboard shortcuts
  85. if (typeof Sidebar !== 'undefined' && Sidebar && typeof Sidebar.toggle === 'function') {
  86. if (process.env.DEBUG === 'true') {
  87. console.log('Using Sidebar.toggle()');
  88. }
  89. Sidebar.toggle();
  90. } else {
  91. if (process.env.DEBUG === 'true') {
  92. console.warn('Sidebar not available, trying alternative approach');
  93. }
  94. // Try to trigger the sidebar through the global Blaze helper
  95. if (typeof Blaze !== 'undefined' && Blaze._globalHelpers && Blaze._globalHelpers.Sidebar) {
  96. const sidebar = Blaze._globalHelpers.Sidebar();
  97. if (sidebar && typeof sidebar.toggle === 'function') {
  98. if (process.env.DEBUG === 'true') {
  99. console.log('Using Blaze helper Sidebar.toggle()');
  100. }
  101. sidebar.toggle();
  102. }
  103. }
  104. }
  105. },
  106. 'click .js-open-filter-view'() {
  107. if (Sidebar) {
  108. Sidebar.setView('filter');
  109. } else {
  110. console.warn('Sidebar not available for setView');
  111. }
  112. },
  113. 'click .js-sort-cards': Popup.open('cardsSort'),
  114. /*
  115. 'click .js-open-sort-view'(evt) {
  116. const target = evt.target;
  117. if (target.tagName === 'I') {
  118. // click on the text, popup choices
  119. this.changeDirection();
  120. } else {
  121. // change the sort order
  122. Popup.open('listsort')(evt);
  123. }
  124. },
  125. */
  126. 'click .js-filter-reset'(event) {
  127. event.stopPropagation();
  128. if (Sidebar) {
  129. Sidebar.setView();
  130. } else {
  131. console.warn('Sidebar not available for setView');
  132. }
  133. Filter.reset();
  134. },
  135. 'click .js-sort-reset'() {
  136. Session.set('sortBy', '');
  137. },
  138. 'click .js-open-search-view'() {
  139. if (Sidebar) {
  140. Sidebar.setView('search');
  141. } else {
  142. console.warn('Sidebar not available for setView');
  143. }
  144. },
  145. 'click .js-multiselection-activate'() {
  146. const currentCard = Utils.getCurrentCardId();
  147. MultiSelection.activate();
  148. if (currentCard) {
  149. MultiSelection.add(currentCard);
  150. }
  151. },
  152. 'click .js-multiselection-reset'(event) {
  153. event.stopPropagation();
  154. MultiSelection.disable();
  155. },
  156. 'click .js-log-in'() {
  157. FlowRouter.go('atSignIn');
  158. },
  159. },
  160. ];
  161. },
  162. }).register('boardHeaderBar');
  163. Template.boardHeaderBar.helpers({
  164. boardView() {
  165. return Utils.boardView();
  166. },
  167. isSortActive() {
  168. return Session.get('sortBy') ? true : false;
  169. },
  170. sortCardsIcon() {
  171. const sortBy = Session.get('sortBy');
  172. if (!sortBy) {
  173. return '🃏'; // Card icon when nothing is selected
  174. }
  175. // Determine which sort option is active based on sortBy object
  176. if (sortBy.dueAt) {
  177. return '📅'; // Due date icon
  178. } else if (sortBy.title) {
  179. return '🔤'; // Alphabet icon
  180. } else if (sortBy.createdAt) {
  181. return sortBy.createdAt === 1 ? '⬆️' : '⬇️'; // Up/down arrow based on direction
  182. }
  183. return '🃏'; // Default card icon
  184. },
  185. });
  186. Template.boardChangeViewPopup.events({
  187. 'click .js-open-lists-view'() {
  188. Utils.setBoardView('board-view-lists');
  189. Popup.back();
  190. },
  191. 'click .js-open-swimlanes-view'() {
  192. Utils.setBoardView('board-view-swimlanes');
  193. Popup.back();
  194. },
  195. 'click .js-open-cal-view'() {
  196. Utils.setBoardView('board-view-cal');
  197. Popup.back();
  198. },
  199. 'click .js-open-gantt-view'() {
  200. Utils.setBoardView('board-view-gantt');
  201. Popup.back();
  202. },
  203. });
  204. const CreateBoard = BlazeComponent.extendComponent({
  205. template() {
  206. return 'createBoard';
  207. },
  208. onCreated() {
  209. this.visibilityMenuIsOpen = new ReactiveVar(false);
  210. this.visibility = new ReactiveVar('private');
  211. this.boardId = new ReactiveVar('');
  212. Meteor.subscribe('tableVisibilityModeSettings');
  213. },
  214. notAllowPrivateVisibilityOnly(){
  215. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  216. },
  217. visibilityCheck() {
  218. return this.currentData() === this.visibility.get();
  219. },
  220. setVisibility(visibility) {
  221. this.visibility.set(visibility);
  222. this.visibilityMenuIsOpen.set(false);
  223. },
  224. toggleVisibilityMenu() {
  225. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  226. },
  227. toggleAddTemplateContainer() {
  228. $('#add-template-container').toggleClass('is-checked');
  229. },
  230. onSubmit(event) {
  231. event.preventDefault();
  232. const title = this.find('.js-new-board-title').value;
  233. const addTemplateContainer = $('#add-template-container.is-checked').length > 0;
  234. if (addTemplateContainer) {
  235. //const templateContainerId = Meteor.call('setCreateTemplateContainer');
  236. //Utils.goBoardId(templateContainerId);
  237. //alert('niinku template ' + Meteor.call('setCreateTemplateContainer'));
  238. this.boardId.set(
  239. Boards.insert({
  240. // title: TAPi18n.__('templates'),
  241. title: title,
  242. permission: 'private',
  243. type: 'template-container',
  244. migrationVersion: 1, // Latest version - no migration needed
  245. }),
  246. );
  247. // Insert the card templates swimlane
  248. Swimlanes.insert({
  249. // title: TAPi18n.__('card-templates-swimlane'),
  250. title: 'Card Templates',
  251. boardId: this.boardId.get(),
  252. sort: 1,
  253. type: 'template-container',
  254. }),
  255. // Insert the list templates swimlane
  256. Swimlanes.insert(
  257. {
  258. // title: TAPi18n.__('list-templates-swimlane'),
  259. title: 'List Templates',
  260. boardId: this.boardId.get(),
  261. sort: 2,
  262. type: 'template-container',
  263. },
  264. );
  265. // Insert the board templates swimlane
  266. Swimlanes.insert(
  267. {
  268. //title: TAPi18n.__('board-templates-swimlane'),
  269. title: 'Board Templates',
  270. boardId: this.boardId.get(),
  271. sort: 3,
  272. type: 'template-container',
  273. },
  274. );
  275. // Assign to space if one was selected
  276. const spaceId = Session.get('createBoardInWorkspace');
  277. if (spaceId) {
  278. Meteor.call('assignBoardToWorkspace', this.boardId.get(), spaceId, (err) => {
  279. if (err) console.error('Error assigning board to space:', err);
  280. });
  281. Session.set('createBoardInWorkspace', null); // Clear after use
  282. }
  283. Utils.goBoardId(this.boardId.get());
  284. } else {
  285. const visibility = this.visibility.get();
  286. this.boardId.set(
  287. Boards.insert({
  288. title,
  289. permission: visibility,
  290. migrationVersion: 1, // Latest version - no migration needed
  291. }),
  292. );
  293. Swimlanes.insert({
  294. title: 'Default',
  295. boardId: this.boardId.get(),
  296. });
  297. // Assign to space if one was selected
  298. const spaceId = Session.get('createBoardInWorkspace');
  299. if (spaceId) {
  300. Meteor.call('assignBoardToWorkspace', this.boardId.get(), spaceId, (err) => {
  301. if (err) console.error('Error assigning board to space:', err);
  302. });
  303. Session.set('createBoardInWorkspace', null); // Clear after use
  304. }
  305. Utils.goBoardId(this.boardId.get());
  306. }
  307. },
  308. events() {
  309. return [
  310. {
  311. 'click .js-select-visibility'() {
  312. this.setVisibility(this.currentData());
  313. },
  314. 'click .js-change-visibility': this.toggleVisibilityMenu,
  315. 'click .js-import': Popup.open('boardImportBoard'),
  316. submit: this.onSubmit,
  317. 'click .js-import-board': Popup.open('chooseBoardSource'),
  318. 'click .js-board-template': Popup.open('searchElement'),
  319. 'click .js-toggle-add-template-container': this.toggleAddTemplateContainer,
  320. },
  321. ];
  322. },
  323. }).register('createBoardPopup');
  324. (class CreateTemplateContainerPopup extends CreateBoard {
  325. onRendered() {
  326. // Always pre-check the template container checkbox for this popup
  327. $('#add-template-container').addClass('is-checked');
  328. }
  329. }).register('createTemplateContainerPopup');
  330. (class HeaderBarCreateBoard extends CreateBoard {
  331. onSubmit(event) {
  332. super.onSubmit(event);
  333. // Immediately star boards crated with the headerbar popup.
  334. ReactiveCache.getCurrentUser().toggleBoardStar(this.boardId.get());
  335. }
  336. }.register('headerBarCreateBoardPopup'));
  337. BlazeComponent.extendComponent({
  338. notAllowPrivateVisibilityOnly(){
  339. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  340. },
  341. visibilityCheck() {
  342. const currentBoard = Utils.getCurrentBoard();
  343. return this.currentData() === currentBoard.permission;
  344. },
  345. selectBoardVisibility() {
  346. const currentBoard = Utils.getCurrentBoard();
  347. const visibility = this.currentData();
  348. currentBoard.setVisibility(visibility);
  349. Popup.back();
  350. },
  351. events() {
  352. return [
  353. {
  354. 'click .js-select-visibility': this.selectBoardVisibility,
  355. },
  356. ];
  357. },
  358. }).register('boardChangeVisibilityPopup');
  359. BlazeComponent.extendComponent({
  360. watchLevel() {
  361. const currentBoard = Utils.getCurrentBoard();
  362. return currentBoard.getWatchLevel(Meteor.userId());
  363. },
  364. watchCheck() {
  365. return this.currentData() === this.watchLevel();
  366. },
  367. events() {
  368. return [
  369. {
  370. 'click .js-select-watch'() {
  371. const level = this.currentData();
  372. Meteor.call(
  373. 'watch',
  374. 'board',
  375. Session.get('currentBoard'),
  376. level,
  377. (err, ret) => {
  378. if (!err && ret) Popup.back();
  379. },
  380. );
  381. },
  382. },
  383. ];
  384. },
  385. }).register('boardChangeWatchPopup');
  386. /*
  387. BlazeComponent.extendComponent({
  388. onCreated() {
  389. //this.sortBy = new ReactiveVar();
  390. ////this.sortDirection = new ReactiveVar();
  391. //this.setSortBy();
  392. this.downClass = DOWNCLS;
  393. this.upClass = UPCLS;
  394. },
  395. allowedSortValues() {
  396. const types = [];
  397. const pushed = {};
  398. ReactiveCache.getCurrentUser()
  399. .getListSortTypes()
  400. .forEach(type => {
  401. const key = type.replace(/^-/, '');
  402. if (pushed[key] === undefined) {
  403. types.push({
  404. name: key,
  405. label: `list-label-${key}`,
  406. shortLabel: `list-label-short-${key}`,
  407. });
  408. pushed[key] = 1;
  409. }
  410. });
  411. return types;
  412. },
  413. Direction() {
  414. return ReactiveCache.getCurrentUser().getListSortByDirection() === -1
  415. ? this.downClass
  416. : this.upClass;
  417. },
  418. sortby() {
  419. return ReactiveCache.getCurrentUser().getListSortBy();
  420. },
  421. setSortBy(type = null) {
  422. const user = ReactiveCache.getCurrentUser();
  423. if (type === null) {
  424. type = user._getListSortBy();
  425. } else {
  426. let value = '';
  427. if (type.map) {
  428. // is an array
  429. value = (type[1] === -1 ? '-' : '') + type[0];
  430. }
  431. Meteor.call('setListSortBy', value);
  432. }
  433. //this.sortBy.set(type[0]);
  434. //this.sortDirection.set(type[1]);
  435. },
  436. events() {
  437. return [
  438. {
  439. 'click .js-sort-by'(evt) {
  440. evt.preventDefault();
  441. const target = evt.target;
  442. const sortby = target.getAttribute('name');
  443. const down = !!target.querySelector(`.${this.upClass}`);
  444. const direction = down ? -1 : 1;
  445. this.setSortBy([sortby, direction]);
  446. if (Utils.isMiniScreen) {
  447. Popup.back();
  448. }
  449. },
  450. },
  451. ];
  452. },
  453. }).register('listsortPopup');
  454. */
  455. BlazeComponent.extendComponent({
  456. events() {
  457. return [
  458. {
  459. 'click .js-sort-due'() {
  460. const sortBy = {
  461. dueAt: 1,
  462. };
  463. Session.set('sortBy', sortBy);
  464. sortCardsBy.set(TAPi18n.__('due-date'));
  465. Popup.back();
  466. },
  467. 'click .js-sort-title'() {
  468. const sortBy = {
  469. title: 1,
  470. };
  471. Session.set('sortBy', sortBy);
  472. sortCardsBy.set(TAPi18n.__('title'));
  473. Popup.back();
  474. },
  475. 'click .js-sort-created-asc'() {
  476. const sortBy = {
  477. createdAt: 1,
  478. };
  479. Session.set('sortBy', sortBy);
  480. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  481. Popup.back();
  482. },
  483. 'click .js-sort-created-desc'() {
  484. const sortBy = {
  485. createdAt: -1,
  486. };
  487. Session.set('sortBy', sortBy);
  488. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  489. Popup.back();
  490. },
  491. },
  492. ];
  493. },
  494. }).register('cardsSortPopup');