boardHeader.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. Utils.goBoardId(this.boardId.get());
  272. } else {
  273. const visibility = this.visibility.get();
  274. this.boardId.set(
  275. Boards.insert({
  276. title,
  277. permission: visibility,
  278. migrationVersion: 1, // Latest version - no migration needed
  279. }),
  280. );
  281. Swimlanes.insert({
  282. title: 'Default',
  283. boardId: this.boardId.get(),
  284. });
  285. Utils.goBoardId(this.boardId.get());
  286. }
  287. },
  288. events() {
  289. return [
  290. {
  291. 'click .js-select-visibility'() {
  292. this.setVisibility(this.currentData());
  293. },
  294. 'click .js-change-visibility': this.toggleVisibilityMenu,
  295. 'click .js-import': Popup.open('boardImportBoard'),
  296. submit: this.onSubmit,
  297. 'click .js-import-board': Popup.open('chooseBoardSource'),
  298. 'click .js-board-template': Popup.open('searchElement'),
  299. 'click .js-toggle-add-template-container': this.toggleAddTemplateContainer,
  300. },
  301. ];
  302. },
  303. }).register('createBoardPopup');
  304. (class HeaderBarCreateBoard extends CreateBoard {
  305. onSubmit(event) {
  306. super.onSubmit(event);
  307. // Immediately star boards crated with the headerbar popup.
  308. ReactiveCache.getCurrentUser().toggleBoardStar(this.boardId.get());
  309. }
  310. }.register('headerBarCreateBoardPopup'));
  311. BlazeComponent.extendComponent({
  312. notAllowPrivateVisibilityOnly(){
  313. return !TableVisibilityModeSettings.findOne('tableVisibilityMode-allowPrivateOnly').booleanValue;
  314. },
  315. visibilityCheck() {
  316. const currentBoard = Utils.getCurrentBoard();
  317. return this.currentData() === currentBoard.permission;
  318. },
  319. selectBoardVisibility() {
  320. const currentBoard = Utils.getCurrentBoard();
  321. const visibility = this.currentData();
  322. currentBoard.setVisibility(visibility);
  323. Popup.back();
  324. },
  325. events() {
  326. return [
  327. {
  328. 'click .js-select-visibility': this.selectBoardVisibility,
  329. },
  330. ];
  331. },
  332. }).register('boardChangeVisibilityPopup');
  333. BlazeComponent.extendComponent({
  334. watchLevel() {
  335. const currentBoard = Utils.getCurrentBoard();
  336. return currentBoard.getWatchLevel(Meteor.userId());
  337. },
  338. watchCheck() {
  339. return this.currentData() === this.watchLevel();
  340. },
  341. events() {
  342. return [
  343. {
  344. 'click .js-select-watch'() {
  345. const level = this.currentData();
  346. Meteor.call(
  347. 'watch',
  348. 'board',
  349. Session.get('currentBoard'),
  350. level,
  351. (err, ret) => {
  352. if (!err && ret) Popup.back();
  353. },
  354. );
  355. },
  356. },
  357. ];
  358. },
  359. }).register('boardChangeWatchPopup');
  360. /*
  361. BlazeComponent.extendComponent({
  362. onCreated() {
  363. //this.sortBy = new ReactiveVar();
  364. ////this.sortDirection = new ReactiveVar();
  365. //this.setSortBy();
  366. this.downClass = DOWNCLS;
  367. this.upClass = UPCLS;
  368. },
  369. allowedSortValues() {
  370. const types = [];
  371. const pushed = {};
  372. ReactiveCache.getCurrentUser()
  373. .getListSortTypes()
  374. .forEach(type => {
  375. const key = type.replace(/^-/, '');
  376. if (pushed[key] === undefined) {
  377. types.push({
  378. name: key,
  379. label: `list-label-${key}`,
  380. shortLabel: `list-label-short-${key}`,
  381. });
  382. pushed[key] = 1;
  383. }
  384. });
  385. return types;
  386. },
  387. Direction() {
  388. return ReactiveCache.getCurrentUser().getListSortByDirection() === -1
  389. ? this.downClass
  390. : this.upClass;
  391. },
  392. sortby() {
  393. return ReactiveCache.getCurrentUser().getListSortBy();
  394. },
  395. setSortBy(type = null) {
  396. const user = ReactiveCache.getCurrentUser();
  397. if (type === null) {
  398. type = user._getListSortBy();
  399. } else {
  400. let value = '';
  401. if (type.map) {
  402. // is an array
  403. value = (type[1] === -1 ? '-' : '') + type[0];
  404. }
  405. Meteor.call('setListSortBy', value);
  406. }
  407. //this.sortBy.set(type[0]);
  408. //this.sortDirection.set(type[1]);
  409. },
  410. events() {
  411. return [
  412. {
  413. 'click .js-sort-by'(evt) {
  414. evt.preventDefault();
  415. const target = evt.target;
  416. const sortby = target.getAttribute('name');
  417. const down = !!target.querySelector(`.${this.upClass}`);
  418. const direction = down ? -1 : 1;
  419. this.setSortBy([sortby, direction]);
  420. if (Utils.isMiniScreen) {
  421. Popup.back();
  422. }
  423. },
  424. },
  425. ];
  426. },
  427. }).register('listsortPopup');
  428. */
  429. BlazeComponent.extendComponent({
  430. events() {
  431. return [
  432. {
  433. 'click .js-sort-due'() {
  434. const sortBy = {
  435. dueAt: 1,
  436. };
  437. Session.set('sortBy', sortBy);
  438. sortCardsBy.set(TAPi18n.__('due-date'));
  439. Popup.back();
  440. },
  441. 'click .js-sort-title'() {
  442. const sortBy = {
  443. title: 1,
  444. };
  445. Session.set('sortBy', sortBy);
  446. sortCardsBy.set(TAPi18n.__('title'));
  447. Popup.back();
  448. },
  449. 'click .js-sort-created-asc'() {
  450. const sortBy = {
  451. createdAt: 1,
  452. };
  453. Session.set('sortBy', sortBy);
  454. sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
  455. Popup.back();
  456. },
  457. 'click .js-sort-created-desc'() {
  458. const sortBy = {
  459. createdAt: -1,
  460. };
  461. Session.set('sortBy', sortBy);
  462. sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
  463. Popup.back();
  464. },
  465. },
  466. ];
  467. },
  468. }).register('cardsSortPopup');