Skip to content
Snippets Groups Projects
Commit 99940274 authored by Bertrand PINEL's avatar Bertrand PINEL
Browse files

Add multiple-entity-selector component for handling relationship

parent 740f37ae
No related branches found
No related tags found
No related merge requests found
import Component from '@ember/component';
import injectService from 'ember-service/inject';
import { computed } from '@ember/object';
import { A } from '@ember/array';
import EmberObject from '@ember/object';
export default Component.extend({
store: injectService(),
entityType: '',
entityKey: '',
selectedEntities: [],
entities: [],
tableColumns: computed(function() {
var col = A([
EmberObject.create({
propertyName: "id",
title: "id"
}),
EmberObject.create({
propertyName: this.get('entityKey'),
title: this.get('entityKey')
})
]);
return col;
}),
init(){
this._super(...arguments);
this._getEntities();
},
_getEntities() {
this.get('store').findAll(this.get('entityType')).then((entities) => {
// because this is async you need to guard against the component
// being destroyed before the api call has finished because
// because `this.set` will throw an error.
if (this.isDestroyed) { return; }
this.set('entities', entities);
}
)}
})
{{models-table
data=entities
columns=tableColumns
multipleSelect=true
selectedItems=selectedEntities}}
\ No newline at end of file
export { default } from 'ember-aws-ehipster/components/multiple-entity-selector';
\ No newline at end of file
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
module('Integration | Component | multiple-entity-selector', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
await render(hbs`{{multiple-entity-selector}}`);
assert.equal(this.element.textContent.trim(), '');
// Template block usage:
await render(hbs`
{{#multiple-entity-selector}}
template block text
{{/multiple-entity-selector}}
`);
assert.equal(this.element.textContent.trim(), 'template block text');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment