mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Add context broker mockup with mirage
Mirage mockup is used in development environment. Adapter's host port need to be changed for production environment.
This commit is contained in:
parent
bfb2e155b4
commit
05b404404d
6 changed files with 57 additions and 16 deletions
|
@ -1,8 +1,8 @@
|
|||
import DS from 'ember-data';
|
||||
|
||||
export default DS.RESTAdapter.extend({
|
||||
host: 'http://46.101.131.212:80',
|
||||
namespace: '/api/ngsi10',
|
||||
host: 'http://localhost:4200',
|
||||
namespace: 'api/ngsi10',
|
||||
headers: {
|
||||
Accept: 'application/json'
|
||||
},
|
||||
|
|
|
@ -1,8 +1,32 @@
|
|||
export default function() {
|
||||
this.get('/properties', function(db, request) {
|
||||
this.namespace = '/api/ngsi10';
|
||||
|
||||
this.post('/queryContext', function(db, request) {
|
||||
return {
|
||||
data: db.properties.map(attrs => ({ type: 'properties', id: attrs.id, attributes: attrs }))
|
||||
}
|
||||
contextResponses: db.entities.map(attrs => ({
|
||||
contextElement: {
|
||||
type: attrs.type,
|
||||
isPattern: false,
|
||||
id: attrs.name,
|
||||
attributes: attrs.properties.map(props => ({
|
||||
name: props.name,
|
||||
type: props.type,
|
||||
value: props.value,
|
||||
metadatas: [
|
||||
{
|
||||
name: 'timestamp',
|
||||
type: 'date',
|
||||
value: props.timestamp
|
||||
}
|
||||
]
|
||||
}))
|
||||
},
|
||||
statusCode: {
|
||||
code: 200,
|
||||
reasonPhrase: 'OK'
|
||||
}
|
||||
}))
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
|
22
app/mirage/factories/entity.js
Normal file
22
app/mirage/factories/entity.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
import Mirage, {faker} from 'ember-cli-mirage';
|
||||
|
||||
export default Mirage.Factory.extend({
|
||||
name(i) { return `S${i + 1}_ElectricalGrid`; },
|
||||
|
||||
type: 'ElectricalGridMonitoring',
|
||||
|
||||
properties: function(i) {
|
||||
var data = [];
|
||||
|
||||
for (var j = 0; j < 10; j++) {
|
||||
data.push({
|
||||
name: faker.random.arrayElement(['Current', 'Max. Current', 'Voltage', 'Max. Voltage', 'Power', 'Max. Power']),
|
||||
value: faker.finance.amount(-100, 100, 4),
|
||||
type: faker.random.arrayElement(['A', 'kV', 'MW']),
|
||||
timestamp: faker.date.past()
|
||||
})
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
});
|
|
@ -1,7 +0,0 @@
|
|||
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),
|
||||
type: faker.list.random('A', 'kV', 'MW')
|
||||
});
|
|
@ -1,3 +1,3 @@
|
|||
export default function(server) {
|
||||
server.createList('property', 5);
|
||||
server.createList('entity', 5);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ module.exports = function(environment) {
|
|||
'default-src': "'none'",
|
||||
'script-src': "'self'",
|
||||
'font-src': "'self'",
|
||||
'connect-src': "'self' localhost:8080 46.101.131.212:1026 46.101.131.212:80",
|
||||
'connect-src': "'self'",
|
||||
'img-src': "'self'",
|
||||
'style-src': "'self'",
|
||||
'media-src': "'self'"
|
||||
|
@ -37,7 +37,7 @@ module.exports = function(environment) {
|
|||
// ENV.APP.LOG_VIEW_LOOKUPS = true;
|
||||
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: false
|
||||
enabled: true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,9 @@ module.exports = function(environment) {
|
|||
}
|
||||
|
||||
if (environment === 'production') {
|
||||
|
||||
ENV['ember-cli-mirage'] = {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
|
||||
return ENV;
|
||||
|
|
Loading…
Add table
Reference in a new issue