boardHeader.js 13 KB

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