mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
Global search display total hits
* modify User model to store some session data for searches * Display total hits in search results
This commit is contained in:
parent
c11c3f9a88
commit
3214800741
5 changed files with 49 additions and 7 deletions
|
@ -21,8 +21,10 @@ template(name="globalSearch")
|
|||
| {{_ 'no-results' }}
|
||||
else if $eq resultsCount.get 1
|
||||
| {{_ 'one-result' }}
|
||||
else
|
||||
else if $eq resultsCount.get totalHits.get
|
||||
| {{_ 'n-results' resultsCount.get }}
|
||||
else
|
||||
| {{_ 'n-of-n-results' resultsCount.get totalHits.get }}
|
||||
if queryErrors.get
|
||||
div
|
||||
each msg in errorMessages
|
||||
|
|
|
@ -42,6 +42,7 @@ BlazeComponent.extendComponent({
|
|||
this.query = new ReactiveVar('');
|
||||
this.queryParams = null;
|
||||
this.resultsCount = new ReactiveVar(0);
|
||||
this.totalHits = new ReactiveVar(0);
|
||||
this.queryErrors = new ReactiveVar(null);
|
||||
Meteor.subscribe('setting');
|
||||
},
|
||||
|
@ -50,7 +51,9 @@ BlazeComponent.extendComponent({
|
|||
if (this.queryParams) {
|
||||
const results = Cards.globalSearch(this.queryParams);
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('count:', results.count);
|
||||
// console.log('errors:', results.errors);
|
||||
this.totalHits.set(Meteor.user().sessionData.totalHits);
|
||||
this.resultsCount.set(results.cards.count());
|
||||
this.queryErrors.set(results.errors);
|
||||
return results.cards;
|
||||
|
|
|
@ -872,6 +872,7 @@
|
|||
"globalSearch-title": "Search All Boards",
|
||||
"one-results": "One Result",
|
||||
"n-results": "%s Results",
|
||||
"n-of-n-results": "%s of %s Results",
|
||||
"operator-board": "board",
|
||||
"operator-board-abbrev": "b",
|
||||
"operator-swimlane": "swimlane",
|
||||
|
|
|
@ -1733,7 +1733,7 @@ Cards.mutations({
|
|||
Cards.globalSearch = queryParams => {
|
||||
const userId = Meteor.userId();
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('userId:', userId);
|
||||
// console.log('userId:', userId);
|
||||
|
||||
const errors = {
|
||||
notFound: {
|
||||
|
@ -1756,7 +1756,7 @@ Cards.globalSearch = queryParams => {
|
|||
const queryBoards = [];
|
||||
queryParams.boards.forEach(query => {
|
||||
const boards = Boards.userSearch(userId, {
|
||||
title: query,
|
||||
title: new RegExp(query, 'i'),
|
||||
});
|
||||
if (boards.count()) {
|
||||
boards.forEach(board => {
|
||||
|
@ -1774,7 +1774,7 @@ Cards.globalSearch = queryParams => {
|
|||
const querySwimlanes = [];
|
||||
queryParams.swimlanes.forEach(query => {
|
||||
const swimlanes = Swimlanes.find({
|
||||
title: query,
|
||||
title: new RegExp(query, 'i'),
|
||||
});
|
||||
if (swimlanes.count()) {
|
||||
swimlanes.forEach(swim => {
|
||||
|
@ -1792,7 +1792,7 @@ Cards.globalSearch = queryParams => {
|
|||
const queryLists = [];
|
||||
queryParams.lists.forEach(query => {
|
||||
const lists = Lists.find({
|
||||
title: query,
|
||||
title: new RegExp(query, 'i'),
|
||||
});
|
||||
if (lists.count()) {
|
||||
lists.forEach(list => {
|
||||
|
@ -1885,7 +1885,7 @@ Cards.globalSearch = queryParams => {
|
|||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('selector:', selector);
|
||||
// console.log('selector:', selector);
|
||||
const cards = Cards.find(selector, {
|
||||
fields: {
|
||||
_id: 1,
|
||||
|
@ -1906,7 +1906,16 @@ Cards.globalSearch = queryParams => {
|
|||
});
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('count:', cards.count());
|
||||
// console.log('count:', cards.count());
|
||||
|
||||
if (Meteor.isServer) {
|
||||
Users.update(userId, {
|
||||
$set: {
|
||||
'sessionData.totalHits': cards.count(),
|
||||
'sessionData.lastHit': cards.count() > 50 ? 50 : cards.count(),
|
||||
},
|
||||
});
|
||||
}
|
||||
return { cards, errors };
|
||||
};
|
||||
|
||||
|
|
|
@ -311,6 +311,33 @@ Users.attachSchema(
|
|||
optional: false,
|
||||
defaultValue: 'password',
|
||||
},
|
||||
sessionData: {
|
||||
/**
|
||||
* profile settings
|
||||
*/
|
||||
type: Object,
|
||||
optional: true,
|
||||
// eslint-disable-next-line consistent-return
|
||||
autoValue() {
|
||||
if (this.isInsert && !this.isSet) {
|
||||
return {};
|
||||
}
|
||||
},
|
||||
},
|
||||
'sessionData.totalHits': {
|
||||
/**
|
||||
* Total hits from last search
|
||||
*/
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
'sessionData.lastHit': {
|
||||
/**
|
||||
* last hit that was returned
|
||||
*/
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue