mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
Handle subscriptions better
* use onReady and onStop callbacks when subscribing * show an server error message when the server returns an error * call stop() on subscriptions
This commit is contained in:
parent
28aebaa06b
commit
58020863a8
6 changed files with 65 additions and 52 deletions
|
@ -57,7 +57,7 @@ class DueCardsComponent extends CardSearchPagedComponent {
|
|||
queryParams.users = [Meteor.user().username];
|
||||
}
|
||||
|
||||
this.autorunGlobalSearch(queryParams);
|
||||
this.runGlobalSearch(queryParams);
|
||||
}
|
||||
|
||||
dueCardsView() {
|
||||
|
|
|
@ -50,6 +50,12 @@ template(name="globalSearch")
|
|||
= msg
|
||||
else
|
||||
+resultsPaged(this)
|
||||
else if serverError.get
|
||||
.global-search-page
|
||||
.global-search-help
|
||||
h1 {{_ 'server-error' }}
|
||||
+viewer
|
||||
| {{_ 'server-error-troubleshooting' }}
|
||||
else
|
||||
.global-search-page
|
||||
.global-search-help
|
||||
|
|
|
@ -431,7 +431,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent {
|
|||
return;
|
||||
}
|
||||
|
||||
this.autorunGlobalSearch(params);
|
||||
this.runGlobalSearch(params);
|
||||
}
|
||||
|
||||
searchInstructions() {
|
||||
|
|
|
@ -53,7 +53,7 @@ class MyCardsComponent extends CardSearchPagedComponent {
|
|||
sort: { name: 'dueAt', order: 'des' },
|
||||
};
|
||||
|
||||
this.autorunGlobalSearch(queryParams);
|
||||
this.runGlobalSearch(queryParams);
|
||||
Meteor.subscribe('setting');
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,28 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
this.totalHits = 0;
|
||||
this.queryErrors = null;
|
||||
this.resultsPerPage = 25;
|
||||
this.sessionId = SessionData.getSessionId();
|
||||
this.subscriptionHandle = null;
|
||||
this.serverError = new ReactiveVar(false);
|
||||
|
||||
const that = this;
|
||||
this.subscriptionCallbacks = {
|
||||
onReady() {
|
||||
that.getResults();
|
||||
that.searching.set(false);
|
||||
that.hasResults.set(true);
|
||||
that.serverError.set(false);
|
||||
},
|
||||
onError(error) {
|
||||
that.searching.set(false);
|
||||
that.hasResults.set(false);
|
||||
that.serverError.set(true);
|
||||
console.log('Error.reason:', error.reason);
|
||||
console.log('Error.message:', error.message);
|
||||
console.log('Error.stack:', error.stack);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
resetSearch() {
|
||||
|
@ -21,15 +43,15 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
this.hasResults.set(false);
|
||||
this.hasQueryErrors.set(false);
|
||||
this.resultsHeading.set('');
|
||||
this.serverError.set(false);
|
||||
this.resultsCount = 0;
|
||||
this.totalHits = 0;
|
||||
this.queryErrors = null;
|
||||
}
|
||||
|
||||
getSessionData() {
|
||||
getSessionData(sessionId) {
|
||||
return SessionData.findOne({
|
||||
userId: Meteor.userId(),
|
||||
sessionId: SessionData.getSessionId(),
|
||||
sessionId: sessionId ? sessionId : SessionData.getSessionId(),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -45,6 +67,7 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
const cards = Cards.find({ _id: { $in: sessionData.cards } }, projection);
|
||||
this.queryErrors = sessionData.errors;
|
||||
if (this.queryErrors.length) {
|
||||
// console.log('queryErrors:', this.queryErrorMessages());
|
||||
this.hasQueryErrors.set(true);
|
||||
return null;
|
||||
}
|
||||
|
@ -67,25 +90,21 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
return null;
|
||||
}
|
||||
|
||||
autorunGlobalSearch(params) {
|
||||
this.searching.set(true);
|
||||
stopSubscription() {
|
||||
if (this.subscriptionHandle) {
|
||||
this.subscriptionHandle.stop();
|
||||
}
|
||||
}
|
||||
|
||||
this.autorun(() => {
|
||||
const handle = Meteor.subscribe(
|
||||
'globalSearch',
|
||||
SessionData.getSessionId(),
|
||||
params,
|
||||
);
|
||||
Tracker.nonreactive(() => {
|
||||
Tracker.autorun(() => {
|
||||
if (handle.ready()) {
|
||||
this.getResults();
|
||||
this.searching.set(false);
|
||||
this.hasResults.set(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
runGlobalSearch(params) {
|
||||
this.searching.set(true);
|
||||
this.stopSubscription();
|
||||
this.subscriptionHandle = Meteor.subscribe(
|
||||
'globalSearch',
|
||||
this.sessionId,
|
||||
params,
|
||||
this.subscriptionCallbacks,
|
||||
);
|
||||
}
|
||||
|
||||
queryErrorMessages() {
|
||||
|
@ -103,37 +122,23 @@ export class CardSearchPagedComponent extends BlazeComponent {
|
|||
}
|
||||
|
||||
nextPage() {
|
||||
const sessionData = this.getSessionData();
|
||||
|
||||
this.autorun(() => {
|
||||
const handle = Meteor.subscribe('nextPage', sessionData.sessionId);
|
||||
Tracker.nonreactive(() => {
|
||||
Tracker.autorun(() => {
|
||||
if (handle.ready()) {
|
||||
this.getResults();
|
||||
this.searching.set(false);
|
||||
this.hasResults.set(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
this.searching.set(true);
|
||||
this.stopSubscription();
|
||||
this.subscriptionHandle = Meteor.subscribe(
|
||||
'nextPage',
|
||||
this.sessionId,
|
||||
this.subscriptionCallbacks,
|
||||
);
|
||||
}
|
||||
|
||||
previousPage() {
|
||||
const sessionData = this.getSessionData();
|
||||
|
||||
this.autorun(() => {
|
||||
const handle = Meteor.subscribe('previousPage', sessionData.sessionId);
|
||||
Tracker.nonreactive(() => {
|
||||
Tracker.autorun(() => {
|
||||
if (handle.ready()) {
|
||||
this.getResults();
|
||||
this.searching.set(false);
|
||||
this.hasResults.set(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
this.searching.set(true);
|
||||
this.stopSubscription();
|
||||
this.subscriptionHandle = Meteor.subscribe(
|
||||
'previousPage',
|
||||
this.sessionId,
|
||||
this.subscriptionCallbacks,
|
||||
);
|
||||
}
|
||||
|
||||
getResultsHeading() {
|
||||
|
|
|
@ -978,6 +978,8 @@
|
|||
"sort-cards": "Sort Cards",
|
||||
"cardsSortPopup-title": "Sort Cards",
|
||||
"due-date": "Due Date",
|
||||
"server-error": "Server Error",
|
||||
"server-error-troubleshooting": "Please submit the error generated by the server.\nFor a snap installation on Linux, run: `sudo journalctl -u 'snap.wekan.*'`",
|
||||
"title-alphabetically": "Title (Alphabetically)",
|
||||
"created-at-newest-first": "Created At (Newest First)",
|
||||
"created-at-oldest-first": "Created At (Oldest First)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue