Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(emeis-options): custom user status component #523

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export default class EmeisOptionsService extends Service {
On each model edit view (e.g. users) you can define a custom component. The component will be rendered at the bottom of the edit view, but above the primary form buttons. Each component can be designed freely and the model will be passed into the component as `@model` argument. For a working demo have a look at our "dummy-button" at "dummy/app/components/dummy-button".
*/
customComponent: DummyButton,
/* Exclusively on USER model - define a custom component which will get displayed next to the 'inacitve' pill on top of the user detail view. Ideally this will be an inline element.
*/
statusComponent: DummyStatus,
};

scope = {
Expand Down
4 changes: 4 additions & 0 deletions addon/controllers/users/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default class UsersEditController extends PaginationController {
return this.emeisOptions.user?.metaFields;
}

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

get emailAsUsername() {
return this.emeisOptions.emailAsUsername;
}
Expand Down
5 changes: 5 additions & 0 deletions addon/templates/users/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
{{#unless @model.isActive}}
<span class="uk-badge uk-background-secondary">{{t "emeis.inactive"}}</span>
{{/unless}}
{{#if this.statusComponent}}
{{#let (component (ensure-safe-component this.statusComponent)) as |StatusComponent|}}
<StatusComponent @model={{@model}} />
{{/let}}
{{/if}}
</h3>
<EditForm
@model={{@model}}
Expand Down
3 changes: 3 additions & 0 deletions tests/dummy/app/components/dummy-status/dummy-status.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#each this.badges as |badge|}}
<span class="uk-badge uk-background-primary">{{optional-translate badge.label}}</span>
{{/each}}
11 changes: 11 additions & 0 deletions tests/dummy/app/components/dummy-status/dummy-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Component from "@glimmer/component";

export default class DummyStatusComponent extends Component {
get badges() {
return [
{
label: `${this.args.model.username}'s custom status`,
},
];
}
}
2 changes: 2 additions & 0 deletions tests/dummy/app/services/emeis-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Service from "@ember/service";
import { timeout } from "ember-concurrency";

import TestButtonComponent from "../components/dummy-button/dummy-button"; // template and component file must have the same name (if not template only)
import TestStatusComponent from "../components/dummy-status/dummy-status"; // template and component file must have the same name (if not template only)

export default class EmeisOptionsService extends Service {
emailAsUsername = false;
Expand Down Expand Up @@ -57,6 +58,7 @@ export default class EmeisOptionsService extends Service {
// readOnly: false,
// },
],
statusComponent: TestStatusComponent,
};

// scope view specific settings
Expand Down