mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A feature's guide now sits under the menu it is used from, read from the templates rather than from where somebody once put it: Header-Bar, All-Boards, Pages, Board-Header (search and every Board View), Board-Sidebar (Board Settings, Filter, Members, Labels, Archive), Rules, Swimlanes, Lists, Cards, Member-Settings, Admin-Panel and Login-Page. Topics used from several menus (editor, history, theme, translations, email, troubleshooting) are in General. - Each area has a README mapping its menu entries to their guides and to the template or server module that implements them. Board-Header/README.md lists all 40 Board View entries with the template boardBody.jade renders; five views (Table, Calendar Mode, Time, Timeline, Map) have no guide of their own yet and say so. - Board-View.md listed 25 views while BOARD_VIEWS has 40; it now lists all of them with their English labels. - Pages keep their file names. Where a released changelog links an old path, a "# Moved" page stays there and points to the new one; test-menu.sh skips folders holding only those. - Undo was filed under Login; it is General/Undo now. - Every link in docs, code comments, scripts and tests follows the move; docsLinksResolve checks them all. Tests that read a doc follow it to its new place. boardViewSettings now fails when Board-View.md or Board-Header/README.md differs from BOARD_VIEWS, or names a template boardBody.jade does not render. Thanks to xet7 !
256 lines
8.0 KiB
JavaScript
256 lines
8.0 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { TAPi18n } from '/imports/i18n';
|
|
import Cards from '../../models/cards';
|
|
import SessionData from '../../models/usersessiondata';
|
|
import {QueryDebug} from "../../config/query-classes";
|
|
import {OPERATOR_DEBUG} from "../../config/search-const";
|
|
import { TABLE_PAGE_ROWS_PER_PAGE } from '/models/lib/tablePage';
|
|
|
|
// Plain helper class for search pages with pagination.
|
|
// Not a BlazeComponent; instantiated in each template's onCreated.
|
|
export class CardSearchPaged {
|
|
constructor(templateInstance) {
|
|
this.tpl = templateInstance;
|
|
this.searching = new ReactiveVar(false);
|
|
this.hasResults = new ReactiveVar(false);
|
|
this.hasQueryErrors = new ReactiveVar(false);
|
|
this.query = new ReactiveVar('');
|
|
this.resultsHeading = new ReactiveVar('');
|
|
this.searchLink = new ReactiveVar(null);
|
|
this.results = new ReactiveVar([]);
|
|
this.hasNextPage = new ReactiveVar(false);
|
|
this.hasPreviousPage = new ReactiveVar(false);
|
|
this.resultsCount = 0;
|
|
this.totalHits = 0;
|
|
this.queryErrors = null;
|
|
// The one rows-per-page of the app (docs/Features/General/Table.md): a search page
|
|
// is a paginated page too, so it loads the same 10 rows at a time.
|
|
this.resultsPerPage = TABLE_PAGE_ROWS_PER_PAGE;
|
|
this.sessionId = SessionData.getSessionId();
|
|
this.subscriptionHandle = null;
|
|
this.serverError = new ReactiveVar(false);
|
|
this.sessionData = null;
|
|
this.debug = new ReactiveVar(new QueryDebug());
|
|
|
|
const that = this;
|
|
this.subscriptionCallbacks = {
|
|
onReady() {
|
|
const cardsInCollection = Cards.find().count();
|
|
|
|
// Wait for session data to be available (with timeout)
|
|
let waitCount = 0;
|
|
const maxWaitCount = 50; // 10 seconds max wait
|
|
|
|
const waitForSessionData = () => {
|
|
waitCount++;
|
|
const sessionData = that.getSessionData();
|
|
|
|
if (sessionData) {
|
|
const results = that.getResults();
|
|
|
|
// If no results and this is a due cards search, try to retry
|
|
if ((!results || results.length === 0) && that.searchRetryCount !== undefined && that.searchRetryCount < that.maxRetries) {
|
|
that.searchRetryCount++;
|
|
Meteor.setTimeout(() => {
|
|
if (that.performSearch) {
|
|
that.performSearch();
|
|
}
|
|
}, 500);
|
|
return;
|
|
}
|
|
|
|
// Set the results in the ReactiveVar so they display in the template
|
|
that.results.set(results);
|
|
that.resultsHeading.set(that.getResultsHeading());
|
|
that.searching.set(false);
|
|
that.hasResults.set(true);
|
|
that.serverError.set(false);
|
|
} else if (waitCount < maxWaitCount) {
|
|
// Session data not available yet, wait a bit more
|
|
Meteor.setTimeout(waitForSessionData, 200);
|
|
} else {
|
|
// Timeout reached, try fallback search
|
|
const results = that.getResults();
|
|
|
|
if (results && results.length > 0) {
|
|
that.results.set(results);
|
|
that.resultsHeading.set(that.getResultsHeading());
|
|
that.searching.set(false);
|
|
that.hasResults.set(true);
|
|
that.serverError.set(false);
|
|
} else {
|
|
that.searching.set(false);
|
|
that.hasResults.set(false);
|
|
that.serverError.set(true);
|
|
}
|
|
}
|
|
};
|
|
|
|
// Start waiting for session data
|
|
Meteor.setTimeout(waitForSessionData, 100);
|
|
},
|
|
onError(error) {
|
|
that.searching.set(false);
|
|
that.hasResults.set(false);
|
|
that.serverError.set(true);
|
|
},
|
|
};
|
|
}
|
|
|
|
resetSearch() {
|
|
this.searching.set(false);
|
|
this.results.set([]);
|
|
this.hasResults.set(false);
|
|
this.hasQueryErrors.set(false);
|
|
this.resultsHeading.set('');
|
|
this.serverError.set(false);
|
|
this.resultsCount = 0;
|
|
this.totalHits = 0;
|
|
this.queryErrors = null;
|
|
this.debug.set(new QueryDebug());
|
|
}
|
|
|
|
getSessionData(sessionId) {
|
|
const sessionIdToUse = sessionId || SessionData.getSessionId();
|
|
|
|
// Use SessionData.findOne() directly - it's synchronous on the client
|
|
const sessionData = SessionData.findOne({
|
|
userId: Meteor.userId(),
|
|
sessionId: sessionIdToUse,
|
|
});
|
|
|
|
return sessionData;
|
|
}
|
|
|
|
getResults() {
|
|
this.sessionData = this.getSessionData();
|
|
const cards = [];
|
|
|
|
if (this.sessionData && this.sessionData.cards && this.sessionData.cards.length > 0) {
|
|
Cards.find({ _id: { $in: this.sessionData.cards } }).forEach(card => {
|
|
if (card && card._id) cards.push(card);
|
|
});
|
|
this.queryErrors = this.sessionData.errors || [];
|
|
} else if (this.sessionData) {
|
|
this.queryErrors = this.sessionData.errors || [];
|
|
} else {
|
|
this.queryErrors = [];
|
|
}
|
|
if (this.queryErrors.length) {
|
|
// console.log('queryErrors:', this.queryErrorMessages());
|
|
this.hasQueryErrors.set(true);
|
|
// return null;
|
|
}
|
|
this.debug.set(new QueryDebug(this.sessionData ? this.sessionData.debug : null));
|
|
|
|
if (cards) {
|
|
if (this.sessionData) {
|
|
this.totalHits = this.sessionData.totalHits || 0;
|
|
this.resultsCount = cards.length;
|
|
this.resultsStart = this.sessionData.lastHit - this.resultsCount + 1;
|
|
this.resultsEnd = this.sessionData.lastHit;
|
|
this.resultsHeading.set(this.getResultsHeading());
|
|
this.results.set(cards);
|
|
this.hasNextPage.set(this.sessionData.lastHit < this.sessionData.totalHits);
|
|
this.hasPreviousPage.set(
|
|
this.sessionData.lastHit - this.sessionData.resultsCount > 0,
|
|
);
|
|
} else {
|
|
this.totalHits = cards.length;
|
|
this.resultsCount = cards.length;
|
|
this.resultsStart = 1;
|
|
this.resultsEnd = cards.length;
|
|
this.resultsHeading.set(this.getResultsHeading());
|
|
this.results.set(cards);
|
|
this.hasNextPage.set(false);
|
|
this.hasPreviousPage.set(false);
|
|
}
|
|
return cards;
|
|
}
|
|
|
|
this.resultsCount = 0;
|
|
return null;
|
|
}
|
|
|
|
stopSubscription() {
|
|
if (this.subscriptionHandle) {
|
|
this.subscriptionHandle.stop();
|
|
}
|
|
}
|
|
|
|
getSubscription(queryParams) {
|
|
// Subscribe to globalSearch which includes sessionData as the 11th cursor
|
|
const globalSearchHandle = Meteor.subscribe(
|
|
'globalSearch',
|
|
this.sessionId,
|
|
queryParams.params,
|
|
queryParams.text,
|
|
this.subscriptionCallbacks,
|
|
);
|
|
|
|
return globalSearchHandle;
|
|
}
|
|
|
|
runGlobalSearch(queryParams) {
|
|
this.searching.set(true);
|
|
this.debug.set(new QueryDebug());
|
|
this.stopSubscription();
|
|
this.subscriptionHandle = this.getSubscription(queryParams);
|
|
}
|
|
|
|
queryErrorMessages() {
|
|
const messages = [];
|
|
|
|
this.queryErrors.forEach(err => {
|
|
let value = err.color ? TAPi18n.__(`color-${err.value}`) : err.value;
|
|
if (!value) {
|
|
value = err.value;
|
|
}
|
|
messages.push(TAPi18n.__(err.tag, value));
|
|
});
|
|
|
|
return messages;
|
|
}
|
|
|
|
nextPage() {
|
|
this.searching.set(true);
|
|
this.stopSubscription();
|
|
this.subscriptionHandle = Meteor.subscribe(
|
|
'nextPage',
|
|
this.sessionId,
|
|
this.subscriptionCallbacks,
|
|
);
|
|
}
|
|
|
|
previousPage() {
|
|
this.searching.set(true);
|
|
this.stopSubscription();
|
|
this.subscriptionHandle = Meteor.subscribe(
|
|
'previousPage',
|
|
this.sessionId,
|
|
this.subscriptionCallbacks,
|
|
);
|
|
}
|
|
|
|
getResultsHeading() {
|
|
if (this.resultsCount === 0) {
|
|
return TAPi18n.__('no-cards-found');
|
|
} else if (this.resultsCount === 1) {
|
|
return TAPi18n.__('one-card-found');
|
|
} else if (this.resultsCount === this.totalHits) {
|
|
return TAPi18n.__('n-cards-found', {sprintf: [this.resultsCount]});
|
|
}
|
|
|
|
return TAPi18n.__('n-n-of-n-cards-found', {
|
|
start: this.resultsStart,
|
|
end: this.resultsEnd,
|
|
total: this.totalHits,
|
|
});
|
|
}
|
|
|
|
getSearchHref() {
|
|
const baseUrl = window.location.href.replace(/([?#].*$|\s*$)/, '');
|
|
return `${baseUrl}?q=${encodeURIComponent(this.query.get())}`;
|
|
}
|
|
}
|