mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
Global search - add error messages for terms that are not found
This commit is contained in:
parent
4ab1a04814
commit
80b23e5cc1
7 changed files with 129 additions and 57 deletions
|
@ -19,6 +19,11 @@ template(name="globalSearch")
|
||||||
h1
|
h1
|
||||||
= resultsCount.get
|
= resultsCount.get
|
||||||
| Results
|
| Results
|
||||||
|
if queryErrors.get
|
||||||
|
div
|
||||||
|
each msg in errorMessages
|
||||||
|
span.global-search-error-messages
|
||||||
|
| {{_ msg.tag msg.value }}
|
||||||
each card in results
|
each card in results
|
||||||
.global-search-card-wrapper
|
.global-search-card-wrapper
|
||||||
a.minicard-wrapper.card-title(href=card.absoluteUrl)
|
a.minicard-wrapper.card-title(href=card.absoluteUrl)
|
||||||
|
|
|
@ -42,33 +42,50 @@ BlazeComponent.extendComponent({
|
||||||
this.query = new ReactiveVar('');
|
this.query = new ReactiveVar('');
|
||||||
this.queryParams = null;
|
this.queryParams = null;
|
||||||
this.resultsCount = new ReactiveVar(0);
|
this.resultsCount = new ReactiveVar(0);
|
||||||
|
this.queryErrors = new ReactiveVar(null);
|
||||||
// this.autorun(() => {
|
|
||||||
// const handle = subManager.subscribe('globalSearch');
|
|
||||||
// Tracker.nonreactive(() => {
|
|
||||||
// Tracker.autorun(() => {
|
|
||||||
// this.isPageReady.set(handle.ready());
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
Meteor.subscribe('setting');
|
Meteor.subscribe('setting');
|
||||||
},
|
},
|
||||||
|
|
||||||
results() {
|
results() {
|
||||||
if (this.queryParams) {
|
if (this.queryParams) {
|
||||||
const cards = Cards.globalSearch(this.queryParams);
|
const results = Cards.globalSearch(this.queryParams);
|
||||||
this.resultsCount.set(cards.count());
|
// eslint-disable-next-line no-console
|
||||||
return cards;
|
console.log('errors:', results.errors);
|
||||||
|
this.resultsCount.set(results.cards.count());
|
||||||
|
this.queryErrors.set(results.errors);
|
||||||
|
return results.cards;
|
||||||
}
|
}
|
||||||
|
this.resultsCount.set(0);
|
||||||
return [];
|
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() {
|
events() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
'submit .js-search-query-form'(evt) {
|
'submit .js-search-query-form'(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
this.query.set(evt.target.searchQuery.value);
|
this.query.set(evt.target.searchQuery.value);
|
||||||
|
this.queryErrors.set(null);
|
||||||
|
|
||||||
if (!this.query.get()) {
|
if (!this.query.get()) {
|
||||||
this.searching.set(false);
|
this.searching.set(false);
|
||||||
|
|
|
@ -67,3 +67,6 @@
|
||||||
|
|
||||||
.global-search-context-list
|
.global-search-context-list
|
||||||
margin-bottom: 0.7rem
|
margin-bottom: 0.7rem
|
||||||
|
|
||||||
|
.global-search-error-messages
|
||||||
|
color: darkred
|
||||||
|
|
|
@ -861,5 +861,9 @@
|
||||||
"dueCardsViewChange-title": "Due Cards View",
|
"dueCardsViewChange-title": "Due Cards View",
|
||||||
"dueCardsViewChange-choice-me": "Me",
|
"dueCardsViewChange-choice-me": "Me",
|
||||||
"dueCardsViewChange-choice-all": "All Users",
|
"dueCardsViewChange-choice-all": "All Users",
|
||||||
"dueCardsViewChange-choice-all-description": "Shows all incomplete cards with a *Due* date from boards for which the user has permission."
|
"dueCardsViewChange-choice-all-description": "Shows all incomplete cards with a *Due* date from boards for which the user has permission.",
|
||||||
|
"board-title-not-found": "Board '%s' not found.",
|
||||||
|
"swimlane-title-not-found": "Swimlane '%s' not found.",
|
||||||
|
"list-title-not-found": "List '%s' not found.",
|
||||||
|
"user-username-not-found": "Username '%s' not found."
|
||||||
}
|
}
|
||||||
|
|
|
@ -1208,6 +1208,20 @@ function boardRemover(userId, doc) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Boards.userSearch = (userId, includeArchived = false, selector = {}) => {
|
||||||
|
if (!includeArchived) {
|
||||||
|
selector = {
|
||||||
|
archived: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
selector.$or = [
|
||||||
|
{ permission: 'public' },
|
||||||
|
{ members: { $elemMatch: { userId, isActive: true } } },
|
||||||
|
];
|
||||||
|
|
||||||
|
return Boards.find(selector);
|
||||||
|
};
|
||||||
|
|
||||||
Boards.userBoards = (userId, includeArchived = false, selector = {}) => {
|
Boards.userBoards = (userId, includeArchived = false, selector = {}) => {
|
||||||
if (!includeArchived) {
|
if (!includeArchived) {
|
||||||
selector = {
|
selector = {
|
||||||
|
|
115
models/cards.js
115
models/cards.js
|
@ -1735,6 +1735,15 @@ Cards.globalSearch = queryParams => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('userId:', this.userId);
|
console.log('userId:', this.userId);
|
||||||
|
|
||||||
|
const errors = {
|
||||||
|
notFound: {
|
||||||
|
boards: [],
|
||||||
|
swimlanes: [],
|
||||||
|
lists: [],
|
||||||
|
users: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const selector = {
|
const selector = {
|
||||||
archived: false,
|
archived: false,
|
||||||
type: 'cardType-card',
|
type: 'cardType-card',
|
||||||
|
@ -1743,58 +1752,78 @@ Cards.globalSearch = queryParams => {
|
||||||
listId: { $nin: Lists.archivedListIds() },
|
listId: { $nin: Lists.archivedListIds() },
|
||||||
};
|
};
|
||||||
|
|
||||||
if ('swimlanesSelector' in queryParams) {
|
if (queryParams.boards.length) {
|
||||||
const swimSelector = {
|
const queryBoards = [];
|
||||||
archived: false,
|
queryParams.boards.forEach(query => {
|
||||||
};
|
const boards = Boards.userSearch(userId, {
|
||||||
|
title: query,
|
||||||
for (const key in queryParams.swimlanesSelector) {
|
});
|
||||||
swimSelector[key] = queryParams.swimlanesSelector[key];
|
if (boards.count()) {
|
||||||
}
|
boards.forEach(board => {
|
||||||
|
queryBoards.push(board._id);
|
||||||
selector.swimlaneId.$in = Swimlanes.find(swimSelector).map(swim => {
|
});
|
||||||
return swim._id;
|
} else {
|
||||||
|
errors.notFound.boards.push(query);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
selector.boardId.$in = queryBoards;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('listsSelector' in queryParams) {
|
if (queryParams.swimlanes.length) {
|
||||||
const listsSelector = {
|
const querySwimlanes = [];
|
||||||
archived: false,
|
queryParams.swimlanes.forEach(query => {
|
||||||
};
|
const swimlanes = Swimlanes.find({
|
||||||
|
title: query,
|
||||||
// eslint-disable-next-line no-console
|
});
|
||||||
// console.log('listsSelector:', queryParams.listsSelector.keys());
|
if (swimlanes.count()) {
|
||||||
for (const key in queryParams.listsSelector) {
|
swimlanes.forEach(swim => {
|
||||||
listsSelector[key] = queryParams.listsSelector[key];
|
querySwimlanes.push(swim._id);
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
// eslint-disable-next-line no-console
|
errors.notFound.swimlanes.push(query);
|
||||||
console.log('search list selector:', selector);
|
}
|
||||||
selector.listId.$in = Lists.find(listsSelector).map(list => {
|
|
||||||
return list._id;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
selector.swimlaneId.$in = querySwimlanes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (queryParams.lists.length) {
|
||||||
|
const queryLists = [];
|
||||||
|
queryParams.lists.forEach(query => {
|
||||||
|
const lists = Lists.find({
|
||||||
|
title: query,
|
||||||
|
});
|
||||||
|
if (lists.count()) {
|
||||||
|
lists.forEach(list => {
|
||||||
|
queryLists.push(list._id);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
errors.notFound.lists.push(query);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
selector.listId.$in = queryLists;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queryParams.users.length) {
|
if (queryParams.users.length) {
|
||||||
const users = [];
|
const queryUsers = [];
|
||||||
Users.find({ username: { $in: queryParams.users } }).forEach(user => {
|
queryParams.users.forEach(query => {
|
||||||
users.push(user._id);
|
const users = Users.find({
|
||||||
|
username: query,
|
||||||
|
});
|
||||||
|
if (users.count()) {
|
||||||
|
users.forEach(user => {
|
||||||
|
queryUsers.push(user._id);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
errors.notFound.users.push(query);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (users.length) {
|
|
||||||
selector.$or = [
|
|
||||||
{ members: { $in: users } },
|
|
||||||
{ assignees: { $in: users } },
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (queryParams.text) {
|
|
||||||
const regex = new RegExp(queryParams.text, 'i');
|
|
||||||
|
|
||||||
selector.$or = [
|
selector.$or = [
|
||||||
{ title: regex },
|
{ members: { $in: queryUsers } },
|
||||||
{ description: regex },
|
{ assignees: { $in: queryUsers } },
|
||||||
{ customFields: { $elemMatch: { value: regex } } },
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1820,7 +1849,7 @@ Cards.globalSearch = queryParams => {
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('count:', cards.count());
|
console.log('count:', cards.count());
|
||||||
return cards;
|
return { cards, errors };
|
||||||
};
|
};
|
||||||
|
|
||||||
//FUNCTIONS FOR creation of Activities
|
//FUNCTIONS FOR creation of Activities
|
||||||
|
|
|
@ -181,7 +181,7 @@ Meteor.publish('globalSearch', function(queryParams) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('queryParams:', queryParams);
|
console.log('queryParams:', queryParams);
|
||||||
|
|
||||||
const cards = Cards.globalSearch(queryParams);
|
const cards = Cards.globalSearch(queryParams).cards;
|
||||||
|
|
||||||
const boards = [];
|
const boards = [];
|
||||||
const swimlanes = [];
|
const swimlanes = [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue