Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Content/job.model.js @ 14699

Last change on this file since 14699 was 9395, checked in by fschoepp, 12 years ago

#1888:

  • Added visual extensions (dynamic JavaScript) which will be used to render additional result parameters specific to scenarios (e. g. create a graphical representation of a TSP).
  • Added relationship between jobs and experiments (otherwise, it's not possible to get the job's experiment).
  • Updated Admin page to allow removal/addition of visual extensions.
  • Added back-end logic to store/retrieve/delete visual extensions.
  • Added visual extension functionality to the JavaScript views/controllers (job.*.js).
  • Added tsp.js which is a visual extension for the "Genetic Algorithm - TSP" scenario. It adds a graphical representation of the TSP (just like the C# version does) to the results.
File size: 2.8 KB
Line 
1// Adapting the module pattern to prevent namespace polution; it's related to the namespace pattern
2// http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
3// http://stackoverflow.com/questions/881515/javascript-namespace-declaration#answer-3588712
4var OAAS_MODEL = (function (my, Backbone) {
5    // ================= MODEL ===================
6    my.Job = Backbone.Model.extend({
7        idAttribute: "Id",
8        defaults: {
9            Id: null,
10            Name: null,
11            Resource: null,
12            Group: null,
13            DateCreated: null,
14            State: 'Waiting',
15            Loading: true
16        },
17        url: function () {
18            return '/Job/Job?jobId=' + this.get('Id');
19        },
20        initialize: function (spec) {
21            // waiting or calculating
22            this.set({ Loading: spec.State == 0 || spec.State == 1 });
23        }
24    });
25
26    my.JobList = Backbone.Collection.extend({
27        url: function () {
28            return "/Job/JobList";
29        },
30        initialize: function (spec) {
31            this.listenTo(this, 'sync', this.adjustDate);
32        },
33        _poll: function () {
34            var self = this;
35            setTimeout(function () { self.poll() }, 5000);
36        },
37        poll: function () {
38            var self = this;
39            this.fetch({ cache: false, reset: true, success: function () {
40                self._poll();
41            }
42            });
43        },
44        adjustDate: function () {
45            for (var i = 0; i < this.models.length; i++) {
46                // convert the MS date format here
47                var date = this.models[i].get('DateCreated');
48                // remove /Date(
49                if (!(date instanceof Date)) {
50                    var value = new Date(parseInt(date.substr(6)));
51                    this.models[i].set('DateCreated', value);
52                }
53            }
54            this.trigger('updated', this);
55        },
56        model: my.Job
57    });
58
59    my.Run = Backbone.Model.extend({
60        defaults: {
61            id: null,
62            name: null,
63            results: null,
64            inputs: null,
65            algorithmName: null
66        }
67    });
68
69    my.RunList = Backbone.Collection.extend({
70        initialize: function (spec) {
71            this.jobId = spec.jobId;
72        },
73        url: function () {
74            return "/Job/RunList?jobId=" + this.jobId;
75        },
76        model: my.Run
77    });
78
79    my.VisualExtension = Backbone.Model.extend({
80        defaults: {
81            id: null,
82            js: null
83        },
84        url: function () {
85            return '/Job/VisualExtension?scenarioId=' + this.get('id');
86        }
87    });
88
89    return my;
90} (OAAS_MODEL || {}, Backbone));
Note: See TracBrowser for help on using the repository browser.