diff --git a/app/components/plot-abstract.js b/app/components/plot-abstract.js index eded6a2..5df157f 100644 --- a/app/components/plot-abstract.js +++ b/app/components/plot-abstract.js @@ -79,9 +79,9 @@ export default Ember.Component.extend(Resizable, Draggable, { } }.observes('editing', 'grid').on('init'), - doubleClick() { + /*doubleClick() { if (this.get('editing')) { this.sendAction('showPlotDialog', this.get('plot')); } - } + }*/ }); diff --git a/app/components/plot-value.js b/app/components/plot-value.js index 338d900..b526080 100644 --- a/app/components/plot-value.js +++ b/app/components/plot-value.js @@ -26,5 +26,124 @@ export default PlotAbstract.extend({ Ember.run.later(this, function() { this.notifyPropertyChange('data.' + this.get('plot.simulator') + '.values'); }, 1000); - }.property('data.2.values', 'plot.simulator', 'plot.signal') + }.property('data.2.values', 'plot.simulator', 'plot.signal'), + + doubleClick() { + if (this.get('editing') === true) { + // prepare modal + this.set('name', this.get('plot.name')); + + // get signal mapping for simulation model + let self = this; + let simulatorid = this.get('plot.simulator'); + + this.get('plot.visualization').then((visualization) => { + visualization.get('project').then((project) => { + project.get('simulation').then((simulation) => { + simulation.get('models').then((simulationModels) => { + // find simulation model by simulatorid + simulationModels.forEach(function(simulationModel) { + simulationModel.get('simulator').then((simulator) => { + if (simulator.get('simulatorid') === simulatorid) { + // set simulation model + self.set('simulationModel', simulationModel); + self.set('simulationModelName', simulationModel.get('name')); + + // set signal + let mapping = simulationModel.get('mapping'); + self.set('signalName', mapping[self.get('plot.signal')]); + } + }); + }); + }); + }); + }); + }); + + // shot modal + this.set('isShowingModal', true); + } + }, + + actions: { + submitModal() { + // verify properties + let properties = this.getProperties('name'); + if (properties['name'] === null || properties['name'] === "") { + this.set('errorMessage', 'Plot name is missing'); + return; + } + + // set simulator by simulation model name + let simulationModelName = this.get('simulationModelName'); + let self = this; + + this.get('plot.visualization').then((visualization) => { + visualization.get('project').then((project) => { + project.get('simulation').then((simulation) => { + simulation.get('models').then((simulationModels) => { + // find simulation model by name + simulationModels.forEach(function(simulationModel) { + if (simulationModel.get('name') === simulationModelName) { + simulationModel.get('simulator').then((simulator) => { + // set simulator + properties['simulator'] = simulator.get('simulatorid'); + + // set signal by name + let mapping = simulationModel.get('mapping'); + let signalName = self.get('signalName'); + + for (let i = 0; i < mapping.length; i++) { + if (mapping[i] === signalName) { + properties['signal'] = i; + } + } + + // save properties + self.get('plot').setProperties(properties); + + self.get('plot').save().then(function() { + self.set('isShowingModal', false); + }); + }); + } + }); + }); + }); + }); + }); + }, + + cancelModal() { + this.set('isShowingModal', false); + }, + + selectSimulationModel(simulationModelName) { + // save simulation model + this.set('simulationModelName', simulationModelName); + + // get signal mapping for simulation model + let self = this; + let simulatorid = this.get('plot.simulator'); + + this.get('plot.visualization').then((visualization) => { + visualization.get('project').then((project) => { + project.get('simulation').then((simulation) => { + simulation.get('models').then((simulationModels) => { + // find simulation model by name + simulationModels.forEach(function(simulationModel) { + if (simulationModel.get('name') === simulationModelName) { + self.set('simulationModel', simulationModel); + } + }); + }); + }); + }); + }); + }, + + selectSignal(signalName) { + this.set('signalName', signalName); + } + } }); diff --git a/app/routes/visualization/new.js b/app/controllers/dialog/plot/value.js similarity index 69% rename from app/routes/visualization/new.js rename to app/controllers/dialog/plot/value.js index 12d85c7..427431e 100644 --- a/app/routes/visualization/new.js +++ b/app/controllers/dialog/plot/value.js @@ -1,14 +1,13 @@ /** - * File: new.js + * File: value.js * Author: Markus Grigull - * Date: 28.06.2016 + * Date: 12.07.2016 * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. * Unauthorized copying of this file, via any medium is strictly prohibited. **********************************************************************************/ import Ember from 'ember'; -import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend(AuthenticatedRouteMixin, { +export default Ember.Controller.extend({ }); diff --git a/app/controllers/simulation-model/index.js b/app/controllers/simulation-model/index.js index 3481e21..e8ba731 100644 --- a/app/controllers/simulation-model/index.js +++ b/app/controllers/simulation-model/index.js @@ -10,38 +10,4 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - values: function() { - return this.get('simulationData.values'); - }.property('simulationData.values.@each'), - - _getData: function() { - if (this.get('model.simulation.running') === true) { - var simulator = this.get('model.simulator'); - if (simulator == null) { - return; - } - - var data = this.store.peekRecord('simulation-data', simulator); - this.set('simulationData', data); - - // load model again if simulation data is null - // this prevents from simulation data not being loaded when the controller - // is loaded before the websocket connects - if (data === null) { - Ember.run.later(this, function() { - // trigger _getData - this.notifyPropertyChange('model'); - }, 1000); - } - } else { - // clear simulation data - this.set('simulationData', null); - - // check again if simulation is running now - Ember.run.later(this, function() { - // trigger _getData - this.notifyPropertyChange('model'); - }, 1000); - } - }.observes('model').on('init') }); diff --git a/app/controllers/simulation/index.js b/app/controllers/simulation/index.js index d201f3a..8db5c58 100644 --- a/app/controllers/simulation/index.js +++ b/app/controllers/simulation/index.js @@ -21,7 +21,7 @@ export default Ember.Controller.extend({ _updateSimulators: function() { if (this.get('model.simulators') != null && this.get('model.simulators.length') > 0) { - var simulators = this.get('model.simulators'); + let simulators = this.get('model.simulators'); this.set('simulatorName', simulators.toArray()[0].get('name')); } }.observes('model'), @@ -31,6 +31,7 @@ export default Ember.Controller.extend({ // reset properties this.set('errorMessage', null); this.set('name', null); + this.set('length', 1); // show the dialog this.set('isShowingNewModal', true); @@ -41,10 +42,11 @@ export default Ember.Controller.extend({ this.set('errorMessage', null); this.set('simulationModel', simulationModel); this.set('name', simulationModel.get('name')); + this.set('length', simulationModel.get('length')); - var simulators = this.get('model.simulators'); - var simulatorId = simulationModel.get('simulator.id'); - var simulatorName = null; + let simulators = this.get('model.simulators'); + let simulatorId = simulationModel.get('simulator.id'); + let simulatorName = null; simulators.forEach(function(simulator) { if (simulator.get('id') === simulatorId) { @@ -68,19 +70,19 @@ export default Ember.Controller.extend({ submitNew() { // verify properties - var properties = this.getProperties('name'); + let properties = this.getProperties('name', 'length'); if (properties['name'] == null || properties['name'] === "") { this.set('errorMessage', 'Simulation model name is missing'); return; } // set simuatlion properties - var simulation = this.get('model.simulation'); + let simulation = this.get('model.simulation'); properties['simulation'] = simulation; - // get the simulator id by simulator name - var simulators = this.get('model.simulators'); - var simulatorName = this.get('simulatorName'); + // get the simulator by simulator name + let simulators = this.get('model.simulators'); + let simulatorName = this.get('simulatorName'); simulators.forEach(function(simulator) { if (simulator.get('name') === simulatorName) { @@ -88,13 +90,22 @@ export default Ember.Controller.extend({ } }); + // create mapping + let mapping = []; + + for (let i = 0; i < properties['length']; i++) { + mapping.pushObject("Signal " + (i + 1)); + } + + properties['mapping'] = mapping; + // create new model - var simulationModel = this.store.createRecord('simulation-model', properties); + let simulationModel = this.store.createRecord('simulation-model', properties); // this change will not be saved, but it is nessecary otherwise ember will omit the simulation's id in the post request simulation.get('models').pushObject(simulationModel); - var controller = this; + let controller = this; simulationModel.save().then(function() { controller.set('isShowingNewModal', false); @@ -109,36 +120,28 @@ export default Ember.Controller.extend({ submitEdit() { // verify properties - var properties = this.getProperties('name'); + let properties = this.getProperties('name', 'length'); if (properties['name'] == null || properties['name'] === "") { this.set('errorMessage', 'Simulation model name is missing'); return; } // set simuatlion properties - var simulation = this.get('model.simulation'); - properties['simulation'] = simulation.get('id'); + let simulation = this.get('model.simulation'); + properties['simulation'] = simulation; - // get the simulator id by simulator name - var simulators = this.get('model.simulators'); - var simulatorId = null; - var simulatorName = this.get('simulatorName'); + // get the simulator by simulator name + let simulators = this.get('model.simulators'); + let simulatorName = this.get('simulatorName'); simulators.forEach(function(simulator) { if (simulator.get('name') === simulatorName) { - simulatorId = simulator.get('simulatorid'); + properties['simulator'] = simulator; } }); - if (simulatorId == null) { - Ember.debug('Unable to find simulator by name'); - return; - } - - properties['simulator'] = simulatorId; - // save properties - var controller = this; + let controller = this; this.get('simulationModel').setProperties(properties); @@ -155,7 +158,7 @@ export default Ember.Controller.extend({ confirmDelete() { // delete the model - var simulationModel = this.get('simulationModel'); + let simulationModel = this.get('simulationModel'); simulationModel.destroyRecord(); // hide the dialog diff --git a/app/controllers/visualization/delete.js b/app/controllers/visualization/delete.js deleted file mode 100644 index 99bb874..0000000 --- a/app/controllers/visualization/delete.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * File: delete.js - * Author: Markus Grigull - * Date: 28.06.2016 - * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC - * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. - * Unauthorized copying of this file, via any medium is strictly prohibited. - **********************************************************************************/ - -import Ember from 'ember'; - -export default Ember.Controller.extend({ - actions: { - cancelDelete() { - // go back to visualization edit view - let visualizationId = this.get('model.id'); - this.transitionToRoute('/visualization/' + visualizationId); - }, - - confirmDelete() { - // get the objects - var projectId = this.get('model.project.id'); - - var visualization = this.get('model'); - visualization.destroyRecord(); - - this.transitionToRoute('/project/' + projectId); - } - } -}); diff --git a/app/controllers/visualization/edit.js b/app/controllers/visualization/edit.js index c864a5a..a7c1845 100644 --- a/app/controllers/visualization/edit.js +++ b/app/controllers/visualization/edit.js @@ -18,8 +18,16 @@ export default Ember.Controller.extend(FetchLiveDataMixin, { plot: null, name: null, simulator: null, + simulatorName: null, signal: null, + _updateSimulators: function() { + if (this.get('model.simulators') !== null && this.get('model.simulators.length') > 0) { + let simulators = this.get('model.simulators'); + this.set('simulatorName', simulators.toArray()[0].get('name')); + } + }.observes('model'), + actions: { addPlot(name) { var plot = null; @@ -30,7 +38,7 @@ export default Ember.Controller.extend(FetchLiveDataMixin, { } else if (name === 'table') { plot = this.store.createRecord('plot', { name: 'Table 1', type: 'plot-table', width: 500, height: 200, title: 'Table 1' }); } else if (name === 'value') { - plot = this.store.createRecord('plot', { name: 'Value 1', type: 'plot-value' }); + plot = this.store.createRecord('plot', { name: 'Value 1', type: 'plot-value', simulator: 2 }); } else { // DEBUG console.log('Add plot: ' + name); @@ -79,9 +87,10 @@ export default Ember.Controller.extend(FetchLiveDataMixin, { if (plotType === 'plot-value') { // set properties this.set('plot', plot); - this.set('name', plot.get('name')); - this.set('simulator', plot.get('simulator')); - this.set('signal', plot.get('signal')); + /*this.set('name', plot.get('name')); + this.set('signal', plot.get('signal'));*/ + + //this.set('simulatorName', simulatorName); this.set('isShowingPlotValueModal', true); } @@ -112,6 +121,10 @@ export default Ember.Controller.extend(FetchLiveDataMixin, { cancelValuePlot() { this.set('isShowingPlotValueModal', false); + }, + + selectSimulator(simulator) { + this.set('simulatorName', simulator); } } }); diff --git a/app/models/plot.js b/app/models/plot.js index ab6cf46..6349409 100644 --- a/app/models/plot.js +++ b/app/models/plot.js @@ -17,7 +17,6 @@ export default Model.extend({ simulator: attr('number', { defaultValue: 1 }), width: attr('number', { defaultValue: 100 }), height: attr('number', { defaultValue: 100 }), - title: attr('string'), type: attr('string'), x: attr('number', { defaultValue: 0 }), y: attr('number', { defaultValue: 0 }), diff --git a/app/router.js b/app/router.js index 5e95c68..924f60b 100644 --- a/app/router.js +++ b/app/router.js @@ -27,9 +27,7 @@ Router.map(function() { this.route('visualization', function() { this.route('index', { path: '/:visualizationid' }); - this.route('new'); this.route('edit', { path: '/edit/:visualizationid' }); - this.route('delete', { path: '/delete/:visualizationid' }); }); this.route('user', function() { @@ -53,7 +51,9 @@ Router.map(function() { this.route('simulator'); this.route('dialog', function() { - this.route('plot', function() {}); + this.route('plot', function() { + this.route('value'); + }); }); }); diff --git a/app/routes/dialog/plot/value.js b/app/routes/dialog/plot/value.js new file mode 100644 index 0000000..26d9f31 --- /dev/null +++ b/app/routes/dialog/plot/value.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/app/styles/app.scss b/app/styles/app.scss index 3c17c3b..f650627 100644 --- a/app/styles/app.scss +++ b/app/styles/app.scss @@ -12,6 +12,7 @@ @import 'simulations'; @import 'projects'; @import 'simulators'; +@import 'simulation-models'; @import "ember-modal-dialog/ember-modal-structure"; @import "ember-modal-dialog/ember-modal-appearance"; diff --git a/app/routes/visualization/delete.js b/app/styles/simulation-models.scss similarity index 55% rename from app/routes/visualization/delete.js rename to app/styles/simulation-models.scss index a6f5f3e..04aea01 100644 --- a/app/routes/visualization/delete.js +++ b/app/styles/simulation-models.scss @@ -1,17 +1,19 @@ /** - * File: delete.js + * File: simulation-models.css * Author: Markus Grigull - * Date: 28.06.2016 + * Date: 12.10.2016 * Copyright: 2016, Institute for Automation of Complex Power Systems, EONERC * This file is part of VILLASweb. All Rights Reserved. Proprietary and confidential. * Unauthorized copying of this file, via any medium is strictly prohibited. **********************************************************************************/ -import Ember from 'ember'; -import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; +/** + * Route: simulation-model/index + */ +.simulation-model-index-mapping { + margin-top: 20px; +} -export default Ember.Route.extend(AuthenticatedRouteMixin, { - model(params) { - return this.store.findRecord('visualization', params.visualizationid); - } -}); +.simulation-model-index-buttons { + margin-top: 20px; +} diff --git a/app/templates/components/plot-value.hbs b/app/templates/components/plot-value.hbs index b824785..0e68e9a 100644 --- a/app/templates/components/plot-value.hbs +++ b/app/templates/components/plot-value.hbs @@ -1 +1,54 @@ {{name}}: {{value}} + +{{#if isShowingModal}} + {{#modal-dialog attachment="middle center" translucentOverlay=true}} +

Value

+ +
+ + + + + + + + + + + + + + + + +
+ + + {{input id='name' placeholder='Enter plot name' value=name}} +
+ + + +
+ + + +
+ + +
+
+ + {{#if errorMessage}} +

Error: {{errorMessage}}

+ {{/if}} + {{/modal-dialog}} +{{/if}} diff --git a/app/templates/dialog/plot/value.hbs b/app/templates/dialog/plot/value.hbs index 971e9ec..8f11e5f 100644 --- a/app/templates/dialog/plot/value.hbs +++ b/app/templates/dialog/plot/value.hbs @@ -1,44 +1,5 @@ -{{#if isShowingPlotValueModal}} - {{#modal-dialog attachment="middle center" translucentOverlay=true}} -

Value

+

Test

-
- - - - - - - - - - - - - - - - -
- - - {{input id='name' placeholder='Enter plot name' value=name}} -
- - - {{input id='simulator' type='number' value=simulator min='1' max='255'}} -
- - - {{input id='signal' type='number' value=signal min='1'}} -
- - -
-
- - {{#if errorMessage}} -

Error: {{errorMessage}}

- {{/if}} - {{/modal-dialog}} -{{/if}} + + + diff --git a/app/templates/dialog/simulation.hbs b/app/templates/dialog/simulation.hbs index aaa09a0..9e2bfb6 100644 --- a/app/templates/dialog/simulation.hbs +++ b/app/templates/dialog/simulation.hbs @@ -24,6 +24,14 @@ + + + + + + {{input id='length' type='number' value=length min='1'}} + + @@ -65,6 +73,14 @@ + + + + + + {{input id='length' type='number' value=length min='1'}} + + diff --git a/app/templates/simulation-model/index.hbs b/app/templates/simulation-model/index.hbs index d993484..b1d2c6c 100644 --- a/app/templates/simulation-model/index.hbs +++ b/app/templates/simulation-model/index.hbs @@ -1,18 +1,29 @@ +{{#link-to 'simulation.index' model.simulation.id}}Back to {{model.simulation.name}}{{/link-to}} +

{{model.name}}

-

- Running: {{model.simulation.running}} -

+

Mapping

-

- Simulator: {{model.simulator}} -

+
+ + + + + + {{#each-in model.mapping as |signal name|}} + + + + + {{/each-in}} +
SignalName
+ {{signal}} + + {{name}} +
+
-

- Data: -

- -{{#each values as |value|}} - {{value}} -
-{{/each}} +
+ + +
diff --git a/app/templates/simulations.hbs b/app/templates/simulations.hbs index 70b16d1..698d9a7 100644 --- a/app/templates/simulations.hbs +++ b/app/templates/simulations.hbs @@ -5,7 +5,7 @@ Name Running - + {{#each model as |simulation|}} diff --git a/app/templates/visualization/delete.hbs b/app/templates/visualization/delete.hbs deleted file mode 100644 index 0be5279..0000000 --- a/app/templates/visualization/delete.hbs +++ /dev/null @@ -1,6 +0,0 @@ -

Delete

- -

Are you sure you want to delete the visualization?

- - - diff --git a/app/templates/visualization/edit.hbs b/app/templates/visualization/edit.hbs index 46c89e7..a6872ac 100644 --- a/app/templates/visualization/edit.hbs +++ b/app/templates/visualization/edit.hbs @@ -1,14 +1,14 @@ -

{{model.name}}

+

{{model.ame}}

Toolbox

- {{#draggable-item content='chart'}} + - {{#draggable-item content='table'}} + {{#draggable-item content='value'}} Value @@ -23,5 +23,3 @@

- -{{partial "dialog/plot/value"}} diff --git a/app/templates/visualization/new.hbs b/app/templates/visualization/new.hbs deleted file mode 100644 index c9904d4..0000000 --- a/app/templates/visualization/new.hbs +++ /dev/null @@ -1 +0,0 @@ -

New visualization

diff --git a/tests/unit/controllers/visualization/delete-test.js b/tests/unit/controllers/dialog/plot/value-test.js similarity index 75% rename from tests/unit/controllers/visualization/delete-test.js rename to tests/unit/controllers/dialog/plot/value-test.js index dc98464..7b1555b 100644 --- a/tests/unit/controllers/visualization/delete-test.js +++ b/tests/unit/controllers/dialog/plot/value-test.js @@ -1,6 +1,6 @@ import { moduleFor, test } from 'ember-qunit'; -moduleFor('controller:visualization/delete', 'Unit | Controller | visualization/delete', { +moduleFor('controller:dialog/plot/value', 'Unit | Controller | dialog/plot/value', { // Specify the other units that are required for this test. // needs: ['controller:foo'] }); diff --git a/tests/unit/routes/visualization/new-test.js b/tests/unit/routes/dialog/plot/value-test.js similarity index 75% rename from tests/unit/routes/visualization/new-test.js rename to tests/unit/routes/dialog/plot/value-test.js index 0f09f4a..259de45 100644 --- a/tests/unit/routes/visualization/new-test.js +++ b/tests/unit/routes/dialog/plot/value-test.js @@ -1,6 +1,6 @@ import { moduleFor, test } from 'ember-qunit'; -moduleFor('route:visualization/new', 'Unit | Route | visualization/new', { +moduleFor('route:dialog/plot/value', 'Unit | Route | dialog/plot/value', { // Specify the other units that are required for this test. // needs: ['controller:foo'] }); diff --git a/tests/unit/routes/visualization/delete-test.js b/tests/unit/routes/visualization/delete-test.js deleted file mode 100644 index 635f4ac..0000000 --- a/tests/unit/routes/visualization/delete-test.js +++ /dev/null @@ -1,11 +0,0 @@ -import { moduleFor, test } from 'ember-qunit'; - -moduleFor('route:visualization/delete', 'Unit | Route | visualization/delete', { - // Specify the other units that are required for this test. - // needs: ['controller:foo'] -}); - -test('it exists', function(assert) { - let route = this.subject(); - assert.ok(route); -});