2021-07-10 10:55:54 +02:00
|
|
|
import { TAPi18n } from '/imports/i18n';
|
2021-03-01 01:49:56 +02:00
|
|
|
import { CardSearchPagedComponent } from '../../lib/cardSearch';
|
2021-03-09 19:30:04 +02:00
|
|
|
import Boards from '../../../models/boards';
|
2021-03-10 12:39:39 +02:00
|
|
|
import { Query, QueryErrors } from '../../../config/query-classes';
|
2021-03-01 01:49:56 +02:00
|
|
|
|
|
|
|
|
// const subManager = new SubsManager();
|
2021-01-10 21:52:25 +02:00
|
|
|
|
|
|
|
|
BlazeComponent.extendComponent({
|
|
|
|
|
events() {
|
|
|
|
|
return [
|
|
|
|
|
{
|
|
|
|
|
'click .js-due-cards-view-change': Popup.open('globalSearchViewChange'),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
},
|
|
|
|
|
}).register('globalSearchHeaderBar');
|
|
|
|
|
|
|
|
|
|
Template.globalSearch.helpers({
|
|
|
|
|
userId() {
|
|
|
|
|
return Meteor.userId();
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2021-03-01 01:49:56 +02:00
|
|
|
class GlobalSearchComponent extends CardSearchPagedComponent {
|
2021-01-10 21:52:25 +02:00
|
|
|
onCreated() {
|
2021-03-01 01:49:56 +02:00
|
|
|
super.onCreated();
|
2021-01-20 21:52:27 +02:00
|
|
|
this.myLists = new ReactiveVar([]);
|
2021-01-21 01:48:24 +02:00
|
|
|
this.myLabelNames = new ReactiveVar([]);
|
|
|
|
|
this.myBoardNames = new ReactiveVar([]);
|
2021-03-09 19:30:04 +02:00
|
|
|
this.parsingErrors = new QueryErrors();
|
2021-03-01 01:49:56 +02:00
|
|
|
this.queryParams = null;
|
2021-01-20 21:52:27 +02:00
|
|
|
|
|
|
|
|
Meteor.call('myLists', (err, data) => {
|
|
|
|
|
if (!err) {
|
|
|
|
|
this.myLists.set(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-01-21 01:48:24 +02:00
|
|
|
Meteor.call('myLabelNames', (err, data) => {
|
|
|
|
|
if (!err) {
|
|
|
|
|
this.myLabelNames.set(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Meteor.call('myBoardNames', (err, data) => {
|
|
|
|
|
if (!err) {
|
|
|
|
|
this.myBoardNames.set(data);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-21 01:48:24 +02:00
|
|
|
|
2021-01-25 00:07:50 +02:00
|
|
|
onRendered() {
|
2021-01-10 21:52:25 +02:00
|
|
|
Meteor.subscribe('setting');
|
2021-01-25 15:39:36 +02:00
|
|
|
|
2021-02-02 17:56:18 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2021-02-02 18:31:13 +02:00
|
|
|
//console.log('lang:', TAPi18n.getLanguage());
|
2021-01-25 15:39:36 +02:00
|
|
|
|
2021-01-17 16:01:42 +02:00
|
|
|
if (Session.get('globalQuery')) {
|
|
|
|
|
this.searchAllBoards(Session.get('globalQuery'));
|
|
|
|
|
}
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-17 16:01:42 +02:00
|
|
|
|
|
|
|
|
resetSearch() {
|
2021-03-01 01:49:56 +02:00
|
|
|
super.resetSearch();
|
2021-03-09 19:30:04 +02:00
|
|
|
this.parsingErrors = new QueryErrors();
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-10 22:58:29 +02:00
|
|
|
|
2021-01-13 01:14:49 +02:00
|
|
|
errorMessages() {
|
2021-03-09 19:30:04 +02:00
|
|
|
if (this.parsingErrors.hasErrors()) {
|
|
|
|
|
return this.parsingErrors.errorMessages();
|
2021-01-25 15:39:36 +02:00
|
|
|
}
|
|
|
|
|
return this.queryErrorMessages();
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-25 15:39:36 +02:00
|
|
|
|
|
|
|
|
parsingErrorMessages() {
|
2021-03-09 19:30:04 +02:00
|
|
|
this.parsingErrors.errorMessages();
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-25 15:39:36 +02:00
|
|
|
|
2021-03-10 12:39:39 +02:00
|
|
|
searchAllBoards(queryText) {
|
|
|
|
|
queryText = queryText.trim();
|
2021-01-24 15:38:44 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2021-03-10 12:39:39 +02:00
|
|
|
//console.log('queryText:', queryText);
|
2021-01-24 15:38:44 +02:00
|
|
|
|
2021-03-10 12:39:39 +02:00
|
|
|
this.query.set(queryText);
|
2021-01-17 16:01:42 +02:00
|
|
|
|
|
|
|
|
this.resetSearch();
|
|
|
|
|
|
2021-03-10 12:39:39 +02:00
|
|
|
if (!queryText) {
|
2021-01-17 16:01:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 12:52:49 +02:00
|
|
|
this.searching.set(true);
|
|
|
|
|
|
2021-03-10 12:39:39 +02:00
|
|
|
const query = new Query();
|
|
|
|
|
query.buildParams(queryText);
|
2021-01-22 23:07:38 +02:00
|
|
|
|
2021-01-26 18:39:09 +02:00
|
|
|
// eslint-disable-next-line no-console
|
2021-03-10 12:39:39 +02:00
|
|
|
// console.log('params:', query.getParams());
|
2021-01-25 19:01:07 +02:00
|
|
|
|
2021-03-31 13:05:39 +02:00
|
|
|
this.queryParams = query.getQueryParams().getParams();
|
2021-01-17 16:01:42 +02:00
|
|
|
|
2021-03-10 12:39:39 +02:00
|
|
|
if (query.hasErrors()) {
|
2021-01-24 15:38:44 +02:00
|
|
|
this.searching.set(false);
|
2021-03-10 12:39:39 +02:00
|
|
|
this.queryErrors = query.errors();
|
2021-01-26 18:39:09 +02:00
|
|
|
this.hasResults.set(true);
|
2021-01-24 15:38:44 +02:00
|
|
|
this.hasQueryErrors.set(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-31 13:05:39 +02:00
|
|
|
this.runGlobalSearch(query.getQueryParams());
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-28 16:31:49 +02:00
|
|
|
|
2021-01-17 00:05:45 +02:00
|
|
|
searchInstructions() {
|
2021-03-01 01:49:56 +02:00
|
|
|
const tags = {
|
2021-01-17 00:05:45 +02:00
|
|
|
operator_board: TAPi18n.__('operator-board'),
|
|
|
|
|
operator_list: TAPi18n.__('operator-list'),
|
|
|
|
|
operator_swimlane: TAPi18n.__('operator-swimlane'),
|
2021-01-26 18:39:09 +02:00
|
|
|
operator_comment: TAPi18n.__('operator-comment'),
|
2021-01-17 00:05:45 +02:00
|
|
|
operator_label: TAPi18n.__('operator-label'),
|
|
|
|
|
operator_label_abbrev: TAPi18n.__('operator-label-abbrev'),
|
|
|
|
|
operator_user: TAPi18n.__('operator-user'),
|
|
|
|
|
operator_user_abbrev: TAPi18n.__('operator-user-abbrev'),
|
2021-01-17 16:01:42 +02:00
|
|
|
operator_member: TAPi18n.__('operator-member'),
|
|
|
|
|
operator_member_abbrev: TAPi18n.__('operator-member-abbrev'),
|
|
|
|
|
operator_assignee: TAPi18n.__('operator-assignee'),
|
|
|
|
|
operator_assignee_abbrev: TAPi18n.__('operator-assignee-abbrev'),
|
2021-04-01 23:41:32 +02:00
|
|
|
operator_creator: TAPi18n.__('operator-creator'),
|
2021-01-26 18:39:09 +02:00
|
|
|
operator_due: TAPi18n.__('operator-due'),
|
|
|
|
|
operator_created: TAPi18n.__('operator-created'),
|
|
|
|
|
operator_modified: TAPi18n.__('operator-modified'),
|
|
|
|
|
operator_status: TAPi18n.__('operator-status'),
|
2021-02-21 19:57:35 +02:00
|
|
|
operator_has: TAPi18n.__('operator-has'),
|
2021-02-26 18:51:54 +02:00
|
|
|
operator_sort: TAPi18n.__('operator-sort'),
|
|
|
|
|
operator_limit: TAPi18n.__('operator-limit'),
|
2021-12-22 23:26:41 +02:00
|
|
|
operator_debug: TAPi18n.__('operator-debug'),
|
|
|
|
|
operator_org: TAPi18n.__('operator-org'),
|
|
|
|
|
operator_team: TAPi18n.__('operator-team'),
|
2021-01-26 18:39:09 +02:00
|
|
|
predicate_overdue: TAPi18n.__('predicate-overdue'),
|
|
|
|
|
predicate_archived: TAPi18n.__('predicate-archived'),
|
|
|
|
|
predicate_all: TAPi18n.__('predicate-all'),
|
|
|
|
|
predicate_ended: TAPi18n.__('predicate-ended'),
|
|
|
|
|
predicate_week: TAPi18n.__('predicate-week'),
|
|
|
|
|
predicate_month: TAPi18n.__('predicate-month'),
|
|
|
|
|
predicate_quarter: TAPi18n.__('predicate-quarter'),
|
|
|
|
|
predicate_year: TAPi18n.__('predicate-year'),
|
2021-02-21 19:57:35 +02:00
|
|
|
predicate_attachment: TAPi18n.__('predicate-attachment'),
|
|
|
|
|
predicate_description: TAPi18n.__('predicate-description'),
|
|
|
|
|
predicate_checklist: TAPi18n.__('predicate-checklist'),
|
2021-02-23 17:56:28 +02:00
|
|
|
predicate_public: TAPi18n.__('predicate-public'),
|
|
|
|
|
predicate_private: TAPi18n.__('predicate-private'),
|
2021-02-26 18:51:54 +02:00
|
|
|
predicate_due: TAPi18n.__('predicate-due'),
|
|
|
|
|
predicate_created: TAPi18n.__('predicate-created'),
|
|
|
|
|
predicate_modified: TAPi18n.__('predicate-modified'),
|
2021-02-27 02:26:58 +02:00
|
|
|
predicate_start: TAPi18n.__('predicate-start'),
|
|
|
|
|
predicate_end: TAPi18n.__('predicate-end'),
|
|
|
|
|
predicate_assignee: TAPi18n.__('predicate-assignee'),
|
|
|
|
|
predicate_member: TAPi18n.__('predicate-member'),
|
2021-12-22 23:34:12 +02:00
|
|
|
predicate_selector: TAPi18n.__('predicate-selector'),
|
|
|
|
|
predicate_projection: TAPi18n.__('predicate-projection'),
|
2021-01-17 00:05:45 +02:00
|
|
|
};
|
|
|
|
|
|
2021-03-04 02:13:22 +02:00
|
|
|
let text = '';
|
2021-02-27 17:02:42 +02:00
|
|
|
[
|
2021-03-04 02:13:22 +02:00
|
|
|
['# ', 'globalSearch-instructions-heading'],
|
|
|
|
|
['\n', 'globalSearch-instructions-description'],
|
|
|
|
|
['\n\n', 'globalSearch-instructions-operators'],
|
2021-06-29 13:38:57 +03:00
|
|
|
['\n- ', 'globalSearch-instructions-operator-board'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-list'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-swimlane'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-comment'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-label'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-hash'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-user'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-at'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-member'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-assignee'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-creator'],
|
2021-12-22 23:26:41 +02:00
|
|
|
['\n- ', 'globalSearch-instructions-operator-org'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-team'],
|
2021-06-29 13:38:57 +03:00
|
|
|
['\n- ', 'globalSearch-instructions-operator-due'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-created'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-modified'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-status'],
|
|
|
|
|
['\n - ', 'globalSearch-instructions-status-archived'],
|
|
|
|
|
['\n - ', 'globalSearch-instructions-status-public'],
|
|
|
|
|
['\n - ', 'globalSearch-instructions-status-private'],
|
|
|
|
|
['\n - ', 'globalSearch-instructions-status-all'],
|
|
|
|
|
['\n - ', 'globalSearch-instructions-status-ended'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-has'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-sort'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-operator-limit'],
|
2021-03-04 02:13:22 +02:00
|
|
|
['\n## ', 'heading-notes'],
|
2021-06-29 13:38:57 +03:00
|
|
|
['\n- ', 'globalSearch-instructions-notes-1'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-notes-2'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-notes-3'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-notes-3-2'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-notes-4'],
|
|
|
|
|
['\n- ', 'globalSearch-instructions-notes-5'],
|
2021-03-04 02:13:22 +02:00
|
|
|
].forEach(([prefix, instruction]) => {
|
2021-06-29 13:38:57 +03:00
|
|
|
text += `${prefix}${TAPi18n.__(instruction, tags)}`
|
|
|
|
|
// Replace *<text>* with `<text>` so markdown shows correctly
|
|
|
|
|
.replace(/\*\</, '`<')
|
|
|
|
|
.replace(/\>\*/, '\>\`')
|
2021-02-27 17:02:42 +02:00
|
|
|
});
|
2021-01-17 00:05:45 +02:00
|
|
|
return text;
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-17 00:05:45 +02:00
|
|
|
|
2021-01-20 13:15:10 +02:00
|
|
|
labelColors() {
|
|
|
|
|
return Boards.simpleSchema()._schema['labels.$.color'].allowedValues.map(
|
|
|
|
|
color => {
|
|
|
|
|
return { color, name: TAPi18n.__(`color-${color}`) };
|
|
|
|
|
},
|
|
|
|
|
);
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
2021-01-20 13:15:10 +02:00
|
|
|
|
2021-01-10 21:52:25 +02:00
|
|
|
events() {
|
2021-04-06 12:24:08 +02:00
|
|
|
return super.events().concat([
|
2021-01-10 21:52:25 +02:00
|
|
|
{
|
|
|
|
|
'submit .js-search-query-form'(evt) {
|
|
|
|
|
evt.preventDefault();
|
2021-01-17 16:01:42 +02:00
|
|
|
this.searchAllBoards(evt.target.searchQuery.value);
|
2021-01-10 21:52:25 +02:00
|
|
|
},
|
2021-01-21 01:48:24 +02:00
|
|
|
'click .js-label-color'(evt) {
|
|
|
|
|
evt.preventDefault();
|
2021-01-25 01:35:44 +02:00
|
|
|
const input = document.getElementById('global-search-input');
|
2021-01-21 01:48:24 +02:00
|
|
|
this.query.set(
|
2021-01-25 01:35:44 +02:00
|
|
|
`${input.value} ${TAPi18n.__('operator-label')}:"${
|
2021-01-21 01:48:24 +02:00
|
|
|
evt.currentTarget.textContent
|
|
|
|
|
}"`,
|
|
|
|
|
);
|
2021-01-21 11:55:58 +02:00
|
|
|
document.getElementById('global-search-input').focus();
|
2021-01-21 01:48:24 +02:00
|
|
|
},
|
2021-12-20 14:33:42 +02:00
|
|
|
'click .js-copy-debug-selector'(evt) {
|
|
|
|
|
/* Get the text field */
|
|
|
|
|
const selector = document.getElementById("debug-selector");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
navigator.clipboard.writeText(selector.textContent);
|
|
|
|
|
alert("Selector copied to clipboard");
|
|
|
|
|
} catch(err) {
|
|
|
|
|
alert("Error copying text: " + err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
'click .js-copy-debug-projection'(evt) {
|
|
|
|
|
/* Get the text field */
|
|
|
|
|
const projection = document.getElementById("debug-projection");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
navigator.clipboard.writeText(projection.textContent);
|
|
|
|
|
alert("Projection copied to clipboard");
|
|
|
|
|
} catch(err) {
|
|
|
|
|
alert("Error copying text: " + err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
2021-01-21 01:48:24 +02:00
|
|
|
'click .js-board-title'(evt) {
|
|
|
|
|
evt.preventDefault();
|
2021-01-25 01:35:44 +02:00
|
|
|
const input = document.getElementById('global-search-input');
|
2021-01-20 13:15:10 +02:00
|
|
|
this.query.set(
|
2021-01-25 01:35:44 +02:00
|
|
|
`${input.value} ${TAPi18n.__('operator-board')}:"${
|
2021-01-21 01:48:24 +02:00
|
|
|
evt.currentTarget.textContent
|
|
|
|
|
}"`,
|
2021-01-20 13:15:10 +02:00
|
|
|
);
|
2021-01-21 11:55:58 +02:00
|
|
|
document.getElementById('global-search-input').focus();
|
2021-01-20 13:15:10 +02:00
|
|
|
},
|
2021-01-20 21:52:27 +02:00
|
|
|
'click .js-list-title'(evt) {
|
2021-01-21 01:48:24 +02:00
|
|
|
evt.preventDefault();
|
2021-01-25 01:35:44 +02:00
|
|
|
const input = document.getElementById('global-search-input');
|
2021-01-21 01:48:24 +02:00
|
|
|
this.query.set(
|
2021-01-25 01:35:44 +02:00
|
|
|
`${input.value} ${TAPi18n.__('operator-list')}:"${
|
2021-01-21 01:48:24 +02:00
|
|
|
evt.currentTarget.textContent
|
|
|
|
|
}"`,
|
|
|
|
|
);
|
2021-01-21 11:55:58 +02:00
|
|
|
document.getElementById('global-search-input').focus();
|
2021-01-21 01:48:24 +02:00
|
|
|
},
|
|
|
|
|
'click .js-label-name'(evt) {
|
|
|
|
|
evt.preventDefault();
|
2021-01-25 01:35:44 +02:00
|
|
|
const input = document.getElementById('global-search-input');
|
2021-01-20 21:52:27 +02:00
|
|
|
this.query.set(
|
2021-01-25 01:35:44 +02:00
|
|
|
`${input.value} ${TAPi18n.__('operator-label')}:"${
|
2021-01-21 01:48:24 +02:00
|
|
|
evt.currentTarget.textContent
|
|
|
|
|
}"`,
|
2021-01-20 21:52:27 +02:00
|
|
|
);
|
2021-01-21 11:55:58 +02:00
|
|
|
document.getElementById('global-search-input').focus();
|
2021-01-20 21:52:27 +02:00
|
|
|
},
|
2021-03-28 02:46:11 +02:00
|
|
|
'click .js-new-search'(evt) {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
const input = document.getElementById('global-search-input');
|
|
|
|
|
input.value = '';
|
|
|
|
|
this.query.set('');
|
|
|
|
|
this.hasResults.set(false);
|
|
|
|
|
},
|
2021-01-10 21:52:25 +02:00
|
|
|
},
|
2021-04-06 12:24:08 +02:00
|
|
|
]);
|
2021-03-01 01:49:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GlobalSearchComponent.register('globalSearch');
|