var es; var suspended_redrawing = 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 model_loaded = new Event("model:loaded", {"bubbles":true, "cancelable":false}); var save = {}; save['endpoints'] = undefined; save['dataelements'] = undefined; save['attributes'] = undefined; var node_state = {}; function global_init() { suspended_redrawing = false; loading = false; subscription = undefined; subscription_state = 'less'; save['states']= {}; save['state']= undefined; save['dsl'] = undefined; save['activity_red_states'] = {} save['activity_blue_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'] = []; save['modeltype'] = 'CPEE'; save['modifiers'] = {}; save['modifiers_active'] = {}; save['modifiers_additional'] = {}; save['resources'] = undefined; node_state = {}; } global_init(); var sub_more = 'topic' + '=' + 'activity' + '&' +// {{{ 'events' + '=' + 'calling,status,manipulating,failed,done' + '&' + 'topic' + '=' + 'activity' + '&' + 'votes' + '=' + 'syncing_after' + '&' + 'topic' + '=' + 'description' + '&' + 'events' + '=' + 'change,error' + '&' + 'topic' + '=' + 'position' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'state' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'dataelements' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'endpoints' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'attributes' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'task' + '&' + 'events' + '=' + 'instantiation' + '&' + 'topic' + '=' + 'transformation' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'executionhandler' + '&' + 'events' + '=' + 'error,change' + '&' + 'topic' + '=' + 'handlers' + '&' + 'events' + '=' + 'change';// }}} var sub_less = 'topic' + '=' + 'activity' + '&' +// {{{ 'events' + '=' + 'calling,status,manipulating,failed,done' + '&' + 'topic' + '=' + 'position' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'description' + '&' + 'events' + '=' + 'change,error' + '&' + 'topic' + '=' + 'state' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'dataelements' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'endpoints' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'attributes' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'task' + '&' + 'events' + '=' + 'instantiation' + '&' + 'topic' + '=' + 'transformation' + '&' + 'events' + '=' + 'change' + '&' + 'topic' + '=' + 'executionhandler' + '&' + 'events' + '=' + 'error,change' + '&' + 'topic' + '=' + 'handlers' + '&' + 'events' + '=' + 'change';// }}} function cockpit() { //{{{ $("button[name=base]").click(function(){ create_instance($("input[name=base-url]").val(),null,false,false); }); $("button[name=instance]").click(function(){ uidash_activate_tab("#tabinstance"); monitor_instance($("input[name=instance-url]").val(),$("input[name=res-url]").val(),false,false); }); $("button[name=loadtestset]").click(function(e){new CustomMenu(e).menu($('#templates'),function(){ load_testset(false) } ); }); $("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).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_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); $("#modifiers").on('change','div.select select',function(e){ modifiers_update(e); }); $.ajax({ url: $('body').attr('current-templates'), dataType: 'json', success: function(res){ $(res).each(function(){ if (this.type == 'file') { $('#templates').append($("
").text(this.name.replace(/\.xml/,''))); } }); }, error: function() { $("button[name=loadtestset]").attr('disabled','disabled'); }, complete: function() { var q = $.parseQuerySimple(); if (q.min || q.min == "") { uidash_toggle_vis_tab($('#instance')); uidash_toggle_vis_tab($('#parameters')); } if (q.monitor && q.load) { if (q.load.match(/https?:\/\//)) { $('body').attr('load-testset',q.load); } else { $("#templates div.menuitem").each(function(k,v){ if ($(v).text() == q.load) { $(v).attr('data-selected','selected'); } }); } uidash_activate_tab("#tabexecution"); monitor_instance(q.monitor,$("body").attr('current-resources'),true,false); } else if (q.load) { if (q.load.match(/https?:\/\//)) { $('body').attr('load-testset',q.load); } else { $("#templates div.menuitem").each(function(k,v){ if ($(v).text() == q.load) { $(v).attr('data-selected','selected'); } }); } uidash_activate_tab("#tabexecution"); create_instance($("body").attr('current-base'),q.load,true,false); } else if (q.instantiate) { if (q.instantiate.match(/https?:\/\//)) { uidash_activate_tab("#tabexecution"); create_instance_from($("body").attr('current-base'),q.instantiate,false); } else { alert('Nope. Url!'); } } else if (q.new || q.new == "") { uidash_activate_tab("#tabinstance"); create_instance($("body").attr('current-base'),"Plain Instance",false,false); } else if (q.monitor) { uidash_activate_tab("#tabinstance"); monitor_instance(q.monitor,$("body").attr('current-resources'),false,false); } else if (q.exec) { if (q.exec.match(/https?:\/\//)) { $('body').attr('load-testset',q.load); } else { $("#templates div.menuitem").each(function(k,v){ if ($(v).text() == q.exec) { $(v).attr('data-selected','selected'); } }); } uidash_activate_tab("#tabexecution"); create_instance($("body").attr('current-base'),q.exec,true,true); } } }); $.ajax({ url: "transformations.xml", dataType: 'xml', success: function(res){ $('transformation',res).each(function(){ var ts = $(this).text(); $('#modeltypes').append($("").text(ts)); }); } }); } //}}} function sanitize_url(url) { //{{{ var lastChar = url.substr(url.length - 1) if (lastChar != '/') { url = (url + '/'); } return url; } //}}} function check_subscription() { // {{{ 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", 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 }); subscription_state = 'less'; } }// }}} function create_instance_from(base,url,exec) {// {{{ $.get({ url: url, dataType: "text", success: function(res) { $.ajax({ type: "POST", url: base, contentType: 'application/xml', dataType: "text", headers: { 'CONTENT-ID': 'xml' }, data: res, success: function(res){ var iu = (base + "//" + res + "/").replace(/\/+/g,"/").replace(/:\//,"://"); monitor_instance(iu,$("body").attr('current-resources'),false,exec); }, error: function(a,b,c) { alert("No CPEE running."); } }); } }); }// }}} function create_instance(base,name,load,exec) {// {{{ var info = name ? name : prompt("Instance info?", "Enter info here"); if (info != null) { if (info.match(/\S/)) { $.ajax({ type: "POST", url: base, dataType: "text", data: "info=" + info, success: function(res){ var iu = (base + "//" + res + "/").replace(/\/+/g,"/").replace(/:\//,"://"); if (name) { monitor_instance(iu,$("body").attr('current-resources'),load,exec); } else { $("body").attr('current-instance', sanitize_url(iu)); $("input[name=instance-url]").val(iu); } }, error: function(a,b,c) { alert("No CPEE running."); } }); } else { alert("An instance info is necessary!"); } } }// }}} async function sse() { //{{{ var url = $('body').attr('current-instance'); if (subscription) { es = new EventSource(url + "/notifications/subscriptions/" + subscription + "/sse/"); es.onopen = function() { append_to_log("monitoring", "opened", "nice."); }; es.onmessage = async function(e) { data = JSON.parse(e.data); if (data['type'] == 'event') { switch(data['topic']) { case 'dataelements': monitor_instance_values("dataelements",data.content.values); break; case 'description': monitor_instance_dsl(); break; case 'endpoints': monitor_instance_values("endpoints"); break; case 'attributes': if (save['resources'] != data.content.values.resource) { await monitor_instance_values("attributes"); monitor_instance_values("endpoints"); } else { monitor_instance_values("attributes"); } if (save['graph_theme'] != data.content.values.theme) { monitor_graph_change(true); } break; case 'task': if ($('#trackcolumn').length > 0) { $('#trackcolumn').append($('')); $('#graphcolumn').addClass('resize'); } break; case 'state': save['states'][data['content']['state']] = Date.parse(data.timestamp); monitor_instance_state_change(data['content']['state']); break; case 'position': monitor_instance_pos_change(data['content']); break; case 'activity': monitor_instance_running(data['content'],data['name']); break; } } if (data['type'] == 'vote') { monitor_instance_vote_add(data['content']); } append_to_log(data['type'], data['topic'] + '/' + data['name'], JSON.stringify(data['content'])); }; es.onerror = function() { append_to_log("monitoring", "closed", "finished or abandoned or not existing or server down. one of these, i assume."); // setTimeout(sse,10000); }; } await monitor_instance_values("attributes"); // attributes first, to catch the