Skip to content

Commit

Permalink
feat(users): introduce metafields
Browse files Browse the repository at this point in the history
  • Loading branch information
Akanksh Saxena committed Oct 20, 2021
1 parent 0daa8b0 commit 4727484
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/controllers/scopes/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class ScopesEditIndexController extends Controller {
@service intl;

get metaFields() {
return this.emeisOptions.metaFields.scope;
return this.emeisOptions.metaFields?.scope;
}

@action
Expand Down
11 changes: 11 additions & 0 deletions addon/controllers/users/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default class UsersEditIndexController extends Controller {
@service intl;
@service emeisOptions;

get metaFields() {
return this.emeisOptions.metaFields?.user;
}

@action
updateModel(model, formElements) {
model.firstName = formElements.firstName.value;
Expand All @@ -29,6 +33,13 @@ export default class UsersEditIndexController extends Controller {
return model;
}

@action
updateMetaField(field, model, event) {
const value = event.target.value;
model.meta = { ...model.meta, [field.slug]: value };
model.notifyPropertyChange("meta");
}

get emailAsUsername() {
return this.emeisOptions.emailAsUsername;
}
Expand Down
14 changes: 14 additions & 0 deletions addon/templates/users/edit/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@
</EditForm::Element>
{{/if}}

{{#each this.metaFields as |field|}}
{{#if field.visible}}
<EditForm::Element @label={{get field.label this.intl.primaryLocale}}>
<input
class="uk-input"
type="text"
value={{get @model.meta field.slug}}
disabled={{field.readOnly}}
{{on "input" (fn this.updateMetaField field @model)}}
>
</EditForm::Element>
{{/if}}
{{/each}}

<EditForm::Element @label={{t "emeis.users.headings.isActive"}}>
<input
class="uk-checkbox"
Expand Down
12 changes: 12 additions & 0 deletions tests/dummy/app/services/emeis-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export default class EmeisOptionsService extends Service {
// };
// navigationEntries = ["users", "scopes"];
metaFields = {
user: [
{
slug: "user-meta-example",
label: {
en: "Example for custom text field",
de: "Beispiel für benutzerdefiniertes Textfeld",
},
type: "text",
visible: true,
readOnly: false,
},
],
scope: [
{
slug: "meta-example",
Expand Down

0 comments on commit 4727484

Please sign in to comment.