Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Services.Optimization.Web/Content/Datatypemapping.js

Last change on this file 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: 6.1 KB
Line 
1var OAAS_VIEW = (function (my, _, $, Backbone) {
2    my.DatatypeMapper = function () {
3        this.cb = {};
4        _.extend(this.cb, Backbone.Events);
5
6        this.mapHtml = function (property, el) {
7            var parameter = property.Value;
8            var key = property.Name;
9            if (property.Options) {
10                var osv = new OAAS_VIEW.SelectionView({ model: property, el: el });
11                this.cb.listenTo(osv, 'selected', function (model) {
12                    property.Value = model.value;
13                });
14                osv.render();
15                return osv;
16            }
17            else if (parameter instanceof Array) {
18                // parameter is a matrix or vector of numbers
19                var tev = new OAAS_VIEW.TableEditView({ model: parameter, el: el, editable: true });
20                tev.render();
21                return tev;
22            }
23            else if (typeof (parameter) == 'boolean') {
24                var osv = new OAAS_VIEW.OptionSelectionView({ model: parameter, el: el, hideText: true });
25                this.cb.listenTo(osv, 'changed', function (model) {
26                    property.Value = model.checked;
27                });
28                osv.render();
29                return osv;
30            }
31            // parameter is a number
32            else if (!isNaN(parameter)) {
33                var nev = new OAAS_VIEW.NumberEditableView({ model: property, el: el });
34                nev.render();
35                return nev;
36            }
37            return 'No mapping for ' + typeof (parameter) + ' (Key: ' + key + ')';
38        };
39
40
41    }
42
43
44    function DatatypeMapper_mapStrings(key, param, selected) {
45        // http://stackoverflow.com/questions/4814512/how-to-create-dropdown-list-dynamically-using-jquery
46        var s = $('<select name="' + key + '"/>');
47        for (var i = 0; i < param.length; i++) {
48            $('<option />', { value: param[i], text: param[i] }).appendTo(s);
49        }
50        s.val(selected);
51        return s;
52    }
53
54    function DatatypeMapper_mapNumber(key, param) {
55        return $('<input type="text" name="' + key + '" />').val(param);
56    }
57
58    function DatatypeMapper_mapBoolean(key, param) {
59        var s = $('<select name="' + key + '"/>');
60        $('<option />', { value: 'true', text: 'true' }).appendTo(s);
61        $('<option />', { value: 'false', text: 'false' }).appendTo(s);
62        return s;
63    }
64
65    function DatatypeMapper_mapNumbers(key, param) {
66        // http: //stackoverflow.com/questions/8749236/create-table-with-jquery-append
67        var table = $('<table></table>').addClass('editableTable');
68        var head = $('<thead></thead>');
69        // create head elements
70        var headerRow = $('<tr></tr>');
71        $('<td />').text(key + ' Column').appendTo(headerRow);
72        headerRow.appendTo(head);
73        head.appendTo(table);
74        var body = $('<tbody></tbody>');
75        for (var i = 0; i < param.length; i++) {
76            var row = $('<tr></tr>');
77            var td = $('<td />').appendTo(row);
78            $('<input type="text" name="' + key + '_' + i + '" />').val(param[i]).appendTo(td);
79            row.appendTo(body);
80        }
81        body.appendTo(table);
82        return table;
83    }
84
85    function DatatypeMapper_mapMatrix(key, param) {
86        // http: //stackoverflow.com/questions/8749236/create-table-with-jquery-append
87        var table = $('<table></table>').addClass('editableTable');
88        var head = $('<thead></thead>');
89        // create head elements
90        var headerRow = $('<tr></tr>');
91        for (var i = 0; i < param[0].length; i++) {
92            $('<td />').text(key + ' Column ' + i).appendTo(headerRow);
93        }
94        headerRow.appendTo(head);
95        head.appendTo(table);
96        var body = $('<tbody></tbody>');
97        for (var i = 0; i < param.length; i++) {
98            var row = $('<tr></tr>');
99            for (var j = 0; j < param[i].length; j++) {
100                var td = $('<td />').appendTo(row);
101                $('<input type="text" name="' + key + '_' + i + '_' + j + '" />').val(param[i][j]).appendTo(td);
102            }
103            row.appendTo(body);
104        }
105        body.appendTo(table);
106        return table;
107
108        /*var table = '<table class="editableTable"><thead><tr>';
109        for (var i = 0; i < param[0].length; i++) {
110        table += '<th>' + key + ' Column ' + (i + 1) + '</th>';
111        }
112        table += '</tr>';
113        // foreach value entry (2d entry)
114        for (var i = 0; i < param.length; i++) {
115        table += '<tr>';
116        for (var j = 0; j < param[i].length; j++) {
117        table += '<td><input type="text" name="' + key + '_' + i + '_' + j + '" /></td>';
118        }
119        table += '</tr>';
120        }
121        return $*/
122    }
123
124    /*
125    DatatypeMapper.prototype.mapString = function (value) {
126    if (value == "true") return true;
127    else if (value == "false") return false;
128    else if (!isNaN(value)) return parseFloat(value.replace(',', '.'));
129    return value;
130    }
131
132    DatatypeMapper.prototype.aggregateTables = function (data) {
133    // aggregate tables:
134    for (var dataKey in data) {
135    var entry = data[dataKey];
136    var tableEntries = {};
137    var toRemove = [];
138    for (var key in entry) {
139    if (key.indexOf('_') != -1) {
140    var splitted = key.split('_');
141    var name = splitted[0];
142    var row = parseInt(splitted[1]);
143    if (!(name in tableEntries)) {
144    tableEntries[name] = []
145    }
146
147    if (splitted.length == 2) { // its a vector of elements
148    tableEntries[name].push(entry[key])
149    } else if (splitted.length == 3) { // its a matrix of elements
150    column = parseInt(splitted[2]);
151    if (tableEntries[name].length < row + 1)
152    tableEntries[name].push([]);
153    tableEntries[name][row][column] = entry[key];
154    }
155    toRemove.push(key);
156    }
157    }
158
159    for (var i = 0; i < toRemove.length; i++) {
160    delete entry[toRemove[i]];
161    }
162
163    for (var key in tableEntries) {
164    entry[key] = tableEntries[key];
165    }
166    }
167    }*/
168    return my;
169} (OAAS_VIEW || {}, _, $, Backbone));
Note: See TracBrowser for help on using the repository browser.