diff --git a/app/components/entity-title.js b/app/components/entity-title.js new file mode 100644 index 0000000..db250f6 --- /dev/null +++ b/app/components/entity-title.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: 'h2' +}); diff --git a/app/serializers/application.js b/app/serializers/application.js index 074d7ac..871d3a8 100644 --- a/app/serializers/application.js +++ b/app/serializers/application.js @@ -4,6 +4,26 @@ export default DS.RESTSerializer.extend({ normalizeFindAllResponse: function(store, primaryModelClass, payload, id, requestType) { var json = { data: [] }; + this._normalizePayload(payload, function(entity) { + json.data.push(entity); + return true; + }); + + return json; + }, + + normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + var json = { data: {} }; + + this._normalizePayload(payload, function(entity) { + json.data = entity; + return false; + }); + + return json; + }, + + _normalizePayload: function(payload, handleEntity) { // check if payload has context responses if (payload.contextResponses) { payload.contextResponses.forEach(function(item) { @@ -29,50 +49,13 @@ export default DS.RESTSerializer.extend({ 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: [] - } + // pass entity to caller function + if (handleEntity(entity) == false) { + // if false returned the caller needs no more entites + return; } - - 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; } }); diff --git a/app/templates/components/entity-title.hbs b/app/templates/components/entity-title.hbs new file mode 100644 index 0000000..4af51a6 --- /dev/null +++ b/app/templates/components/entity-title.hbs @@ -0,0 +1 @@ +{{entity.id}} diff --git a/app/templates/components/properties-table.hbs b/app/templates/components/properties-table.hbs index e39df49..3609f4f 100644 --- a/app/templates/components/properties-table.hbs +++ b/app/templates/components/properties-table.hbs @@ -2,7 +2,7 @@ Name Value -{{#each properties as |property|}} +{{#each entity.properties as |property|}} {{property.name}} {{property.value}} {{property.type}} diff --git a/app/templates/lab-mashup/entity.hbs b/app/templates/lab-mashup/entity.hbs index 9a1e8be..7e7e964 100644 --- a/app/templates/lab-mashup/entity.hbs +++ b/app/templates/lab-mashup/entity.hbs @@ -1,5 +1,5 @@ -

+{{entity-title entity=model}} -{{properties-table}} +{{properties-table entity=model}} {{#link-to 'lab-mashup'}}Entities{{/link-to}}