From af82ec287f6433128d271645addf7a31817ea1b4 Mon Sep 17 00:00:00 2001 From: Akanksh Saxena Date: Fri, 17 Sep 2021 14:54:52 +0200 Subject: [PATCH] feat(scopes): introduce meta fields (#272) Meta fields can contain additional information on scopes and can be passed by the `emeisOptions` service. The fields are customizable in terms of readability and visibility. --- addon/controllers/scopes/edit.js | 15 ++++++++ addon/models/scope.js | 1 + addon/templates/scopes/edit.hbs | 27 +++++++++++++ tests/dummy/app/services/emeis-options.js | 47 +++++++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/addon/controllers/scopes/edit.js b/addon/controllers/scopes/edit.js index 5b3f4f91..739ddab0 100644 --- a/addon/controllers/scopes/edit.js +++ b/addon/controllers/scopes/edit.js @@ -1,7 +1,15 @@ import Controller from "@ember/controller"; import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; export default class ScopesEditController extends Controller { + @service emeisOptions; + @service intl; + + get metaFields() { + return this.emeisOptions.metaFields.scope; + } + @action updateModel(model, formElements) { model.name = formElements.name.value; @@ -9,4 +17,11 @@ export default class ScopesEditController extends Controller { return model; } + + @action + updateMetaField(field, model, optionOrEvent) { + const value = optionOrEvent.target?.value ?? optionOrEvent.value; + model.meta = { ...model.meta, [field.slug]: value }; + model.notifyPropertyChange("meta"); + } } diff --git a/addon/models/scope.js b/addon/models/scope.js index 8e5da83b..b3477c16 100644 --- a/addon/models/scope.js +++ b/addon/models/scope.js @@ -7,6 +7,7 @@ export default class ScopeModel extends LocalizedModel { @localizedAttr name; @localizedAttr description; @attr level; + @attr meta; @belongsTo("scope", { inverse: "children" }) parent; @hasMany("scope", { inverse: "parent" }) children; diff --git a/addon/templates/scopes/edit.hbs b/addon/templates/scopes/edit.hbs index 7ebc0f8f..0310d6da 100644 --- a/addon/templates/scopes/edit.hbs +++ b/addon/templates/scopes/edit.hbs @@ -30,4 +30,31 @@ {{scope.name}} + + {{#each this.metaFields as |field|}} + {{#if field.visible}} + + {{#if (eq field.type "choice")}} + + {{get option.label this.intl.primaryLocale}} + + {{else}} + + {{/if}} + + {{/if}} + {{/each}} diff --git a/tests/dummy/app/services/emeis-options.js b/tests/dummy/app/services/emeis-options.js index 844b3159..9576cedc 100644 --- a/tests/dummy/app/services/emeis-options.js +++ b/tests/dummy/app/services/emeis-options.js @@ -8,4 +8,51 @@ export default class EmeisOptionsService extends Service { // language: "optional", // }; // navigationEntries = ["users", "scopes"]; + metaFields = { + scope: [ + { + slug: "meta-example", + label: { + en: "Example for custom choice field", + de: "Beispiel für benutzerdefiniertes Dropdown-Feld", + }, + type: "choice", // initially supported: "text", "choice" + options: [ + { + value: "option-1", + label: { + en: "Ham", + de: "Schinken", + }, + }, + { + value: "Option 2", + label: { + en: "Cheese", + de: "Käse", + }, + }, + { + value: "Option 3", + label: { + en: "Onion", + de: "Zwiebel", + }, + }, + ], + visible: true, + readOnly: false, + }, + { + slug: "meta-example-2", + label: { + en: "Example for custom text field", + de: "Beispiel für benutzerdefiniertes Textfeld", + }, + type: "text", + visible: true, + readOnly: false, + }, + ], + }; }