cockpit/js/instance.js in cpee-1.5.27 vs cockpit/js/instance.js in cpee-2.0

- old
+ new

@@ -1,28 +1,40 @@ -var ws; +var es; 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 paths = '#dat_details input, #dat_details textarea, #dat_details select, #dat_details button, #dat_details [contenteditable], #dat_dataelements input, #dat_dataelements textarea, #dat_dataelements select, #dat_dataelements button, #dat_dataelements [contenteditable], #dat_endpoints input, #dat_endpoints textarea, #dat_endpoints select, #dat_endpoints button, #dat_endpoints [contenteditable], #dat_attributes input, #dat_attributes textarea, #dat_attributes select, #dat_attributes button, #dat_attributes [contenteditable]'; var loading = false; var subscription; var subscription_state = 'less'; var graph_changed = new Event("graph:changed", {"bubbles":true, "cancelable":false}); var save = {}; - save['state']= undefined; - save['dsl'] = undefined; - save['graph'] = undefined; - save['graph_theme'] = undefined; - save['graph_adaptor'] = undefined; save['endpoints'] = undefined; - save['endpoints_cache'] = {}; - save['endpoints_list'] = {}; save['dataelements'] = undefined; save['attributes'] = undefined; - save['details'] = undefined; - save['details_target'] = undefined; - save['instance_pos'] = []; var node_state = {}; + +function global_init() { + suspended_monitoring = false; + loading = false; + subscription = undefined; + subscription_state = 'less'; + save['state']= undefined; + save['dsl'] = undefined; + save['activity_states'] = {} + save['graph'] = undefined; + save['graph_theme'] = undefined; + save['graph_adaptor'] = undefined; + save['endpoints_cache'] = {}; + save['endpoints_list'] = {}; + save['details'] = undefined; + save['details_target'] = undefined; + save['instance_pos'] = []; + node_state = {}; +} + +global_init(); + var sub_more = 'topic' + '=' + 'activity' + '&' +// {{{ 'events' + '=' + 'calling,status,manipulating,failed,done' + '&' + 'topic' + '=' + 'activity' + '&' + 'votes' + '=' + 'syncing_after' + '&' + 'topic' + '=' + 'description' + '&' + @@ -75,20 +87,20 @@ $("button[name=loadtestsetfile]").click(load_testsetfile); $("button[name=loadmodelfile]").click(load_modelfile); $("button[name=loadmodeltype]").click(function(e){new CustomMenu(e).menu($('#modeltypes'),load_modeltype, $("button[name=loadmodeltype]")); }); $("button[name=savetestsetfile]").click(function(){ save_testsetfile(); }); $("button[name=savesvgfile]").click(function(){ save_svgfile(); }); - $("button[name=state_start]").click(function(){ $(this).attr("disabled","disabled");start_instance(); }); - $("button[name=state_stop]").click(function(){ $(this).attr("disabled","disabled");stop_instance(); }); - $("button[name=state_replay]").click(function(){ $(this).attr("disabled","disabled");replay_instance(); }); + $("button[name=state_start]").click(function(){ $(this).parent().find('button').attr("disabled","disabled");start_instance(); }); + $("button[name=state_stop]").click(function(){ $(this).parent().find('button').attr("disabled","disabled");stop_instance(); }); + $("button[name=state_replay]").click(function(){ $(this).parent().find('button').attr("disabled","disabled");replay_instance(); }); $("button[name=state_abandon]").click(function(){ aba_instance(); }); $("input[name=votecontinue]").click(check_subscription); $("input[name=testsetfile]").change(load_testsetfile_after); $("input[name=modelfile]").change(load_modelfile_after); $.ajax({ - url: $('body').attr('current-testsets') + "testsets.xml", + url: $('body').attr('current-templates') + ".templates.xml", dataType: 'xml', success: function(res){ $('testset',res).each(function(){ var ts = $(this).text(); $('#templates').append($("<div class='menuitem'></div>").text(ts)); @@ -143,11 +155,11 @@ create_instance($("body").attr('current-base'),q.exec,true,true); } } }); $.ajax({ - url: $('body').attr('current-testsets') + "transformations.xml", + url: $('body').attr('current-templates') + ".transformations.xml", dataType: 'xml', success: function(res){ $('transformation',res).each(function(){ var ts = $(this).text(); $('#modeltypes').append($("<div class='menuitem'></div>").text(ts)); @@ -169,31 +181,22 @@ var num = 0; if ($("input[name=votecontinue]").is(':checked')) num += 1; if (num > 0 && subscription_state == 'less') { $.ajax({ type: "PUT", - url: url + "/notifications/subscriptions/" + subscription, - data: ( - sub_more + '&' + - 'message-uid' + '=' + 'xxx' + '&' + - 'fingerprint-with-producer-secret' + '=' + 'xxx' - ) + url: url + "/notifications/subscriptions/" + subscription + '/', + data: sub_more }); subscription_state = 'more'; } if (num == 0 && subscription_state == 'more') { $.ajax({ type: "PUT", - url: url + "/notifications/subscriptions/" + subscription, - data: ( - sub_less + '&' + - 'message-uid' + '=' + 'xxx' + '&' + - 'fingerprint-with-producer-secret' + '=' + 'xxx' - ) + url: url + "/notifications/subscriptions/" + subscription + '/', + data: sub_less }); subscription_state = 'less'; - format_visual_vote_clear(); } }// }}} function create_instance_from(base,url,exec) {// {{{ $.get({ @@ -244,22 +247,20 @@ alert("An instance info is necessary!"); } } }// }}} -function websocket() { //{{{ +function sse() { //{{{ 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() { + es = new EventSource(url + "/notifications/subscriptions/" + subscription + "/sse/"); + es.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()) { + es.onmessage = function(e) { + data = JSON.parse(e.data); + if (data['type'] == 'event') { + switch(data['topic']) { case 'dataelements': monitor_instance_values("dataelements"); break; case 'description': monitor_instance_dsl(); @@ -268,43 +269,38 @@ monitor_instance_values("endpoints"); break; case 'attributes': monitor_instance_values("attributes"); monitor_instance_transformation(); - if (!suspended_monitoring) { // or else it would load twice, because dsl changes also + if (!suspended_monitoring) { // or else it would load twice, because dsl changes also trigger monitor_graph_change(true); } break; case 'task': if ($('#trackcolumn').length > 0) { - var details = JSON.parse($('event > notification',data).text()); - $('#trackcolumn').append($('<iframe src="track.html?monitor=' + details.received['CPEE-INSTANCE-URL'].replace(/\/*$/,'/') + '"></iframe>')); + $('#trackcolumn').append($('<iframe src="track.html?monitor=' + data.content.received['CPEE-INSTANCE-URL'].replace(/\/*$/,'/') + '"></iframe>')); } break; case 'state': - monitor_instance_state_change(JSON.parse($('event > notification',data).text()).state); + monitor_instance_state_change(data['content']['state']); break; case 'position': - monitor_instance_pos_change($('event > notification',data).text()); + monitor_instance_pos_change(data['content']); break; - case 'transformation': - monitor_instance_transformation(); - break; case 'activity': - monitor_instance_running($('event > notification',data).text(),$('event > event',data).text()); + monitor_instance_running(data['content'],data['name']); 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); + if (data['type'] == 'vote') { + monitor_instance_vote_add(data['content']); } + append_to_log(data['type'], data['topic'] + '/' + data['name'], JSON.stringify(data['content'])); }; - ws.onclose = function() { + es.onerror = function() { append_to_log("monitoring", "closed", "server down i assume."); + // setTimeout(sse,10000); }; monitor_instance_values("dataelements"); monitor_instance_values("endpoints"); monitor_instance_values("attributes"); @@ -312,10 +308,14 @@ monitor_instance_dsl(); monitor_instance_state(); } //}}} function monitor_instance(cin,rep,load,exec) {// {{{ + global_init(); + format_visual_clear(); + format_visual_vote_clear(); + $("body").attr('current-instance',sanitize_url(cin)); $("body").attr('current-resources',sanitize_url(rep)); $("input[name=instance-url]").val($("body").attr('current-instance')); $("input[name=res-url]").val($("body").attr('current-resources')); @@ -325,11 +325,11 @@ url = $("body").attr('current-instance'); $.ajax({ type: "GET", - url: url + "/properties/schema/", + url: url, 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"); @@ -345,25 +345,19 @@ var q = $.parseQuerySimple(); history.replaceState({}, '', '?' + (q.min || q.min=="" ? "min&" : "") + 'monitor='+url); // Change url to return to current instance when reloading (because new subscription is made) $("input[name=votecontinue]").prop( "checked", false ); - subscription_state = 'less'; $.ajax({ type: "POST", url: url + "/notifications/subscriptions/", data: sub_less, success: function(res){ - res = res.unserialize(); - $.each(res,function(a,b){ - if (b[0] == 'key') { - subscription = b[1]; - } - }); + subscription = res; append_to_log("monitoring", "id", subscription); - websocket(); + sse(); if (load || exec) { load_testset(exec); } } }); @@ -380,17 +374,17 @@ var rep = $('body').attr('current-resources'); var bas = $('body').attr('current-base'); $.ajax({ type: "GET", - url: url + "/properties/values/" + val + "/", + url: url + "/properties/" + val + "/", success: function(res){ save[val].content(res); if (val == "endpoints") { save['endpoints_list'] = {}; var tmp = {}; - $(res).find(" > value > *").each(function(k,v) { + $(res).find(" > endpoints > *").each(function(k,v) { save['endpoints_list'][v.localName] = v.lastChild.nodeValue; $.ajax({ url: rep + encodeURIComponent($(v).text()), success: function() { tmp[v.tagName] = {}; @@ -427,11 +421,11 @@ }); } }); }); } else if(val == "attributes") { - var text = $(" > value > info",res).text() + " (" + url.replace(/\/$/,'').split(/[\\/]/).pop() + ")"; + var text = $(" > attributes > info",res).text() + " (" + url.replace(/\/$/,'').split(/[\\/]/).pop() + ")"; $('#title').text(text); document.title = text; } } }); @@ -509,16 +503,25 @@ graphrealization.set_label_container($('#graphgrid')); graphrealization.set_description($(dslx), true); graphrealization.notify = function(svgid) { var g = graphrealization.get_description(); save['graph'] = $X(g); - save['graph'].find('[xmlns]').removeAttr('xmlns'); + save['graph'].removeAttr('svg-id'); + save['graph'].removeAttr('svg-type'); + save['graph'].removeAttr('svg-subtype'); + save['graph'].removeAttr('svg-label'); document.dispatchEvent(graph_changed); $.ajax({ type: "PUT", - url: url + "/properties/values/description/", - data: ({'content': '<content>' + g + '</content>'}) + url: url + "/properties/description/", + contentType: 'text/xml', + headers: { + 'Content-ID': 'description', + 'CPEE-Event-Source': myid + }, + data: g, + error: report_failure }); adaptor_update(); manifestation.events.click(svgid); format_instance_pos(); if (manifestation.selected() == "unknown") { // nothing selected @@ -542,18 +545,18 @@ function monitor_graph_change(force) { //{{{ var url = $('body').attr('current-instance'); $.ajax({ type: "GET", - url: url + "/properties/values/dslx/", + url: url + "/properties/dslx/", success: function(dslx){ - if (force || !save['graph'] || (save['graph'] && save['graph'].serializePrettyXML() != $(dslx).serializePrettyXML())) { + if (force || !save['graph'] || (save['graph'] && save['graph'].serializePrettyXML() != $(dslx.documentElement).serializePrettyXML())) { $.ajax({ type: "GET", - url: url + "/properties/values/attributes/theme/", + url: url + "/properties/attributes/theme/", success: function(res){ - adaptor_init(url,$('value',res).text(),dslx); + adaptor_init(url,res,dslx); }, error: function() { adaptor_init(url,'preset',dslx); } }); @@ -565,11 +568,11 @@ function monitor_instance_dsl() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "GET", dataType: "text", - url: url + "/properties/values/dsl/", + url: url + "/properties/dsl/", success: function(res){ if (res != save['dsl']) { save['dsl'] = res; var ctv = $("#areadsl"); ctv.empty(); @@ -587,24 +590,24 @@ function monitor_instance_state() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "GET", - url: url + "/properties/values/state/", + url: url + "/properties/state/", dataType: "text", success: function(res){ monitor_instance_state_change(res); } }); }// }}} function monitor_instance_transformation() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "GET", - url: url + "/properties/values/attributes/modeltype", + url: url + "/properties/attributes/modeltype", success: function(res){ - $("#currentmodel").text($(res.documentElement).text()); + $("#currentmodel").text(res); }, error: function() { $("#currentmodel").text('???'); } }); @@ -612,26 +615,34 @@ function monitor_instance_pos() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "GET", - url: url + "/properties/values/positions/", + url: url + "/properties/positions/", success: function(res){ - save['instance_pos'] = $("value > *",res); + save['instance_pos'] = $("positions > *",res); format_visual_clear(); format_instance_pos(); } }); }// }}} -function monitor_instance_running(notification,event) {// {{{ +function monitor_instance_running(content,event) {// {{{ if (save['state'] == "stopping") return; - var parts = JSON.parse(notification); - if (event == "calling") - format_visual_add(parts.activity,"active") - if (event == "done") - format_visual_remove(parts.activity,"active") + if (event == "calling") { + save['activity_states'][content.activity_uuid] = true + format_visual_add(content.activity,"active") + } + if (event == "manipulating") { + if (!save['activity_states'][content.activity_uuid]) { + format_visual_add(content.activity,"active") + } + } + if (event == "done") { + delete save['activity_states'][content.activity_uuid]; + format_visual_remove(content.activity,"active") + } } // }}} function monitor_instance_state_change(notification) { //{{{ if ($('#trackcolumn').length > 0) { if (notification == "finished") { parent.closeIFrame(window.location.search); @@ -666,53 +677,58 @@ $('#state_extended').hide(); $("button[name=state_start]").hide(); $("button[name=state_stop]").show(); $("button[name=state_replay]").hide(); $("button[name=state_abandon]").hide(); + } else { + $('#state_extended').hide(); + $("button[name=state_start]").hide(); + $("button[name=state_stop]").hide(); + $("button[name=state_replay]").hide(); + $("button[name=state_abandon]").hide(); } // disable all input, also check themes format_visual_forms(); // remove all markings with state change if (save['graph_adaptor'] && save['graph_adaptor'].illustrator) { save['graph_adaptor'].illustrator.get_elements().removeClass('marked'); } - if (notification == "finished" || notification == "abandoned") { + if (notification != "ready" && notification != "stopped" && notification != "running") { $('.tabbehind button').hide(); $('#state_any').hide(); } else { $('#parameters .tabbehind button').show(); + $('#state_any').show(); } $("#state_text").text(notification); } } //}}} -function monitor_instance_pos_change(notification) {// {{{ - var parts = JSON.parse(notification); - if (parts['unmark']) { - $.each(parts['unmark'],function(a,b){ +function monitor_instance_pos_change(content) {// {{{ + if (content['unmark']) { + $.each(content['unmark'],function(a,b){ format_visual_remove(b.position,"passive") }); } - if (parts['at']) { - $.each(parts['at'],function(a,b){ - format_visual_add(b.position,"passive") + if (content['at']) { + $.each(content['at'],function(a,b){ + format_visual_add(b.position,"passive"); }); } - if (!parts['at'] && !parts['unmark'] && !parts['after'] && !parts['wait']) { + if (!content['at'] && !content['unmark'] && !content['after'] && !content['wait']) { monitor_instance_pos(); } } // }}} -function monitor_instance_vote_add(notification) {// {{{ - var parts = JSON.parse(notification); +function monitor_instance_vote_add(parts) {// {{{ var ctv = $("#votes"); astr = ''; if ($("input[name=votecontinue]").is(':checked')) - 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>"; + astr += "<button id='vote_to_continue-" + parts.activity + "-" + parts.key + "' onclick='$(this).attr(\"disabled\",\"disabled\");monitor_instance_vote_remove(\"" + parts.activity + "\",\"" + parts.key + "\",\"true\");'>" + parts.activity + "</button>"; ctv.append(astr); format_visual_add(parts.activity,"vote") }// }}} function monitor_instance_vote_remove(activity,callback,value) {//{{{ var url = $('body').attr('current-instance'); @@ -728,39 +744,39 @@ function start_instance() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", - url: url + "/properties/values/state", + url: url + "/properties/state", data: ({value: "running"}), error: report_failure }); }// }}} function replay_instance() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", - url: url + "/properties/values/state", + url: url + "/properties/state", data: ({value: "replaying"}), error: report_failure }); }// }}} function aba_instance() {// {{{ monitor_instance_state_change('abandoned'); var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", - url: url + "/properties/values/state", + url: url + "/properties/state", data: ({value: "abandoned"}), error: report_failure }); }// }}} function stop_instance() {// {{{ var url = $('body').attr('current-instance'); $.ajax({ type: "PUT", - url: url + "/properties/values/state", + url: url + "/properties/state", data: ({value: "stopping"}), error: report_failure }); }// }}} @@ -775,63 +791,29 @@ get_testset(def); }// }}} function get_testset(deferred) {// {{{ var url = $('body').attr('current-instance'); - var testset = $X('<testset/>'); $.ajax({ type: "GET", - url: url + "/properties/values/dataelements/", + url: url + "/properties/", success: function(res){ - var pars = $X('<dataelements/>'); - pars.append($(res.documentElement).children()); - testset.append(pars); - $.ajax({ - type: "GET", - url: url + "/properties/values/handlerwrapper/", - success: function(res){ - var pars = $X('<handlerwrapper>' + res + '</handlerwrapper>'); - testset.append(pars); - $.ajax({ - type: "GET", - url: url + "/properties/values/endpoints/", - success: function(res){ - var pars = $X('<endpoints/>'); - pars.append($(res.documentElement).children()); - testset.append(pars); - $.ajax({ - type: "GET", - 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: 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(); - testset.append(pars); - deferred.resolve(name,testset); - }, - error: function() { deferred.reject(); report_failure(); } - }); - }, - error: function() { deferred.reject(); report_failure(); } - }); - }, - error: function() { deferred.reject(); report_failure(); } - }); - }, - error: function() { deferred.reject(); report_failure(); } - }); + var testset = $X('<testset xmlns="http://cpee.org/ns/properties/2.0"/>'); + testset.append($(res.documentElement).children()); + $('testset > state',testset).remove(); + $('testset > status',testset).remove(); + $('testset > positions',testset).remove(); + $('testset > dsl',testset).remove(); + $('testset > description > *',testset).remove(); + $('testset > description',testset).append($('testset > dslx',testset).children()); + $('testset > transformation',testset).remove(); + $('testset > dsl',testset).remove(); + $('testset > dslx',testset).remove(); + testset.append($X('<transformation xmlns="http://cpee.org/ns/properties/2.0"><description type="copy"/><dataelements type="none"/><endpoints type="none"/></transformation>')); + var name = $('testset > attributes > info',testset).text(); + deferred.resolve(name,testset); }, error: function() { deferred.reject(); report_failure(); } }); }// }}} function save_svgfile() {// {{{ @@ -868,11 +850,11 @@ loc.attr('style',loc.attr('style') + ' display: none'); } }); $.ajax({ type: "GET", - url: url + "/properties/values/attributes/info/", + url: url + "/properties/attributes/info/", success: function(res){ var name = $(res.documentElement).text(); $('#savesvgfile').attr('download',name + '.svg'); $('#savesvgfile').attr('href','data:application/xml;charset=utf-8;base64,' + $B64(gc.serializeXML())); @@ -887,10 +869,19 @@ var url = $('body').attr('current-instance'); suspended_monitoring = true; var promises = []; + var tset = $X('<properties xmlns="http://cpee.org/ns/properties/2.0"/>'); + tset.append($("testset > handlerwrapper",testset)); + tset.append($("testset > positions",testset)); + tset.append($("testset > dataelements",testset)); + tset.append($("testset > endpoints",testset)); + tset.append($("testset > attributes",testset)); + tset.append($("testset > description",testset)); + tset.append($("testset > transformation",testset)); + promises.push( $.ajax({ type: "GET", url: url + "/notifications/subscriptions/", error: report_failure @@ -901,48 +892,36 @@ values.each(function(){ vals.push($(this).attr('url')); }); await load_testset_handlers(url,testset,vals); }) - ) - promises.push(load_testset_dataelements(url,testset)); - promises.push(load_testset_attributes(url,testset)); - promises.push(load_testset_endpoints(url,testset)); - promises.push(load_testset_pos(url,testset)); + ); + promises.push( + $.ajax({ + type: 'PATCH', + url: url + "/properties/", + contentType: 'text/xml', + headers: { + 'Content-ID': 'properties', + 'CPEE-Event-Source': myid + }, + data: tset.serializeXML(), + error: report_failure + }) + ); - if ($("testset > transformation",testset).length > 0) { - var ser = ''; - $("testset > transformation > *",testset).each(function(){ - ser += $(this).serializeXML() + "\n"; - }); - var val = "<content>" + ser + "</content>"; - promises.push( - $.ajax({ - type: "PUT", - url: url + "/properties/values/transformation", - data: ({content: val}), - error: report_failure - }).then(async function(){ - await load_testset_des(url,testset); - }) - ); - } else { - promises.push(load_testset_des(url,testset)); - } - - promises.push(load_testset_hw(url,testset)); await Promise.all(promises); suspended_monitoring = false; $.ajax({ type: "GET", - url: url + "/properties/values/state/", + url: url + "/properties/state/", dataType: "text", success: function(res){ $.ajax({ type: "PUT", - url: url + "/properties/values/state", + url: url + "/properties/state", data: ({value: res}), error: report_failure, success: function(res){ if (exec) start_instance(); } @@ -1002,11 +981,11 @@ loading = true; var name = $("#templates div.menuitem[data-selected=selected]").text(); var url; if (name) { - url = $('body').attr('current-testsets') + name + ".xml"; + url = $('body').attr('current-templates') + name + ".xml"; } else { if ($('body').attr('load-testset').length > 0) { url = $('body').attr('load-testset'); } } @@ -1036,15 +1015,15 @@ var name = $("#modeltypes div.menuitem[data-selected=selected]").text(); $.ajax({ cache: false, dataType: 'xml', - url: $('body').attr('current-testsets') + "." + name + ".xml", + url: $('body').attr('current-templates') + "." + name + ".xml", success: function(res){ $.ajax({ type: "PUT", - url: url + "/properties/values/attributes/modeltype", + url: url + "/properties/attributes/modeltype", data: ({value: name}), success: function(){ set_testset(res,false); }, error: report_failure @@ -1055,120 +1034,29 @@ } }); }// }}} async function load_des(url,model) { //{{{ - model = model.replace(/<\?[^\?]+\?>/,''); - var val = "<content>" + model + "</content>"; return $.ajax({ type: "PUT", - url: url + "/properties/values/description", - data: ({content: val}), + url: url + "/properties/description/", + contentType: 'text/xml', + headers: { + 'Content-ID': 'description', + 'CPEE-Event-Source': myid + }, + data: model, error: report_failure }); } //}}} - -async function load_testset_des(url,testset) {// {{{ - if ($("testset > description",testset).length == 0) { return; } - var ser = ''; - $("testset > description > *",testset).each(function(){ - ser += $(this).serializeXML() + "\n"; - }); - return load_des(url,ser); -} // }}} -async function load_testset_hw(url,testset) {// {{{ - var promises = []; - $("testset > handlerwrapper",testset).each(function(){ - var val = $(this).text(); - promises.push( - $.ajax({ - type: "PUT", - url: url + "/properties/values/handlerwrapper", - data: ({value: val}), - error: report_failure - }) - ); - }); - return Promise.all(promises); -} // }}} -async function load_testset_dataelements(url,testset) {// {{{ - if ($("testset > dataelements",testset).length == 0) { return; } - var ser = ''; - $("testset > dataelements > *",testset).each(function(){ - ser += $(this).serializeXML() + "\n"; - }); - var val = "<content>" + ser + "</content>"; - return $.ajax({ - type: "PUT", - url: url + "/properties/values/dataelements", - data: ({content: val}), - error: report_failure - }); -}// }}} -async function load_testset_attributes(url,testset) {// {{{ - var promises = []; - if ($("testset > attributes",testset).length == 0) { return; } - var ser = ''; - $.ajax({ - type: "GET", - url: url + "/properties/values/attributes/uuid", - success: function(res){ - var uuid = $X('<uuid xmlns="http://riddl.org/ns/common-patterns/properties/1.0"/>'); - uuid.text($('value',res).text()); - $("testset > attributes",testset).prepend(uuid); - $("testset > attributes > *",testset).each(function(){ - ser += $(this).serializeXML() + "\n"; - }); - var val = "<content>" + ser + "</content>"; - promises.push( - $.ajax({ - type: "PUT", - url: url + "/properties/values/attributes", - data: ({content: val}), - error: report_failure - }) - ); - } - }); - return Promise.all(promises); -}// }}} -async function load_testset_endpoints(url,testset) {// {{{ - if ($("testset > endpoints",testset).length == 0) { return; } - var ser = ''; - $("testset > endpoints > *",testset).each(function(){ - ser += $(this).serializeXML() + "\n"; - }); - var val = "<content>" + ser + "</content>"; - return $.ajax({ - type: "PUT", - url: url + "/properties/values/endpoints/", - data: ({content: val}), - error: report_failure - }); -}// }}} -async function load_testset_pos(url,testset) {// {{{ - if ($("testset > positions",testset).length == 0) { return; } - var ser = ''; - $("testset > positions > *",testset).each(function(){ - ser += $(this).serializeXML() + "\n"; - }); - var val = "<content>" + ser + "</content>"; - return $.ajax({ - type: "PUT", - url: url + "/properties/values/positions/", - data: ({content: val}), - success: monitor_instance_pos, - error: report_failure - }); -}// }}} async function load_testset_handlers(url,testset,vals) {// {{{ var promises = []; $("testset > handlers > *",testset).each(async function(){ var han = this; var suburl = $(han).attr('url'); if ($.inArray(suburl,vals) == -1) { - var inp = "url="+encodeURIComponent(suburl); + var inp = "url="+encodeURIComponent(suburl).replace(/~/,'%7E'); $("*",han).each(function(){ inp += "&topic=" + $(this).attr('topic'); inp += "&" + this.nodeName + "=" + $(this).text(); }); promises.push( @@ -1195,10 +1083,12 @@ if (node_state[what] == undefined) node_state[what] = {}; if (node_state[what][cls] == undefined) node_state[what][cls] = 0; node_state[what][cls] -= 1; + if (node_state[what][cls] < 0) + node_state[what][cls] = 0; format_visual_set(what); }//}}} function scroll_into_view(what) { //{{{ var tcontainer = $('#graphcanvas').parent()[0]; @@ -1278,10 +1168,11 @@ } else { b.setAttribute('class','activities'); } }); $('#votes').empty(); + }//}}} function format_visual_vote_clear() {//{{{ node_state = {}; $('.super .vote').each(function(a,b){b.setAttribute("class","vote");}); $("#votes").empty(); @@ -1369,11 +1260,17 @@ message = message.replace(/,\{/g,', {'); message = message.replace(/,\[/g,', ['); message = message.replace(/:\"/g,': "'); message = message.replace(/:\{/g,': {'); message = message.replace(/:\[/g,': ['); - $("#dat_log").append("<tr><td class='fixed top'><a title=\"" + d.strftime("[%d/%b/%Y %H:%M:%S]") + "\">D</a></td><td class='fixed'>&#160;-&#160;</td><td class='fixed'><a title=\"" + what + "\">T</a></td><td class='fixed'>&#160;-&#160;</td><td class='fixed'>" + type + "</td><td class='fixed'>&#160;-&#160;</td><td class='long'>" + message + "</td></tr>"); + $("#dat_log").prepend("<tr><td class='fixed'><a title=\"" + d.strftime("[%d/%b/%Y %H:%M:%S]") + "\">D</a></td><td class='fixed'>&#160;-&#160;</td><td class='fixed'><a title=\"" + what + "\">T</a></td><td class='fixed'>&#160;-&#160;</td><td class='fixed'>" + type + "</td><td class='fixed'>&#160;-&#160;</td><td class='long'>" + message + "</td></tr>"); + var dle = $("#dat_log").children(); + if (dle.length > 100) { + dle.slice(100).each((k,ele) => { + $(ele).remove(); + }); + } }//}}} function report_failure(){} function ui_pos(e,bl) { @@ -1385,14 +1282,19 @@ coll = bl(coll); var vals = ""; $(coll).each(function(k,ele){ vals += "<" + ele + ">at</" + ele + ">"; }); - vals = "<content>" + vals + "</content>"; + vals = "<positions xmlns='http://cpee.org/ns/properties/2.0'>" + vals + "</positions>"; $.ajax({ type: "PUT", - url: url + "/properties/values/positions/", - data: ({content: vals}), + url: url + "/properties/positions/", + contentType: 'application/xml', + headers: { + 'Content-ID': 'positions', + 'CPEE-Event-Source': myid + }, + data: vals, success: monitor_instance_pos, error: report_failure }); } function del_ui_pos(e) {