Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Optimization.Web/Content/ExperimentSupport.js @ 14042

Last change on this file since 14042 was 9215, checked in by fschoepp, 11 years ago

#1888:

  • Janitor is now working as expected in Windows Azure
  • Added basic support for experiments (draggable experiments)
  • Added methods to save/read experiments from TableStorage
  • The job status can now be retrieved by using the GetTasks/GetTaskData methods
  • Added a class to convert JSON-objects to Algorithm instances
  • Web page: Added experiment button to navigation
File size: 5.2 KB
Line 
1function workInProgress(isWorking) {
2    var loader = $(".loader");
3    var submitButton = $(".submitter");
4    if (isWorking) {
5        loader.removeClass("unseen");
6        submitButton.attr("disabled", "disabled");
7    } else {
8        loader.addClass("unseen");
9        submitButton.removeAttr("disabled");
10    }
11}
12
13function log(arguments) {
14    if (window.console && console && console.log) {
15        if ($.isArray(arguments)) {
16            if ((Array.prototype.slice.call(arguments)).length == 1 && typeof Array.prototype.slice.call(arguments)[0] == 'string') {
17                var txt = (Array.prototype.slice.call(arguments)).toString();
18                console.log(txt);
19                return txt;
20            }
21            else {
22                var txt = Array.prototype.slice.call(arguments);
23                console.log(txt);
24                return txt;
25            }
26        } else {
27            console.log(arguments);
28            return arguments;
29        }
30    }
31}
32
33$(document).ready(function () {
34    var tree = $('#container').dynatree({
35        onActivate: function (node) {
36            if (node && node.data.title !== "Experiment") {
37                $('input[name="RemoveNode"]').removeAttr("disabled");
38            } else if (node) {
39                $('input[name="RemoveNode"]').attr("disabled", "disabled");
40            }
41        },
42        onDeactivate: function (node) {
43        },
44        dnd: {
45            autoExpandMS: 750,
46
47            onDragStart: function (node) {
48                return node.data.title !== "Experiment";
49            },
50            onDragEnter: function (node, sourceNode) {
51                return true;
52            },
53            onDragOver: function (node, sourceNode, hitMode) {
54                return node.data.title !== "Experiment" || hitMode === "over";
55            },
56            onDrop: function (node, sourceNode, hitMode, ui, draggable) {
57                if (sourceNode) {
58                    sourceNode.move(node, hitMode);
59                }
60                else {
61                    newNode = { title: draggable.element[0].id };
62                    if (hitMode == "over") {
63                        node.addChild(newNode);
64                        node.expand(true);
65                    }
66                    else if (hitMode == "before") {
67                        node.parent.addChild(newNode, node);
68                    }
69                    else {
70                        node.parent.addChild(newNode, node.getNextSibling());
71                    }
72                }
73            },
74            onDragLeave: function (node, sourceNode) {
75            }
76        }
77    });
78
79    $('.dragables').each(function () {
80        $(this).draggable({
81            revert: true,
82            connectToDynatree: true,
83            cursorAt: { top: -5, left: -5 },
84            helper: "clone"
85        });
86    });
87
88    $(".submitter").each(function () {
89        var btn = $(this);
90        $(this).click(function () {
91            workInProgress(true);
92            var name = $('input[name="Name"]').val();
93            var root = {
94                Experiment: $("#container").dynatree("getTree").toDict(),
95                Name: name
96            };
97            $.ajax({
98                type: "POST",
99                url: '/Experiment/Save',
100                contentType: "application/json; charset=utf-8",
101                dataType: "json",
102                data: JSON.stringify(root),
103                success: function (result) {
104                    log(result);
105                    if (result.success) {
106                        var clearers = $("#experiments .clearer");
107                        if (clearers && clearers.length > 0) {
108                            var experimentDiv = $('<div class="dragables" id="' + name + '"><p>' + name + '</p></div>').draggable({
109                                revert: true,
110                                connectToDynatree: true,
111                                cursorAt: { top: -5, left: -5 },
112                                helper: "clone"
113                            });
114                            experimentDiv.insertBefore("#experiments .clearer");
115                            //$(clearers[clearers.length - 1]).parent().before().append('<div class="dragables" id="' + name + '"><p>' + name + '</p></div>');
116                            log("Added new div to experiments");
117                            $("#jsonMessage").text("Saved experiment '" + result.data + "'!");
118                        }
119                    } else {
120                        $("#jsonMessage").text(result.error);
121                    }
122                    workInProgress(false);
123                },
124                error: function (errMsg) {
125                    var txt = log(errMsg);
126                    $("#jsonMessage").text(txt);
127                    workInProgress(false);
128                }
129            });
130            return false;
131        });
132    });
133
134    $('input[name="RemoveNode"]').click(function () {
135        var node = $("#container").dynatree("getActiveNode");
136        if (node && node.data.title !== "Experiment")
137            node.remove();
138        $(this).attr("disabled", "disabled");
139    });
140});
Note: See TracBrowser for help on using the repository browser.