globalSearch.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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-open': 'open',
  217. 'predicate-ended': 'ended',
  218. 'predicate-public': 'public',
  219. 'predicate-private': 'private',
  220. },
  221. sorts: {
  222. 'predicate-due': 'dueAt',
  223. 'predicate-created': 'createdAt',
  224. 'predicate-modified': 'modifiedAt',
  225. },
  226. has: {
  227. 'predicate-description': 'description',
  228. 'predicate-checklist': 'checklist',
  229. 'predicate-attachment': 'attachment',
  230. 'predicate-start': 'startAt',
  231. 'predicate-end': 'endAt',
  232. 'predicate-due': 'dueAt',
  233. 'predicate-assignee': 'assignees',
  234. 'predicate-member': 'members',
  235. },
  236. };
  237. const predicateTranslations = {};
  238. Object.entries(predicates).forEach(([category, catPreds]) => {
  239. predicateTranslations[category] = {};
  240. Object.entries(catPreds).forEach(([tag, value]) => {
  241. predicateTranslations[category][TAPi18n.__(tag)] = value;
  242. });
  243. });
  244. // eslint-disable-next-line no-console
  245. // console.log('predicateTranslations:', predicateTranslations);
  246. const operatorMap = {};
  247. Object.entries(operators).forEach(([key, value]) => {
  248. operatorMap[TAPi18n.__(key).toLowerCase()] = value;
  249. });
  250. // eslint-disable-next-line no-console
  251. // console.log('operatorMap:', operatorMap);
  252. const params = {
  253. limit: this.resultsPerPage,
  254. boards: [],
  255. swimlanes: [],
  256. lists: [],
  257. users: [],
  258. members: [],
  259. assignees: [],
  260. labels: [],
  261. status: [],
  262. dueAt: null,
  263. createdAt: null,
  264. modifiedAt: null,
  265. comments: [],
  266. has: [],
  267. };
  268. let text = '';
  269. while (query) {
  270. m = query.match(reOperator1);
  271. if (!m) {
  272. m = query.match(reOperator2);
  273. if (m) {
  274. query = query.replace(reOperator2, '');
  275. }
  276. } else {
  277. query = query.replace(reOperator1, '');
  278. }
  279. if (m) {
  280. let op;
  281. if (m.groups.operator) {
  282. op = m.groups.operator.toLowerCase();
  283. } else {
  284. op = m.groups.abbrev.toLowerCase();
  285. }
  286. // eslint-disable-next-line no-prototype-builtins
  287. if (operatorMap.hasOwnProperty(op)) {
  288. const operator = operatorMap[op];
  289. let value = m.groups.value;
  290. if (operator === 'labels') {
  291. if (value in this.colorMap) {
  292. value = this.colorMap[value];
  293. // console.log('found color:', value);
  294. }
  295. } else if (['dueAt', 'createdAt', 'modifiedAt'].includes(operator)) {
  296. let days = parseInt(value, 10);
  297. let duration = null;
  298. if (isNaN(days)) {
  299. // duration was specified as text
  300. if (predicateTranslations.durations[value]) {
  301. duration = predicateTranslations.durations[value];
  302. let date = null;
  303. switch (duration) {
  304. case 'week':
  305. let week = moment().week();
  306. if (week === 52) {
  307. date = moment(1, 'W');
  308. date.set('year', date.year() + 1);
  309. } else {
  310. date = moment(week + 1, 'W');
  311. }
  312. break;
  313. case 'month':
  314. let month = moment().month();
  315. // .month() is zero indexed
  316. if (month === 11) {
  317. date = moment(1, 'M');
  318. date.set('year', date.year() + 1);
  319. } else {
  320. date = moment(month + 2, 'M');
  321. }
  322. break;
  323. case 'quarter':
  324. let quarter = moment().quarter();
  325. if (quarter === 4) {
  326. date = moment(1, 'Q');
  327. date.set('year', date.year() + 1);
  328. } else {
  329. date = moment(quarter + 1, 'Q');
  330. }
  331. break;
  332. case 'year':
  333. date = moment(moment().year() + 1, 'YYYY');
  334. break;
  335. }
  336. if (date) {
  337. value = {
  338. operator: '$lt',
  339. value: date.format('YYYY-MM-DD'),
  340. };
  341. }
  342. } else if (operator === 'dueAt' && value === 'overdue') {
  343. value = {
  344. operator: '$lt',
  345. value: moment().format('YYYY-MM-DD'),
  346. };
  347. } else {
  348. this.parsingErrors.push({
  349. tag: 'operator-number-expected',
  350. value: { operator: op, value },
  351. });
  352. value = null;
  353. }
  354. } else {
  355. if (operator === 'dueAt') {
  356. value = {
  357. operator: '$lt',
  358. value: moment(moment().format('YYYY-MM-DD'))
  359. .add(days + 1, duration ? duration : 'days')
  360. .format(),
  361. };
  362. } else {
  363. value = {
  364. operator: '$gte',
  365. value: moment(moment().format('YYYY-MM-DD'))
  366. .subtract(days, duration ? duration : 'days')
  367. .format(),
  368. };
  369. }
  370. }
  371. } else if (operator === 'sort') {
  372. let negated = false;
  373. const m = value.match(reNegatedOperator);
  374. if (m) {
  375. value = m.groups.operator;
  376. negated = true;
  377. }
  378. if (!predicateTranslations.sorts[value]) {
  379. this.parsingErrors.push({
  380. tag: 'operator-sort-invalid',
  381. value,
  382. });
  383. } else {
  384. value = {
  385. name: predicateTranslations.sorts[value],
  386. order: negated ? 'des' : 'asc',
  387. };
  388. }
  389. } else if (operator === 'status') {
  390. if (!predicateTranslations.status[value]) {
  391. this.parsingErrors.push({
  392. tag: 'operator-status-invalid',
  393. value,
  394. });
  395. } else {
  396. value = predicateTranslations.status[value];
  397. }
  398. } else if (operator === 'has') {
  399. let negated = false;
  400. const m = value.match(reNegatedOperator);
  401. if (m) {
  402. value = m.groups.operator;
  403. negated = true;
  404. }
  405. if (!predicateTranslations.has[value]) {
  406. this.parsingErrors.push({
  407. tag: 'operator-has-invalid',
  408. value,
  409. });
  410. } else {
  411. value = {
  412. field: predicateTranslations.has[value],
  413. exists: !negated,
  414. };
  415. }
  416. } else if (operator === 'limit') {
  417. const limit = parseInt(value, 10);
  418. if (isNaN(limit) || limit < 1) {
  419. this.parsingErrors.push({
  420. tag: 'operator-limit-invalid',
  421. value,
  422. });
  423. } else {
  424. value = limit;
  425. }
  426. }
  427. if (Array.isArray(params[operator])) {
  428. params[operator].push(value);
  429. } else {
  430. params[operator] = value;
  431. }
  432. } else {
  433. this.parsingErrors.push({
  434. tag: 'operator-unknown-error',
  435. value: op,
  436. });
  437. }
  438. continue;
  439. }
  440. m = query.match(reQuotedText);
  441. if (!m) {
  442. m = query.match(reText);
  443. if (m) {
  444. query = query.replace(reText, '');
  445. }
  446. } else {
  447. query = query.replace(reQuotedText, '');
  448. }
  449. if (m) {
  450. text += (text ? ' ' : '') + m.groups.text;
  451. }
  452. }
  453. // eslint-disable-next-line no-console
  454. // console.log('text:', text);
  455. params.text = text;
  456. // eslint-disable-next-line no-console
  457. console.log('params:', params);
  458. this.queryParams = params;
  459. if (this.parsingErrors.length) {
  460. this.searching.set(false);
  461. this.queryErrors = this.parsingErrorMessages();
  462. this.hasResults.set(true);
  463. this.hasQueryErrors.set(true);
  464. return;
  465. }
  466. this.autorun(() => {
  467. const handle = Meteor.subscribe(
  468. 'globalSearch',
  469. SessionData.getSessionId(),
  470. params,
  471. );
  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. nextPage() {
  484. const sessionData = this.getSessionData();
  485. this.autorun(() => {
  486. const handle = Meteor.subscribe('nextPage', 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. previousPage() {
  499. const sessionData = this.getSessionData();
  500. this.autorun(() => {
  501. const handle = Meteor.subscribe('previousPage', sessionData.sessionId);
  502. Tracker.nonreactive(() => {
  503. Tracker.autorun(() => {
  504. if (handle.ready()) {
  505. this.getResults();
  506. this.searching.set(false);
  507. this.hasResults.set(true);
  508. }
  509. });
  510. });
  511. });
  512. },
  513. getResultsHeading() {
  514. if (this.resultsCount === 0) {
  515. return TAPi18n.__('no-cards-found');
  516. } else if (this.resultsCount === 1) {
  517. return TAPi18n.__('one-card-found');
  518. } else if (this.resultsCount === this.totalHits) {
  519. return TAPi18n.__('n-cards-found', this.resultsCount);
  520. }
  521. return TAPi18n.__('n-n-of-n-cards-found', {
  522. start: this.resultsStart,
  523. end: this.resultsEnd,
  524. total: this.totalHits,
  525. });
  526. },
  527. getSearchHref() {
  528. const baseUrl = window.location.href.replace(/([?#].*$|\s*$)/, '');
  529. return `${baseUrl}?q=${encodeURIComponent(this.query.get())}`;
  530. },
  531. searchInstructions() {
  532. tags = {
  533. operator_board: TAPi18n.__('operator-board'),
  534. operator_list: TAPi18n.__('operator-list'),
  535. operator_swimlane: TAPi18n.__('operator-swimlane'),
  536. operator_comment: TAPi18n.__('operator-comment'),
  537. operator_label: TAPi18n.__('operator-label'),
  538. operator_label_abbrev: TAPi18n.__('operator-label-abbrev'),
  539. operator_user: TAPi18n.__('operator-user'),
  540. operator_user_abbrev: TAPi18n.__('operator-user-abbrev'),
  541. operator_member: TAPi18n.__('operator-member'),
  542. operator_member_abbrev: TAPi18n.__('operator-member-abbrev'),
  543. operator_assignee: TAPi18n.__('operator-assignee'),
  544. operator_assignee_abbrev: TAPi18n.__('operator-assignee-abbrev'),
  545. operator_due: TAPi18n.__('operator-due'),
  546. operator_created: TAPi18n.__('operator-created'),
  547. operator_modified: TAPi18n.__('operator-modified'),
  548. operator_status: TAPi18n.__('operator-status'),
  549. operator_has: TAPi18n.__('operator-has'),
  550. operator_sort: TAPi18n.__('operator-sort'),
  551. operator_limit: TAPi18n.__('operator-limit'),
  552. predicate_overdue: TAPi18n.__('predicate-overdue'),
  553. predicate_archived: TAPi18n.__('predicate-archived'),
  554. predicate_all: TAPi18n.__('predicate-all'),
  555. predicate_ended: TAPi18n.__('predicate-ended'),
  556. predicate_week: TAPi18n.__('predicate-week'),
  557. predicate_month: TAPi18n.__('predicate-month'),
  558. predicate_quarter: TAPi18n.__('predicate-quarter'),
  559. predicate_year: TAPi18n.__('predicate-year'),
  560. predicate_attachment: TAPi18n.__('predicate-attachment'),
  561. predicate_description: TAPi18n.__('predicate-description'),
  562. predicate_checklist: TAPi18n.__('predicate-checklist'),
  563. predicate_public: TAPi18n.__('predicate-public'),
  564. predicate_private: TAPi18n.__('predicate-private'),
  565. predicate_due: TAPi18n.__('predicate-due'),
  566. predicate_created: TAPi18n.__('predicate-created'),
  567. predicate_modified: TAPi18n.__('predicate-modified'),
  568. predicate_start: TAPi18n.__('predicate-start'),
  569. predicate_end: TAPi18n.__('predicate-end'),
  570. predicate_assignee: TAPi18n.__('predicate-assignee'),
  571. predicate_member: TAPi18n.__('predicate-member'),
  572. };
  573. text = `# ${TAPi18n.__('globalSearch-instructions-heading')}`;
  574. text += `\n${TAPi18n.__('globalSearch-instructions-description', tags)}`;
  575. text += `\n${TAPi18n.__('globalSearch-instructions-operators', tags)}`;
  576. text += `\n* ${TAPi18n.__(
  577. 'globalSearch-instructions-operator-board',
  578. tags,
  579. )}`;
  580. text += `\n* ${TAPi18n.__(
  581. 'globalSearch-instructions-operator-list',
  582. tags,
  583. )}`;
  584. text += `\n* ${TAPi18n.__(
  585. 'globalSearch-instructions-operator-swimlane',
  586. tags,
  587. )}`;
  588. text += `\n* ${TAPi18n.__(
  589. 'globalSearch-instructions-operator-comment',
  590. tags,
  591. )}`;
  592. text += `\n* ${TAPi18n.__(
  593. 'globalSearch-instructions-operator-label',
  594. tags,
  595. )}`;
  596. text += `\n* ${TAPi18n.__(
  597. 'globalSearch-instructions-operator-hash',
  598. tags,
  599. )}`;
  600. text += `\n* ${TAPi18n.__(
  601. 'globalSearch-instructions-operator-user',
  602. tags,
  603. )}`;
  604. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-at', tags)}`;
  605. text += `\n* ${TAPi18n.__(
  606. 'globalSearch-instructions-operator-member',
  607. tags,
  608. )}`;
  609. text += `\n* ${TAPi18n.__(
  610. 'globalSearch-instructions-operator-assignee',
  611. tags,
  612. )}`;
  613. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-due', tags)}`;
  614. text += `\n* ${TAPi18n.__(
  615. 'globalSearch-instructions-operator-created',
  616. tags,
  617. )}`;
  618. text += `\n* ${TAPi18n.__(
  619. 'globalSearch-instructions-operator-modified',
  620. tags,
  621. )}`;
  622. text += `\n* ${TAPi18n.__(
  623. 'globalSearch-instructions-status-archived',
  624. tags,
  625. )}`;
  626. text += `\n* ${TAPi18n.__(
  627. 'globalSearch-instructions-status-public',
  628. tags,
  629. )}`;
  630. text += `\n* ${TAPi18n.__(
  631. 'globalSearch-instructions-status-private',
  632. tags,
  633. )}`;
  634. text += `\n* ${TAPi18n.__('globalSearch-instructions-status-all', tags)}`;
  635. text += `\n* ${TAPi18n.__('globalSearch-instructions-status-ended', tags)}`;
  636. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-has', tags)}`;
  637. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-sort', tags)}`;
  638. text += `\n* ${TAPi18n.__('globalSearch-instructions-operator-limit', tags)}`;
  639. text += `\n## ${TAPi18n.__('heading-notes')}`;
  640. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-1', tags)}`;
  641. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-2', tags)}`;
  642. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-3', tags)}`;
  643. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-3-2', tags)}`;
  644. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-4', tags)}`;
  645. text += `\n* ${TAPi18n.__('globalSearch-instructions-notes-5', tags)}`;
  646. return text;
  647. },
  648. labelColors() {
  649. return Boards.simpleSchema()._schema['labels.$.color'].allowedValues.map(
  650. color => {
  651. return { color, name: TAPi18n.__(`color-${color}`) };
  652. },
  653. );
  654. },
  655. events() {
  656. return [
  657. {
  658. 'submit .js-search-query-form'(evt) {
  659. evt.preventDefault();
  660. this.searchAllBoards(evt.target.searchQuery.value);
  661. },
  662. 'click .js-next-page'(evt) {
  663. evt.preventDefault();
  664. this.nextPage();
  665. },
  666. 'click .js-previous-page'(evt) {
  667. evt.preventDefault();
  668. this.previousPage();
  669. },
  670. 'click .js-label-color'(evt) {
  671. evt.preventDefault();
  672. const input = document.getElementById('global-search-input');
  673. this.query.set(
  674. `${input.value} ${TAPi18n.__('operator-label')}:"${
  675. evt.currentTarget.textContent
  676. }"`,
  677. );
  678. document.getElementById('global-search-input').focus();
  679. },
  680. 'click .js-board-title'(evt) {
  681. evt.preventDefault();
  682. const input = document.getElementById('global-search-input');
  683. this.query.set(
  684. `${input.value} ${TAPi18n.__('operator-board')}:"${
  685. evt.currentTarget.textContent
  686. }"`,
  687. );
  688. document.getElementById('global-search-input').focus();
  689. },
  690. 'click .js-list-title'(evt) {
  691. evt.preventDefault();
  692. const input = document.getElementById('global-search-input');
  693. this.query.set(
  694. `${input.value} ${TAPi18n.__('operator-list')}:"${
  695. evt.currentTarget.textContent
  696. }"`,
  697. );
  698. document.getElementById('global-search-input').focus();
  699. },
  700. 'click .js-label-name'(evt) {
  701. evt.preventDefault();
  702. const input = document.getElementById('global-search-input');
  703. this.query.set(
  704. `${input.value} ${TAPi18n.__('operator-label')}:"${
  705. evt.currentTarget.textContent
  706. }"`,
  707. );
  708. document.getElementById('global-search-input').focus();
  709. },
  710. },
  711. ];
  712. },
  713. }).register('globalSearch');