diff --git a/app/adapters/application.js b/app/adapters/application.js index 2ebf237..b317bc5 100644 --- a/app/adapters/application.js +++ b/app/adapters/application.js @@ -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' }, diff --git a/app/mirage/config.js b/app/mirage/config.js index 93550ca..3c9a9c7 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -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' + } + })) + }; }); } diff --git a/app/mirage/factories/entity.js b/app/mirage/factories/entity.js new file mode 100644 index 0000000..c8d2cfc --- /dev/null +++ b/app/mirage/factories/entity.js @@ -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; + } +}); diff --git a/app/mirage/factories/property.js b/app/mirage/factories/property.js deleted file mode 100644 index 8ab983f..0000000 --- a/app/mirage/factories/property.js +++ /dev/null @@ -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') -}); diff --git a/app/mirage/scenarios/default.js b/app/mirage/scenarios/default.js index 93bbb90..84d07c0 100644 --- a/app/mirage/scenarios/default.js +++ b/app/mirage/scenarios/default.js @@ -1,3 +1,3 @@ export default function(server) { - server.createList('property', 5); + server.createList('entity', 5); } diff --git a/config/environment.js b/config/environment.js index 3fac5b7..d78b118 100644 --- a/config/environment.js +++ b/config/environment.js @@ -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;