From fefac5812526f1753909942dea3338c67f77c4a1 Mon Sep 17 00:00:00 2001 From: Markus Grigull Date: Thu, 8 Oct 2015 16:04:06 +0200 Subject: [PATCH] Moved on with layout --- app/adapters/{application.js => entity.js} | 4 + app/models/category.js | 7 + app/models/entity.js | 3 +- app/models/property.js | 3 +- app/router.js | 2 +- app/routes/lab-mashup.js | 25 ++++ app/routes/lab-mashup/entity/category.js | 4 + app/routes/lab-mashup/entity/property.js | 7 - app/serializers/application.js | 89 ------------ app/serializers/entity.js | 128 ++++++++++++++++++ app/styles/app.css | 65 +++------ app/templates/components/properties-table.hbs | 5 +- app/templates/lab-mashup.hbs | 7 +- app/templates/lab-mashup/entity.hbs | 14 +- app/templates/lab-mashup/entity/category.hbs | 1 + app/templates/lab-mashup/entity/index.hbs | 2 +- app/templates/lab-mashup/entity/property.hbs | 1 - app/templates/lab-mashup/static1.hbs | 2 +- 18 files changed, 208 insertions(+), 161 deletions(-) rename app/adapters/{application.js => entity.js} (86%) create mode 100644 app/models/category.js create mode 100644 app/routes/lab-mashup/entity/category.js delete mode 100644 app/routes/lab-mashup/entity/property.js delete mode 100644 app/serializers/application.js create mode 100644 app/serializers/entity.js create mode 100644 app/templates/lab-mashup/entity/category.hbs delete mode 100644 app/templates/lab-mashup/entity/property.hbs diff --git a/app/adapters/application.js b/app/adapters/entity.js similarity index 86% rename from app/adapters/application.js rename to app/adapters/entity.js index a83c261..95b697b 100644 --- a/app/adapters/application.js +++ b/app/adapters/entity.js @@ -35,4 +35,8 @@ export default DS.RESTAdapter.extend({ return this.ajax(this.host + '/' + this.namespace + '/queryContext', 'POST', { data: requestBody }); }, + + query: function(store, type, query) { + return this.ajax(this.host + '/' + this.namespace + '/queryContext', 'POST', { data: query }); + } }); diff --git a/app/models/category.js b/app/models/category.js new file mode 100644 index 0000000..b88c84b --- /dev/null +++ b/app/models/category.js @@ -0,0 +1,7 @@ +import DS from 'ember-data'; + +export default DS.Model.extend({ + name: DS.attr('string'), + properties: DS.hasMany('property'), + entity: DS.belongsTo('entity') +}); diff --git a/app/models/entity.js b/app/models/entity.js index b5f469c..6dec69e 100644 --- a/app/models/entity.js +++ b/app/models/entity.js @@ -3,5 +3,6 @@ import DS from 'ember-data'; export default DS.Model.extend({ type: DS.attr('string'), - properties: DS.hasMany('property') + properties: DS.hasMany('property'), + categories: DS.hasMany('category') }); diff --git a/app/models/property.js b/app/models/property.js index a0bccae..2a9b4e3 100644 --- a/app/models/property.js +++ b/app/models/property.js @@ -5,5 +5,6 @@ export default DS.Model.extend({ value: DS.attr('number'), type: DS.attr('string'), timestamp: DS.attr('date'), - entity: DS.belongsTo('entity') + entity: DS.belongsTo('entity'), + category: DS.belongsTo('category') }); diff --git a/app/router.js b/app/router.js index 7e67158..ea4bab1 100644 --- a/app/router.js +++ b/app/router.js @@ -9,7 +9,7 @@ Router.map(function() { this.route('lab-mashup', { path: '/' }, function() { // dynamic routes this.route('entity', { path: '/:entity_id' }, function() { - this.route('property', { path: '/:property_id'}); + this.route('category', { path: '/:category_id'}); }); // static routes diff --git a/app/routes/lab-mashup.js b/app/routes/lab-mashup.js index 567b3a3..3942304 100644 --- a/app/routes/lab-mashup.js +++ b/app/routes/lab-mashup.js @@ -2,6 +2,18 @@ import Ember from 'ember'; export default Ember.Route.extend({ model() { + /*return this.store.query('entity', { entities: [ + { + id: 'S1_ElectricalGrid', + isPattern: false, + type: 'ElectricalGridMonitoring' + }, + { + id: 'S2_ElectricalGrid', + isPattern: false, + type: 'ElectricalGridMonitoring' + } + ]});*/ return this.store.findAll('entity'); }, @@ -14,6 +26,19 @@ export default Ember.Route.extend({ refreshEntities: function() { // fetch new data from server + /*this.store.query('entity', { entities: [ + { + id: 'S1_ElectricalGrid', + isPattern: false, + type: 'ElectricalGridMonitoring' + }, + { + id: 'S2_ElectricalGrid', + isPattern: false, + type: 'ElectricalGridMonitoring' + } + ]});*/ + this.store.findAll('entity'); // reschedule refresh diff --git a/app/routes/lab-mashup/entity/category.js b/app/routes/lab-mashup/entity/category.js new file mode 100644 index 0000000..26d9f31 --- /dev/null +++ b/app/routes/lab-mashup/entity/category.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/app/routes/lab-mashup/entity/property.js b/app/routes/lab-mashup/entity/property.js deleted file mode 100644 index 40054d9..0000000 --- a/app/routes/lab-mashup/entity/property.js +++ /dev/null @@ -1,7 +0,0 @@ -import Ember from 'ember'; - -export default Ember.Route.extend({ - model(params) { - return this.store.findRecord('property', params.property_id); - } -}); diff --git a/app/serializers/application.js b/app/serializers/application.js deleted file mode 100644 index 771799e..0000000 --- a/app/serializers/application.js +++ /dev/null @@ -1,89 +0,0 @@ -import DS from 'ember-data'; - -export default DS.RESTSerializer.extend({ - normalizeFindAllResponse: function(store, primaryModelClass, payload, id, requestType) { - var json = { data: [] }; - - this._normalizePayload(payload, function(entity) { - json.data.push(entity); - return true; - }); - - return json; - }, - - normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType) { - var json = { data: {} }; - - this._normalizePayload(payload, function(entity) { - json.data = entity; - return false; - }); - - return json; - }, - - _normalizePayload: function(payload, handleEntity) { - var propertyIndex = 0; - - // 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: [] - }, - relationships: { - properties: { - data: [] - } - } - } - - if (item.contextElement.attributes) { - item.contextElement.attributes.forEach(function(attribute) { - // create property - var property = { - type: 'property', - id: 'property_' + propertyIndex++, - attributes: { - name: attribute.name, - type: attribute.type, - value: attribute.value, - }, - relationships: { - entity: { - data: { type: 'entity', id: entity.id } - } - } - } - - // find timestamp - attribute.metadatas.forEach(function(metadata) { - if (metadata.name === 'timestamp') { - property.attributes.timestamp = metadata.value; - } - }); - - entity.relationships.properties.data.push({ type: 'property', id: property.id }); - - handleEntity(property); - }); - } - - // pass entity to caller function - if (handleEntity(entity) == false) { - // if false returned the caller needs no more entites - return; - } - } - }); - } - } -}); diff --git a/app/serializers/entity.js b/app/serializers/entity.js new file mode 100644 index 0000000..f173d72 --- /dev/null +++ b/app/serializers/entity.js @@ -0,0 +1,128 @@ +import DS from 'ember-data'; + +export default DS.RESTSerializer.extend({ + normalizeFindAllResponse: function(store, primaryModelClass, payload, id, requestType) { + var json = { data: [] }; + + this._normalizePayload(payload, function(item) { + json.data.push(item); + return true; + }); + + return json; + }, + + normalizeFindRecordResponse: function(store, primaryModelClass, payload, id, requestType) { + var json = { data: {} }; + + this._normalizePayload(payload, function(item) { + json.data = item; + return false; + }); + + return json; + }, + + normalizeQueryResponse: function(store, primaryModelClass, payload, id, requestType) { + var json = { data: [] }; + + this._normalizePayload(payload, function(item) { + if (item.type === 'entity') { + json.data.push(item); + } else { + _createRecord(store, item); + } + + return true; + }); + + return json; + }, + + _normalizePayload: function(payload, handleItem) { + var propertyIndex = 0; + + // 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: [] + }, + relationships: { + properties: { + data: [] + } + } + } + + if (item.contextElement.attributes) { + item.contextElement.attributes.forEach(function(attribute) { + if (attribute.type !== 'category') { + // create property + var property = { + type: 'property', + id: 'property_' + propertyIndex++, + attributes: { + name: attribute.name, + type: attribute.type, + value: attribute.value, + }, + relationships: { + entity: { + data: { type: 'entity', id: entity.id } + } + } + } + + // find timestamp + attribute.metadatas.forEach(function(metadata) { + if (metadata.name === 'timestamp') { + property.attributes.timestamp = metadata.value; + } + }); + + entity.relationships.properties.data.push({ type: 'property', id: property.id }); + + handleItem(property); + } else { + var category = { + type: 'category', + id: 'category_' + propertyIndex++, + attributes: { + name: attribute.name, + }, + relationships: { + entity: { + data: { type: 'entity', id: entity.id } + } + } + } + + handleItem(category); + } + }); + } + + // pass entity to caller function + if (handleItem(entity) == false) { + // if false returned the caller needs no more entites + return; + } + } + }); + } + }, + + _createRecord: function(store, item) { + store.createRecord(item.type, { + + }); + } +}); diff --git a/app/styles/app.css b/app/styles/app.css index 7a29417..83b644e 100644 --- a/app/styles/app.css +++ b/app/styles/app.css @@ -40,39 +40,14 @@ header { -moz-text-rendering: optimizeLegibitliy; } -#menu { - background-color: #6060C9; +footer { + color: #777; - border-top: 1px solid #3030C9; + margin: 35px auto 0; - width: 100%; -} - -.nav-tabs { - color: #ccc; - background-color: #6060C9; - - padding-left: 30px; - - border: 0; -} - -.nav-tabs > li > a { - color: #ccc; - background-color: #5050C9; - box-shadow: none; - - border: 0; -} - -.nav-tabs > li > a:hoverĀ { - color: #ccc; - background-color: #7070C9; - - box-shadow: none; - - border: 0; - border-radius: 0; + font-size: 12px; + text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); + text-align: center; } #main { @@ -102,23 +77,6 @@ header { clear: both; } -#info { - color: #777; - - margin: 35px auto 0; - - font-size: 12px; - text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5); - text-align: center; -} - -#last-update-info { - padding: 0px 0 20px 0; - - font-size: 15px; - text-align: left; -} - .data-table { background: #eee; @@ -153,3 +111,14 @@ header { width: 45%; margin: 0; } + +.mockup-image { + width: 600px; + height: 400px; + + border: 1px solid black; + + text-align: center; + vertical-align: middle; + line-height: 400px; +} diff --git a/app/templates/components/properties-table.hbs b/app/templates/components/properties-table.hbs index aaf0673..50af553 100644 --- a/app/templates/components/properties-table.hbs +++ b/app/templates/components/properties-table.hbs @@ -3,9 +3,10 @@ Value Date -{{#each entity.properties as |property|}} +{{#each properties as |property|}} - {{#link-to 'lab-mashup.entity.property' property}}{{property.name}}{{/link-to}} + + {{property.name}} {{property.value}} {{property.type}} {{property.timestamp}} diff --git a/app/templates/lab-mashup.hbs b/app/templates/lab-mashup.hbs index 0b4b1de..c7c1ee6 100644 --- a/app/templates/lab-mashup.hbs +++ b/app/templates/lab-mashup.hbs @@ -1,7 +1,10 @@ diff --git a/app/templates/lab-mashup/entity.hbs b/app/templates/lab-mashup/entity.hbs index 82b3fb7..6d5efa9 100644 --- a/app/templates/lab-mashup/entity.hbs +++ b/app/templates/lab-mashup/entity.hbs @@ -1,13 +1,13 @@ -

{{model.id}}

- -{{#if model.properties}}
- {{properties-table entity=model}} +
[Node Layout Image]
+ + {{outlet}}
-{{else}} -

No properties

-{{/if}} diff --git a/app/templates/lab-mashup/entity/category.hbs b/app/templates/lab-mashup/entity/category.hbs new file mode 100644 index 0000000..ef763bf --- /dev/null +++ b/app/templates/lab-mashup/entity/category.hbs @@ -0,0 +1 @@ +{{properties-table properties=model.properties}} diff --git a/app/templates/lab-mashup/entity/index.hbs b/app/templates/lab-mashup/entity/index.hbs index 0233710..ef763bf 100644 --- a/app/templates/lab-mashup/entity/index.hbs +++ b/app/templates/lab-mashup/entity/index.hbs @@ -1 +1 @@ -

Select a property

+{{properties-table properties=model.properties}} diff --git a/app/templates/lab-mashup/entity/property.hbs b/app/templates/lab-mashup/entity/property.hbs deleted file mode 100644 index 76b21c4..0000000 --- a/app/templates/lab-mashup/entity/property.hbs +++ /dev/null @@ -1 +0,0 @@ -

{{model.name}}: {{model.value}} {{model.type}}

diff --git a/app/templates/lab-mashup/static1.hbs b/app/templates/lab-mashup/static1.hbs index 387f099..4ef4c3e 100644 --- a/app/templates/lab-mashup/static1.hbs +++ b/app/templates/lab-mashup/static1.hbs @@ -1 +1 @@ -

Static 1 page

+
[Static 1 Image]