const subManager = new SubsManager(); BlazeComponent.extendComponent({ events() { return [ { 'click .js-due-cards-view-change': Popup.open('globalSearchViewChange'), }, ]; }, }).register('globalSearchHeaderBar'); Template.globalSearch.helpers({ userId() { return Meteor.userId(); }, }); BlazeComponent.extendComponent({ events() { return [ { 'click .js-due-cards-view-me'() { Utils.setDueCardsView('me'); Popup.close(); }, 'click .js-due-cards-view-all'() { Utils.setDueCardsView('all'); Popup.close(); }, }, ]; }, }).register('globalSearchViewChangePopup'); BlazeComponent.extendComponent({ onCreated() { this.isPageReady = new ReactiveVar(true); this.searching = new ReactiveVar(false); this.hasResults = new ReactiveVar(false); this.query = new ReactiveVar(''); this.queryParams = null; this.resultsCount = new ReactiveVar(0); this.queryErrors = new ReactiveVar(null); Meteor.subscribe('setting'); }, results() { if (this.queryParams) { const results = Cards.globalSearch(this.queryParams); // eslint-disable-next-line no-console // console.log('errors:', results.errors); this.resultsCount.set(results.cards.count()); this.queryErrors.set(results.errors); return results.cards; } this.resultsCount.set(0); return []; }, errorMessages() { const errors = this.queryErrors.get(); const messages = []; errors.notFound.boards.forEach(board => { messages.push({ tag: 'board-title-not-found', value: board }); }); errors.notFound.swimlanes.forEach(swim => { messages.push({ tag: 'swimlane-title-not-found', value: swim }); }); errors.notFound.lists.forEach(list => { messages.push({ tag: 'list-title-not-found', value: list }); }); errors.notFound.users.forEach(user => { messages.push({ tag: 'user-username-not-found', value: user }); }); return messages; }, events() { return [ { 'submit .js-search-query-form'(evt) { evt.preventDefault(); this.query.set(evt.target.searchQuery.value); this.queryErrors.set(null); if (!this.query.get()) { this.searching.set(false); this.hasResults.set(false); return; } this.searching.set(true); this.hasResults.set(false); let query = this.query.get(); // eslint-disable-next-line no-console // console.log('query:', query); const reUser = /^@(?[\w.:]+)(\s+|$)/; const reLabel = /^#(?