From e81bb5ca2c8deacac774566ba08d3f3614c29a6e Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 5 Jul 2024 13:00:22 -0700 Subject: [PATCH] Basic frontend implementation --- src-ui/messages.xlf | 72 ++++++++++--------- .../custom-field-display.component.html | 3 + .../custom-field-display.component.spec.ts | 10 +++ .../custom-field-display.component.ts | 4 ++ .../input/select/select.component.spec.ts | 8 +++ .../common/input/select/select.component.ts | 5 ++ .../document-detail.component.html | 10 +++ src-ui/src/app/data/custom-field.ts | 6 ++ 8 files changed, 84 insertions(+), 34 deletions(-) diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf index e6559cb71..c4e70f1fe 100644 --- a/src-ui/messages.xlf +++ b/src-ui/messages.xlf @@ -525,7 +525,7 @@ src/app/components/document-detail/document-detail.component.html - 337 + 347 @@ -584,7 +584,7 @@ src/app/components/document-detail/document-detail.component.html - 329 + 339 src/app/components/document-list/save-view-config-dialog/save-view-config-dialog.component.html @@ -718,7 +718,7 @@ src/app/components/document-detail/document-detail.component.html - 346 + 356 src/app/components/document-list/document-list.component.html @@ -1080,7 +1080,7 @@ src/app/components/document-detail/document-detail.component.html - 305 + 315 src/app/components/document-list/bulk-editor/bulk-editor.component.html @@ -4676,7 +4676,7 @@ src/app/components/common/input/select/select.component.ts - 158 + 163 @@ -4758,7 +4758,7 @@ Private src/app/components/common/input/select/select.component.ts - 57 + 62 src/app/components/common/tag/tag.component.html @@ -4777,7 +4777,7 @@ No items found src/app/components/common/input/select/select.component.ts - 92 + 97 @@ -5101,6 +5101,10 @@ src/app/components/document-list/document-list.component.html 6 + + src/app/data/custom-field.ts + 50 + Please select an object @@ -5844,14 +5848,14 @@ Content src/app/components/document-detail/document-detail.component.html - 201 + 211 Metadata src/app/components/document-detail/document-detail.component.html - 210 + 220 src/app/components/document-detail/metadata-collapse/metadata-collapse.component.ts @@ -5862,119 +5866,119 @@ Date modified src/app/components/document-detail/document-detail.component.html - 217 + 227 Date added src/app/components/document-detail/document-detail.component.html - 221 + 231 Media filename src/app/components/document-detail/document-detail.component.html - 225 + 235 Original filename src/app/components/document-detail/document-detail.component.html - 229 + 239 Original MD5 checksum src/app/components/document-detail/document-detail.component.html - 233 + 243 Original file size src/app/components/document-detail/document-detail.component.html - 237 + 247 Original mime type src/app/components/document-detail/document-detail.component.html - 241 + 251 Archive MD5 checksum src/app/components/document-detail/document-detail.component.html - 246 + 256 Archive file size src/app/components/document-detail/document-detail.component.html - 252 + 262 Original document metadata src/app/components/document-detail/document-detail.component.html - 261 + 271 Archived document metadata src/app/components/document-detail/document-detail.component.html - 264 + 274 Preview src/app/components/document-detail/document-detail.component.html - 271 + 281 Notes src/app/components/document-detail/document-detail.component.html - 283,286 + 293,296 History src/app/components/document-detail/document-detail.component.html - 294 + 304 Save & next src/app/components/document-detail/document-detail.component.html - 331 + 341 Save & close src/app/components/document-detail/document-detail.component.html - 334 + 344 Enter Password src/app/components/document-detail/document-detail.component.html - 385 + 395 @@ -7841,56 +7845,56 @@ Boolean src/app/data/custom-field.ts - 17 + 18 Date src/app/data/custom-field.ts - 21 + 22 Integer src/app/data/custom-field.ts - 25 + 26 Number src/app/data/custom-field.ts - 29 + 30 Monetary src/app/data/custom-field.ts - 33 + 34 Text src/app/data/custom-field.ts - 37 + 38 Url src/app/data/custom-field.ts - 41 + 42 Document Link src/app/data/custom-field.ts - 45 + 46 diff --git a/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.html b/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.html index 812c283e2..b8cd1dd9d 100644 --- a/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.html +++ b/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.html @@ -30,6 +30,9 @@ } + @case (CustomFieldDataType.Select) { + {{getSelectValue(field, value)}} + } @default { {{value}} } diff --git a/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.spec.ts b/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.spec.ts index e347d2189..43d101611 100644 --- a/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.spec.ts +++ b/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.spec.ts @@ -12,6 +12,12 @@ const customFields: CustomField[] = [ { id: 1, name: 'Field 1', data_type: CustomFieldDataType.String }, { id: 2, name: 'Field 2', data_type: CustomFieldDataType.Monetary }, { id: 3, name: 'Field 3', data_type: CustomFieldDataType.DocumentLink }, + { + id: 4, + name: 'Field 4', + data_type: CustomFieldDataType.Select, + extra_data: ['Option 1', 'Option 2', 'Option 3'], + }, ] const document: Document = { id: 1, @@ -103,4 +109,8 @@ describe('CustomFieldDisplayComponent', () => { expect(component.currency).toEqual('EUR') expect(component.value).toEqual(100) }) + + it('should show select value', () => { + expect(component.getSelectValue(customFields[3], 2)).toEqual('Option 3') + }) }) diff --git a/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.ts b/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.ts index 086ac217e..1b309506b 100644 --- a/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.ts +++ b/src-ui/src/app/components/common/custom-field-display/custom-field-display.component.ts @@ -115,6 +115,10 @@ export class CustomFieldDisplayComponent implements OnInit, OnDestroy { return this.docLinkDocuments?.find((d) => d.id === docId)?.title } + public getSelectValue(field: CustomField, value: number): string { + return field.extra_data[value] + } + ngOnDestroy(): void { this.unsubscribeNotifier.next(true) this.unsubscribeNotifier.complete() diff --git a/src-ui/src/app/components/common/input/select/select.component.spec.ts b/src-ui/src/app/components/common/input/select/select.component.spec.ts index 79eec16e8..2c39035a2 100644 --- a/src-ui/src/app/components/common/input/select/select.component.spec.ts +++ b/src-ui/src/app/components/common/input/select/select.component.spec.ts @@ -132,4 +132,12 @@ describe('SelectComponent', () => { const expectedTitle = `Filter documents with this ${component.title}` expect(component.filterButtonTitle).toEqual(expectedTitle) }) + + it('should support setting items as a plain array', () => { + component.itemsArray = ['foo', 'bar'] + expect(component.items).toEqual([ + { id: 0, name: 'foo' }, + { id: 1, name: 'bar' }, + ]) + }) }) diff --git a/src-ui/src/app/components/common/input/select/select.component.ts b/src-ui/src/app/components/common/input/select/select.component.ts index 19f6375ad..d9976698e 100644 --- a/src-ui/src/app/components/common/input/select/select.component.ts +++ b/src-ui/src/app/components/common/input/select/select.component.ts @@ -34,6 +34,11 @@ export class SelectComponent extends AbstractInputComponent { if (items && this.value) this.checkForPrivateItems(this.value) } + @Input() + set itemsArray(items: any[]) { + this._items = items.map((item, index) => ({ id: index, name: item })) + } + writeValue(newValue: any): void { if (newValue && this._items) { this.checkForPrivateItems(newValue) diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index 8486e1816..370202f4b 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -186,6 +186,16 @@ [horizontal]="true" [error]="getCustomFieldError(i)"> } + @case (CustomFieldDataType.Select) { + + } } } diff --git a/src-ui/src/app/data/custom-field.ts b/src-ui/src/app/data/custom-field.ts index e858f06be..54f6045bc 100644 --- a/src-ui/src/app/data/custom-field.ts +++ b/src-ui/src/app/data/custom-field.ts @@ -9,6 +9,7 @@ export enum CustomFieldDataType { Float = 'float', Monetary = 'monetary', DocumentLink = 'documentlink', + Select = 'select', } export const DATA_TYPE_LABELS = [ @@ -44,10 +45,15 @@ export const DATA_TYPE_LABELS = [ id: CustomFieldDataType.DocumentLink, name: $localize`Document Link`, }, + { + id: CustomFieldDataType.Select, + name: $localize`Select`, + }, ] export interface CustomField extends ObjectWithId { data_type: CustomFieldDataType name: string created?: Date + extra_data?: any }