diff --git a/app/adapters/application.js b/app/adapters/application.js new file mode 100644 index 0000000..98e3b38 --- /dev/null +++ b/app/adapters/application.js @@ -0,0 +1,37 @@ +import DS from 'ember-data'; + +export default DS.RESTAdapter.extend({ + host: 'http://46.101.131.212:80', + namespace: 'ngsi10', + headers: { + Accept: 'application/json' + }, + + findAll: function(store, type, sinceToken) { + var requestBody = { + entities: [ + { + type: 'ElectricalGridMonitoring', + isPattern: true, + id: 'S?_ElectricalGrid' + } + ] + }; + + return this.ajax(this.host + '/' + this.namespace + '/queryContext', 'POST', { data: requestBody }); + }, + + findRecord: function(store, type, id, snapshot) { + var requestBody = { + entities: [ + { + type: 'ElectricalGridMonitoring', + isPattern: false, + id: id + } + ] + }; + + return this.ajax(this.host + '/' + this.namespace + '/queryContext', 'POST', { data: requestBody }); + }, +}); diff --git a/app/components/entities-table.js b/app/components/entities-table.js new file mode 100644 index 0000000..b47b62e --- /dev/null +++ b/app/components/entities-table.js @@ -0,0 +1,6 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: 'table', + classNames: ['properties-table'] +}); diff --git a/app/mirage/factories/property.js b/app/mirage/factories/property.js index 56d85e7..8ab983f 100644 --- a/app/mirage/factories/property.js +++ b/app/mirage/factories/property.js @@ -3,5 +3,5 @@ import Mirage, {faker} from 'ember-cli-mirage' export default Mirage.Factory.extend({ name(i) { return `Property ${i}`; }, value: faker.list.random(1.23, 2.34, 3.45, 4.56), - unit: faker.list.random('A', 'kV', 'MW') + type: faker.list.random('A', 'kV', 'MW') }); diff --git a/app/models/entity.js b/app/models/entity.js new file mode 100644 index 0000000..29b0c4a --- /dev/null +++ b/app/models/entity.js @@ -0,0 +1,6 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + type: DS.attr('string'), + properties: DS.attr() +}); diff --git a/app/models/property.js b/app/models/property.js deleted file mode 100644 index 0f672b9..0000000 --- a/app/models/property.js +++ /dev/null @@ -1,7 +0,0 @@ -import DS from 'ember-data'; - -export default DS.Model.extend({ - name: DS.attr('string'), - value: DS.attr('number'), - unit: DS.attr('string') -}); diff --git a/app/router.js b/app/router.js index b43c911..d4875f9 100644 --- a/app/router.js +++ b/app/router.js @@ -6,7 +6,9 @@ var Router = Ember.Router.extend({ }); Router.map(function() { - this.route('lab-mashup', { path: '/' }, function() {}); + this.route('lab-mashup', { path: '/' }, function() { + this.route('entity', { path: '/:entity_id' }); + }); }); export default Router; diff --git a/app/routes/lab-mashup.js b/app/routes/lab-mashup.js index a7bf346..26d9f31 100644 --- a/app/routes/lab-mashup.js +++ b/app/routes/lab-mashup.js @@ -1,8 +1,4 @@ import Ember from 'ember'; export default Ember.Route.extend({ - model() { - return this.store.findAll('property'); - } }); - diff --git a/app/routes/lab-mashup/entity.js b/app/routes/lab-mashup/entity.js new file mode 100644 index 0000000..5ac36df --- /dev/null +++ b/app/routes/lab-mashup/entity.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + return this.store.findRecord('entity', params.entity_id); + } +}); diff --git a/app/routes/lab-mashup/index.js b/app/routes/lab-mashup/index.js new file mode 100644 index 0000000..3ac0567 --- /dev/null +++ b/app/routes/lab-mashup/index.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model() { + return this.store.findAll('entity'); + } +}); diff --git a/app/serializers/application.js b/app/serializers/application.js new file mode 100644 index 0000000..074d7ac --- /dev/null +++ b/app/serializers/application.js @@ -0,0 +1,78 @@ +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; + } +}); diff --git a/app/templates/components/entities-table.hbs b/app/templates/components/entities-table.hbs new file mode 100644 index 0000000..a1981b0 --- /dev/null +++ b/app/templates/components/entities-table.hbs @@ -0,0 +1,10 @@ +