diff --git a/app/controllers/simulation-model/new.js b/app/controllers/simulation-model/new.js index bb24e26..b72bc7f 100644 --- a/app/controllers/simulation-model/new.js +++ b/app/controllers/simulation-model/new.js @@ -10,19 +10,26 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - simulator: 1, + simulator: null, actions: { newModel() { // get the simulation - var simulation = this.get('model'); - var simulationId = this.get('model.id'); + var simulation = this.get('model.simulation'); + var simulationId = this.get('model.simulation.id'); // create new model from properties - var properties = this.getProperties('name', 'simulator'); + var properties = this.getProperties('name'); properties['simulation'] = simulationId; - var simulationModel = this.store.createRecord('simulation-model', properties); + // get the simulator id by simulator name + if (this.get('simulator') == null) { + this.set('simulator', this.get('model.simulators')[0]); + } + + console.log(this.get('model.simulators')[0]); + + /*var 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); @@ -33,12 +40,16 @@ export default Ember.Controller.extend({ controller.transitionToRoute('/simulation/' + simulationId); }, function() { Ember.debug('Error saving new model'); - }); + });*/ }, cancelNewModel() { - var simulationId = this.get('model.id'); + var simulationId = this.get('model.simulation.id'); this.transitionToRoute('/simulation/' + simulationId); + }, + + selectSimulator(simulator) { + this.set('simulator', simulator); } } }); diff --git a/app/controllers/simulators.js b/app/controllers/simulators.js new file mode 100644 index 0000000..af9cb28 --- /dev/null +++ b/app/controllers/simulators.js @@ -0,0 +1,119 @@ +/** + * File: simulators.js + * Author: Markus Grigull + * Date: 30.09.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({ + isShowingNewModal: false, + isShowingDeleteModal: false, + isShowingEditModal: false, + + simulatorid: 1, + errorMessage: null, + simulator: null, + simulatorName: null, + simulatorEdit: null, + + actions: { + showNewModal() { + // reset the properties + this.set('errorMessage', null); + this.set('simulatorid', 1); + this.set('name', null); + this.set('endpoint', null); + + // show the modal dialog + this.set('isShowingNewModal', true); + }, + + showDeleteModal(simulator) { + this.set('isShowingDeleteModal', true); + this.set('simulator', simulator); + }, + + showEditModal(simulator) { + // set properties + this.set('errorMessage', null); + this.set('simulator', simulator); + this.set('simulatorid', simulator.get('simulatorid')); + this.set('simulatorName', simulator.get('name')); + this.set('simulatorEndpoint', simulator.get('endpoint')); + + // show the modal dialog + this.set('isShowingEditModal', true); + }, + + newSimulator() { + // verify properties + var properties = this.getProperties('name', 'simulatorid', 'endpoint'); + if (properties['name'] == null) { + this.set('errorMessage', 'Simulator name is missing'); + return; + } else if (properties['endpoint'] == null) { + this.set('errorMessage', 'Simulator endpoint is missing'); + return; + } + + // create new simulator from properties + var simulator = this.store.createRecord('simulator', properties); + var controller = this; + + simulator.save().then(function() { + controller.set('isShowingNewModal', false); + }, function() { + Ember.debug('Error saving new simulator'); + }); + }, + + cancelNewSimulator() { + this.set('isShowingNewModal', false); + }, + + cancelDeleteSimulator() { + this.set('isShowingDeleteModal', false); + }, + + confirmDeleteSimulator() { + // delete the simulator + var simulator = this.get('simulator'); + simulator.destroyRecord(); + + // hide the modal dialog + this.set('isShowingDeleteModal', false); + }, + + editSimulator() { + // verify new properties + if (this.get('simulatorName') == null) { + this.set('errorMessage', 'Simulator name is missing'); + return; + } else if (this.get('simulatorEndpoint') == null) { + this.set('errorMessage', 'Simulator endpoint is missing'); + return; + } + + // save property changes + this.get('simulator').set('name', this.get('simulatorName')); + this.get('simulator').set('simulatorid', this.get('simulatorid')); + this.get('simulator').set('endpoint', this.get('simulatorEndpoint')); + + var controller = this; + + this.get('simulator').save().then(function() { + controller.set('isShowingEditModal', false); + }, function() { + Ember.debug('Error saving edit simulator'); + }); + }, + + cancelEditSimulator() { + this.set('isShowingEditModal', false); + } + } +}); diff --git a/app/models/simulator.js b/app/models/simulator.js new file mode 100644 index 0000000..5e45673 --- /dev/null +++ b/app/models/simulator.js @@ -0,0 +1,18 @@ +/** + * File: simulator.js + * Author: Markus Grigull + * Date: 28.09.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 DS from 'ember-data'; +import attr from 'ember-data/attr'; + +export default DS.Model.extend({ + name: attr('string'), + running: attr('boolean'), + simulatorid: attr('number'), + endpoint: attr('string') +}); diff --git a/app/router.js b/app/router.js index ffdfa56..513436f 100644 --- a/app/router.js +++ b/app/router.js @@ -58,6 +58,9 @@ Router.map(function() { this.route('new'); this.route('edit', { path: '/edit/:simulationid' }); }); + + this.route('simulators'); + this.route('simulator'); }); export default Router; diff --git a/app/routes/simulation-model/new.js b/app/routes/simulation-model/new.js index 7ff8a7a..fc60ffc 100644 --- a/app/routes/simulation-model/new.js +++ b/app/routes/simulation-model/new.js @@ -12,6 +12,9 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout export default Ember.Route.extend(AuthenticatedRouteMixin, { model(params) { - return this.store.findRecord('simulation', params.simulationid); + return Ember.RSVP.hash({ + simulation: this.store.findRecord('simulation', params.simulationid), + simulators: this.store.findAll('simulator') + }); } }); diff --git a/app/routes/simulators.js b/app/routes/simulators.js new file mode 100644 index 0000000..8c32bcc --- /dev/null +++ b/app/routes/simulators.js @@ -0,0 +1,18 @@ +/** + * File: simulators.js + * Author: Markus Grigull + * Date: 28.09.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, { + model() { + // get simulators + return this.store.findAll('simulator'); + } +}); diff --git a/app/styles/app.css b/app/styles/app.scss similarity index 91% rename from app/styles/app.css rename to app/styles/app.scss index 575e542..c740665 100644 --- a/app/styles/app.css +++ b/app/styles/app.scss @@ -11,6 +11,10 @@ @import 'models.css'; @import 'simulations.css'; @import 'projects.css'; +@import 'simulators.css'; + +@import "ember-modal-dialog/ember-modal-structure"; +@import "ember-modal-dialog/ember-modal-appearance"; * { margin: 0; @@ -235,6 +239,24 @@ footer { background: #373; } +button { + background-color: #151; + color: #fff; + + font-size: 14px; + + margin-top: 10px; + padding: 4px 8px; + + border: none; + + cursor: pointer; +} + +button:hover { + background: #373; +} + /** * */ diff --git a/app/styles/simulators.css b/app/styles/simulators.css new file mode 100644 index 0000000..2943dc2 --- /dev/null +++ b/app/styles/simulators.css @@ -0,0 +1,27 @@ +/** + * File: simulators.css + * Author: Markus Grigull + * Date: 30.09.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. + **********************************************************************************/ + +/** + * Route: simulators + */ +.simulators-container { + margin-top: 20px; +} + +.simulators-row-controls { + float: right; +} + +.simulators-row-controls a { + margin-left: 10px; +} + +.simulators-new-container { + margin-top: 50px; +} diff --git a/app/templates/application.hbs b/app/templates/application.hbs index ab79005..4e8c036 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -10,6 +10,7 @@
  • {{#link-to 'index'}}Home{{/link-to}}
  • {{#link-to 'projects'}}Projects{{/link-to}}
  • {{#link-to 'simulations'}}Simulations{{/link-to}}
  • +
  • {{#link-to 'simulators'}}Simulators{{/link-to}}
  • {{#link-to 'me'}}Account{{/link-to}}
  • {{#link-to 'logout'}}Logout{{/link-to}}
  • diff --git a/app/templates/simulation-model/new.hbs b/app/templates/simulation-model/new.hbs index 7cb6197..5fa523d 100644 --- a/app/templates/simulation-model/new.hbs +++ b/app/templates/simulation-model/new.hbs @@ -15,7 +15,11 @@ - {{input id='simulator' value=simulator type='number' min=1 max=255 step=1}} + diff --git a/app/templates/simulators.hbs b/app/templates/simulators.hbs new file mode 100644 index 0000000..e860e7b --- /dev/null +++ b/app/templates/simulators.hbs @@ -0,0 +1,143 @@ +

    Simulators

    + +
    + + + + + + + + + {{#each model as |simulator|}} + + + + + + + + {{/each}} +
    NameIDRunningEndpoint
    + + {{simulator.name}} + + {{simulator.simulatorid}} + + {{simulator.running}} + + {{simulator.endpoint}} + +
    + + + Edit + Delete +
    +
    +
    + +
    + +
    + +{{#if isShowingNewModal}} + {{#modal-dialog attachment="middle center" translucentOverlay=true}} +

    New simulator

    + +
    + + + + + + + + + + + + + + + + +
    + + + {{input id='name' placeholder='Enter simulator name' value=name}} +
    + + + {{input id='simulatorid' type='number' value=simulatorid min='1' max='255'}} +
    + + + {{input id='endpoint' placeholder='Enter endpoint' value=endpoint}} +
    + + +
    +
    + + {{#if errorMessage}} +

    Error: {{errorMessage}}

    + {{/if}} + {{/modal-dialog}} +{{/if}} + +{{#if isShowingDeleteModal}} + {{#modal-dialog attachment="middle center" translucentOverlay=true}} +

    Delete simulator

    + +

    Are you sure you want to delete the simulator {{simulator.name}}?

    + + + + {{/modal-dialog}} +{{/if}} + +{{#if isShowingEditModal}} + {{#modal-dialog attachment="middle center" translucentOverlay=true}} +

    New simulator

    + +
    + + + + + + + + + + + + + + + + +
    + + + {{input id='name' placeholder='Enter simulator name' value=simulatorName}} +
    + + + {{input id='simulatorid' type='number' value=simulatorid min='1' max='255'}} +
    + + + {{input id='endpoint' placeholder='Enter endpoint' value=simulatorEndpoint}} +
    + + +
    +
    + + {{#if errorMessage}} +

    Error: {{errorMessage}}

    + {{/if}} + {{/modal-dialog}} +{{/if}} diff --git a/package.json b/package.json index 0eb3da4..bea92e8 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,16 @@ "ember-cli-jshint": "^1.0.0", "ember-cli-qunit": "^1.4.0", "ember-cli-release": "0.2.8", + "ember-cli-sass": "5.5.2", "ember-cli-sri": "^2.1.0", "ember-cli-uglify": "^1.2.0", "ember-data": "^2.5.0", "ember-export-application-global": "^1.0.5", "ember-load-initializers": "^0.5.1", + "ember-modal-dialog": "^0.9.0", "ember-resolver": "^2.0.3", "ember-simple-auth": "^1.1.0", + "ember-tether": "0.3.1", "loader.js": "^4.0.1" }, "dependencies": {} diff --git a/tests/unit/controllers/simulators-test.js b/tests/unit/controllers/simulators-test.js new file mode 100644 index 0000000..285361d --- /dev/null +++ b/tests/unit/controllers/simulators-test.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('controller:simulators', 'Unit | Controller | simulators', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let controller = this.subject(); + assert.ok(controller); +}); diff --git a/tests/unit/models/simulator-test.js b/tests/unit/models/simulator-test.js new file mode 100644 index 0000000..8a6206a --- /dev/null +++ b/tests/unit/models/simulator-test.js @@ -0,0 +1,12 @@ +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('simulator', 'Unit | Model | simulator', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('it exists', function(assert) { + let model = this.subject(); + // let store = this.store(); + assert.ok(!!model); +}); diff --git a/tests/unit/routes/simulators-test.js b/tests/unit/routes/simulators-test.js new file mode 100644 index 0000000..8dbfe46 --- /dev/null +++ b/tests/unit/routes/simulators-test.js @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:simulators', 'Unit | Route | simulators', { + // 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); +}); diff --git a/tests/unit/routes/simulators/delete-test.js b/tests/unit/routes/simulators/delete-test.js new file mode 100644 index 0000000..98ca109 --- /dev/null +++ b/tests/unit/routes/simulators/delete-test.js @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:simulators/delete', 'Unit | Route | simulators/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); +}); diff --git a/tests/unit/routes/simulators/edit-test.js b/tests/unit/routes/simulators/edit-test.js new file mode 100644 index 0000000..be49ba0 --- /dev/null +++ b/tests/unit/routes/simulators/edit-test.js @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:simulators/edit', 'Unit | Route | simulators/edit', { + // 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); +}); diff --git a/tests/unit/routes/simulators/index-test.js b/tests/unit/routes/simulators/index-test.js new file mode 100644 index 0000000..dfccfba --- /dev/null +++ b/tests/unit/routes/simulators/index-test.js @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:simulators/index', 'Unit | Route | simulators/index', { + // 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); +});