From 3e6787b04e3eb09907f4bb4b1dac087ecbc8ece7 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 20 Jul 2024 13:33:02 +0300 Subject: [PATCH] https://github.com/PhoenixNazarov/prompt-admin/issues/9 create sort for prompts --- client/src/stores/config/mapping.store.ts | 2 ++ client/src/stores/prompt.store.ts | 1 + client/src/views/Tables/Edit/InputItem.vue | 2 +- .../views/Tables/Edit/MappingEntityItem.vue | 2 +- client/src/views/Tables/Edit/MappingItem.vue | 17 ++++++++-- .../Workplace/Menu/WorkplaceMenuView.vue | 31 +++++++++++++++++-- server/promptadmin/api/dto/prompt.py | 1 + server/promptadmin/api/routers/prompts.py | 6 ++-- server/promptadmin/data/entity/mapping.py | 4 +-- server/promptadmin/data/init.sql | 2 ++ 10 files changed, 57 insertions(+), 11 deletions(-) diff --git a/client/src/stores/config/mapping.store.ts b/client/src/stores/config/mapping.store.ts index f1be031..7f035eb 100644 --- a/client/src/stores/config/mapping.store.ts +++ b/client/src/stores/config/mapping.store.ts @@ -12,6 +12,8 @@ export interface Mapping extends BaseEntity { description: string field_name: string + field_order?: string + desc?: boolean connection_name: string } diff --git a/client/src/stores/prompt.store.ts b/client/src/stores/prompt.store.ts index 55d126f..4af7449 100644 --- a/client/src/stores/prompt.store.ts +++ b/client/src/stores/prompt.store.ts @@ -10,6 +10,7 @@ export interface Prompt { value: string name?: string preview?: boolean + sort_value?: any auditData?: { audit: PromptAudit, diff --git a/client/src/views/Tables/Edit/InputItem.vue b/client/src/views/Tables/Edit/InputItem.vue index 2da1e62..57aa131 100644 --- a/client/src/views/Tables/Edit/InputItem.vue +++ b/client/src/views/Tables/Edit/InputItem.vue @@ -47,7 +47,7 @@ export default defineComponent({ default_type: this.default_type, default: this.default_, }) - await RouterService.goToTableItem('macro', result.id) + await RouterService.goToTableItem('input', result.id) this.loadingSave = false } } diff --git a/client/src/views/Tables/Edit/MappingEntityItem.vue b/client/src/views/Tables/Edit/MappingEntityItem.vue index c98213a..c4227dd 100644 --- a/client/src/views/Tables/Edit/MappingEntityItem.vue +++ b/client/src/views/Tables/Edit/MappingEntityItem.vue @@ -79,7 +79,7 @@ export default defineComponent({ entity_id: this.entity_id_, id: this.id, }) - await RouterService.goToTableItem('output', result.id) + await RouterService.goToTableItem('mapping-entity', result.id) this.loadingSave = false } } diff --git a/client/src/views/Tables/Edit/MappingItem.vue b/client/src/views/Tables/Edit/MappingItem.vue index bcef2a9..bbe90c4 100644 --- a/client/src/views/Tables/Edit/MappingItem.vue +++ b/client/src/views/Tables/Edit/MappingItem.vue @@ -33,6 +33,8 @@ export default defineComponent({ description: mapping?.description, field_name: mapping?.field_name, connection_name: mapping?.connection_name, + field_order: mapping?.field_order, + desc: mapping?.desc, loadingSave: false } @@ -47,9 +49,11 @@ export default defineComponent({ field: this.field, description: this.description, field_name: this.field_name, - connection_name: this.connection_name + connection_name: this.connection_name, + field_order: this.field_order, + desc: this.desc }) - await RouterService.goToTableItem('output', result.id) + await RouterService.goToTableItem('mapping', result.id) this.loadingSave = false } } @@ -87,6 +91,15 @@ export default defineComponent({ hint="Description of the remote product" persistent-hint/> + + + + + + + + diff --git a/client/src/views/Workplace/Menu/WorkplaceMenuView.vue b/client/src/views/Workplace/Menu/WorkplaceMenuView.vue index 5a0652e..0d757d9 100644 --- a/client/src/views/Workplace/Menu/WorkplaceMenuView.vue +++ b/client/src/views/Workplace/Menu/WorkplaceMenuView.vue @@ -1,10 +1,19 @@ @@ -75,7 +100,7 @@ export default defineComponent({ v-if="promptStore.loadings.loadAll" > {{ prompt.name }} diff --git a/server/promptadmin/api/dto/prompt.py b/server/promptadmin/api/dto/prompt.py index f79d094..6596b79 100644 --- a/server/promptadmin/api/dto/prompt.py +++ b/server/promptadmin/api/dto/prompt.py @@ -8,3 +8,4 @@ class Prompt(BaseModel): id: int value: str name: str | None + sort_value: str | int | None = None diff --git a/server/promptadmin/api/routers/prompts.py b/server/promptadmin/api/routers/prompts.py index f4e6d70..a376787 100644 --- a/server/promptadmin/api/routers/prompts.py +++ b/server/promptadmin/api/routers/prompts.py @@ -38,8 +38,9 @@ async def load_mapping(mapping: Mapping) -> list[Prompt]: return [] mapping_name = f', {mapping.field_name}' if mapping.field_name else '' + order_name = f', {mapping.field_order}' if mapping.field_order else '' - row = await conn.fetch(f'SELECT id, {mapping.field} {mapping_name} FROM {mapping.table}') + row = await conn.fetch(f'SELECT id, {mapping.field} {mapping_name} {order_name} FROM {mapping.table}') result = [] for i in row: @@ -50,7 +51,8 @@ async def load_mapping(mapping: Mapping) -> list[Prompt]: field=mapping.field, id=i['id'], value=i[mapping.field], - name=i.get(mapping.field_name) + name=i.get(mapping.field_name), + sort_value=i.get(mapping.field_order) ) ) return result diff --git a/server/promptadmin/data/entity/mapping.py b/server/promptadmin/data/entity/mapping.py index 431f066..1d21cfd 100644 --- a/server/promptadmin/data/entity/mapping.py +++ b/server/promptadmin/data/entity/mapping.py @@ -9,8 +9,8 @@ class MappingData(BaseModel): description: str field_name: str | None = None - # field_order: str | None = None - # desc: bool = False + field_order: str | None = None + desc: bool = False connection_name: str diff --git a/server/promptadmin/data/init.sql b/server/promptadmin/data/init.sql index 914661b..7b3dd40 100644 --- a/server/promptadmin/data/init.sql +++ b/server/promptadmin/data/init.sql @@ -33,6 +33,8 @@ create table pa_mapping field varchar(128) not null, description varchar(1000) not null, field_name varchar(128), + field_order varchar(128), + "desc" boolean default false, connection_name varchar(128) not null );