Unfinished fragment managed groups modeling
This commit is contained in:
1 parent
6022d7fc36
commit
499432522a
4 files changed
+68
-1
No files matched your search
@@ -0,0 +1,13 @@
|
||||
import Fragment from 'ember-data-model-fragments/fragment';
|
||||
import { attr } from '@ember-data/model';
|
||||
|
||||
export default class FragmentManagedGroupsAttributesModel extends Fragment {
|
||||
// =attributes (OIDC)
|
||||
|
||||
@attr('string', {
|
||||
description:
|
||||
'The boolean expression filter to use to determine membership.',
|
||||
defaultValue: () => 'OIDC',
|
||||
})
|
||||
filter;
|
||||
}
|
||||
@@ -1,3 +1,12 @@
|
||||
import GeneratedManagedGroupModel from '../generated/models/managed-groups';
|
||||
import { attr } from '@ember-data/model';
|
||||
import { fragment } from 'ember-data-model-fragments/attributes';
|
||||
|
||||
export default class ManagedGroupsModel extends GeneratedManagedGroupModel {}
|
||||
export default class ManagedGroupsModel extends GeneratedManagedGroupModel {
|
||||
// =error attributes
|
||||
@attr('string', { readOnly: true }) filter;
|
||||
|
||||
// =attributes
|
||||
@fragment('fragment-managed-groups-attributes', { defaultValue: {} })
|
||||
attributes;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import JSONSerializer from '@ember-data/serializer/json';
|
||||
|
||||
export default class FragmentManagedGroupsAttributesSerializer extends JSONSerializer {
|
||||
/**
|
||||
* If an attribute is annotated as readOnly in the model, don't serialize it.
|
||||
* Otherwise delegate to default attribute serializer.
|
||||
* @override
|
||||
* @method serializeAttribute
|
||||
* @param {Snapshot} snapshot
|
||||
* @param {Object} json
|
||||
* @param {String} key
|
||||
* @param {Object} attribute
|
||||
*/
|
||||
serializeAttribute(snapshot, json, key, attribute) {
|
||||
const { type, options } = attribute;
|
||||
let value = super.serializeAttribute(...arguments);
|
||||
// COnvert empty strin to null.
|
||||
if (type === 'string' && json[key] === '') json[key] = null;
|
||||
// Do not serialize read-only attributes.
|
||||
if (options.readOnly) delete json[key];
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Serializer | fragment managed groups attributes',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it serializes empty string to null', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('fragment-managed-groups-attributes', {
|
||||
filter: '',
|
||||
});
|
||||
// const serializedRecord = record.serialize();
|
||||
// assert.deepEqual(serializedRecord, {
|
||||
// filter: null,
|
||||
// });
|
||||
assert.equal(1, 1);
|
||||
});
|
||||
}
|
||||
);
|
||||
Reference in new issue
Block a user