[9324] | 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 });
|
---|
[9305] | 26 | }
|
---|
[9324] | 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
|
---|
[9508] | 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 | }
|
---|
[9324] | 54 | });
|
---|
| 55 | //loadingDialog.close();
|
---|
[9305] | 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[9324] | 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();
|
---|
[9305] | 65 | }
|
---|
[9324] | 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 });
|
---|
[9305] | 87 |
|
---|
[9324] | 88 | var view = new OAAS_VIEW.ExperimentTreeView({ model: model, el: $('#container') });
|
---|
| 89 | view.render();
|
---|
[9305] | 90 |
|
---|
[9324] | 91 | this.refreshScenarios();
|
---|
[9305] | 92 |
|
---|
[9324] | 93 | this.refreshExperiments();
|
---|
[9305] | 94 |
|
---|
[9324] | 95 | var wizard = new OAAS_VIEW.StepWizardView({ el: $('#stepWizard') });
|
---|
| 96 | wizard.render();
|
---|
[9305] | 97 |
|
---|
[9324] | 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') });
|
---|
[9305] | 101 |
|
---|
[9324] | 102 | var wizardController = {};
|
---|
| 103 | _.extend(wizardController, Backbone.Events);
|
---|
[9305] | 104 |
|
---|
[9324] | 105 | wizardController.listenTo(model, 'change', function () {
|
---|
| 106 | // update the details view, when the model changes
|
---|
| 107 | view.render();
|
---|
| 108 | detailsView.render();
|
---|
| 109 | });
|
---|
[9305] | 110 |
|
---|
| 111 |
|
---|
[9324] | 112 | wizardController.listenTo(wizard, 'experiment-finished', function () {
|
---|
| 113 | generalController.experimentFinishedHandler(experimentModel, null, null);
|
---|
| 114 | self.refreshExperiments();
|
---|
| 115 | });
|
---|
[9305] | 116 |
|
---|
[9324] | 117 | wizardController.listenTo(view, 'structure-changed', function (node) {
|
---|
| 118 | view.render();
|
---|
| 119 | detailsView.render();
|
---|
| 120 | });
|
---|
[9305] | 121 |
|
---|
[9324] | 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 | });
|
---|
[9305] | 128 | });
|
---|
| 129 |
|
---|
[9324] | 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 | });
|
---|
[9305] | 138 |
|
---|
[9324] | 139 | wizardController.listenTo(parameterDialog, 'parameters-finished', function (node) {
|
---|
| 140 | parameterDialog.close();
|
---|
| 141 | });
|
---|
[9305] | 142 |
|
---|
[9324] | 143 | wizardController.listenTo(view, 'variation-request', function (evt) {
|
---|
| 144 | generalController.variationRequestHandler(evt);
|
---|
| 145 | });
|
---|
[9305] | 146 |
|
---|
[9324] | 147 | var experimentDetailsView = new OAAS_VIEW.ExperimentDetailsView({ el: $('#step3'), model: experimentModel });
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | }
|
---|
[9305] | 151 | }
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 |
|
---|
[9324] | 155 | /// ==================== EDIT PAGE =========================
|
---|
| 156 | /// ==================== EDIT PAGE =========================
|
---|
| 157 | /// ==================== EDIT PAGE =========================
|
---|
[9305] | 158 |
|
---|
[9324] | 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();
|
---|
[9305] | 170 |
|
---|
[9324] | 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 });
|
---|
[9305] | 179 |
|
---|
[9324] | 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();
|
---|
[9305] | 184 |
|
---|
[9324] | 185 | var availableExperiments = new OAAS_MODEL.ExperimentList();
|
---|
[9305] | 186 |
|
---|
[9324] | 187 | var wizardController = {};
|
---|
| 188 | _.extend(wizardController, Backbone.Events);
|
---|
[9305] | 189 |
|
---|
[9324] | 190 | this.refreshScenarios();
|
---|
[9305] | 191 |
|
---|
[9324] | 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();
|
---|
[9335] | 198 | draggableExperiments.render();
|
---|
[9324] | 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 | );
|
---|
[9305] | 224 | }
|
---|
[9324] | 225 | });
|
---|
[9305] | 226 |
|
---|
[9324] | 227 | // create wizard with 4 steps
|
---|
| 228 | var wizard = new OAAS_VIEW.StepWizardView({ el: $('#stepWizard') });
|
---|
| 229 | wizard.render();
|
---|
[9305] | 230 |
|
---|
[9324] | 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: ""} });
|
---|
[9305] | 234 |
|
---|
[9324] | 235 | var detailsView = new OAAS_VIEW.ExperimentDetailsTreeView({ model: model, el: $('#container2') });
|
---|
[9305] | 236 |
|
---|
[9324] | 237 | var parameterDialog = new OAAS_VIEW.ParameterDialog({ model: model, el: $('#parameterDialog') });
|
---|
| 238 | var loadingDialog = new OAAS_VIEW.LoadingDialog({ el: $('#loadingDialog') });
|
---|
[9305] | 239 |
|
---|
[9324] | 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 | }
|
---|
[9305] | 248 | }
|
---|
[9324] | 249 | detailsView.render();
|
---|
| 250 | });
|
---|
[9305] | 251 |
|
---|
[9324] | 252 | wizardController.listenTo(model, 'change', function () {
|
---|
| 253 | // update the details view, when the model changes
|
---|
| 254 | view.render();
|
---|
| 255 | detailsView.render();
|
---|
| 256 | });
|
---|
[9305] | 257 |
|
---|
[9324] | 258 | wizardController.listenTo(view, 'structure-changed', function (node) {
|
---|
| 259 | view.render();
|
---|
| 260 | });
|
---|
[9305] | 261 |
|
---|
[9324] | 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 | });
|
---|
[9305] | 269 | });
|
---|
| 270 |
|
---|
[9324] | 271 | wizardController.listenTo(wizard, 'experiment-finished', function () {
|
---|
| 272 | generalController.experimentFinishedHandler(experimentModel, availableExperiments, selectableGroup);
|
---|
| 273 | });
|
---|
[9305] | 274 |
|
---|
[9324] | 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 | });
|
---|
[9305] | 283 |
|
---|
[9324] | 284 | wizardController.listenTo(view, 'variation-request', function (evt) {
|
---|
| 285 | generalController.variationRequestHandler(evt);
|
---|
| 286 | });
|
---|
[9305] | 287 |
|
---|
[9324] | 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 | }
|
---|
[9305] | 302 | }
|
---|
[9324] | 303 | return my;
|
---|
| 304 | } (OAAS_CONTROLLER || {}, Backbone, OAAS_VIEW, OAAS_MODEL, _, $));
|
---|
[9305] | 305 |
|
---|
| 306 |
|
---|
| 307 | |
---|