boardHeader.js 15 KB

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