1 | var OAAS_CONTROLLER = (function (my, Backbone, OAAS_VIEW, OAAS_MODEL, _, $) {
|
---|
2 | my.GeneralController = function () {
|
---|
3 | this.variationRequestHandler = function (evt) {
|
---|
4 | var self = this;
|
---|
5 | var dialog = new OAAS_VIEW.VariationDialog({ model: evt.model });
|
---|
6 | var dialogController = {};
|
---|
7 | _.extend(dialogController, Backbone.Events);
|
---|
8 | dialogController.listenTo(dialog, 'variations-generated', function (variations) {
|
---|
9 | var parent = evt.model.get('parent');
|
---|
10 | for (var i = 0; i < variations.length; i++) {
|
---|
11 | var title = evt.model.get('title');
|
---|
12 | var offset = title.indexOf('(')
|
---|
13 | if (offset != -1) {
|
---|
14 | title = title.substring(0, offset);
|
---|
15 | }
|
---|
16 | title += '(';
|
---|
17 | for (var j = 0; j < variations[i].length; j++) {
|
---|
18 | title += variations[i][j].Name + " = " + variations[i][j].Value + "; ";
|
---|
19 | }
|
---|
20 | title += ')';
|
---|
21 | var data = { AlgorithmParameters: variations[i] };
|
---|
22 | if (evt.model.attributes.data.ProblemParameters) {
|
---|
23 | data.ProblemParameters = evt.model.attributes.data.ProblemParameters;
|
---|
24 | }
|
---|
25 | parent.addNode({ title: title, nodeId: evt.model.get('nodeId'), data: data });
|
---|
26 | }
|
---|
27 | self.model.trigger('change');
|
---|
28 | });
|
---|
29 | dialog.render();
|
---|
30 | },
|
---|
31 | this.experimentFinishedHandler = function (experimentModel, availableExperiments, selectableGroup) {
|
---|
32 | var loadingDialog = new OAAS_VIEW.LoadingDialog({ el: $('#loadingDialog') });
|
---|
33 | // start the loading dialog
|
---|
34 | loadingDialog.setLoading(true);
|
---|
35 | loadingDialog.text('Saving experiment ' + experimentModel.get('title') + '...');
|
---|
36 | loadingDialog.render();
|
---|
37 | // send experiment to server
|
---|
38 | experimentModel.save({}, {
|
---|
39 | success: function () {
|
---|
40 | loadingDialog.setLoading(false);
|
---|
41 | loadingDialog.text('Experiment successfully saved!');
|
---|
42 | loadingDialog.render();
|
---|
43 | if (availableExperiments)
|
---|
44 | availableExperiments.fetch({ cache: false, success: function (itm) {
|
---|
45 | selectableGroup.render();
|
---|
46 | }
|
---|
47 | });
|
---|
48 | },
|
---|
49 | error: function (model, response, options) {
|
---|
50 | loadingDialog.setLoading(false);
|
---|
51 | loadingDialog.text('Failed to save Experiment - Please log off an and on and try again!');
|
---|
52 | loadingDialog.render();
|
---|
53 | }
|
---|
54 | });
|
---|
55 | //loadingDialog.close();
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | my.ExperimentPageController = function () {
|
---|
60 | this.refreshExperiments = function () {
|
---|
61 | var availableExperiments = new OAAS_MODEL.ExperimentList();
|
---|
62 | availableExperiments.fetch({ cache: false, success: function (itm) {
|
---|
63 | var group = new OAAS_VIEW.DraggableGroup({ collection: availableExperiments, el: $('#experiments') });
|
---|
64 | group.render();
|
---|
65 | }
|
---|
66 | });
|
---|
67 | },
|
---|
68 | this.refreshScenarios = function () {
|
---|
69 | var availableScenarios = new OAAS_MODEL.ScenarioList();
|
---|
70 | availableScenarios.fetch({ cache: false, success: function (itm) {
|
---|
71 | var group = new OAAS_VIEW.DraggableGroup({ collection: availableScenarios, el: $('#algorithms') });
|
---|
72 | group.render();
|
---|
73 | }
|
---|
74 | });
|
---|
75 | },
|
---|
76 | this.create = function () {
|
---|
77 | var self = this;
|
---|
78 | var generalController = new my.GeneralController();
|
---|
79 | // create all models + required view for the experiment page
|
---|
80 | var model = new OAAS_MODEL.ExperimentNode({
|
---|
81 | title: 'Experiment',
|
---|
82 | key: 0,
|
---|
83 | isExperiment: true
|
---|
84 | }, { parse: true });
|
---|
85 | generalController.model = model;
|
---|
86 | var experimentModel = new OAAS_MODEL.Experiment({ experiment: model });
|
---|
87 |
|
---|
88 | var view = new OAAS_VIEW.ExperimentTreeView({ model: model, el: $('#container') });
|
---|
89 | view.render();
|
---|
90 |
|
---|
91 | this.refreshScenarios();
|
---|
92 |
|
---|
93 | this.refreshExperiments();
|
---|
94 |
|
---|
95 | var wizard = new OAAS_VIEW.StepWizardView({ el: $('#stepWizard') });
|
---|
96 | wizard.render();
|
---|
97 |
|
---|
98 | var detailsView = new OAAS_VIEW.ExperimentDetailsTreeView({ model: model, el: $('#container2') });
|
---|
99 | var validationView = new OAAS_VIEW.ValidationHintsView({ model: { header: "Validation failed!", text: ""} });
|
---|
100 | var parameterDialog = new OAAS_VIEW.ParameterDialog({ model: model, el: $('#parameterDialog') });
|
---|
101 |
|
---|
102 | var wizardController = {};
|
---|
103 | _.extend(wizardController, Backbone.Events);
|
---|
104 |
|
---|
105 | wizardController.listenTo(model, 'change', function () {
|
---|
106 | // update the details view, when the model changes
|
---|
107 | view.render();
|
---|
108 | detailsView.render();
|
---|
109 | });
|
---|
110 |
|
---|
111 |
|
---|
112 | wizardController.listenTo(wizard, 'experiment-finished', function () {
|
---|
113 | generalController.experimentFinishedHandler(experimentModel, null, null);
|
---|
114 | self.refreshExperiments();
|
---|
115 | });
|
---|
116 |
|
---|
117 | wizardController.listenTo(view, 'structure-changed', function (node) {
|
---|
118 | view.render();
|
---|
119 | detailsView.render();
|
---|
120 | });
|
---|
121 |
|
---|
122 | wizardController.listenTo(view, 'node-added', function (node) {
|
---|
123 | // get details about the node
|
---|
124 | node.fetch({ success: function (itm) {
|
---|
125 | model.trigger('change', {});
|
---|
126 | }
|
---|
127 | });
|
---|
128 | });
|
---|
129 |
|
---|
130 | wizardController.listenTo(detailsView, 'node-clicked', function (node) {
|
---|
131 | // get details about the node
|
---|
132 | var modelNode = OAAS_MODEL.ExperimentNode.lookup(node.data.key);
|
---|
133 | if (!modelNode.get('isExperiment')) {
|
---|
134 | parameterDialog.model = modelNode;
|
---|
135 | parameterDialog.render();
|
---|
136 | }
|
---|
137 | });
|
---|
138 |
|
---|
139 | wizardController.listenTo(parameterDialog, 'parameters-finished', function (node) {
|
---|
140 | parameterDialog.close();
|
---|
141 | });
|
---|
142 |
|
---|
143 | wizardController.listenTo(view, 'variation-request', function (evt) {
|
---|
144 | generalController.variationRequestHandler(evt);
|
---|
145 | });
|
---|
146 |
|
---|
147 | var experimentDetailsView = new OAAS_VIEW.ExperimentDetailsView({ el: $('#step3'), model: experimentModel });
|
---|
148 |
|
---|
149 |
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 | /// ==================== EDIT PAGE =========================
|
---|
156 | /// ==================== EDIT PAGE =========================
|
---|
157 | /// ==================== EDIT PAGE =========================
|
---|
158 |
|
---|
159 | my.ExperimentEditPageController = function () {
|
---|
160 | this.refreshScenarios = function () {
|
---|
161 | var availableScenarios = new OAAS_MODEL.ScenarioList();
|
---|
162 | availableScenarios.fetch({ cache: false, success: function (itm) {
|
---|
163 | var group = new OAAS_VIEW.DraggableGroup({ collection: availableScenarios, el: $('#draggableAlgorithms') });
|
---|
164 | group.render();
|
---|
165 | }
|
---|
166 | });
|
---|
167 | },
|
---|
168 | this.create = function () {
|
---|
169 | var generalController = new my.GeneralController();
|
---|
170 |
|
---|
171 | var self = this;
|
---|
172 | // create all models + required view for the experiment page
|
---|
173 | var controllerModel = new OAAS_MODEL.ControllerModel();
|
---|
174 | var model = new OAAS_MODEL.ExperimentNode({
|
---|
175 | title: 'Experiment',
|
---|
176 | key: 0,
|
---|
177 | isExperiment: true
|
---|
178 | }, { parse: true });
|
---|
179 |
|
---|
180 | generalController.model = model;
|
---|
181 | var experimentModel = new OAAS_MODEL.Experiment({ experiment: model });
|
---|
182 | var experimentDetailsView = new OAAS_VIEW.ExperimentDetailsView({ el: $('#step4'), model: experimentModel });
|
---|
183 | experimentDetailsView.render();
|
---|
184 |
|
---|
185 | var availableExperiments = new OAAS_MODEL.ExperimentList();
|
---|
186 |
|
---|
187 | var wizardController = {};
|
---|
188 | _.extend(wizardController, Backbone.Events);
|
---|
189 |
|
---|
190 | this.refreshScenarios();
|
---|
191 |
|
---|
192 | var selectableGroup = new OAAS_VIEW.SelectableGroup({ collection: availableExperiments, el: $('#experiments') });
|
---|
193 | //selectableGroup.render();
|
---|
194 | var draggableExperiments = new OAAS_VIEW.DraggableGroup({ collection: availableExperiments, el: $('#draggableExperiments') });
|
---|
195 | availableExperiments.fetch({ cache: false, success: function (itm) {
|
---|
196 | // selectableGroup = new OAAS_VIEW.SelectableGroup({ collection: availableExperiments, el: $('#experiments') });
|
---|
197 | selectableGroup.render();
|
---|
198 | draggableExperiments.render();
|
---|
199 |
|
---|
200 | wizardController.listenTo(selectableGroup, 'node-selected', function (nodeId) {
|
---|
201 | var node = availableExperiments.find(function (itm) { return itm.get('nodeId') == nodeId; });
|
---|
202 |
|
---|
203 | var newNode = new OAAS_MODEL.ExperimentNode(node.attributes);
|
---|
204 | newNode.fetch({ success: function () {
|
---|
205 | experimentModel.set({
|
---|
206 | experiment: newNode,
|
---|
207 | title: node.get('title'),
|
---|
208 | nodeId: node.get('nodeId'),
|
---|
209 | run: node.get('run'),
|
---|
210 | repititions: node.get('repititions'),
|
---|
211 | group: node.get('group')
|
---|
212 | });
|
---|
213 | controllerModel.set({ selectedNode: newNode });
|
---|
214 | $('#deleteExperimentButton').removeAttr('disabled');
|
---|
215 | detailsView.model = newNode;
|
---|
216 | detailsView.render();
|
---|
217 | view.model = newNode;
|
---|
218 | view.render();
|
---|
219 | experimentDetailsView.render();
|
---|
220 | }
|
---|
221 | });
|
---|
222 | }
|
---|
223 | );
|
---|
224 | }
|
---|
225 | });
|
---|
226 |
|
---|
227 | // create wizard with 4 steps
|
---|
228 | var wizard = new OAAS_VIEW.StepWizardView({ el: $('#stepWizard') });
|
---|
229 | wizard.render();
|
---|
230 |
|
---|
231 | var view = new OAAS_VIEW.ExperimentTreeView({ model: model, el: $('#container') });
|
---|
232 | view.render();
|
---|
233 | var validationView = new OAAS_VIEW.ValidationHintsView({ model: { header: "Validation failed!", text: ""} });
|
---|
234 |
|
---|
235 | var detailsView = new OAAS_VIEW.ExperimentDetailsTreeView({ model: model, el: $('#container2') });
|
---|
236 |
|
---|
237 | var parameterDialog = new OAAS_VIEW.ParameterDialog({ model: model, el: $('#parameterDialog') });
|
---|
238 | var loadingDialog = new OAAS_VIEW.LoadingDialog({ el: $('#loadingDialog') });
|
---|
239 |
|
---|
240 | wizardController.listenTo(wizard, 'step-validated', function (validationModel) {
|
---|
241 | // update the details view
|
---|
242 | if (validationModel.stepNumber == 1) {
|
---|
243 | if (controllerModel.get('selectedNode') == null) {
|
---|
244 | validationView.model["text"] = 'Please select an experiment to continue!';
|
---|
245 | validationView.render();
|
---|
246 | validationModel.succeeded = false;
|
---|
247 | }
|
---|
248 | }
|
---|
249 | detailsView.render();
|
---|
250 | });
|
---|
251 |
|
---|
252 | wizardController.listenTo(model, 'change', function () {
|
---|
253 | // update the details view, when the model changes
|
---|
254 | view.render();
|
---|
255 | detailsView.render();
|
---|
256 | });
|
---|
257 |
|
---|
258 | wizardController.listenTo(view, 'structure-changed', function (node) {
|
---|
259 | view.render();
|
---|
260 | });
|
---|
261 |
|
---|
262 | wizardController.listenTo(view, 'node-added', function (node) {
|
---|
263 | // get details about the node
|
---|
264 | //if (!node.get('isExperiment'))
|
---|
265 | node.fetch({ success: function (itm) {
|
---|
266 | model.trigger('change', {});
|
---|
267 | }
|
---|
268 | });
|
---|
269 | });
|
---|
270 |
|
---|
271 | wizardController.listenTo(wizard, 'experiment-finished', function () {
|
---|
272 | generalController.experimentFinishedHandler(experimentModel, availableExperiments, selectableGroup);
|
---|
273 | });
|
---|
274 |
|
---|
275 | wizardController.listenTo(detailsView, 'node-clicked', function (node) {
|
---|
276 | // get details about the node
|
---|
277 | var modelNode = OAAS_MODEL.ExperimentNode.lookup(node.data.key);
|
---|
278 | if (!modelNode.get('isExperiment')) {
|
---|
279 | parameterDialog.model = modelNode;
|
---|
280 | parameterDialog.render();
|
---|
281 | }
|
---|
282 | });
|
---|
283 |
|
---|
284 | wizardController.listenTo(view, 'variation-request', function (evt) {
|
---|
285 | generalController.variationRequestHandler(evt);
|
---|
286 | });
|
---|
287 |
|
---|
288 | wizardController.listenTo(parameterDialog, 'parameters-finished', function (node) {
|
---|
289 | parameterDialog.close();
|
---|
290 | });
|
---|
291 |
|
---|
292 | $('#deleteExperimentButton').click(function (evt) {
|
---|
293 | var node = controllerModel.get('selectedNode');
|
---|
294 | var nodes = availableExperiments.where({ nodeId: node.get('nodeId') });
|
---|
295 | if (nodes.length == 1) {
|
---|
296 | nodes[0].destroy();
|
---|
297 | $('#deleteExperimentButton').attr('disabled', 'disabled');
|
---|
298 | controllerModel.set('selectedNode', null);
|
---|
299 | }
|
---|
300 | });
|
---|
301 | }
|
---|
302 | }
|
---|
303 | return my;
|
---|
304 | } (OAAS_CONTROLLER || {}, Backbone, OAAS_VIEW, OAAS_MODEL, _, $));
|
---|
305 |
|
---|
306 |
|
---|
307 | |
---|