From edcffa516f1a57e5f01505f7639b942db503424d Mon Sep 17 00:00:00 2001 From: Akanksh Saxena Date: Thu, 16 Sep 2021 17:17:30 +0200 Subject: [PATCH] feat(scopes): introduce meta fields 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 | 14 +++++++ addon/models/scope.js | 1 + addon/templates/scopes/edit.hbs | 27 +++++++++++++ tests/dummy/app/services/emeis-options.js | 49 +++++++++++++++++++++++ 4 files changed, 91 insertions(+) diff --git a/addon/controllers/scopes/edit.js b/addon/controllers/scopes/edit.js index 5b3f4f91..d372cddd 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,10 @@ export default class ScopesEditController extends Controller { return model; } + + @action + updateMetaField(field, model, option) { + model.meta = { ...model.meta, [field.slug]: option.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..b4b7c9c2 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..dab56ca5 100644 --- a/tests/dummy/app/services/emeis-options.js +++ b/tests/dummy/app/services/emeis-options.js @@ -8,4 +8,53 @@ export default class EmeisOptionsService extends Service { // language: "optional", // }; // navigationEntries = ["users", "scopes"]; + metaFields = { + scope: [ + { + slug: "institution", + label: { + en: "Institution EN", + de: "Institution DE", + fr: "Institution FR", + }, + type: "choice", // initially supported: "text", "choice" + options: [ + { + value: "Option 1", + label: { + en: "Option 1 EN", + de: "Option 1 DE", + fr: "Option 1 FR", + }, + }, + { + value: "Option 2", + label: { + en: "Option 2 EN", + de: "Option 2 DE", + fr: "Option 2 FR", + }, + }, + { + value: "Option 3", + label: { + en: "Option 3 EN", + de: "Option 3 DE", + fr: "Option 3 FR", + }, + }, + { + value: "Option 4", + label: { + en: "Option 4 EN", + de: "Option 4 DE", + fr: "Option 4 FR", + }, + }, + ], + visible: true, + readOnly: false, + }, + ], + }; }