Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Services.Optimization.Web/Content/experiment.model.js @ 17578

Last change on this file since 17578 was 9324, checked in by fschoepp, 12 years ago

#1888:

  • DAL: Added a Delete method which deletes by experiment id.
  • HL DataTables will now be transposed and mapped as double[ROWS][COLUMNS] (transposed)
  • JS: Moved all classes into "modules" to prevent namespace pollution (using OAAS_MODEL for model classes, OAAS_VIEW for views and OAAS_CONTROLLER for controllers)
  • JS: Moved DatatypeMapper classes into Backbone views
  • JS: Models now correctly send DELETE requests
  • Added a new job overview page (which also renders run details) using AJAX
  • Using moment.min.js to format DateTime as string
  • Controllers now inherit from BaseController which provides a RedirectToLoginIfNecessary-method
  • Added loading animations to several AJAX bound places (loading experiments / scenarios)
  • Added a section to _Layout.cshtml which allows page-specific JavaScript includes (<script> only for a certain page)
  • Fixed Build/Edit of experiment menu redirecting to the wrong page
  • The Experiment Variation Dialog disables input fields, if the property has not been activated before
File size: 4.2 KB
Line 
1//================== MODELS =====================
2var OAAS_MODEL = (function (my, Backbone) {
3    Backbone.Relational.store.addModelScope(my);
4
5    my.ControllerModel = Backbone.Model.extend({
6        defaults: {
7            selectedNode: null
8        }
9    });
10
11    my.Experiment = Backbone.RelationalModel.extend({
12        url: function () {
13            return '/Experiment/Experiment?nodeId=' + this.get('nodeId');
14        },
15        isNew: function () { return false; },
16        defaults: {
17            title: 'My Experiment',
18            isExperiment: true,
19            run: false,
20            nodeId: null,
21            repititions: 1,
22            group: 'TESTAZURE'
23        },
24        relations: [{
25            key: 'experiment',
26            relatedModel: 'ExperimentNode'
27        }]
28    });
29
30    my.ExperimentNode = Backbone.RelationalModel.extend({
31        defaults: {
32            title: 'Experiment',
33            key: -1,
34            data: {},
35            parent: null,
36            isExperiment: false,
37            nodeId: null
38        },       
39        relations: [{
40            type: Backbone.HasMany,
41            key: 'children',
42            relatedModel: 'ExperimentNode',
43            collectionType: 'AlgorithmList',
44            reverseRelation: {
45                key: 'parent'
46            }
47        }],
48        url: function () {
49            return this.get('isExperiment') ? '/Experiment/Experiment?nodeId=' + this.get('nodeId') : '/Experiment/Scenario?nodeId=' + this.get('nodeId');
50        },
51        initialize: function (spec) {
52            if (typeof spec.key === 'undefined' || spec.key == -1) {
53                spec.key = my.ExperimentNode.globalKeyCount;
54                this.set({ key: spec.key });
55                my.ExperimentNode.globalKeyCount++;
56            }
57            else if (spec.key >= my.ExperimentNode.globalKeyCount)
58                my.ExperimentNode.globalKeyCount = spec.key + 1;
59
60            my.ExperimentNode.globalNodeMap[spec.key] = this;
61        },
62        // adds a new experimentNode to this node
63        addNode: function (experimentNode) {
64            if (!(experimentNode instanceof my.ExperimentNode)) {
65                experimentNode = new my.ExperimentNode(experimentNode);
66            }
67            this.get('children').add(experimentNode);
68            experimentNode.set({ parent: this });
69            this.trigger('node-added', experimentNode);
70            return experimentNode;
71        },
72        // moves an experimentNode into this node
73        moveNode: function (experimentNode) {
74            var parent = experimentNode.get('parent');
75            if (parent != null) {
76                // remove from parent
77                parent.get('children').remove(experimentNode);
78            }
79            this.addNode(experimentNode);
80        },
81        // delete this node
82        remove: function () {
83            var parent = this.get('parent');
84            if (parent != null) {
85                parent.get('children').remove(this);
86                this.set({ parent: null });
87                // simply replace it with 'undefined'
88                delete my.ExperimentNode.globalNodeMap[this.get('key')];
89            }
90        },
91        lookup: function (key) {
92            return my.ExperimentNode.globalNodeMap[key];
93        }
94    },
95  {
96      globalKeyCount: 0,
97      globalNodeMap: {},
98      lookup: function (key) {
99          return my.ExperimentNode.globalNodeMap[key];
100      },
101      nextGlobalKey: function () {
102          var key = my.ExperimentNode.globalKeyCount;
103          my.ExperimentNode.globalKeyCount++;
104          return key;
105      }
106  }
107  );
108
109    my.ExperimentList = Backbone.Collection.extend({
110        url: function () {
111            return "/Experiment/ExperimentList";
112        },
113        model: my.Experiment
114    });
115
116    my.AlgorithmList = Backbone.Collection.extend({
117        url: function () {
118            return "/Experiment/AlgorithmList";
119        },
120        model: my.ExperimentNode
121    });
122
123    my.ScenarioList = Backbone.Collection.extend({
124        url: function () {
125            return "/Experiment/ScenarioList";
126        },
127        model: my.ExperimentNode
128    });
129    return my;
130} (OAAS_MODEL || {}, Backbone));
Note: See TracBrowser for help on using the repository browser.