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

- old
+ new

@@ -9,10 +9,11 @@ save['dsl'] = undefined; save['graph'] = undefined; save['graph_theme'] = undefined; save['graph_adaptor'] = undefined; save['endpoints'] = undefined; + save['endpoints_cache'] = {}; save['dataelements'] = undefined; save['attributes'] = undefined; save['details'] = undefined; save['details_target'] = undefined; var node_state = {}; @@ -124,21 +125,21 @@ }); } }); } //}}} -function sanitize_url() { //{{{ - var url = $("input[name=instance-url]").val(); +function sanitize_url(it) { //{{{ + var url = it.val(); var lastChar = url.substr(url.length - 1) if (lastChar != '/') { - $("input[name=instance-url]").val(url + '/'); + it.val(url + '/'); } - return $("input[name=instance-url]").val(); + return it.val(); } //}}} function check_subscription() { // {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); var num = 0; if ($("input[name=votecontinue]").is(':checked')) num += 1; if (num > 0 && subscription_state == 'less') { $.ajax({ type: "PUT", @@ -189,11 +190,11 @@ } } }// }}} function websocket() { - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); 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", ""); @@ -252,11 +253,12 @@ monitor_instance_dsl(); monitor_instance_state(); } function monitor_instance(load,exec) {// {{{ - var url = sanitize_url(); + var url = sanitize_url($("input[name=instance-url]")); + var rep = sanitize_url($("input[name=repo-url]")); $('.tabbehind button').hide(); $('#dat_details').empty(); $.ajax({ @@ -265,10 +267,13 @@ success: function(res){ $("ui-tabbed.hidden, ui-rest.hidden").removeClass("hidden"); $("ui-resizehandle.hidden").removeClass("hidden"); $("ui-tabbed ui-tab.hidden, ui-rest ui-tab.hidden").removeClass("hidden"); + $("body").attr('current-instance',url); + $("body").attr('current-repo',rep); + // Change url to return to current instance when reloading $("#current-instance").text(url); $("#current-instance").attr('href',url); $("#current-instance-properties").attr('href',url + 'properties/'); $("#current-instance-properties").text('P'); @@ -307,20 +312,64 @@ } }); }// }}} function monitor_instance_values(val) {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "GET", url: url + "/properties/values/" + val + "/", success: function(res){ save[val].content(res); + if (val == "endpoints") { + var tmp = {}; + $(res).find(" > value > *").each(function(k,v) { + $.ajax({ + url: "https://centurio.work/plan/" + $(v).text(), + success: function() { + tmp[v.tagName] = {}; + var deferreds = []; + deferreds.push( + $.ajax({ + url: "https://centurio.work/plan/" + $(v).text() + "/symbol.svg", + success: function(res) { + tmp[v.tagName]['symbol'] = res; + } + }) + ); + deferreds.push( + $.ajax({ + url: "https://centurio.work/plan/" + $(v).text() + "/schema.rng", + success: function(res) { + tmp[v.tagName]['schema'] = res; + } + }) + ); + $.when.apply($, deferreds).then(function(x) { + save['endpoints_cache'] = tmp; + // when updating attributes clear the attributes, because they might change as well. New arguments are possible. + $('#dat_details').empty(); + adaptor_update(); + }); + } + }); + }); + } } }); } // }}} +function adaptor_update() { + $('g.element[element-endpoint]').each(function(k,ele){ + if (save['endpoints_cache'][$(ele).attr('element-endpoint')]) { + var c = $(ele).find('g.replace'); + var symbol = save['endpoints_cache'][$(ele).attr('element-endpoint')].symbol.documentElement; + c.replaceWith($(symbol).clone()); + } + }); +} + function adaptor_init(url,theme,dslx) { if (save['graph_theme'] != theme) { save['graph_theme'] = theme; save['graph_adaptor'] = new WfAdaptor($('body').data('theme-base') + '/' + theme + '/theme.js',function(graphrealization){ graphrealization.set_svg_container($('#graphcanvas')); @@ -332,27 +381,30 @@ $.ajax({ type: "PUT", url: url + "/properties/values/description/", data: ({'content': '<content>' + g + '</content>'}) }); + adaptor_update(); manifestation.events.click(svgid); }; + adaptor_update(); monitor_instance_pos(); $('#dat_details').empty(); }); } else { save['graph_adaptor'].update(function(graphrealization){ + adaptor_update(); var svgid = manifestation.clicked(); graphrealization.set_description($(dslx)); manifestation.events.click(svgid); monitor_instance_pos(); }); } } function monitor_graph_change(force) { //{{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "GET", url: url + "/properties/values/dslx/", success: function(dslx){ if (force || !save['graph'] || (save['graph'] && save['graph'].serializePrettyXML() != $(dslx).serializePrettyXML())) { @@ -370,11 +422,11 @@ } }); } //}}} function monitor_instance_dsl() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "GET", dataType: "text", url: url + "/properties/values/dsl/", success: function(res){ @@ -393,22 +445,22 @@ } }); }// }}} function monitor_instance_state() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "GET", url: url + "/properties/values/state/", dataType: "text", success: function(res){ monitor_instance_state_change(res); } }); }// }}} function monitor_instance_transformation() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "GET", url: url + "/properties/values/attributes/modeltype", success: function(res){ $("#currentmodel").text($(res.documentElement).text()); @@ -418,11 +470,11 @@ } }); }// }}} function monitor_instance_pos() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "GET", url: url + "/properties/values/positions/", success: function(res){ var values = $("value > *",res); @@ -500,11 +552,11 @@ astr += "<button id='vote_to_continue-" + parts.activity + "-" + parts.callback + "' onclick='$(this).attr(\"disabled\",\"disabled\");monitor_instance_vote_remove(\"" + parts.activity + "\",\"" + parts.callback + "\",\"true\");'>" + parts.activity + "</button>"; ctv.append(astr); format_visual_add(parts.activity,"vote") }// }}} function monitor_instance_vote_remove(activity,callback,value) {//{{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", url: url + "/callbacks/" + callback, data: ({'continue': value}), error: report_failure @@ -512,80 +564,80 @@ format_visual_remove(activity,"vote"); $('#vote_to_continue-' + activity + '-' + callback).remove(); }//}}} function start_instance() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", url: url + "/properties/values/state", data: ({value: "running"}), error: report_failure }); }// }}} function sim_instance() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", url: url + "/properties/values/state", data: ({value: "simulating"}), error: report_failure }); }// }}} function stop_instance() {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", url: url + "/properties/values/state", data: ({value: "stopping"}), error: report_failure }); }// }}} function save_testset() {// {{{ - var base = $("#current-instance").text(); + var url = $('body').attr('current-instance'); var testset = $X('<testset/>'); $.ajax({ type: "GET", - url: base + "/properties/values/dataelements/", + url: url + "/properties/values/dataelements/", success: function(res){ var pars = $X('<dataelements/>'); pars.append($(res.documentElement).children()); testset.append(pars); $.ajax({ type: "GET", - url: base + "/properties/values/handlerwrapper/", + url: url + "/properties/values/handlerwrapper/", success: function(res){ var pars = $X('<handlerwrapper>' + res + '</handlerwrapper>'); testset.append(pars); $.ajax({ type: "GET", - url: base + "/properties/values/endpoints/", + url: url + "/properties/values/endpoints/", success: function(res){ var pars = $X('<endpoints/>'); pars.append($(res.documentElement).children()); testset.append(pars); $.ajax({ type: "GET", - url: base + "/properties/values/positions/", + url: url + "/properties/values/positions/", success: function(res){ var pars = $X('<positions/>'); pars.append($(res.documentElement).children()); testset.append(pars); $.ajax({ type: "GET", - url: base + "/properties/values/dslx/", + url: url + "/properties/values/dslx/", success: function(res){ var pars = $X('<description/>'); pars.append($(res.documentElement)); testset.append(pars); pars = $X("<transformation><description type='copy'/><dataelements type='none'/><endpoints type='none'/></transformation>"); testset.append(pars); $.ajax({ type: "GET", - url: base + "/properties/values/attributes/", + url: url + "/properties/values/attributes/", success: function(res){ var name = $("value > info",res).text(); var pars = $X('<attributes/>'); pars.append($(res.documentElement).children()); pars.find('uuid').remove(); @@ -612,22 +664,22 @@ }, error: report_failure }); }// }}} function save_svg() {// {{{ - var base = $("#current-instance").text(); + var url = $('body').attr('current-instance'); var params = { mimetype: 'image/svg+xml' }; var gc = $('#graphcanvas').clone(); $.ajax({ type: "GET", url: "css/wfadaptor.css", success: function(res){ gc.prepend($X('<style xmlns="http://www.w3.org/2000/svg" type="text/css"><![CDATA[' + res + ']]></style>')); $.ajax({ type: "GET", - url: base + "/properties/values/attributes/info/", + url: url + "/properties/values/attributes/info/", success: function(res){ var name = $(res.documentElement).text(); $('#savesvg').attr('download',name + '.svg'); $('#savesvg').attr('href','data:application/xml;charset=utf-8;base64,' + $B64(gc.serializeXML())); @@ -637,11 +689,11 @@ }); } }); }// }}} function set_testset(testset,exec) {// {{{ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); suspended_monitoring = true; $.ajax({ type: "GET", url: url + "/notifications/subscriptions/", @@ -731,11 +783,11 @@ return; } var files = $('#modelfile').get(0).files; var reader = new FileReader(); reader.onload = function(){ - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); load_des(url,reader.result); loading = false; } reader.onerror = function(){ loading = false; } reader.onabort = function(){ loading = false; } @@ -768,11 +820,11 @@ } }); }// }}} function load_modeltype() {// {{{ if (loading) return; - var url = $("#current-instance").text(); + var url = $('body').attr('current-instance'); loading = true; var name = $("#modeltypes div.menuitem[data-selected=selected]").text(); $.ajax({ cache: false, @@ -924,22 +976,34 @@ if (node_state[what][cls] == undefined) node_state[what][cls] = 0; node_state[what][cls] -= 1; format_visual_set(what); }//}}} + +function scroll_into_view(what) { //{{{ + var tcontainer = $('#graphcolumn')[0]; + if ($('g[element-id="' + what + '"]').length > 0) { + var telement = $('g[element-id="' + what + '"]')[0].getBBox().y; + if (tcontainer.scrollTop > telement) { + tcontainer.scroll( { top: telement - 5, behavior: 'smooth' } ); + } + if (tcontainer.scrollTop + tcontainer.offsetHeight - 40 < telement) { + tcontainer.scroll( { top: telement - tcontainer.offsetHeight + 40, behavior: 'smooth' } ); + } + } +} //}}} + function format_visual_set(what) {//{{{ if (node_state[what] != undefined) { if (node_state[what]['vote'] == undefined) node_state[what]['vote'] = 0; if (node_state[what]['active'] == undefined) node_state[what]['active'] = 0; 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; }); + scroll_into_view(what); if (actives > 0 && votes > 0) $('g[element-id="' + what + '"] .super .colon').each(function(a,b){ b.setAttribute('class','colon necessary'); });