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}}
-
-
-