diff --git a/client/components/main/globalSearch.jade b/client/components/main/globalSearch.jade index c0351f4e4..61ef2f2c4 100644 --- a/client/components/main/globalSearch.jade +++ b/client/components/main/globalSearch.jade @@ -37,12 +37,16 @@ template(name="globalSearch") a.fa.fa-link(title="{{_ 'link-to-search' }}" href="{{ getSearchHref }}") each card in results.get +resultCard(card) - if hasPreviousPage.get - button.js-previous-page - | {{_ 'previous-page' }} - if hasNextPage.get - button.js-next-page - | {{_ 'next-page' }} + table.global-search-footer + tr + td.global-search-previous-page + if hasPreviousPage.get + button.js-previous-page + | {{_ 'previous-page' }} + td.global-search-next-page(align="right") + if hasNextPage.get + button.js-next-page + | {{_ 'next-page' }} else .global-search-instructions h2 {{_ 'boards' }} diff --git a/client/components/main/globalSearch.js b/client/components/main/globalSearch.js index 4da421e67..e17e33505 100644 --- a/client/components/main/globalSearch.js +++ b/client/components/main/globalSearch.js @@ -116,7 +116,7 @@ BlazeComponent.extendComponent({ if (this.queryParams) { const sessionData = this.getSessionData(); // eslint-disable-next-line no-console - console.log('selector:', JSON.parse(sessionData.selector)); + console.log('selector:', sessionData.getSelector()); // console.log('session data:', sessionData); const cards = Cards.find({ _id: { $in: sessionData.cards } }); this.queryErrors = sessionData.errors; @@ -414,7 +414,7 @@ BlazeComponent.extendComponent({ const params = { limit: this.resultsPerPage, - selector: JSON.parse(sessionData.selector), + selector: sessionData.getSelector(), skip: sessionData.lastHit, }; @@ -441,7 +441,7 @@ BlazeComponent.extendComponent({ const params = { limit: this.resultsPerPage, - selector: JSON.parse(sessionData.selector), + selector: sessionData.getSelector(), skip: sessionData.lastHit - sessionData.resultsCount - this.resultsPerPage, }; diff --git a/client/components/main/globalSearch.styl b/client/components/main/globalSearch.styl index b982f4eed..e460f506e 100644 --- a/client/components/main/globalSearch.styl +++ b/client/components/main/globalSearch.styl @@ -104,3 +104,15 @@ code .list-title background-color: darkgray + +.global-search-footer + border: none + width: 100% + +.global-search-next-page + border: none + text-align: right; + +.global-search-previous-page + border: none + text-align: left; diff --git a/models/cardComments.js b/models/cardComments.js index b366fc57d..88f384163 100644 --- a/models/cardComments.js +++ b/models/cardComments.js @@ -121,7 +121,7 @@ CardComments.textSearch = (userId, textArray) => { } // eslint-disable-next-line no-console - console.log('cardComments selector:', selector); + // console.log('cardComments selector:', selector); const comments = CardComments.find(selector); // eslint-disable-next-line no-console diff --git a/models/usersessiondata.js b/models/usersessiondata.js index 8309cf038..129fe56ba 100644 --- a/models/usersessiondata.js +++ b/models/usersessiondata.js @@ -126,6 +126,40 @@ SessionData.attachSchema( }), ); +SessionData.helpers({ + getSelector() { + return SessionData.unpickle(this.selector); + }, +}); + +SessionData.unpickle = pickle => { + return JSON.parse(pickle, (key, value) => { + if (typeof value === 'object') { + if (value.hasOwnProperty('$$class')) { + if (value.$$class === 'RegExp') { + return new RegExp(value.source, value.flags); + } + } + } + return value; + }); +}; + +SessionData.pickle = value => { + return JSON.stringify(value, (key, value) => { + if (typeof value === 'object') { + if (value.constructor.name === 'RegExp') { + return { + $$class: 'RegExp', + source: value.source, + flags: value.flags, + }; + } + } + return value; + }); +}; + if (!Meteor.isServer) { SessionData.getSessionId = () => { let sessionId = Session.get('sessionId'); diff --git a/server/publications/cards.js b/server/publications/cards.js index 7ed1bd597..d27204f77 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -179,6 +179,9 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) { check(sessionId, String); check(queryParams, Object); + // eslint-disable-next-line no-console + // console.log('queryParams:', queryParams); + const userId = Meteor.userId(); // eslint-disable-next-line no-console // console.log('userId:', userId); @@ -338,6 +341,9 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) { } }); + if (!selector.swimlaneId.hasOwnProperty('swimlaneId')) { + selector.swimlaneId = { $in: [] }; + } selector.swimlaneId.$in = querySwimlanes; } @@ -356,6 +362,9 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) { } }); + if (!selector.hasOwnProperty('listId')) { + selector.listId = { $in: [] }; + } selector.listId.$in = queryLists; } @@ -521,9 +530,9 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) { } // eslint-disable-next-line no-console - console.log('selector:', selector); + // console.log('selector:', selector); // eslint-disable-next-line no-console - console.log('selector.$and:', selector.$and); + // console.log('selector.$and:', selector.$and); let cards = null; @@ -585,11 +594,11 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) { } // eslint-disable-next-line no-console - console.log('projection:', projection); + // console.log('projection:', projection); cards = Cards.find(selector, projection); // eslint-disable-next-line no-console - console.log('count:', cards.count()); + // console.log('count:', cards.count()); } const update = { @@ -599,7 +608,7 @@ Meteor.publish('globalSearch', function(sessionId, queryParams) { resultsCount: 0, cards: [], errors: errors.errorMessages(), - selector: JSON.stringify(selector), + selector: SessionData.pickle(selector), }, };