globalSearch.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. const subManager = new SubsManager();
  2. BlazeComponent.extendComponent({
  3. events() {
  4. return [
  5. {
  6. 'click .js-due-cards-view-change': Popup.open('globalSearchViewChange'),
  7. },
  8. ];
  9. },
  10. }).register('globalSearchHeaderBar');
  11. Template.globalSearch.helpers({
  12. userId() {
  13. return Meteor.userId();
  14. },
  15. });
  16. BlazeComponent.extendComponent({
  17. events() {
  18. return [
  19. {
  20. 'click .js-due-cards-view-me'() {
  21. Utils.setDueCardsView('me');
  22. Popup.close();
  23. },
  24. 'click .js-due-cards-view-all'() {
  25. Utils.setDueCardsView('all');
  26. Popup.close();
  27. },
  28. },
  29. ];
  30. },
  31. }).register('globalSearchViewChangePopup');
  32. BlazeComponent.extendComponent({
  33. onCreated() {
  34. this.searching = new ReactiveVar(false);
  35. this.hasResults = new ReactiveVar(false);
  36. this.hasQueryErrors = new ReactiveVar(false);
  37. this.query = new ReactiveVar('');
  38. this.resultsHeading = new ReactiveVar('');
  39. this.searchLink = new ReactiveVar(null);
  40. this.myLists = new ReactiveVar([]);
  41. this.myLabelNames = new ReactiveVar([]);
  42. this.myBoardNames = new ReactiveVar([]);
  43. this.results = new ReactiveVar([]);
  44. this.hasNextPage = new ReactiveVar(false);
  45. this.hasPreviousPage = new ReactiveVar(false);
  46. this.queryParams = null;
  47. this.parsingErrors = [];
  48. this.resultsCount = 0;
  49. this.totalHits = 0;
  50. this.queryErrors = null;
  51. this.colorMap = null;
  52. this.resultsPerPage = 25;
  53. Meteor.call('myLists', (err, data) => {
  54. if (!err) {
  55. this.myLists.set(data);
  56. }
  57. });
  58. Meteor.call('myLabelNames', (err, data) => {
  59. if (!err) {
  60. this.myLabelNames.set(data);
  61. }
  62. });
  63. Meteor.call('myBoardNames', (err, data) => {
  64. if (!err) {
  65. this.myBoardNames.set(data);
  66. }
  67. });
  68. },
  69. onRendered() {
  70. Meteor.subscribe('setting');
  71. // eslint-disable-next-line no-console
  72. //console.log('lang:', TAPi18n.getLanguage());
  73. this.colorMap = Boards.colorMap();
  74. // eslint-disable-next-line no-console
  75. // console.log('colorMap:', this.colorMap);
  76. if (Session.get('globalQuery')) {
  77. this.searchAllBoards(Session.get('globalQuery'));
  78. }
  79. },
  80. resetSearch() {
  81. this.searching.set(false);
  82. this.results.set([]);
  83. this.hasResults.set(false);
  84. this.hasQueryErrors.set(false);
  85. this.resultsHeading.set('');
  86. this.parsingErrors = [];
  87. this.resultsCount = 0;
  88. this.totalHits = 0;
  89. this.queryErrors = null;
  90. },
  91. getSessionData() {
  92. return SessionData.findOne({
  93. userId: Meteor.userId(),
  94. sessionId: SessionData.getSessionId(),
  95. });
  96. },
  97. getResults() {
  98. // eslint-disable-next-line no-console
  99. // console.log('getting results');
  100. if (this.queryParams) {
  101. const sessionData = this.getSessionData();
  102. // eslint-disable-next-line no-console
  103. // console.log('selector:', sessionData.getSelector());
  104. // console.log('session data:', sessionData);
  105. const projection = sessionData.getProjection();
  106. projection.skip = 0;
  107. const cards = Cards.find({ _id: { $in: sessionData.cards } }, projection);
  108. this.queryErrors = sessionData.errors;
  109. if (this.queryErrors.length) {
  110. this.hasQueryErrors.set(true);
  111. return null;
  112. }
  113. if (cards) {
  114. this.totalHits = sessionData.totalHits;
  115. this.resultsCount = cards.count();
  116. this.resultsStart = sessionData.lastHit - this.resultsCount + 1;
  117. this.resultsEnd = sessionData.lastHit;
  118. this.resultsHeading.set(this.getResultsHeading());
  119. this.results.set(cards);
  120. this.hasNextPage.set(sessionData.lastHit < sessionData.totalHits);
  121. this.hasPreviousPage.set(
  122. sessionData.lastHit - sessionData.resultsCount > 0,
  123. );
  124. }
  125. }
  126. this.resultsCount = 0;
  127. return null;
  128. },
  129. errorMessages() {
  130. if (this.parsingErrors.length) {
  131. return this.parsingErrorMessages();
  132. }
  133. return this.queryErrorMessages();
  134. },
  135. parsingErrorMessages() {
  136. const messages = [];
  137. if (this.parsingErrors.length) {
  138. this.parsingErrors.forEach(err => {
  139. messages.push(TAPi18n.__(err.tag, err.value));
  140. });
  141. }
  142. return messages;
  143. },
  144. queryErrorMessages() {
  145. messages = [];
  146. this.queryErrors.forEach(err => {
  147. let value = err.color ? TAPi18n.__(`color-${err.value}`) : err.value;
  148. if (!value) {
  149. value = err.value;
  150. }
  151. messages.push(TAPi18n.__(err.tag, value));
  152. });
  153. return messages;
  154. },
  155. searchAllBoards(query) {
  156. query = query.trim();
  157. // eslint-disable-next-line no-console
  158. //console.log('query:', query);
  159. this.query.set(query);
  160. this.resetSearch();
  161. if (!query) {
  162. return;
  163. }
  164. this.searching.set(true);
  165. const reOperator1 = new RegExp(
  166. '^((?<operator>[\\p{Letter}\\p{Mark}]+):|(?<abbrev>[#@]))(?<value>[\\p{Letter}\\p{Mark}]+)(\\s+|$)',
  167. 'iu',
  168. );
  169. const reOperator2 = new RegExp(
  170. '^((?<operator>[\\p{Letter}\\p{Mark}]+):|(?<abbrev>[#@]))(?<quote>["\']*)(?<value>.*?)\\k<quote>(\\s+|$)',
  171. 'iu',
  172. );
  173. const reText = new RegExp('^(?<text>\\S+)(\\s+|$)', 'u');
  174. const reQuotedText = new RegExp(
  175. '^(?<quote>["\'])(?<text>.*?)\\k<quote>(\\s+|$)',
  176. 'u',
  177. );
  178. const reNegatedOperator = new RegExp('^-(?<operator>.*)$');
  179. const operators = {
  180. 'operator-board': 'boards',
  181. 'operator-board-abbrev': 'boards',
  182. 'operator-swimlane': 'swimlanes',
  183. 'operator-swimlane-abbrev': 'swimlanes',
  184. 'operator-list': 'lists',
  185. 'operator-list-abbrev': 'lists',
  186. 'operator-label': 'labels',
  187. 'operator-label-abbrev': 'labels',
  188. 'operator-user': 'users',
  189. 'operator-user-abbrev': 'users',
  190. 'operator-member': 'members',
  191. 'operator-member-abbrev': 'members',
  192. 'operator-assignee': 'assignees',
  193. 'operator-assignee-abbrev': 'assignees',
  194. 'operator-status': 'status',
  195. 'operator-due': 'dueAt',
  196. 'operator-created': 'createdAt',
  197. 'operator-modified': 'modifiedAt',
  198. 'operator-comment': 'comments',
  199. 'operator-has': 'has',
  200. 'operator-sort': 'sort',
  201. 'operator-limit': 'limit',
  202. };
  203. const predicates = {
  204. due: {
  205. 'predicate-overdue': 'overdue',
  206. },
  207. durations: {
  208. 'predicate-week': 'week',
  209. 'predicate-month': 'month',
  210. 'predicate-quarter': 'quarter',
  211. 'predicate-year': 'year',
  212. },
  213. status: {
  214. 'predicate-archived': 'archived',
  215. 'predicate-all': 'all',
  216. 'predicate-ended': 'ended',
  217. 'predicate-public': 'public',
  218. 'predicate-private': 'private',
  219. },
  220. sorts: {
  221. 'predicate-due': 'dueAt',
  222. 'predicate-created': 'createdAt',
  223. 'predicate-modified': 'modifiedAt',
  224. },
  225. has: {
  226. 'predicate-description': 'description',
  227. 'predicate-checklist': 'checklist',
  228. 'predicate-attachment': 'attachment',
  229. },
  230. };
  231. const predicateTranslations = {};
  232. Object.entries(predicates).forEach(([category, catPreds]) => {
  233. predicateTranslations[category] = {};
  234. Object.entries(catPreds).forEach(([tag, value]) => {
  235. predicateTranslations[category][TAPi18n.__(tag)] = value;
  236. });
  237. });
  238. // eslint-disable-next-line no-console
  239. // console.log('predicateTranslations:', predicateTranslations);
  240. const operatorMap = {};
  241. Object.entries(operators).forEach(([key, value]) => {
  242. operatorMap[TAPi18n.__(key).toLowerCase()] = value;
  243. });
  244. // eslint-disable-next-line no-console
  245. // console.log('operatorMap:', operatorMap);
  246. const params = {
  247. limit: this.resultsPerPage,
  248. boards: [],
  249. swimlanes: [],
  250. lists: [],
  251. users: [],
  252. members: [],
  253. assignees: [],
  254. labels: [],
  255. status: [],
  256. dueAt: null,
  257. createdAt: null,
  258. modifiedAt: null,
  259. comments: [],
  260. has: [],
  261. };
  262. let text = '';
  263. while (query) {
  264. m = query.match(reOperator1);
  265. if (!m) {
  266. m = query.match(reOperator2);
  267. if (m) {
  268. query = query.replace(reOperator2, '');
  269. }
  270. } else {
  271. query = query.replace(reOperator1, '');
  272. }
  273. if (m) {
  274. let op;
  275. if (m.groups.operator) {
  276. op = m.groups.operator.toLowerCase();
  277. } else {
  278. op = m.groups.abbrev.toLowerCase();
  279. }
  280. // eslint-disable-next-line no-prototype-builtins
  281. if (operatorMap.hasOwnProperty(op)) {
  282. const operator = operatorMap[op];
  283. let value = m.groups.value;
  284. if (operator === 'labels') {
  285. if (value in this.colorMap) {
  286. value = this.colorMap[value];
  287. // console.log('found color:', value);
  288. }
  289. } else if (['dueAt', 'createdAt', 'modifiedAt'].includes(operator)) {
  290. let days = parseInt(value, 10);
  291. let duration = null;
  292. if (isNaN(days)) {
  293. // duration was specified as text
  294. if (predicateTranslations.durations[value]) {
  295. duration = predicateTranslations.durations[value];
  296. let date = null;
  297. switch (duration) {
  298. case 'week':
  299. let week = moment().week();
  300. if (week === 52) {
  301. date = moment(1, 'W');
  302. date.set('year', date.year() + 1);
  303. } else {
  304. date = moment(week + 1, 'W');
  305. }
  306. break;
  307. case 'month':
  308. let month = moment().month();
  309. // .month() is zero indexed
  310. if (month === 11) {
  311. date = moment(1, 'M');
  312. date.set('year', date.year() + 1);
  313. } else {
  314. date = moment(month + 2, 'M');
  315. }
  316. break;
  317. case 'quarter':
  318. let quarter = moment().quarter();
  319. if (quarter === 4) {
  320. date = moment(1, 'Q');
  321. date.set('year', date.year() + 1);
  322. } else {
  323. date = moment(quarter + 1, 'Q');
  324. }
  325. break;
  326. case 'year':
  327. date = moment(moment().year() + 1, 'YYYY');
  328. break;
  329. }
  330. if (date) {
  331. value = {
  332. operator: '$lt',
  333. value: date.format(),
  334. };
  335. }
  336. } else if (operator === 'dueAt' && value === 'overdue') {
  337. value = {
  338. operator: '$lt',
  339. value: moment(moment().format('YYYY-MM-DD')).format(),
  340. };
  341. } else {
  342. this.parsingErrors.push({
  343. tag: 'operator-number-expected',
  344. value: { operator: op, value },
  345. });
  346. value = null;
  347. }
  348. } else {
  349. if (operator === 'dueAt') {
  350. value = {
  351. operator: '$lt',
  352. value: moment(moment().format('YYYY-MM-DD'))
  353. .add(days + 1, duration ? duration : 'days')
  354. .format(),
  355. };
  356. } else {
  357. value = {
  358. operator: '$gte',
  359. value: moment(moment().format('YYYY-MM-DD'))
  360. .subtract(days, duration ? duration : 'days')
  361. .format(),
  362. };
  363. }
  364. }
  365. } else if (operator === 'sort') {
  366. let negated = false;
  367. const m = value.match(reNegatedOperator);
  368. if (m) {
  369. value = m.groups.operator;
  370. negated = true;
  371. }
  372. if (!predicateTranslations.sorts[value]) {
  373. this.parsingErrors.push({
  374. tag: 'operator-sort-invalid',
  375. value,
  376. });
  377. } else {
  378. value = {
  379. name: predicateTranslations.sorts[value],
  380. order: negated ? 'des' : 'asc',
  381. };
  382. }
  383. } else if (operator === 'status') {
  384. if (!predicateTranslations.status[value]) {
  385. this.parsingErrors.push({
  386. tag: 'operator-status-invalid',
  387. value,
  388. });
  389. } else {
  390. value = predicateTranslations.status[value];
  391. }
  392. } else if (operator === 'has') {
  393. if (!predicateTranslations.has[value]) {
  394. this.parsingErrors.push({
  395. tag: 'operator-has-invalid',
  396. value,
  397. });
  398. } else {
  399. value = predicateTranslations.has[value];
  400. }
  401. } else if (operator === 'limit') {
  402. const limit = parseInt(value, 10);
  403. if (isNaN(limit) || limit < 1) {
  404. this.parsingErrors.push({
  405. tag: 'operator-limit-invalid',
  406. value,
  407. });
  408. } else {
  409. value = limit;
  410. }
  411. }
  412. if (Array.isArray(params[operator])) {
  413. params[operator].push(value);
  414. } else {
  415. params[operator] = value;
  416. }
  417. } else {
  418. this.parsingErrors.push({
  419. tag: 'operator-unknown-error',
  420. value: op,
  421. });
  422. }
  423. continue;
  424. }
  425. m = query.match(reQuotedText);
  426. if (!m) {
  427. m = query.match(reText);
  428. if (m) {
  429. query = query.replace(reText, '');
  430. }
  431. } else {
  432. query = query.replace(reQuotedText, '');
  433. }
  434. if (m) {
  435. text += (text ? ' ' : '') + m.groups.text;
  436. }
  437. }
  438. // eslint-disable-next-line no-console
  439. // console.log('text:', text);
  440. params.text = text;
  441. // eslint-disable-next-line no-console
  442. console.log('params:', params);
  443. this.queryParams = params;
  444. if (this.parsingErrors.length) {
  445. this.searching.set(false);
  446. this.queryErrors = this.parsingErrorMessages();
  447. this.hasResults.set(true);
  448. this.hasQueryErrors.set(true);
  449. return;
  450. }
  451. this.autorun(() => {
  452. const handle = Meteor.subscribe(
  453. 'globalSearch',
  454. SessionData.getSessionId(),
  455. params,
  456. );
  457. Tracker.nonreactive(() => {
  458. Tracker.autorun(() => {
  459. if (handle.ready()) {
  460. this.getResults();
  461. this.searching.set(false);
  462. this.hasResults.set(true);
  463. }
  464. });
  465. });
  466. });
  467. },
  468. nextPage() {
  469. const sessionData = this.getSessionData();
  470. this.autorun(() => {
  471. const handle = Meteor.subscribe('nextPage', sessionData.sessionId);
  472. Tracker.nonreactive(() => {
  473. Tracker.autorun(() => {
  474. if (handle.ready()) {
  475. this.getResults();
  476. this.searching.set(false);
  477. this.hasResults.set(true);
  478. }
  479. });
  480. });
  481. });
  482. },
  483. previousPage() {
  484. const sessionData = this.getSessionData();
  485. this.autorun(() => {
  486. const handle = Meteor.subscribe('previousPage', sessionData.sessionId);
  487. Tracker.nonreactive(() => {
  488. Tracker.autorun(() => {
  489. if (handle.ready()) {
  490. this.getResults();
  491. this.searching.set(false);
  492. this.hasResults.set(true);
  493. }
  494. });
  495. });
  496. });
  497. },
  498. getResultsHeading() {
  499. if (this.resultsCount === 0) {
  500. return TAPi18n.__('no-cards-found');
  501. } else if (this.resultsCount === 1) {
  502. return TAPi18n.__('one-card-found');
  503. } else if (this.resultsCount === this.totalHits) {
  504. return TAPi18n.__('n-cards-found', this.resultsCount);
  505. }
  506. return TAPi18n.__('n-n-of-n-cards-found', {
  507. start: this.resultsStart,
  508. end: this.resultsEnd,
  509. total: this.totalHits,
  510. });
  511. },
  512. getSearchHref() {
  513. const baseUrl = window.location.href.replace(/([?#].*$|\s*$)/, '');
  514. return `${baseUrl}?q=${encodeURIComponent(this.query.get())}`;
  515. },
  516. searchInstructions() {
  517. tags = {
  518. operator_board: TAPi18n.__('operator-board'),
  519. operator_list: TAPi18n.__('operator-list'),
  520. operator_swimlane: TAPi18n.__('operator-swimlane'),
  521. operator_comment: TAPi18n.__('operator-comment'),
  522. operator_label: TAPi18n.__('operator-label'),
  523. operator_label_abbrev: TAPi18n.__('operator-label-abbrev'),
  524. operator_user: TAPi18n.__('operator-user'),
  525. operator_user_abbrev: TAPi18n.__('operator-user-abbrev'),
  526. operator_member: TAPi18n.__('operator-member'),
  527. operator_member_abbrev: TAPi18n.__('operator-member-abbrev'),
  528. operator_assignee: TAPi18n.__('operator-assignee'),
  529. operator_assignee_abbrev: TAPi18n.__('operator-assignee-abbrev'),
  530. operator_due: TAPi18n.__('operator-due'),
  531. operator_created: TAPi18n.__('operator-created'),
  532. operator_modified: TAPi18n.__('operator-modified'),
  533. operator_status: TAPi18n.__('operator-status'),
  534. operator_has: TAPi18n.__('operator-has'),
  535. predicate_overdue: TAPi18n.__('predicate-overdue'),
  536. predicate_archived: TAPi18n.__('predicate-archived'),
  537. predicate_all: TAPi18n.__('predicate-all'),
  538. predicate_ended: TAPi18n.__('predicate-ended'),
  539. predicate_week: TAPi18n.__('predicate-week'),
  540. predicate_month: TAPi18n.__('predicate-month'),
  541. predicate_quarter: TAPi18n.__('predicate-quarter'),
  542. predicate_year: TAPi18n.__('predicate-year'),
  543. predicate_attachment: TAPi18n.__('predicate-attachment'),
  544. predicate_description: TAPi18n.__('predicate-description'),
  545. predicate_checklist: TAPi18n.__('predicate-checklist'),
  546. predicate_public: TAPi18n.__('predicate-public'),
  547. predicate_private: TAPi18n.__('predicate-private'),
  548. };
  549. text = `# ${TAPi18n.__('globalSearch-instructions-heading')}`;
  550. text += `\n${TAPi18n.__('globalSearch-instructions-description', tags)}`;
  551. text += `\n${TAPi18n.__('globalSearch-instructions-operators', tags)}`;
  552. text += `\n* ${TAPi18n.__(
  553. 'globalSearch-instructions-operator-board',
  554. tags,
  555. )}`;
  556. text += `\n* ${TAPi18n.__(
  557. 'globalSearch-instructions-operator-list',
  558. tags,
  559. )}`;
  560. text += `\n* ${TAPi18n.__(
  561. 'globalSearch-instructions-operator-swimlane',
  562. tags,
  563. )}`;
  564. text += `\n* ${TAPi18n.__(
  565. 'globalSearch-instructions-operator-comment',
  566. tags,
  567. )}`;
  568. text += `\n* ${TAPi18n.__(
  569. 'globalSearch-instructions-operator-label',
  570. tags,
  571. )}`;
  572. text += `\n* ${TAPi18n.__(
  573. 'globalSearch-instructions-operator-hash',
  574. tags,
  575. )}`;
  576. text += `\n* ${TAPi18n.__(
  577. 'globalSearch-instructions-operator-user',
  578. tags,
  579. )}`;
  580. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-at', tags)}`;
  581. text += `\n* ${TAPi18n.__(
  582. 'globalSearch-instructions-operator-member',
  583. tags,
  584. )}`;
  585. text += `\n* ${TAPi18n.__(
  586. 'globalSearch-instructions-operator-assignee',
  587. tags,
  588. )}`;
  589. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-due', tags)}`;
  590. text += `\n* ${TAPi18n.__(
  591. 'globalSearch-instructions-operator-created',
  592. tags,
  593. )}`;
  594. text += `\n* ${TAPi18n.__(
  595. 'globalSearch-instructions-operator-modified',
  596. tags,
  597. )}`;
  598. text += `\n* ${TAPi18n.__(
  599. 'globalSearch-instructions-status-archived',
  600. tags,
  601. )}`;
  602. text += `\n* ${TAPi18n.__(
  603. 'globalSearch-instructions-status-public',
  604. tags,
  605. )}`;
  606. text += `\n* ${TAPi18n.__(
  607. 'globalSearch-instructions-status-private',
  608. tags,
  609. )}`;
  610. text += `\n* ${TAPi18n.__('globalSearch-instructions-status-all', tags)}`;
  611. text += `\n* ${TAPi18n.__('globalSearch-instructions-status-ended', tags)}`;
  612. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-has', tags)}`;
  613. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-sort', tags)}`;
  614. text += `\n## ${TAPi18n.__('heading-notes')}`;
  615. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-1', tags)}`;
  616. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-2', tags)}`;
  617. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-3', tags)}`;
  618. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-3-2', tags)}`;
  619. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-4', tags)}`;
  620. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-5', tags)}`;
  621. return text;
  622. },
  623. labelColors() {
  624. return Boards.simpleSchema()._schema['labels.$.color'].allowedValues.map(
  625. color => {
  626. return { color, name: TAPi18n.__(`color-${color}`) };
  627. },
  628. );
  629. },
  630. events() {
  631. return [
  632. {
  633. 'submit .js-search-query-form'(evt) {
  634. evt.preventDefault();
  635. this.searchAllBoards(evt.target.searchQuery.value);
  636. },
  637. 'click .js-next-page'(evt) {
  638. evt.preventDefault();
  639. this.nextPage();
  640. },
  641. 'click .js-previous-page'(evt) {
  642. evt.preventDefault();
  643. this.previousPage();
  644. },
  645. 'click .js-label-color'(evt) {
  646. evt.preventDefault();
  647. const input = document.getElementById('global-search-input');
  648. this.query.set(
  649. `${input.value} ${TAPi18n.__('operator-label')}:"${
  650. evt.currentTarget.textContent
  651. }"`,
  652. );
  653. document.getElementById('global-search-input').focus();
  654. },
  655. 'click .js-board-title'(evt) {
  656. evt.preventDefault();
  657. const input = document.getElementById('global-search-input');
  658. this.query.set(
  659. `${input.value} ${TAPi18n.__('operator-board')}:"${
  660. evt.currentTarget.textContent
  661. }"`,
  662. );
  663. document.getElementById('global-search-input').focus();
  664. },
  665. 'click .js-list-title'(evt) {
  666. evt.preventDefault();
  667. const input = document.getElementById('global-search-input');
  668. this.query.set(
  669. `${input.value} ${TAPi18n.__('operator-list')}:"${
  670. evt.currentTarget.textContent
  671. }"`,
  672. );
  673. document.getElementById('global-search-input').focus();
  674. },
  675. 'click .js-label-name'(evt) {
  676. evt.preventDefault();
  677. const input = document.getElementById('global-search-input');
  678. this.query.set(
  679. `${input.value} ${TAPi18n.__('operator-label')}:"${
  680. evt.currentTarget.textContent
  681. }"`,
  682. );
  683. document.getElementById('global-search-input').focus();
  684. },
  685. },
  686. ];
  687. },
  688. }).register('globalSearch');