boardHeader.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. });
  200. const CreateBoard = BlazeComponent.extendComponent({
  201. template() {
  202. return 'createBoard';
  203. },
  204. onCreated() {
  205. this.visibilityMenuIsOpen = new ReactiveVar(false);
  206. this.visibility = new ReactiveVar('private');
  207. this.boardId = new ReactiveVar('');
  208. Meteor.subscribe('tableVisibilityModeSettings');
  209. },
  210. notAllowPrivateVisibilityOnly(){
  211. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  212. },
  213. visibilityCheck() {
  214. return this.currentData() === this.visibility.get();
  215. },
  216. setVisibility(visibility) {
  217. this.visibility.set(visibility);
  218. this.visibilityMenuIsOpen.set(false);
  219. },
  220. toggleVisibilityMenu() {
  221. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  222. },
  223. toggleAddTemplateContainer() {
  224. $('#add-template-container').toggleClass('is-checked');
  225. },
  226. onSubmit(event) {
  227. event.preventDefault();
  228. const title = this.find('.js-new-board-title').value;
  229. const addTemplateContainer = $('#add-template-container.is-checked').length > 0;
  230. if (addTemplateContainer) {
  231. //const templateContainerId = Meteor.call('setCreateTemplateContainer');
  232. //Utils.goBoardId(templateContainerId);
  233. //alert('niinku template ' + Meteor.call('setCreateTemplateContainer'));
  234. this.boardId.set(
  235. Boards.insert({
  236. // title: TAPi18n.__('templates'),
  237. title: title,
  238. permission: 'private',
  239. type: 'template-container',
  240. migrationVersion: 1, // Latest version - no migration needed
  241. }),
  242. );
  243. // Insert the card templates swimlane
  244. Swimlanes.insert({
  245. // title: TAPi18n.__('card-templates-swimlane'),
  246. title: 'Card Templates',
  247. boardId: this.boardId.get(),
  248. sort: 1,
  249. type: 'template-container',
  250. }),
  251. // Insert the list templates swimlane
  252. Swimlanes.insert(
  253. {
  254. // title: TAPi18n.__('list-templates-swimlane'),
  255. title: 'List Templates',
  256. boardId: this.boardId.get(),
  257. sort: 2,
  258. type: 'template-container',
  259. },
  260. );
  261. // Insert the board templates swimlane
  262. Swimlanes.insert(
  263. {
  264. //title: TAPi18n.__('board-templates-swimlane'),
  265. title: 'Board Templates',
  266. boardId: this.boardId.get(),
  267. sort: 3,
  268. type: 'template-container',
  269. },
  270. );
  271. // Assign to space if one was selected
  272. const spaceId = Session.get('createBoardInWorkspace');
  273. if (spaceId) {
  274. Meteor.call('assignBoardToWorkspace', this.boardId.get(), spaceId, (err) => {
  275. if (err) console.error('Error assigning board to space:', err);
  276. });
  277. Session.set('createBoardInWorkspace', null); // Clear after use
  278. }
  279. Utils.goBoardId(this.boardId.get());
  280. } else {
  281. const visibility = this.visibility.get();
  282. this.boardId.set(
  283. Boards.insert({
  284. title,
  285. permission: visibility,
  286. migrationVersion: 1, // Latest version - no migration needed
  287. }),
  288. );
  289. Swimlanes.insert({
  290. title: 'Default',
  291. boardId: this.boardId.get(),
  292. });
  293. // Assign to space if one was selected
  294. const spaceId = Session.get('createBoardInWorkspace');
  295. if (spaceId) {
  296. Meteor.call('assignBoardToWorkspace', this.boardId.get(), spaceId, (err) => {
  297. if (err) console.error('Error assigning board to space:', err);
  298. });
  299. Session.set('createBoardInWorkspace', null); // Clear after use
  300. }
  301. Utils.goBoardId(this.boardId.get());
  302. }
  303. },
  304. events() {
  305. return [
  306. {
  307. 'click .js-select-visibility'() {
  308. this.setVisibility(this.currentData());
  309. },
  310. 'click .js-change-visibility': this.toggleVisibilityMenu,
  311. 'click .js-import': Popup.open('boardImportBoard'),
  312. submit: this.onSubmit,
  313. 'click .js-import-board': Popup.open('chooseBoardSource'),
  314. 'click .js-board-template': Popup.open('searchElement'),
  315. 'click .js-toggle-add-template-container': this.toggleAddTemplateContainer,
  316. },
  317. ];
  318. },
  319. }).register('createBoardPopup');
  320. (class CreateTemplateContainerPopup extends CreateBoard {
  321. onRendered() {
  322. // Always pre-check the template container checkbox for this popup
  323. $('#add-template-container').addClass('is-checked');
  324. }
  325. }).register('createTemplateContainerPopup');
  326. (class HeaderBarCreateBoard extends CreateBoard {
  327. onSubmit(event) {
  328. super.onSubmit(event);
  329. // Immediately star boards crated with the headerbar popup.
  330. ReactiveCache.getCurrentUser().toggleBoardStar(this.boardId.get());
  331. }
  332. }.register('headerBarCreateBoardPopup'));
  333. BlazeComponent.extendComponent({
  334. notAllowPrivateVisibilityOnly(){
  335. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  336. },
  337. visibilityCheck() {
  338. const currentBoard = Utils.getCurrentBoard();
  339. return this.currentData() === currentBoard.permission;
  340. },
  341. selectBoardVisibility() {
  342. const currentBoard = Utils.getCurrentBoard();
  343. const visibility = this.currentData();
  344. currentBoard.setVisibility(visibility);
  345. Popup.back();
  346. },
  347. events() {
  348. return [
  349. {
  350. 'click .js-select-visibility': this.selectBoardVisibility,
  351. },
  352. ];
  353. },
  354. }).register('boardChangeVisibilityPopup');
  355. BlazeComponent.extendComponent({
  356. watchLevel() {
  357. const currentBoard = Utils.getCurrentBoard();
  358. return currentBoard.getWatchLevel(Meteor.userId());
  359. },
  360. watchCheck() {
  361. return this.currentData() === this.watchLevel();
  362. },
  363. events() {
  364. return [
  365. {
  366. 'click .js-select-watch'() {
  367. const level = this.currentData();
  368. Meteor.call(
  369. 'watch',
  370. 'board',
  371. Session.get('currentBoard'),
  372. level,
  373. (err, ret) => {
  374. if (!err && ret) Popup.back();
  375. },
  376. );
  377. },
  378. },
  379. ];
  380. },
  381. }).register('boardChangeWatchPopup');
  382. /*
  383. BlazeComponent.extendComponent({
  384. onCreated() {
  385. //this.sortBy = new ReactiveVar();
  386. ////this.sortDirection = new ReactiveVar();
  387. //this.setSortBy();
  388. this.downClass = DOWNCLS;
  389. this.upClass = UPCLS;
  390. },
  391. allowedSortValues() {
  392. const types = [];
  393. const pushed = {};
  394. ReactiveCache.getCurrentUser()
  395. .getListSortTypes()
  396. .forEach(type => {
  397. const key = type.replace(/^-/, '');
  398. if (pushed[key] === undefined) {
  399. types.push({
  400. name: key,
  401. label: `list-label-${key}`,
  402. shortLabel: `list-label-short-${key}`,
  403. });
  404. pushed[key] = 1;
  405. }
  406. });
  407. return types;
  408. },
  409. Direction() {
  410. return ReactiveCache.getCurrentUser().getListSortByDirection() === -1
  411. ? this.downClass
  412. : this.upClass;
  413. },
  414. sortby() {
  415. return ReactiveCache.getCurrentUser().getListSortBy();
  416. },
  417. setSortBy(type = null) {
  418. const user = ReactiveCache.getCurrentUser();
  419. if (type === null) {
  420. type = user._getListSortBy();
  421. } else {
  422. let value = '';
  423. if (type.map) {
  424. // is an array
  425. value = (type[1] === -1 ? '-' : '') + type[0];
  426. }
  427. Meteor.call('setListSortBy', value);
  428. }
  429. //this.sortBy.set(type[0]);
  430. //this.sortDirection.set(type[1]);
  431. },
  432. events() {
  433. return [
  434. {
  435. 'click .js-sort-by'(evt) {
  436. evt.preventDefault();
  437. const target = evt.target;
  438. const sortby = target.getAttribute('name');
  439. const down = !!target.querySelector(`.${this.upClass}`);
  440. const direction = down ? -1 : 1;
  441. this.setSortBy([sortby, direction]);
  442. if (Utils.isMiniScreen) {
  443. Popup.back();
  444. }
  445. },
  446. },
  447. ];
  448. },
  449. }).register('listsortPopup');
  450. */
  451. BlazeComponent.extendComponent({
  452. events() {
  453. return [
  454. {
  455. 'click .js-sort-due'() {
  456. const sortBy = {
  457. dueAt: 1,
  458. };
  459. Session.set('sortBy', sortBy);
  460. sortCardsBy.set(TAPi18n.__('due-date'));
  461. Popup.back();
  462. },
  463. 'click .js-sort-title'() {
  464. const sortBy = {
  465. title: 1,
  466. };
  467. Session.set('sortBy', sortBy);
  468. sortCardsBy.set(TAPi18n.__('title'));
  469. Popup.back();
  470. },
  471. 'click .js-sort-created-asc'() {
  472. const sortBy = {
  473. createdAt: 1,
  474. };
  475. Session.set('sortBy', sortBy);
  476. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  477. Popup.back();
  478. },
  479. 'click .js-sort-created-desc'() {
  480. const sortBy = {
  481. createdAt: -1,
  482. };
  483. Session.set('sortBy', sortBy);
  484. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  485. Popup.back();
  486. },
  487. },
  488. ];
  489. },
  490. }).register('cardsSortPopup');