1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-16 00:00:03 +01:00
VILLASweb/app/serializers/application.js
Markus Grigull 64d1c6e479 Add context broker backend
The context broker is connected via the custom adapter and
serializer. At the moment only the entity IDs are shown
but the property table is empty.

Mirage is disabled.
2015-10-01 14:09:27 +02:00

78 lines
2 KiB
JavaScript

import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeFindAllResponse: function(store, primaryModelClass, payload, id, requestType) {
var json = { data: [] };
// check if payload has context responses
if (payload.contextResponses) {
payload.contextResponses.forEach(function(item) {
// check if item has context element
if (item.contextElement) {
// create new entity object
var entity = {
type: 'entity',
id: item.contextElement.id,
attributes: {
type: item.contextElement.type,
properties: []
}
}
item.contextElement.attributes.forEach(function(attribute) {
var property = {
name: attribute.name,
value: attribute.value,
type: attribute.type
}
entity.attributes.properties.push(property);
});
// add entity to data
json.data.push(entity);
}
});
}
console.log(json);
return json;
},
normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType) {
var json = { data: {} };
// check if payload has context responses
if (payload.contextResponses) {
payload.contextResponses.forEach(function(item) {
// check if item has context element
if (item.contextElement) {
// create new entity object
json.data = {
type: 'entity',
id: item.contextElement.id,
attributes: {
type: item.contextElement.type,
properties: []
}
}
item.contextElement.attributes.forEach(function(attribute) {
var property = {
name: attribute.name,
value: attribute.value,
type: attribute.type
}
json.data.attributes.properties.push(property);
});
}
});
}
console.log(json);
return json;
}
});