cockpit/js/instance.js in cpee-2.1.5 vs cockpit/js/instance.js in cpee-2.1.6
- old
+ new
@@ -26,10 +26,12 @@
save['endpoints_cache'] = {};
save['endpoints_list'] = {};
save['details'] = undefined;
save['details_target'] = undefined;
save['instance_pos'] = [];
+ save['modifiers'] = {};
+ save['modifiers_active'] = {};
node_state = {};
}
global_init();
@@ -93,10 +95,11 @@
$("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){
@@ -274,11 +277,10 @@
case 'endpoints':
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 trigger
if (save['graph_theme'] != data.content.values.theme) {
monitor_graph_change(true);
}
}
@@ -311,11 +313,10 @@
};
}
monitor_instance_values("dataelements");
monitor_instance_values("endpoints");
monitor_instance_values("attributes");
- monitor_instance_transformation();
monitor_instance_dsl();
monitor_instance_state();
} //}}}
function monitor_instance(cin,rep,load,exec) {// {{{
@@ -442,10 +443,15 @@
});
}
});
});
} else if(val == "attributes") {
+ if ($('#modifiers > div').length == 0) {
+ modifiers_display().then(modifiers_select);
+ } else {
+ modifiers_select();
+ }
var text = $(" > attributes > info",res).text() + " (" + url.replace(/\/$/,'').split(/[\\/]/).pop() + ")";
$('#title').text(text);
document.title = text;
if ($('body').attr('current-save')) {
$('body').attr('current-save-dir',$(" > attributes > design_dir",res).text());
@@ -630,23 +636,10 @@
success: function(res){
monitor_instance_state_change(res);
}
});
}// }}}
-function monitor_instance_transformation() {// {{{
- var url = $('body').attr('current-instance');
- $.ajax({
- type: "GET",
- url: url + "/properties/attributes/modeltype/",
- success: function(res){
- $("#currentmodel").text(res);
- },
- error: function() {
- $("#currentmodel").text('???');
- }
- });
-}// }}}
function monitor_instance_pos() {// {{{
var url = $('body').attr('current-instance');
$.ajax({
type: "GET",
@@ -1157,18 +1150,19 @@
}
} else {
if ($("*",han).length == 0) {
$.ajax({
type: "DELETE",
- url: url + "/notifications/subscriptions/" + vals[suburl],
+ url: url + "/notifications/subscriptions/" + vals[suburl] + '/'
})
+ delete vals[suburl];
} else {
let inp = load_testset_extract_handlers([],han,suburl);
promises.push(
$.ajax({
type: "PUT",
- url: url + "/notifications/subscriptions/" + vals[suburl],
+ url: url + "/notifications/subscriptions/" + vals[suburl] + '/',
data: inp.join('&')
})
)
}
}
@@ -1283,11 +1277,10 @@
$("#votes").empty();
}//}}}
function format_instance_pos() { //{{{
$(save['instance_pos']).each(function(){
- console.log(this);
var taskname = this.nodeName;
var taskstate = this.textContent;
format_visual_add(taskname,save['state'] == 'running' ? (taskstate == 'at' ? 'active' : 'passive') : 'passive');
});
} //}}}
@@ -1375,9 +1368,116 @@
dle.slice(100).each((k,ele) => {
$(ele).remove();
});
}
}//}}}
+
+async function modifiers_display() {
+ let promises = [];
+ let rep = $('body').attr('current-resources');
+ $('#modifiers > div').remove();
+
+ promises.push(
+ $.ajax({
+ url: rep + 'modifiers/'
+ }).then(async function(res) {
+ let ipromises = [];
+ $('resource',res).each(function(_,r) {
+ ipromises.push(
+ $.ajax({
+ url: rep + 'modifiers/' + $(r).text()
+ }).then(async function(ses){
+ let clone = document.importNode(document.querySelector('#modifiers template').content,true);
+ let t = $(r).text();
+ $('> div',clone).attr('data-resource',t);
+ $('div.title *',clone).text(decodeURIComponent(t));
+
+ let cpromises = [];
+ $('resource',ses).each(function(_,s) {
+ let opt = $('<option/>');
+ opt.text(decodeURIComponent($(s).text()));
+ $('div.select select',clone).append(opt);
+
+ cpromises.push(
+ $.ajax({
+ url: rep + 'modifiers/' + $(r).text() + '/' + $(s).text() + '/condition.json'
+ }).then(function(tes){
+ save['modifiers'][$(r).text() + '/' + $(s).text()] = tes;
+ })
+ );
+
+ });
+ $(clone).insertBefore($('#modifiers template'));
+
+ await Promise.all(cpromises);
+ })
+ );
+ });
+ await Promise.all(ipromises);
+ })
+ );
+ await Promise.all(promises);
+}
+
+function modifiers_select(e) {
+ let atts = {}
+ let attr = save['attributes'].save();
+ $('> attributes > *',attr).each(function(_,s){
+ atts[s.nodeName] = $(s).text();
+ });
+ $('#modifiers div[data-resource]').each(function(_,r){
+ $('select option',r).each(function(_,s){
+ let where = $(r).attr('data-resource') + '/' + encodeURIComponent($(s).text());
+ let cond = save['modifiers'][where];
+ let success = true;
+ for (x in cond) {
+ if (cond[x] != atts[x]) { success = false; }
+ }
+ if (success) {
+ save['modifiers_active'][$(r).attr('data-resource')] = $(s).text();
+ $('select',r).val($(s).text());
+ }
+ });
+ });
+}
+
+function modifiers_update_patch(url,now) {
+ $.ajax({
+ url: url + '/' + now + '/patch.xml',
+ success: function(res) {
+ set_testset(res,false);
+ }
+ });
+}
+function modifiers_update_unpatch(url,last,now) {
+ $.ajax({
+ url: url + '/' + last + '/unpatch.xml',
+ success: function(res) {
+ set_testset(res,false).then(function() {
+ modifiers_update_patch(url,now);
+ });
+ },
+ error: function() {
+ modifiers_update_patch(url,now);
+ }
+ });
+}
+
+function modifiers_update(e) {
+ // when change path
+ // unpach from what changed
+ // show ui
+ let rep = $('body').attr('current-resources');
+ let top = $(e.target).parents('div[data-resource]').attr('data-resource');
+ let last = save['modifiers_active'][top];
+ let now = $(e.target).val();
+
+ if (last) {
+ modifiers_update_unpatch(rep + 'modifiers/' + top,last,now);
+ } else {
+ modifiers_update_patch(rep + 'modifiers/' + top,now);
+ }
+}
function report_failure(){}
function ui_pos(e,bl) {
var url = $('body').attr('current-instance');