feat(document-service): Unterstützung für die Abfrage von Dokumenten nach Attributen hinzugefügt
- Erforderlich für `DocAttribute.serilizedValue`. - Erweitert `DocQuery` mit optionalem `attributes` Feld. - Aktualisiert `getDocuments` um nach Attribut-Schlüssel-Wert-Paaren zu filtern. - Hilfsfunktion `getDocumentByAttributes` hinzugefügt.
This commit is contained in:
parent
bbb55e9746
commit
c022b96a12
@ -7,8 +7,8 @@ import Typography from '@mui/material/Typography';
|
|||||||
import Pagination from '@mui/material/Pagination';
|
import Pagination from '@mui/material/Pagination';
|
||||||
|
|
||||||
import { DashboardContent } from 'src/layouts/dashboard';
|
import { DashboardContent } from 'src/layouts/dashboard';
|
||||||
import { Doc, getDocuments } from 'src/services/document-service';
|
|
||||||
import { Attribute, getAttributes } from 'src/services/attribute-service';
|
import { Attribute, getAttributes } from 'src/services/attribute-service';
|
||||||
|
import { Doc, getDocumentByAttributes, getDocuments } from 'src/services/document-service';
|
||||||
|
|
||||||
import { Iconify } from 'src/components/iconify';
|
import { Iconify } from 'src/components/iconify';
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ export function DocSearchView() {
|
|||||||
const [attributes, setAttributes] = useState<Record<string, string>>({});
|
const [attributes, setAttributes] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(attributes);
|
getDocumentByAttributes(attributes).then(setDocs);
|
||||||
}, [attributes]);
|
}, [attributes]);
|
||||||
|
|
||||||
function setAttribute(name: string, serilizedValue: string) {
|
function setAttribute(name: string, serilizedValue: string) {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ const validExtensions: FileFormat[] = [
|
|||||||
|
|
||||||
type DocAttribute = {
|
type DocAttribute = {
|
||||||
name: string;
|
name: string;
|
||||||
serilizedValue?: string;
|
serilizedValue: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Doc {
|
export class Doc {
|
||||||
@ -73,7 +73,8 @@ export class Doc {
|
|||||||
|
|
||||||
export type DocQuery = {
|
export type DocQuery = {
|
||||||
id?: number | undefined,
|
id?: number | undefined,
|
||||||
name?: string | undefined
|
name?: string | undefined,
|
||||||
|
attributes?: Record<string, string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDocuments(query: DocQuery | undefined = undefined): Promise<Doc[]> {
|
export function getDocuments(query: DocQuery | undefined = undefined): Promise<Doc[]> {
|
||||||
@ -85,6 +86,11 @@ export function getDocuments(query: DocQuery | undefined = undefined): Promise<D
|
|||||||
if (query?.name)
|
if (query?.name)
|
||||||
documents = documents.filter(d => d.name === query.name);
|
documents = documents.filter(d => d.name === query.name);
|
||||||
|
|
||||||
|
for (const name in query?.attributes) {
|
||||||
|
const attr = query.attributes[name];
|
||||||
|
documents = documents.filter(d => d.attributes.find(a => a.name === name)?.serilizedValue.toLowerCase().includes(attr.toLowerCase()));
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve(documents);
|
return Promise.resolve(documents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,4 +100,8 @@ export function getDocumentById(id: number): Promise<Doc[]> {
|
|||||||
|
|
||||||
export function getDocumentByName(name: string): Promise<Doc[]> {
|
export function getDocumentByName(name: string): Promise<Doc[]> {
|
||||||
return getDocuments({ name: name });
|
return getDocuments({ name: name });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDocumentByAttributes(attributes: Record<string, string>): Promise<Doc[]> {
|
||||||
|
return getDocuments({ attributes: attributes });
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user