add adminOrOwner in afterModel

This commit is contained in:
Shaun Chyxion 2018-11-24 22:15:10 +08:00
parent 20e191e73a
commit ec8399fcd3
4 changed files with 8 additions and 27 deletions

View File

@ -1,8 +0,0 @@
import { helper } from '@ember/component/helper';
export function applicationAdminOrOwner(params/*, hash*/) {
const user = params[1];
return user.admin || params[0].filterBy('owner', user.id).length;
}
export default helper(applicationAdminOrOwner);

View File

@ -2,4 +2,10 @@ import BaseListRoute from './../base-list';
export default BaseListRoute.extend({
breadcrumbs: [{text: 'Customer Application'}],
afterModel(model) {
const me = this;
me._super(...arguments);
const user = me.get('ajax.user');
model.adminOrOwner = user.admin || model.data.filterBy('owner', user.id).length > 0;
}
});

View File

@ -44,7 +44,7 @@
}}
</th>
{{/if}}
{{#if (application/admin-or-owner model.data ajax.user)}}
{{#if model.adminOrOwner}}
<th>
<i class="ace-icon fa fa-exchange bigger-110 hidden-480"></i>
Enabled
@ -76,7 +76,7 @@
{{option-text model.users it.owner 'id' 'name' '$.employeeId ($.name)'}}
</td>
{{/if}}
{{#if (application/admin-or-owner model.data ajax.user)}}
{{#if model.adminOrOwner}}
<td>
{{#if (or ajax.user.admin (eq ajax.user.id it.owner))}}
{{status-cell model=it enabledText='TRUE' disabledText='FALSE'}}

View File

@ -1,17 +0,0 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
moduleForComponent('application/admin-or-owner', 'helper:application/admin-or-owner', {
integration: true
});
// Replace this with your real tests.
test('it renders', function(assert) {
this.set('inputValue', '1234');
this.render(hbs`{{application/admin-or-owner inputValue}}`);
assert.equal(this.$().text().trim(), '1234');
});