boardHeader.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. },
  149. ];
  150. },
  151. }).register('boardHeaderBar');
  152. Template.boardHeaderBar.helpers({
  153. boardView() {
  154. return Utils.boardView();
  155. },
  156. isSortActive() {
  157. return Session.get('sortBy') ? true : false;
  158. },
  159. sortCardsIcon() {
  160. const sortBy = Session.get('sortBy');
  161. if (!sortBy) {
  162. return '🃏'; // Card icon when nothing is selected
  163. }
  164. // Determine which sort option is active based on sortBy object
  165. if (sortBy.dueAt) {
  166. return '📅'; // Due date icon
  167. } else if (sortBy.title) {
  168. return '🔤'; // Alphabet icon
  169. } else if (sortBy.createdAt) {
  170. return sortBy.createdAt === 1 ? '⬆️' : '⬇️'; // Up/down arrow based on direction
  171. }
  172. return '🃏'; // Default card icon
  173. },
  174. });
  175. Template.boardChangeViewPopup.events({
  176. 'click .js-open-lists-view'() {
  177. Utils.setBoardView('board-view-lists');
  178. Popup.back();
  179. },
  180. 'click .js-open-swimlanes-view'() {
  181. Utils.setBoardView('board-view-swimlanes');
  182. Popup.back();
  183. },
  184. 'click .js-open-cal-view'() {
  185. Utils.setBoardView('board-view-cal');
  186. Popup.back();
  187. },
  188. });
  189. const CreateBoard = BlazeComponent.extendComponent({
  190. template() {
  191. return 'createBoard';
  192. },
  193. onCreated() {
  194. this.visibilityMenuIsOpen = new ReactiveVar(false);
  195. this.visibility = new ReactiveVar('private');
  196. this.boardId = new ReactiveVar('');
  197. Meteor.subscribe('tableVisibilityModeSettings');
  198. },
  199. notAllowPrivateVisibilityOnly(){
  200. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  201. },
  202. visibilityCheck() {
  203. return this.currentData() === this.visibility.get();
  204. },
  205. setVisibility(visibility) {
  206. this.visibility.set(visibility);
  207. this.visibilityMenuIsOpen.set(false);
  208. },
  209. toggleVisibilityMenu() {
  210. this.visibilityMenuIsOpen.set(!this.visibilityMenuIsOpen.get());
  211. },
  212. toggleAddTemplateContainer() {
  213. $('#add-template-container').toggleClass('is-checked');
  214. },
  215. onSubmit(event) {
  216. event.preventDefault();
  217. const title = this.find('.js-new-board-title').value;
  218. const addTemplateContainer = $('#add-template-container.is-checked').length > 0;
  219. if (addTemplateContainer) {
  220. //const templateContainerId = Meteor.call('setCreateTemplateContainer');
  221. //Utils.goBoardId(templateContainerId);
  222. //alert('niinku template ' + Meteor.call('setCreateTemplateContainer'));
  223. this.boardId.set(
  224. Boards.insert({
  225. // title: TAPi18n.__('templates'),
  226. title: title,
  227. permission: 'private',
  228. type: 'template-container',
  229. migrationVersion: 1, // Latest version - no migration needed
  230. }),
  231. );
  232. // Insert the card templates swimlane
  233. Swimlanes.insert({
  234. // title: TAPi18n.__('card-templates-swimlane'),
  235. title: 'Card Templates',
  236. boardId: this.boardId.get(),
  237. sort: 1,
  238. type: 'template-container',
  239. }),
  240. // Insert the list templates swimlane
  241. Swimlanes.insert(
  242. {
  243. // title: TAPi18n.__('list-templates-swimlane'),
  244. title: 'List Templates',
  245. boardId: this.boardId.get(),
  246. sort: 2,
  247. type: 'template-container',
  248. },
  249. );
  250. // Insert the board templates swimlane
  251. Swimlanes.insert(
  252. {
  253. //title: TAPi18n.__('board-templates-swimlane'),
  254. title: 'Board Templates',
  255. boardId: this.boardId.get(),
  256. sort: 3,
  257. type: 'template-container',
  258. },
  259. );
  260. Utils.goBoardId(this.boardId.get());
  261. } else {
  262. const visibility = this.visibility.get();
  263. this.boardId.set(
  264. Boards.insert({
  265. title,
  266. permission: visibility,
  267. migrationVersion: 1, // Latest version - no migration needed
  268. }),
  269. );
  270. Swimlanes.insert({
  271. title: 'Default',
  272. boardId: this.boardId.get(),
  273. });
  274. Utils.goBoardId(this.boardId.get());
  275. }
  276. },
  277. events() {
  278. return [
  279. {
  280. 'click .js-select-visibility'() {
  281. this.setVisibility(this.currentData());
  282. },
  283. 'click .js-change-visibility': this.toggleVisibilityMenu,
  284. 'click .js-import': Popup.open('boardImportBoard'),
  285. submit: this.onSubmit,
  286. 'click .js-import-board': Popup.open('chooseBoardSource'),
  287. 'click .js-board-template': Popup.open('searchElement'),
  288. 'click .js-toggle-add-template-container': this.toggleAddTemplateContainer,
  289. },
  290. ];
  291. },
  292. }).register('createBoardPopup');
  293. (class HeaderBarCreateBoard extends CreateBoard {
  294. onSubmit(event) {
  295. super.onSubmit(event);
  296. // Immediately star boards crated with the headerbar popup.
  297. ReactiveCache.getCurrentUser().toggleBoardStar(this.boardId.get());
  298. }
  299. }.register('headerBarCreateBoardPopup'));
  300. BlazeComponent.extendComponent({
  301. notAllowPrivateVisibilityOnly(){
  302. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  303. },
  304. visibilityCheck() {
  305. const currentBoard = Utils.getCurrentBoard();
  306. return this.currentData() === currentBoard.permission;
  307. },
  308. selectBoardVisibility() {
  309. const currentBoard = Utils.getCurrentBoard();
  310. const visibility = this.currentData();
  311. currentBoard.setVisibility(visibility);
  312. Popup.back();
  313. },
  314. events() {
  315. return [
  316. {
  317. 'click .js-select-visibility': this.selectBoardVisibility,
  318. },
  319. ];
  320. },
  321. }).register('boardChangeVisibilityPopup');
  322. BlazeComponent.extendComponent({
  323. watchLevel() {
  324. const currentBoard = Utils.getCurrentBoard();
  325. return currentBoard.getWatchLevel(Meteor.userId());
  326. },
  327. watchCheck() {
  328. return this.currentData() === this.watchLevel();
  329. },
  330. events() {
  331. return [
  332. {
  333. 'click .js-select-watch'() {
  334. const level = this.currentData();
  335. Meteor.call(
  336. 'watch',
  337. 'board',
  338. Session.get('currentBoard'),
  339. level,
  340. (err, ret) => {
  341. if (!err && ret) Popup.back();
  342. },
  343. );
  344. },
  345. },
  346. ];
  347. },
  348. }).register('boardChangeWatchPopup');
  349. /*
  350. BlazeComponent.extendComponent({
  351. onCreated() {
  352. //this.sortBy = new ReactiveVar();
  353. ////this.sortDirection = new ReactiveVar();
  354. //this.setSortBy();
  355. this.downClass = DOWNCLS;
  356. this.upClass = UPCLS;
  357. },
  358. allowedSortValues() {
  359. const types = [];
  360. const pushed = {};
  361. ReactiveCache.getCurrentUser()
  362. .getListSortTypes()
  363. .forEach(type => {
  364. const key = type.replace(/^-/, '');
  365. if (pushed[key] === undefined) {
  366. types.push({
  367. name: key,
  368. label: `list-label-${key}`,
  369. shortLabel: `list-label-short-${key}`,
  370. });
  371. pushed[key] = 1;
  372. }
  373. });
  374. return types;
  375. },
  376. Direction() {
  377. return ReactiveCache.getCurrentUser().getListSortByDirection() === -1
  378. ? this.downClass
  379. : this.upClass;
  380. },
  381. sortby() {
  382. return ReactiveCache.getCurrentUser().getListSortBy();
  383. },
  384. setSortBy(type = null) {
  385. const user = ReactiveCache.getCurrentUser();
  386. if (type === null) {
  387. type = user._getListSortBy();
  388. } else {
  389. let value = '';
  390. if (type.map) {
  391. // is an array
  392. value = (type[1] === -1 ? '-' : '') + type[0];
  393. }
  394. Meteor.call('setListSortBy', value);
  395. }
  396. //this.sortBy.set(type[0]);
  397. //this.sortDirection.set(type[1]);
  398. },
  399. events() {
  400. return [
  401. {
  402. 'click .js-sort-by'(evt) {
  403. evt.preventDefault();
  404. const target = evt.target;
  405. const sortby = target.getAttribute('name');
  406. const down = !!target.querySelector(`.${this.upClass}`);
  407. const direction = down ? -1 : 1;
  408. this.setSortBy([sortby, direction]);
  409. if (Utils.isMiniScreen) {
  410. Popup.back();
  411. }
  412. },
  413. },
  414. ];
  415. },
  416. }).register('listsortPopup');
  417. */
  418. BlazeComponent.extendComponent({
  419. events() {
  420. return [
  421. {
  422. 'click .js-sort-due'() {
  423. const sortBy = {
  424. dueAt: 1,
  425. };
  426. Session.set('sortBy', sortBy);
  427. sortCardsBy.set(TAPi18n.__('due-date'));
  428. Popup.back();
  429. },
  430. 'click .js-sort-title'() {
  431. const sortBy = {
  432. title: 1,
  433. };
  434. Session.set('sortBy', sortBy);
  435. sortCardsBy.set(TAPi18n.__('title'));
  436. Popup.back();
  437. },
  438. 'click .js-sort-created-asc'() {
  439. const sortBy = {
  440. createdAt: 1,
  441. };
  442. Session.set('sortBy', sortBy);
  443. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  444. Popup.back();
  445. },
  446. 'click .js-sort-created-desc'() {
  447. const sortBy = {
  448. createdAt: -1,
  449. };
  450. Session.set('sortBy', sortBy);
  451. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  452. Popup.back();
  453. },
  454. },
  455. ];
  456. },
  457. }).register('cardsSortPopup');