cockpit/js/instance.js in cpee-1.3.226 vs cockpit/js/instance.js in cpee-1.3.227

- old
+ new

@@ -1,8 +1,9 @@ var ws; +var suspended_monitoring = false; var myid = ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)); -var running = false; +var loading = false; var subscription; var subscription_state = 'less'; var save = {}; save['state']= undefined; save['dsl'] = undefined; @@ -56,11 +57,11 @@ 'topic' + '=' + 'handlerwrapper' + '&' + 'events' + '=' + 'error,change' + '&' + 'topic' + '=' + 'handlers' + '&' + 'events' + '=' + 'change';// }}} -function cockpit() { +function cockpit() { //{{{ $("button[name=base]").click(function(){ create_instance(null,false); }); $("button[name=instance]").click(function(){ ui_activate_tab("#tabinstance"); monitor_instance(false,false); }); $("button[name=loadtestset]").click(function(e){new CustomMenu(e).menu($('#predefinedtestsets'),function(){ load_testset(false) } ); }); $("button[name=loadtestsetfile]").click(load_testsetfile); $("button[name=loadmodelfile]").click(load_modelfile); @@ -121,21 +122,21 @@ var ts = $(this).text(); $('#modeltypes').append($("<div class='menuitem'></div>").text(ts)); }); } }); -} +} //}}} -function sanitize_url() { +function sanitize_url() { //{{{ var url = $("input[name=instance-url]").val(); var lastChar = url.substr(url.length - 1) if (lastChar != '/') { $("input[name=instance-url]").val(url + '/'); } return $("input[name=instance-url]").val(); } - + //}}} function check_subscription() { // {{{ var url = $("#current-instance").text(); var num = 0; if ($("input[name=votecontinue]").is(':checked')) num += 1; if (num > 0 && subscription_state == 'less') { @@ -187,10 +188,73 @@ alert("An instance info is necessary!"); } } }// }}} +function websocket() { + var url = $("#current-instance").text(); + var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket; + if (ws) ws.close(); + ws = new Socket(url.replace(/http/,'ws') + "/notifications/subscriptions/" + subscription + "/ws/"); + ws.onopen = function() { + append_to_log("monitoring", "opened", ""); + }; + ws.onmessage = function(e) { + data = $.parseXML(e.data); + if ($('event > topic',data).length > 0) { + switch($('event > topic',data).text()) { + case 'dataelements': + monitor_instance_values("dataelements"); + break; + case 'description': + monitor_instance_dsl(); + break; + case 'endpoints': + monitor_instance_values("endpoints"); + break; + case 'attributes': + monitor_instance_values("attributes"); + monitor_instance_transformation(); + if (suspended_monitoring) { + suspended_monitoring = false; + } else { + monitor_graph_change(true); + } + break; + case 'state': + monitor_instance_state_change(JSON.parse($('event > notification',data).text()).state); + break; + case 'position': + monitor_instance_pos_change($('event > notification',data).text()); + break; + case 'transformation': + monitor_instance_transformation(); + break; + case 'activity': + monitor_instance_running($('event > notification',data).text(),$('event > event',data).text()); + break; + } + append_to_log("event", $('event > topic',data).text() + "/" + $('event > event',data).text(), $('event > notification',data).text()); + } + if ($('vote > topic',data).length > 0) { + var notification = $('vote > notification',data).text(); + append_to_log("vote", $('vote > topic',data).text() + "/" + $('vote > vote',data).text(), notification); + monitor_instance_vote_add(notification); + } + }; + ws.onclose = function() { + append_to_log("monitoring", "closed", "server down i assume."); + }; + + monitor_instance_values("dataelements"); + monitor_instance_values("endpoints"); + monitor_instance_values("attributes"); + monitor_instance_transformation(); + monitor_instance_dsl(); + monitor_instance_state(); +} + function monitor_instance(load,exec) {// {{{ var url = sanitize_url(); $('.tabbehind button').hide(); $('#dat_details').empty(); @@ -229,68 +293,15 @@ if (b[0] == 'key') { subscription = b[1]; } }); append_to_log("monitoring", "id", subscription); - var Socket = "MozWebSocket" in window ? MozWebSocket : WebSocket; - if (ws) ws.close(); - ws = new Socket(url.replace(/http/,'ws') + "/notifications/subscriptions/" + subscription + "/ws/"); - ws.onopen = function() { - append_to_log("monitoring", "opened", ""); - }; - ws.onmessage = function(e) { - data = $.parseXML(e.data); - if ($('event > topic',data).length > 0) { - switch($('event > topic',data).text()) { - case 'dataelements': - monitor_instance_values("dataelements"); - break; - case 'description': - monitor_instance_dsl(); - break; - case 'endpoints': - monitor_instance_values("endpoints"); - break; - case 'attributes': - monitor_instance_values("attributes"); - monitor_instance_transformation(); - monitor_graph_change(true); - break; - case 'state': - monitor_instance_state_change(JSON.parse($('event > notification',data).text()).state); - break; - case 'position': - monitor_instance_pos_change($('event > notification',data).text()); - break; - case 'transformation': - monitor_instance_transformation(); - break; - case 'activity': - monitor_instance_running($('event > notification',data).text(),$('event > event',data).text()); - break; - } - append_to_log("event", $('event > topic',data).text() + "/" + $('event > event',data).text(), $('event > notification',data).text()); - } - if ($('vote > topic',data).length > 0) { - var notification = $('vote > notification',data).text(); - append_to_log("vote", $('vote > topic',data).text() + "/" + $('vote > vote',data).text(), notification); - monitor_instance_vote_add(notification); - } - }; - ws.onclose = function() { - append_to_log("monitoring", "closed", "server down i assume."); - }; - if (load || exec) load_testset(exec); + websocket(); + if (load || exec) + load_testset(exec); } }); - - monitor_instance_values("dataelements"); - monitor_instance_values("endpoints"); - monitor_instance_values("attributes"); - monitor_instance_transformation(); - monitor_instance_dsl(); - monitor_instance_state(); }, error: function(a,b,c) { alert("This ain't no CPEE instance"); ui_activate_tab("#tabnew"); } @@ -627,10 +638,11 @@ } }); }// }}} function set_testset(testset,exec) {// {{{ var url = $("#current-instance").text(); + suspended_monitoring = true; $.ajax({ type: "GET", url: url + "/notifications/subscriptions/", success: function(res){ @@ -687,58 +699,58 @@ } }); }// }}} function load_testsetfile_after() { //{{{ - if (running) return; - running = true; + if (loading) return; + loading = true; if (typeof window.FileReader !== 'function') { alert('FileReader not yet supportet'); return; } var files = $('#testsetfile').get(0).files; var reader = new FileReader(); reader.onload = function(){ set_testset($.parseXML(reader.result),false); document.getElementById('fuckchrome').reset(); - running = false; + loading = false; } - reader.onerror = function(){ console.log('error reading file'); running = false; } - reader.onabort = function(){ console.log('abort reading file'); running = false; } + reader.onerror = function(){ console.log('error reading file'); loading = false; } + reader.onabort = function(){ console.log('abort reading file'); loading = false; } reader.readAsText(files[0]); } //}}} function load_testsetfile() {// {{{ - if (running) return; + if (loading) return; document.getElementById('testsetfile').click(); }// }}} function load_modelfile_after() { //{{{ - if (running) return; - running = true; + if (loading) return; + loading = true; if (typeof window.FileReader !== 'function') { alert('FileReader not yet supportet'); return; } var files = $('#modelfile').get(0).files; var reader = new FileReader(); reader.onload = function(){ var url = $("#current-instance").text(); load_des(url,reader.result); - running = false; + loading = false; } - reader.onerror = function(){ running = false; } - reader.onabort = function(){ running = false; } + reader.onerror = function(){ loading = false; } + reader.onabort = function(){ loading = false; } reader.readAsText(files[0]); } //}}} function load_modelfile() {// {{{ - if (running) return; + if (loading) return; document.getElementById('modelfile').click(); }// }}} function load_testset(exec) {// {{{ - if (running) return; - running = true; + if (loading) return; + loading = true; var name = $("#predefinedtestsets div.menuitem[data-selected=selected]").text(); $.ajax({ cache: false, dataType: 'xml', @@ -750,18 +762,18 @@ document.title = name; set_testset(res,exec); }, complete: function() { - running = false; + loading = false; } }); }// }}} function load_modeltype() {// {{{ - if (running) return; + if (loading) return; var url = $("#current-instance").text(); - running = true; + loading = true; var name = $("#modeltypes div.menuitem[data-selected=selected]").text(); $.ajax({ cache: false, dataType: 'xml', @@ -776,11 +788,11 @@ }, error: report_failure }); }, complete: function() { - running = false; + loading = false; } }); }// }}} function load_des(url,model) { //{{{ @@ -921,9 +933,13 @@ if (node_state[what]['passive'] == undefined) node_state[what]['passive'] = 0; var votes = node_state[what]['vote']; var actives = node_state[what]['active']; var passives = node_state[what]['passive']; + + // TODO scrollIntoView does not work in firefox + // $('g[element-id="' + what + '"]').each(function(a,b){ b.scrollIntoView(true); $('#graphcolumn')[0].scrollTop -= 15; }); + $('g[element-id="' + what + '"]').each(function(a,b){ $('#graphcolumn')[0].scrollTop = b.getBBox().y - 10; }); if (actives > 0 && votes > 0) $('g[element-id="' + what + '"] .super .colon').each(function(a,b){ b.setAttribute('class','colon necessary'); });