1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Add simulations

The simulation model replaces what simulation-model was before. A simulation
is a construct of multiple simulation-models to represent the different
simulator in the simulation.
Added new styling guidelines and global styles for elements.
This commit is contained in:
Markus Grigull 2016-07-26 19:26:15 +02:00
parent 5b09486d3c
commit a4507f095c
43 changed files with 619 additions and 53 deletions

View file

@ -10,30 +10,35 @@
import Ember from 'ember';
export default Ember.Controller.extend({
sessionUser: Ember.inject.service('session-user'),
simulator: 1,
actions: {
newModel() {
// get current user
var user = this.get('sessionUser.user');
// get the simulation
var simulation = this.get('model');
var simulationId = this.get('model.id');
// create new model from properties
var properties = this.getProperties('name');
properties['owner'] = user;
var properties = this.getProperties('name', 'simulator');
properties['simulation'] = simulationId;
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);
var controller = this;
simulationModel.save().then(function() {
Ember.debug('Saved new model');
controller.transitionToRoute('/simulation-models');
controller.transitionToRoute('/simulation/' + simulationId);
}, function() {
Ember.debug('Error saving new model');
});
},
cancelNewModel() {
this.transitionToRoute('/simulation-models');
var simulationId = this.get('model.id');
this.transitionToRoute('/simulation/' + simulationId);
}
}
});

View file

@ -0,0 +1,4 @@
import Ember from 'ember';
export default Ember.Controller.extend({
});

View file

@ -0,0 +1,4 @@
import Ember from 'ember';
export default Ember.Controller.extend({
});

View file

@ -0,0 +1,4 @@
import Ember from 'ember';
export default Ember.Controller.extend({
});

View file

@ -0,0 +1,38 @@
/**
* File: new.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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';
export default Ember.Controller.extend({
sessionUser: Ember.inject.service('session-user'),
actions: {
newSimulation() {
// get current user
var user = this.get('sessionUser.user');
// create new simulation from properties
var properties = this.getProperties('name');
properties['owner'] = user;
var simulation = this.store.createRecord('simulation', properties);
var controller = this;
simulation.save().then(function() {
controller.transitionToRoute('/simulations');
}, function() {
Ember.debug('Error saving new simulation');
});
},
cancelNewSimulation() {
this.transitionToRoute('/simulations');
}
}
});

View file

@ -14,5 +14,6 @@ import { hasMany, belongsTo } from 'ember-data/relationships';
export default Model.extend({
name: attr('string'),
owner: belongsTo('user', { async: true }),
visualizations: hasMany('visualization', { async: true })
visualizations: hasMany('visualization', { async: true }),
simulation: belongsTo('simulation', { async: true })
});

View file

@ -25,7 +25,7 @@ export default Model.extend({
_updateHistory: function() {
this._history.unshift(this.get('values'));
while (this._history.length > 500) {
while (this._history.length > 5) {
this._history.shift();
}
}.observes('values')

View file

@ -13,7 +13,8 @@ import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
name: attr('string'),
running: attr('boolean'),
owner: belongsTo('user', { async: true }),
projects: hasMany('project', { async: true })
simulator: attr('number'),
length: attr('number'),
mapping: attr('array'),
simulation: belongsTo('simulation', { async: true })
});

20
app/models/simulation.js Normal file
View file

@ -0,0 +1,20 @@
/**
* File: simulation.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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 Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default Model.extend({
name: attr('string'),
running: attr('boolean'),
owner: belongsTo('user', { async: true }),
models: hasMany('simulation-model', { aync: true }),
projects: hasMany('project', { async: true })
});

View file

@ -16,6 +16,6 @@ export default Model.extend({
password: attr('string'),
adminLevel: attr('number'),
projects: hasMany('project', { async: true }),
simulationModels: hasMany('simulation-model', { async: true }),
simulations: hasMany('simulation', { async: true }),
mail: attr('string')
});

View file

@ -45,11 +45,19 @@ Router.map(function() {
this.route('simulation-model', function() {
this.route('index', { path: '/:modelid' });
this.route('new');
this.route('new', { path: '/new/:simulationid' });
this.route('delete', { path: '/delete/:modelid' });
this.route('edit', { path: '/edit/:modelid' });
});
this.route('simulation-models');
this.route('simulations');
this.route('simulation', function() {
this.route('index', { path: '/:simulationid' });
this.route('delete', { path: '/delete/:simulationid' });
this.route('new');
this.route('edit', { path: '/edit/:simulationid' });
});
});
export default Router;

View file

@ -11,4 +11,7 @@ import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model(params) {
return this.store.findRecord('simulation', params.simulationid);
}
});

View file

@ -11,11 +11,4 @@ import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
sessionUser: Ember.inject.service('session-user'),
model() {
// get models for current user
var user = this.get('sessionUser.user');
return user.get('simulationModels');
}
});

View file

@ -0,0 +1,4 @@
import Ember from 'ember';
export default Ember.Route.extend({
});

View file

@ -0,0 +1,4 @@
import Ember from 'ember';
export default Ember.Route.extend({
});

View file

@ -0,0 +1,17 @@
/**
* File: index.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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, {
model(params) {
return this.store.findRecord('simulation', params.simulationid);
}
});

View file

@ -0,0 +1,14 @@
/**
* File: new.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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, {
});

21
app/routes/simulations.js Normal file
View file

@ -0,0 +1,21 @@
/**
* File: simulations.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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, {
sessionUser: Ember.inject.service('session-user'),
model() {
// get simulations for current user
var user = this.get('sessionUser.user');
return user.get('simulations');
}
});

View file

@ -11,7 +11,6 @@ import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
attrs: {
owner: { serialize: 'ids' },
projects: { serialize: 'ids' }
simulation: { serialize: 'ids' }
}
});

View file

@ -0,0 +1,18 @@
/**
* File: simulation.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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 ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
attrs: {
owner: { serialize: 'ids' },
models: { serialize: 'ids' },
projects: { serialize: 'ids' }
}
});

View file

@ -9,6 +9,8 @@
@import 'plots.css';
@import 'models.css';
@import 'simulations.css';
@import 'projects.css';
* {
margin: 0;
@ -150,3 +152,83 @@ footer {
background-color: #aaa;
}
}
/**
* Table
*/
.column-center {
text-align: center;
}
/**
* Table full width
*/
.table-full-width {
width: 100%;
border: 0;
border-collapse: collapse;
}
.table-full-width th, td {
padding: 5px;
text-align: left;
border: none;
}
.table-full-width th {
background-color: #151;
color: #fff;
}
.table-full-width tr:nth-child(even) {
background-color: #ddd;
}
/**
* Form create record
*/
.form-create-record {
padding: 0;
width: 400px;
}
.form-create-record table {
border: none;
}
.form-create-record td {
padding: 5px 10px 5px 0;
}
.form-create-record input {
padding: 2px 4px;
width: 100%;
}
.form-create-record input[type=number] {
width: 60px;
padding: 0;
}
.form-create-record button {
background-color: #151;
color: #fff;
font-size: 14px;
padding: 4px 8px;
border: none;
cursor: pointer;
}
.form-create-record button:hover {
background: #373;
}

27
app/styles/projects.css Normal file
View file

@ -0,0 +1,27 @@
/**
* File: projects.css
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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.
**********************************************************************************/
/**
* Route: projects
*/
.projects-container {
margin-top: 20px;
}
.projects-row-controls {
float: right;
}
.projects-row-controls a {
margin-left: 10px;
}
.projects-new-container {
margin-top: 20px;
}

View file

@ -0,0 +1,47 @@
/**
* File: simulations.css
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.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.
**********************************************************************************/
/**
* Route: simulations
*/
.simulations-container {
margin-top: 20px;
}
.simulations-row-controls {
float: right;
}
.simulations-row-controls a {
margin-left: 10px;
}
.simulations-new-container {
margin-top: 20px;
}
/**
* Route: simulation/index
*/
.simulation-index-models-container {
margin-top: 20px;
}
.simulation-index-row-controls {
float: right;
}
.simulation-index-row-controls a {
margin-left: 10px;
}
.simulation-index-new-model {
margin-top: 20px;
}

View file

@ -9,7 +9,7 @@
<ul>
<li>{{#link-to 'index'}}Home{{/link-to}}</li>
<li>{{#link-to 'projects'}}Projects{{/link-to}}</li>
<li>{{#link-to 'simulation-models'}}Models{{/link-to}}</li>
<li>{{#link-to 'simulations'}}Simulations{{/link-to}}</li>
<li>{{#link-to 'me'}}Account{{/link-to}}</li>
<li>{{#link-to 'logout'}}Logout{{/link-to}}</li>
</ul>

View file

@ -1,17 +1,24 @@
<h1>New project</h1>
<section id="project-new">
<form id="project-new-form" {{action 'newProject' on='submit'}} >
<p>
<label for="name">Name</label>
{{input id='name' placeholder='Enter project name' value=name}}
</p>
<form class="form-create-record" {{action 'newProject' on='submit'}} >
<table>
<tr>
<td>
<label for="name">Name</label>
</td>
<td>
{{input id='name' placeholder='Enter project name' value=name}}
</td>
</tr>
<tr>
<td colspan="2">
<button {{action 'cancelNewProject'}}>Cancel</button>
<button type="submit">Create</button>
</td>
</tr>
</table>
<button {{action 'cancelNewProject'}}>Cancel</button>
<button type="submit">Create</button>
{{#if errorMessage}}
<p>{{errorMessage.message}}</p>
{{/if}}
</form>
</section>
{{#if errorMessage}}
<p>{{errorMessage.message}}</p>
{{/if}}
</form>

View file

@ -1,9 +1,27 @@
<h1>Projects</h1>
<ul>
{{#each model as |project|}}
<li>{{#link-to "project.index" project.id}}{{project.name}}{{/link-to}}</li>
{{/each}}
</ul>
<div class="projects-container">
<table class="table-full-width">
<tr>
<th>Name</th>
<th width="100px"></th>
</tr>
{{#each model as |project|}}
<tr>
<td>
{{#link-to "project.index" project.id}}{{project.name}}{{/link-to}}
</td>
<td>
<div class="projects-row-controls">
{{#link-to "project.edit" project.id}}Edit{{/link-to}}
{{#link-to "project.delete" project.id}}Delete{{/link-to}}
</div>
</td>
</tr>
{{/each}}
</table>
</div>
{{#link-to "project.new"}}New project{{/link-to}}
<div class="projects-new-container">
{{#link-to "project.new"}}New project{{/link-to}}
</div>

View file

@ -1,11 +1,28 @@
<h1>New model</h1>
<form {{action 'newModel' on='submit'}}>
<p>
<label for="name">Name</label>
{{input id='name' placeholder='Enter model name' value=name}}
</p>
<button {{action 'cancelNewModel'}}>Cancel</button>
<button type="submit">Create</button>
<form class="form-create-record" {{action 'newModel' on='submit'}}>
<table>
<tr>
<td>
<label for="name">Name</label>
</td>
<td>
{{input id='name' placeholder='Enter model name' value=name}}
</td>
</tr>
<tr>
<td>
<label for="simulator">Simulator</label>
</td>
<td>
{{input id='simulator' value=simulator type='number' min=1 max=255 step=1}}
</td>
</tr>
<tr>
<td colspan="2">
<button {{action 'cancelNewModel'}}>Cancel</button>
<button type="submit">Create</button>
</td>
</tr>
</table>
</form>

View file

@ -0,0 +1 @@
{{outlet}}

View file

@ -0,0 +1 @@
{{outlet}}

View file

@ -0,0 +1,31 @@
<h1>{{model.name}}</h1>
<div class="simulation-index-models-container">
<table class="table-full-width">
<tr>
<th>Name</th>
<th width="80px" class="column-center">Simulator</th>
<th width="100px"></th>
</tr>
{{#each model.models as |simulationModel|}}
<tr>
<td>
{{#link-to "simulation-model.index" simulationModel.id}}{{simulationModel.name}}{{/link-to}}
</td>
<td class="column-center">
{{simulationModel.simulator}}
</td>
<td>
<div class="simulation-index-row-controls">
{{#link-to "simulation-model.edit" simulationModel.id}}Edit{{/link-to}}
{{#link-to "simulation-model.delete" simulationModel.id}}Delete{{/link-to}}
</div>
</td>
</tr>
{{/each}}
</table>
</div>
<div class="simulation-index-new-model">
{{#link-to "simulation-model.new" model.id}}New model{{/link-to}}
</div>

View file

@ -0,0 +1,20 @@
<h1>New simulation</h1>
<form class="form-create-record" {{action 'newSimulation' on='submit'}}>
<table>
<tr>
<td>
<label for="name">Name</label>
</td>
<td>
{{input id='name' placeholder='Enter simulation name' value=name}}
</td>
</tr>
<tr>
<td colspan="2">
<button {{action 'cancelNewSimulation'}}>Cancel</button>
<button type="submit">Create</button>
</td>
</tr>
</table>
</form>

View file

@ -0,0 +1,27 @@
<h1>Simulations</h1>
<div class="simulations-container">
<table class="table-full-width">
<tr>
<th>Name</th>
<th width="100px"></th>
</tr>
{{#each model as |simulation|}}
<tr>
<td>
{{#link-to "simulation.index" simulation.id}}{{simulation.name}}{{/link-to}}
</td>
<td>
<div class="simulations-row-controls">
{{#link-to "simulation.edit" simulation.id}}Edit{{/link-to}}
{{#link-to "simulation.delete" simulation.id}}Delete{{/link-to}}
</div>
</td>
</tr>
{{/each}}
</table>
</div>
<div class="simulations-new-container">
{{#link-to "simulation.new"}}New simulation{{/link-to}}
</div>

View file

@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:simulation/delete', 'Unit | Controller | simulation/delete', {
// 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);
});

View file

@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:simulation/edit', 'Unit | Controller | simulation/edit', {
// 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);
});

View file

@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:simulation/index', 'Unit | Controller | simulation/index', {
// 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);
});

View file

@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('controller:simulation/new', 'Unit | Controller | simulation/new', {
// 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);
});

View file

@ -0,0 +1,12 @@
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('simulation', 'Unit | Model | simulation', {
// 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);
});

View file

@ -0,0 +1,11 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:simulation/delete', 'Unit | Route | simulation/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);
});

View file

@ -0,0 +1,11 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:simulation/edit', 'Unit | Route | simulation/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);
});

View file

@ -0,0 +1,11 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:simulation/index', 'Unit | Route | simulation/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);
});

View file

@ -0,0 +1,11 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:simulation/new', 'Unit | Route | simulation/new', {
// 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);
});

View file

@ -0,0 +1,11 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('route:simulations', 'Unit | Route | simulations', {
// 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);
});

View file

@ -0,0 +1,15 @@
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('simulation', 'Unit | Serializer | simulation', {
// Specify the other units that are required for this test.
needs: ['serializer:simulation']
});
// Replace this with your real tests.
test('it serializes records', function(assert) {
let record = this.subject();
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});