cockpit/js/instance.js in cpee-2.1.2 vs cockpit/js/instance.js in cpee-2.1.4
- old
+ new
@@ -404,32 +404,32 @@
save['endpoints_list'] = {};
var tmp = {};
$(res).find(" > endpoints > *").each(function(k,v) {
save['endpoints_list'][v.localName] = v.lastChild.nodeValue;
$.ajax({
- url: rep + encodeURIComponent($(v).text()),
+ url: rep + 'endpoints/' + encodeURIComponent($(v).text()),
success: function() {
tmp[v.tagName] = {};
var deferreds = [new $.Deferred(), new $.Deferred(), new $.Deferred()];
$.ajax({
- url: rep + encodeURIComponent($(v).text()) + "/symbol.svg",
+ url: rep + 'endpoints/' + encodeURIComponent($(v).text()) + "/symbol.svg",
success: function(res) {
tmp[v.tagName]['symbol'] = res;
deferreds[0].resolve(true);
},
error: deferreds[0].resolve
})
$.ajax({
- url: rep + encodeURIComponent($(v).text()) + "/schema.rng",
+ url: rep + 'endpoints/' + encodeURIComponent($(v).text()) + "/schema.rng",
success: function(res) {
tmp[v.tagName]['schema'] = res;
deferreds[1].resolve(true);
},
error: deferreds[1].resolve
})
$.ajax({
- url: rep + encodeURIComponent($(v).text()) + "/properties.json",
+ url: rep + 'endpoints/' + encodeURIComponent($(v).text()) + "/properties.json",
success: function(res) {
tmp[v.tagName]['properties'] = res;
deferreds[2].resolve(true);
},
error: deferreds[2].resolve
@@ -729,11 +729,10 @@
localStorage.removeItem('marked');
localStorage.removeItem('marked_from');
}
if (notification != "ready" && notification != "stopped" && notification != "running") {
- console.log('rrr');
$('#parameters ui-content ui-area > button').attr('disabled','disabled');
$('#state_any').hide();
} else {
$('#parameters ui-content ui-area > button').removeAttr('disabled');
$('#state_any').show();
@@ -843,11 +842,40 @@
$('[xmlns]',testset).each((idx,ele) => {
if (ele.parentNode.namespaceURI == ele.getAttribute('xmlns')) {
ele.removeAttribute('xmlns');
}
});
- deferred.resolve(name,testset);
+ $.ajax({
+ type: "GET",
+ url: url + "/notifications/subscriptions/",
+ success: async function(res){
+ let values = $("subscriptions > subscription[url]",res);
+ let subs = $X('<subscriptions xmlns="http://riddl.org/ns/common-patterns/notifications-producer/2.0"/>');
+ let promises = [];
+ let scount = 0;
+ values.each(function(){
+ let sid = $(this).attr('id');
+ if (sid.match(/^_/)) {
+ scount += 1;
+ promises.push(
+ $.ajax({
+ type: "GET",
+ url: url + "/notifications/subscriptions/" + sid,
+ error: report_failure
+ }).then(function(a) {
+ subs.append($(a.documentElement));
+ })
+ );
+ };
+ });
+ await Promise.all(promises);
+ if (scount > 0) { testset.append(subs); }
+ deferred.resolve(name,testset);
+ },
+ error: function() { deferred.reject(); report_failure(); }
+ });
+
},
error: function() { deferred.reject(); report_failure(); }
});
}// }}}
function save_svgfile() {// {{{
@@ -917,15 +945,14 @@
$.ajax({
type: "GET",
url: url + "/notifications/subscriptions/",
error: report_failure
}).then(async function(res) {
- var rcount = 0;
var values = $("subscriptions > subscription[url]",res);
- var vals = [];
+ var vals = {};
values.each(function(){
- vals.push($(this).attr('url'));
+ vals[$(this).attr('url')] = $(this).attr('id');
});
await load_testset_handlers(url,testset,vals);
})
);
promises.push(
@@ -1081,27 +1108,70 @@
},
data: model,
error: report_failure
});
} //}}}
+
+function load_testset_extract_handlers(inp,han,suburl) { //{{{
+ inp.push("url="+encodeURIComponent(suburl).replace(/~/,'%7E'));
+ $(">*",han).each(function(_,top){
+ let events = [];
+ let votes = [];
+ $(">*",top).each(function(_,it){
+ if (it.nodeName == 'event') {
+ events.push($(it).text());
+ }
+ if (it.nodeName == 'vote') {
+ votes.push($(it).text());
+ }
+ });
+ if (events.length > 0) {
+ inp.push("topic=" + $(top).attr('id'));
+ inp.push("events=" + events.join(','));
+ }
+ if (votes.length > 0) {
+ inp.push("topic=" + $(top).attr('id'));
+ inp.push("votes=" + votes.join(','));
+ }
+ });
+ return inp;
+} //}}}
+
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).replace(/~/,'%7E');
- $("*",han).each(function(){
- inp += "&topic=" + $(this).attr('topic');
- inp += "&" + this.nodeName + "=" + $(this).text();
- });
- promises.push(
+ $("testset > subscriptions > *",testset).each(async function(){
+ let han = this;
+ let sid = $(han).attr('id');
+ let suburl = $(han).attr('url');
+ if (typeof(vals[suburl]) == 'undefined') {
+ if ($("*",han).length > 0) {
+ let inp = [];
+ if (sid) { inp.push("id="+encodeURIComponent(sid)); }
+ inp = load_testset_extract_handlers(inp,han,suburl);
+ promises.push(
+ $.ajax({
+ type: "POST",
+ url: url + "/notifications/subscriptions/",
+ data: inp.join('&')
+ })
+ )
+ }
+ } else {
+ if ($("*",han).length == 0) {
$.ajax({
- type: "POST",
- url: url + "/notifications/subscriptions/",
- data: inp
+ type: "DELETE",
+ url: url + "/notifications/subscriptions/" + vals[suburl],
})
- )
+ } else {
+ let inp = load_testset_extract_handlers([],han,suburl);
+ promises.push(
+ $.ajax({
+ type: "PUT",
+ url: url + "/notifications/subscriptions/" + vals[suburl],
+ data: inp.join('&')
+ })
+ )
+ }
}
});
return Promise.all(promises);
}// }}}