mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
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.
This commit is contained in:
parent
7a15b1d953
commit
64d1c6e479
18 changed files with 196 additions and 16 deletions
37
app/adapters/application.js
Normal file
37
app/adapters/application.js
Normal file
|
@ -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 });
|
||||
},
|
||||
});
|
6
app/components/entities-table.js
Normal file
6
app/components/entities-table.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
tagName: 'table',
|
||||
classNames: ['properties-table']
|
||||
});
|
|
@ -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')
|
||||
});
|
||||
|
|
6
app/models/entity.js
Normal file
6
app/models/entity.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import DS from 'ember-data';
|
||||
|
||||
export default DS.Model.extend({
|
||||
type: DS.attr('string'),
|
||||
properties: DS.attr()
|
||||
});
|
|
@ -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')
|
||||
});
|
|
@ -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;
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model() {
|
||||
return this.store.findAll('property');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
7
app/routes/lab-mashup/entity.js
Normal file
7
app/routes/lab-mashup/entity.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model(params) {
|
||||
return this.store.findRecord('entity', params.entity_id);
|
||||
}
|
||||
});
|
7
app/routes/lab-mashup/index.js
Normal file
7
app/routes/lab-mashup/index.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model() {
|
||||
return this.store.findAll('entity');
|
||||
}
|
||||
});
|
78
app/serializers/application.js
Normal file
78
app/serializers/application.js
Normal file
|
@ -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;
|
||||
}
|
||||
});
|
10
app/templates/components/entities-table.hbs
Normal file
10
app/templates/components/entities-table.hbs
Normal file
|
@ -0,0 +1,10 @@
|
|||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Type</th>
|
||||
</tr>
|
||||
{{#each entities as |entity|}}
|
||||
<tr>
|
||||
<td>{{#link-to 'lab-mashup.entity' entity}}{{entity.id}}{{/link-to}}</td>
|
||||
<td>{{entity.type}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
|
@ -5,6 +5,6 @@
|
|||
{{#each properties as |property|}}
|
||||
<tr>
|
||||
<td>{{property.name}}</td>
|
||||
<td>{{property.value}} {{property.unit}}</td>
|
||||
<td>{{property.value}} {{property.type}}</td>
|
||||
</tr>
|
||||
{{/each}}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
<section id="main">
|
||||
{{properties-table properties=model}}
|
||||
{{outlet}}
|
||||
</section>
|
||||
|
|
5
app/templates/lab-mashup/entity.hbs
Normal file
5
app/templates/lab-mashup/entity.hbs
Normal file
|
@ -0,0 +1,5 @@
|
|||
<h2></h2>
|
||||
|
||||
{{properties-table}}
|
||||
|
||||
{{#link-to 'lab-mashup'}}Entities{{/link-to}}
|
1
app/templates/lab-mashup/index.hbs
Normal file
1
app/templates/lab-mashup/index.hbs
Normal file
|
@ -0,0 +1 @@
|
|||
{{entities-table entities=model}}
|
12
app/transforms/property.js
Normal file
12
app/transforms/property.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
import Ember from 'ember';
|
||||
import DS from 'ember-data';
|
||||
|
||||
export default DS.Transform.extend({
|
||||
deserialize: function(value) {
|
||||
return Ember.create({ name: value[0], value: value[1], type: value[2]});
|
||||
},
|
||||
|
||||
serialize: function(value) {
|
||||
return [value.get('name'), value.get('value'), value.get('type')];
|
||||
}
|
||||
});
|
|
@ -16,6 +16,16 @@ module.exports = function(environment) {
|
|||
APP: {
|
||||
// Here you can pass flags/options to your application instance
|
||||
// when it is created
|
||||
},
|
||||
|
||||
contentSecurityPolicy: {
|
||||
'default-src': "'none'",
|
||||
'script-src': "'self'",
|
||||
'font-src': "'self'",
|
||||
'connect-src': "'self' localhost:8080 46.101.131.212:1026 46.101.131.212:80",
|
||||
'img-src': "'self'",
|
||||
'style-src': "'self'",
|
||||
'media-src': "'self'"
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -25,6 +35,10 @@ module.exports = function(environment) {
|
|||
// ENV.APP.LOG_TRANSITIONS = true;
|
||||
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
|
||||
// ENV.APP.LOG_VIEW_LOOKUPS = true;
|
||||
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
|
||||
if (environment === 'test') {
|
||||
|
|
|
@ -37,6 +37,12 @@
|
|||
"ember-data": "1.13.8",
|
||||
"ember-disable-proxy-controllers": "^1.0.0",
|
||||
"ember-export-application-global": "^1.0.3",
|
||||
"mirage": "0.0.5"
|
||||
"glob": "^4.5.3",
|
||||
"http-proxy": "^1.11.2",
|
||||
"mirage": "0.0.5",
|
||||
"morgan": "^1.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"ember-cli-cors": "0.0.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue