Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions api-gateway/src/api/service/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,14 @@ export class SchemaApi {
required: false,
example: 'text'
})
@ApiQuery({
name: 'searchOptions',
type: String,
description: 'Search Options',
required: false,
isArray: true,
example: 'name'
})
@ApiOkResponse({
description: 'Successful operation.',
isArray: true,
Expand All @@ -440,6 +448,7 @@ export class SchemaApi {
@Query('toolId') toolId: string,
@Query('topicId') topicId: string,
@Query('search') search: string,
@Query('searchOptions') searchOptions: string[] | string,
@Response() res: any
): Promise<SchemaDTO[]> {
try {
Expand Down Expand Up @@ -468,6 +477,13 @@ export class SchemaApi {
if (search) {
options.search = search;
}
if (searchOptions) {
if (Array.isArray(searchOptions)) {
options.searchOptions = searchOptions;
} else if (typeof searchOptions === 'string') {
options.searchOptions = searchOptions.split(',');
}
}
options.fields = Object.values(SCHEMA_REQUIRED_PROPS)

const { items, count } = await guardians.getSchemasByOwnerV2(options, owner);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/services/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class SchemaService {
category?: SchemaCategory,
topicId?: string,
search?: string,
searchOptions?: string[],
pageIndex?: number,
pageSize?: number | string,
}): Observable<HttpResponse<ISchema[]>> {
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/app/views/schemas/schemas.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@
</p-dropdown>
</div>
<div *ngIf="isPolicy || isTool || isModule" class="guardian-input-container text-search">
<p-multiSelect
[(ngModel)]="textSearchOptionsValue"
[options]="textSearchOptions"
class="guardian-multiselect"
appendTo="body"
placeholder="Not selected"
optionLabel="label"
optionValue="value"
[showHeader]="false"
[filter]="false"
panelStyleClass="guardian-multiselect-panel schema-text-search-options"
(onPanelHide)="onFilter()">
</p-multiSelect>
<input
(change)="onFilter()"
[(ngModel)]="textSearch"
Expand Down
35 changes: 33 additions & 2 deletions frontend/src/app/views/schemas/schemas.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,29 @@ a {

.text-search {
position: relative;
display: grid;
grid-template-columns: 140px auto;

&::ng-deep {
.guardian-multiselect {
.p-multiselect {
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
}

&:hover {
z-index: 2;
}
}
}

input {
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
position: relative;
left: -1px;
z-index: 1;
}

.search-icon {
position: absolute;
Expand All @@ -664,6 +687,12 @@ a {
}
}

::ng-deep .schema-text-search-options {
.p-multiselect-items-wrapper {
max-height: 300px !important;
}
}

.guardian-user-not-data {
position: absolute;
left: 50%;
Expand Down Expand Up @@ -790,7 +819,7 @@ a {
}
}

.p-treetable .p-treetable-thead > tr > th {
.p-treetable .p-treetable-thead>tr>th {
padding: 0;
}

Expand All @@ -817,10 +846,12 @@ a {
background-color: var(--color-grey-white, #FFF);
border-top-left-radius: 8px;
border-top-right-radius: 8px;

&:first-child {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}

&:last-child {
border-top-right-radius: 8px;
}
Expand Down Expand Up @@ -882,4 +913,4 @@ a {
}
}
}
}
}
11 changes: 11 additions & 0 deletions frontend/src/app/views/schemas/schemas.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ export class SchemaConfigComponent implements OnInit {
{ label: 'System Schemas', value: SchemaType.System }
];
public textSearch: any;
public textSearchOptionsValue: string[] = [
'uuid', 'name', 'description', 'references', 'fields'
];
public textSearchOptions: { label: string; value: string }[] = [
{ label: 'UUID', value: 'uuid' },
{ label: 'Name', value: 'name' },
{ label: 'Description', value: 'description' },
{ label: 'References', value: 'references' },
{ label: 'Fields', value: 'fields' },
];

public element: any = {};

Expand Down Expand Up @@ -616,6 +626,7 @@ export class SchemaConfigComponent implements OnInit {
category,
topicId: this.currentTopic || '',
search: this.textSearch,
searchOptions: this.textSearchOptionsValue,
pageIndex: this.pageIndex,
pageSize: this.pageSize
});
Expand Down
65 changes: 51 additions & 14 deletions guardian-service/src/api/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,8 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
}
const [items, count] = await DatabaseServer.getSchemasAndCount(filter, otherOptions);
const pipeline = [
{$match: filter},
{$group: {_id: '$topicId', count: {$sum: 1}}}
{ $match: filter },
{ $group: { _id: '$topicId', count: { $sum: 1 } } }
] as unknown[];
const countByTopic = await new DataBaseHelper(SchemaCollection).aggregate(pipeline) as unknown[] as { _id: string, count: number }[];
items.forEach((item) => {
Expand Down Expand Up @@ -619,6 +619,7 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
toolId?: string,
topicId?: string,
search?: string
searchOptions?: string[]
},
owner: IOwner,
}) => {
Expand Down Expand Up @@ -708,36 +709,72 @@ export async function schemaAPI(logger: PinoLogger): Promise<void> {
//search
if (options.search) {
let search = options.search.toLowerCase();
let global = false;
if (search.startsWith('@')) {
global = true;
if (search.startsWith('@') || search.startsWith('#')) {
search = search.substring(1);
}
const searchOptions = options.searchOptions || ['uuid', 'name', 'description', 'references', 'fields'];
const fields = ['_id'];
if (searchOptions.includes('uuid')) {
fields.push('iri');
}
if (searchOptions.includes('name')) {
fields.push('name');
}
if (searchOptions.includes('description')) {
fields.push('description');
}
if (searchOptions.includes('references') || searchOptions.includes('fields')) {
fields.push('documentFileId');
}
let schemas = await DatabaseServer.getSchemas(filter, {
orderBy: { createDate: 'DESC' },
limit: 10000,
offset: 0,
fields: ['_id', 'documentFileId']
fields
});
schemas = schemas.filter((s) => {
if (s.document) {
if (!global) {
if (searchOptions.includes('uuid')) {
if (s.iri && s.iri.toLowerCase().includes(search)) {
return true;
}
}
if (searchOptions.includes('name')) {
if (s.name && s.name.toLowerCase().includes(search)) {
return true;
}
}
if (searchOptions.includes('description')) {
if (s.description && s.description.toLowerCase().includes(search)) {
return true;
}
}
if (searchOptions.includes('references')) {
if (s.document?.$defs) {
const text = JSON.stringify(s.document.$defs).toLowerCase();
if (text.includes(search)) {
return true;
}
}
}
if (searchOptions.includes('fields')) {
if (s.document) {
delete s.document.$defs;
const text = JSON.stringify(s.document).toLowerCase();
if (text.includes(search)) {
return true;
}
}
const text = JSON.stringify(s.document).toLowerCase();
return text.indexOf(search) > -1;
} else {
return false;
}
return false;
})
const ids = schemas.map((s) => s._id);
filter._id = { $in: ids };
}

const [items, count] = await DatabaseServer.getSchemasAndCount(filter, otherOptions);
const pipeline = [
{$match: filter},
{$group: {_id: '$topicId', count: {$sum: 1}}}
{ $match: filter },
{ $group: { _id: '$topicId', count: { $sum: 1 } } }
] as unknown[];
const countByTopic = await new DataBaseHelper(SchemaCollection).aggregate(pipeline) as unknown[] as { _id: string, count: number }[];
items.forEach((item) => {
Expand Down
9 changes: 9 additions & 0 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9325,6 +9325,15 @@ paths:
schema:
example: text
type: string
- name: searchOptions
required: false
in: query
description: Search Options
schema:
example: name
type: array
items:
type: string
responses:
'200':
description: Successful operation.
Expand Down