filtering by status added
This commit is contained in:
@@ -33,6 +33,58 @@ export const NotesSidebar: Component<{
|
||||
return new Set<string>();
|
||||
}
|
||||
});
|
||||
const [jobFilterIds] = createResource(
|
||||
() => {
|
||||
const f = store.noteFilter;
|
||||
const normalize = (items: Array<string | { name: string; excluded: boolean }> | undefined) => {
|
||||
if (!items) return [] as { name: string; excluded: boolean }[];
|
||||
return items.map((i: any) => (typeof i === "string" ? { name: i, excluded: false } : { name: i.name, excluded: !!i.excluded }));
|
||||
};
|
||||
const status = normalize(f.jobStatus as any).sort((a, b) => a.name.localeCompare(b.name));
|
||||
const division = normalize(f.jobDivision as any).sort((a, b) => a.name.localeCompare(b.name));
|
||||
const key = JSON.stringify({ status, division });
|
||||
return key;
|
||||
},
|
||||
async (key) => {
|
||||
if (!key) return null;
|
||||
const parsed = JSON.parse(key) as { status: Array<{ name: string; excluded: boolean }>; division: Array<{ name: string; excluded: boolean }> };
|
||||
const status = parsed.status || [];
|
||||
const division = parsed.division || [];
|
||||
if (status.length === 0 && division.length === 0) return null;
|
||||
|
||||
const parts: string[] = [];
|
||||
const statusInclude = status.filter(s => !s.excluded).map(s => s.name);
|
||||
const statusExclude = status.filter(s => s.excluded).map(s => s.name);
|
||||
const divisionInclude = division.filter(d => !d.excluded).map(d => d.name);
|
||||
const divisionExclude = division.filter(d => d.excluded).map(d => d.name);
|
||||
|
||||
if (statusInclude.length > 0) {
|
||||
parts.push(`(${statusInclude.map(s => `Job_Status = "${s}"`).join(" || ")})`);
|
||||
}
|
||||
if (statusExclude.length > 0) {
|
||||
parts.push(`(${statusExclude.map(s => `Job_Status != "${s}"`).join(" && ")})`);
|
||||
}
|
||||
if (divisionInclude.length > 0) {
|
||||
parts.push(`(${divisionInclude.map(d => `Job_Division = "${d}"`).join(" || ")})`);
|
||||
}
|
||||
if (divisionExclude.length > 0) {
|
||||
parts.push(`(${divisionExclude.map(d => `Job_Division != "${d}"`).join(" && ")})`);
|
||||
}
|
||||
|
||||
const filter = parts.join(" && ");
|
||||
try {
|
||||
const items = await pb.collection('Job_Info_Prod').getFullList({
|
||||
filter,
|
||||
fields: "id",
|
||||
requestKey: null
|
||||
});
|
||||
return new Set(items.map((r: any) => String(r.id)));
|
||||
} catch (e) {
|
||||
console.warn("Failed to load job filter list for notes:", e);
|
||||
return new Set<string>();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const filteredNotes = createMemo(() => {
|
||||
const filter = store.noteFilter;
|
||||
@@ -90,6 +142,19 @@ export const NotesSidebar: Component<{
|
||||
});
|
||||
}
|
||||
|
||||
// Job Status / Division Filter (notes only)
|
||||
if ((filter.jobStatus?.length || 0) > 0 || (filter.jobDivision?.length || 0) > 0) {
|
||||
const allowedJobIds = jobFilterIds();
|
||||
n = n.filter(note => {
|
||||
if (!note.tags?.includes("prism_job")) return false;
|
||||
if (!allowedJobIds) return false;
|
||||
const jobIdTag = note.tags.find(t => t.startsWith("job_id:"));
|
||||
const jobId = jobIdTag?.split(":")[1]?.trim();
|
||||
if (!jobId) return false;
|
||||
return allowedJobIds.has(jobId);
|
||||
});
|
||||
}
|
||||
|
||||
// Starred Filter
|
||||
if (filter.starred) {
|
||||
n = n.filter(note => note.tags?.includes(getFavoriteTag()));
|
||||
|
||||
Reference in New Issue
Block a user