boardHeader.js 14 KB

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