Skip to content

Commit

Permalink
only apply filter on filter change (background poll continues), nav: …
Browse files Browse the repository at this point in the history
…host icon always shows locals, nodel icon always shows all nodes
  • Loading branch information
Justin Parker authored and scroix committed Apr 1, 2024
1 parent 21a3cac commit 8859e10
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion nodel-webui-js/src/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if (request.status === 200) window.location.href = "index.xml";
else window.location.href = "nodel.xml";
}
else window.location.href = "nodes.xml";
else window.location.href = "locals.xml";
</script>
</head>
</html>
71 changes: 39 additions & 32 deletions nodel-webui-js/src/nodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ $(function() {
// get the node name
if(pageType === ePageType.NODE) node = decodeURIComponent(window.location.pathname.split( '/' )[2].replace(/\+/g, '%20'));
if(node) {
if($('body').hasClass('core')) $('.navbar-brand a').attr("href", window.document.location.protocol+"//"+host+"/locals.xml"); // go to locals
if($('body').hasClass('core')) $('.navbar-brand a').attr("href", window.document.location.protocol+"//"+host+"/nodes.xml"); // go to locals
getNodeDetails().then(function(){
updatepadding();
$.when(createDynamicElements().then(function(){
Expand Down Expand Up @@ -890,46 +890,53 @@ var getNodeList = function(filterstr){
return d.promise();
}

var getLocalsList = function(filterstr){
if(!_.isUndefined(filterstr)) $.observable(localsList['flt'] = filterstr);
var fltstr = localsList['flt'];
var lastLocalNodes = null; // cache of last local nodes list

var getLocalsList = function(){
var d = $.Deferred();
if(localsListreq) localsListreq.abort();
var localhost = 'localhost';
localsListreq = $.getJSON(proto+'//'+host+'/REST',function(info) {
// info : {started:, nodes: { 'node-name': {}...}}
var data = info['nodes'];
var filtered = []; // [{name: 'aa-bb-cc', desc:, started:, nodelVersion:, webSocketPort: }...]
if (!_.isUndefined(data)) {
Object.keys(data).forEach(function (key) {
if (_.isUndefined(fltstr)) {
filtered.push(data[key]);
} else {
if (key.toLowerCase().indexOf(fltstr.toLowerCase()) > -1) {
filtered.push(data[key]);
}
}
});
for (var i=0; i<filtered.length; i++) {
filtered[i].host = localhost;
filtered[i].node = getSimpleName(filtered[i].name);
filtered[i].address = '/nodes/' + encodeURIComponent(getVerySimpleName(filtered[i].name)) + '/nodel.xml';
if(_.isUndefined(localsList['hosts'][encodr(localhost)])) {
var hosts = updateHost(filtered[i].host, localsList);
hosts[localhost].icon = generateHostIcon(host); // makes it identical to the current host's one
hosts[localhost].checked = true; // always true
hosts[localhost].reachable = true; // always true
$.observable(localsList).setProperty('hosts', hosts);
}
}
}
$.observable(localsList['lst']).refresh(filtered);
lastLocalNodes = info['nodes'];
applyLocalsFilter();
}).always(function(){
d.resolve();
});
return d.promise();
}

var applyLocalsFilter = function(filterstr) {
if(!_.isUndefined(filterstr)) $.observable(localsList['flt'] = filterstr);
var fltstr = localsList['flt'];
var localhost = 'localhost';
var data = lastLocalNodes;
var filtered = []; // [{name: 'aa-bb-cc', desc:, started:, nodelVersion:, webSocketPort: }...]
if (!_.isUndefined(data)) {
Object.keys(data).forEach(function (key) {
if (_.isUndefined(fltstr)) {
filtered.push(data[key]);
} else {
if (key.toLowerCase().indexOf(fltstr.toLowerCase()) > -1) {
filtered.push(data[key]);
}
}
});
for (var i=0; i<filtered.length; i++) {
filtered[i].host = localhost;
filtered[i].node = getSimpleName(filtered[i].name);
filtered[i].address = '/nodes/' + encodeURIComponent(getVerySimpleName(filtered[i].name)) + '/nodel.xml';
if(_.isUndefined(localsList['hosts'][encodr(localhost)])) {
var hosts = updateHost(filtered[i].host, localsList);
hosts[localhost].icon = generateHostIcon(host); // makes it identical to the current host's one
hosts[localhost].checked = true; // always true
hosts[localhost].reachable = true; // always true
$.observable(localsList).setProperty('hosts', hosts);
}
}
}
$.observable(localsList['lst']).refresh(filtered);
};

var checkReachable = function(host){
var d = $.Deferred();
$.ajax({
Expand Down Expand Up @@ -1872,7 +1879,7 @@ var setEvents = function(){
var charCode = e.charCode || e.keyCode;
if((charCode !== 40) && (charCode !== 38) && (charCode !== 13) && (charCode !== 27)) {
var filterstr = $(this).val();
getLocalsList(filterstr);
applyLocalsFilter(filterstr);
};
});
$('body').on('click','.nodel-list .listmore', function(){
Expand Down
2 changes: 1 addition & 1 deletion nodel-webui-js/src/templates.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@
<xsl:text>addgrp_</xsl:text>
<xsl:value-of select="generate-id(.)"/>
</xsl:attribute>
<xsl:text>Add node</xsl:text>
<xsl:text>Add node here</xsl:text>
</button>
<ul class="dropdown-menu">
<xsl:attribute name="aria-labelledby">
Expand Down

0 comments on commit 8859e10

Please sign in to comment.