Skip to content

Commit

Permalink
feat(scopes): introduce meta fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Akanksh Saxena authored and czosel committed Sep 17, 2021
1 parent 146d6f3 commit edcffa5
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
14 changes: 14 additions & 0 deletions addon/controllers/scopes/edit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
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;
model.description = formElements.description.value;

return model;
}

@action
updateMetaField(field, model, option) {
model.meta = { ...model.meta, [field.slug]: option.value };
model.notifyPropertyChange("meta");
}
}
1 change: 1 addition & 0 deletions addon/models/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions addon/templates/scopes/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,31 @@
{{scope.name}}
</RelationshipSelect>
</EditForm::Element>

{{#each this.metaFields as |field|}}
{{#if field.visible}}
<EditForm::Element @label={{get field.label this.intl.primaryLocale}}>
{{#if (eq field.type "choice")}}
<PowerSelect
@disabled={{field.readOnly}}
@options={{field.options}}
@selected={{find-by "value" (get @model.meta field.slug) field.options}}
@onChange={{fn this.updateMetaField field @model}}
@placeholder={{get field.label this.intl.primaryLocale}}
as |option|
>
{{get option.label this.intl.primaryLocale}}
</PowerSelect>
{{else}}
<input
class="uk-input"
type="text"
value={{field.value}}
disabled={{field.readOnly}}
{{on "input" (fn this.updateMetaField field @model)}}
>
{{/if}}
</EditForm::Element>
{{/if}}
{{/each}}
</EditForm>
49 changes: 49 additions & 0 deletions tests/dummy/app/services/emeis-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
};
}

0 comments on commit edcffa5

Please sign in to comment.