From 0837fc28465c70c7c39b674d9d678287f31c7101 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Mon, 29 Dec 2025 14:24:11 +0800 Subject: [PATCH] feat: Fixed custom field render and input & added more file component options --- addon/components/custom-field/input.hbs | 2 +- addon/components/custom-field/value.hbs | 2 + addon/components/custom-field/value.js | 29 ++++++- addon/components/file.hbs | 102 +++++++++++++++--------- addon/components/file.js | 4 + package.json | 2 +- 6 files changed, 99 insertions(+), 42 deletions(-) diff --git a/addon/components/custom-field/input.hbs b/addon/components/custom-field/input.hbs index 5026473..bf4530d 100644 --- a/addon/components/custom-field/input.hbs +++ b/addon/components/custom-field/input.hbs @@ -27,7 +27,7 @@ {{else if (eq this.customFieldComponent "money-input")}} - + {{else if (eq this.customFieldComponent "date-time-input")}} diff --git a/addon/components/custom-field/value.hbs b/addon/components/custom-field/value.hbs index 1cef310..3ede375 100644 --- a/addon/components/custom-field/value.hbs +++ b/addon/components/custom-field/value.hbs @@ -3,6 +3,8 @@
{{#if this.isBoolean}} {{if this.value "Yes" "No"}} + {{else if this.isFile}} + {{else}} {{n-a this.value}} {{/if}} diff --git a/addon/components/custom-field/value.js b/addon/components/custom-field/value.js index 6a4f19b..b15813f 100644 --- a/addon/components/custom-field/value.js +++ b/addon/components/custom-field/value.js @@ -1,12 +1,22 @@ import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; -import { equal } from '@ember/object/computed'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; export default class CustomFieldValueComponent extends Component { + @service store; + @service fetch; @tracked customField; @tracked value; @tracked subject; - @equal('args.customField.type', 'boolean') isBoolean; + + get isBoolean() { + return this.customField?.type === 'boolean'; + } + + get isFile() { + return this.customField?.type === 'file-upload'; + } constructor(owner, { customField, subject }) { super(...arguments); @@ -17,7 +27,18 @@ export default class CustomFieldValueComponent extends Component { #getValueFromSubject(customField, subject) { const cfValue = (subject.get('custom_field_values') ?? []).find((cfv) => cfv.custom_field_uuid === customField.id); - if (cfValue) return cfValue.value; - return null; + let value = cfValue?.value ?? null; + // If custom field is file upload normalize value to image + if (value && customField?.type === 'file-upload') { + const parsed = typeof value === 'string' ? JSON.parse(value) : value; + const normalized = this.store.normalize('file', parsed); + value = this.store.push(normalized); + } + return value; + } + + @action downloadFile() { + const file = this.value; + return this.fetch.download('files/download', { file: file.id }, { fileName: file.filename, mimeType: file.content_type }); } } diff --git a/addon/components/file.hbs b/addon/components/file.hbs index f5e6abb..d64a9d4 100644 --- a/addon/components/file.hbs +++ b/addon/components/file.hbs @@ -12,44 +12,74 @@ {{/if}}
-
- -