diff --git a/app/adapters/entity.js b/app/adapters/application.js similarity index 94% rename from app/adapters/entity.js rename to app/adapters/application.js index 95b697b..98724cb 100644 --- a/app/adapters/entity.js +++ b/app/adapters/application.js @@ -38,5 +38,9 @@ export default DS.RESTAdapter.extend({ query: function(store, type, query) { return this.ajax(this.host + '/' + this.namespace + '/queryContext', 'POST', { data: query }); + }, + + updateRecord: function(store, type, snapshot) { + } }); diff --git a/app/components/line-chart.js b/app/components/line-chart.js new file mode 100644 index 0000000..eab77dd --- /dev/null +++ b/app/components/line-chart.js @@ -0,0 +1,17 @@ +import Ember from 'ember'; + +const { Component, computed } = Ember; + +export default Ember.Component.extend({ + tagName: 'canvas', + classNames: ['line-chart'], + + didInsertElement: function() { + // create chart + var element = this.get('element'); + this.chart = new Chart(element.getContext('2d')); + this.chart.Line(this.chartData, { + + }); + } +}); diff --git a/app/controllers/lab-mashup/entity/property.js b/app/controllers/lab-mashup/entity/property.js new file mode 100644 index 0000000..1210744 --- /dev/null +++ b/app/controllers/lab-mashup/entity/property.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + model(params) { + Ember.run.later(this, function() { + this.refresh(); + }, 500); + + var record = this.store.peekRecord('property', params.property_id); + return record; + } +}); diff --git a/app/models/property.js b/app/models/property.js index 2a9b4e3..d1f042a 100644 --- a/app/models/property.js +++ b/app/models/property.js @@ -5,6 +5,7 @@ export default DS.Model.extend({ value: DS.attr('number'), type: DS.attr('string'), timestamp: DS.attr('date'), + history: DS.attr(), entity: DS.belongsTo('entity'), category: DS.belongsTo('category') }); diff --git a/app/router.js b/app/router.js index ea4bab1..e6116d4 100644 --- a/app/router.js +++ b/app/router.js @@ -9,7 +9,8 @@ Router.map(function() { this.route('lab-mashup', { path: '/' }, function() { // dynamic routes this.route('entity', { path: '/:entity_id' }, function() { - this.route('category', { path: '/:category_id'}); + //this.route('category', { path: '/:category_id'}); + this.route('property', { path: '/:property_id'}); }); // static routes diff --git a/app/routes/lab-mashup/entity/property.js b/app/routes/lab-mashup/entity/property.js new file mode 100644 index 0000000..b2a2a2b --- /dev/null +++ b/app/routes/lab-mashup/entity/property.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + model(params) { + Ember.run.later(this, function() { + this.refresh(); + }, 500); + + var record = this.store.peekRecord('property', params.property_id); + return record; + }, + + chartData() { + return { + name: 'test' + }; + } +}); diff --git a/app/serializers/entity.js b/app/serializers/application.js similarity index 67% rename from app/serializers/entity.js rename to app/serializers/application.js index f173d72..b1764c1 100644 --- a/app/serializers/entity.js +++ b/app/serializers/application.js @@ -5,7 +5,21 @@ export default DS.RESTSerializer.extend({ var json = { data: [] }; this._normalizePayload(payload, function(item) { - json.data.push(item); + if (item.type === 'entity') { + json.data.push(item); + } else if (item.type === 'property') { + // create record if needed, otherwise add to current one + var record = store.peekRecord('property', item.id); + if (record) { + var length = record.get('history')[0].length; + record.get('history')[0].push([length, record.get('value')]); + record.set('value', item.attributes.value); + } else { + // add new item + store.push(item); + } + } + return true; }); @@ -16,8 +30,25 @@ export default DS.RESTSerializer.extend({ var json = { data: {} }; this._normalizePayload(payload, function(item) { - json.data = item; - return false; + //json.data = item; + //return false; + + if (item.type === 'entity') { + json.data = item; + } else if (item.type === 'property') { + // create record if needed, otherwise add to current one + var record = store.peekRecord('property', item.id); + if (record) { + var length = record.get('history').length; + record.get('history')[0].push([length, record.get('value')]); + record.set('value', item.attributes.value); + } else { + // add new item + store.push(item); + } + } + + return true; }); return json; @@ -29,8 +60,17 @@ export default DS.RESTSerializer.extend({ this._normalizePayload(payload, function(item) { if (item.type === 'entity') { json.data.push(item); - } else { - _createRecord(store, item); + } else if (item.type === 'property') { + // create record if needed, otherwise add to current one + var record = store.peekRecord('property', item.id); + if (record) { + var length = record.get('history').length; + record.get('history')[0].push([length, record.get('value')]); + record.set('value', item.attributes.value); + } else { + // add new item + store.push(item); + } } return true; @@ -73,6 +113,7 @@ export default DS.RESTSerializer.extend({ name: attribute.name, type: attribute.type, value: attribute.value, + history: [[[0, attribute.value]]] }, relationships: { entity: { @@ -118,11 +159,5 @@ export default DS.RESTSerializer.extend({ } }); } - }, - - _createRecord: function(store, item) { - store.createRecord(item.type, { - - }); } }); diff --git a/app/styles/app.css b/app/styles/app.css index 83b644e..2549145 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -8,7 +8,7 @@ body { color: #4d4d4d; min-width: 300px; - max-width: 1500px; + /*max-width: 1500px;*/ margin: 0 auto; font: 16px 'Helvetica Neue', Helvetica, Arial, sans-serif; @@ -45,6 +45,8 @@ footer { margin: 35px auto 0; + width: 100%; + font-size: 12px; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); text-align: center; @@ -53,30 +55,40 @@ footer { #main { margin-top: 15px; margin-left: 15px; + + width: 100%; } -#main-left { +.layout-left { float: left; - width: 45%; + width: 50%; padding-top: 10px; /*padding-left: 25px;*/ } -#main-right { +.layout-right { float: right; - width: 45%; + width: 50%; padding-top: 10px; /*padding-right: 25px;*/ } -#main::after { +.layout::after { display: block; content: ""; clear: both; } +#properties > .layout-left { + width: 30%; +} + +#properties > .layout-right { + width: 70%; +} + .data-table { background: #eee; @@ -112,6 +124,13 @@ footer { margin: 0; } +canvas.line-chart { + width: 90%; + height: 90%; + + margin: 10px; +} + .mockup-image { width: 600px; height: 400px; diff --git a/app/templates/components/line-chart.hbs b/app/templates/components/line-chart.hbs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/app/templates/components/line-chart.hbs @@ -0,0 +1 @@ + diff --git a/app/templates/components/properties-table.hbs b/app/templates/components/properties-table.hbs index 50af553..d64e118 100644 --- a/app/templates/components/properties-table.hbs +++ b/app/templates/components/properties-table.hbs @@ -5,8 +5,8 @@ {{#each properties as |property|}} - - {{property.name}} + {{#link-to 'lab-mashup.entity.property' property}}{{property.name}}{{/link-to}} + {{property.value}} {{property.type}} {{property.timestamp}} diff --git a/app/templates/lab-mashup/entity.hbs b/app/templates/lab-mashup/entity.hbs index 6d5efa9..2cda9fc 100644 --- a/app/templates/lab-mashup/entity.hbs +++ b/app/templates/lab-mashup/entity.hbs @@ -1,13 +1,30 @@ -
+
[Node Layout Image]
-
+
- {{outlet}} +
+
+ + + + + {{#each model.properties as |property|}} + + + + {{/each}} +
Name
{{#link-to 'lab-mashup.entity.property' property}}{{property.name}}{{/link-to}}
+
+ +
+ {{outlet}} +
+
diff --git a/app/templates/lab-mashup/entity/index.hbs b/app/templates/lab-mashup/entity/index.hbs index ef763bf..8b13789 100644 --- a/app/templates/lab-mashup/entity/index.hbs +++ b/app/templates/lab-mashup/entity/index.hbs @@ -1 +1 @@ -{{properties-table properties=model.properties}} + diff --git a/app/templates/lab-mashup/entity/property.hbs b/app/templates/lab-mashup/entity/property.hbs new file mode 100644 index 0000000..4ff2748 --- /dev/null +++ b/app/templates/lab-mashup/entity/property.hbs @@ -0,0 +1,7 @@ +{{#if property}} +

{{property.name}}

+{{/if}} + +{{chartData.name}} + +{{flot-chart height="500px" data=model.history}} diff --git a/bower.json b/bower.json index 006e7c6..8e85056 100644 --- a/bower.json +++ b/bower.json @@ -15,6 +15,8 @@ "pretender": "~0.9.0", "lodash": "~3.7.0", "Faker": "~3.0.0", - "bootstrap": "~3.3.2" + "bootstrap": "~3.3.2", + "chart.js": "~0.1.0", + "flot-charts": "*" } } diff --git a/config/environment.js b/config/environment.js index 3072554..68518d8 100644 --- a/config/environment.js +++ b/config/environment.js @@ -22,11 +22,11 @@ module.exports = function(environment) { contentSecurityPolicy: { 'default-src': "'none'", - 'script-src': "'self'", + 'script-src': "'self' 'unsafe-eval'", 'font-src': "'self'", 'connect-src': "'self' 46.101.131.212:80", 'img-src': "'self'", - 'style-src': "'self'", + 'style-src': "'self' 'unsafe-inline'", 'media-src': "'self'" } }; diff --git a/package.json b/package.json index db43701..6acbd3b 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "morgan": "^1.6.1" }, "dependencies": { - "ember-cli-cors": "0.0.1" + "ember-cli-cors": "0.0.1", + "ember-cli-flot": "0.0.3" } }