Skip to content

Commit

Permalink
Use /REST
Browse files Browse the repository at this point in the history
and add a new page for Locals
  • Loading branch information
morimoriysmoon authored and scroix committed Apr 1, 2024
1 parent f6a70fb commit dae1832
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 40 deletions.
14 changes: 0 additions & 14 deletions nodel-jyhost/src/main/java/org/nodel/jyhost/NodelHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -642,20 +642,6 @@ public List<NodeURL> getNodeURLsForNode(SimpleName name) throws IOException {
return Nodel.getNodeURLsForNode(name);
}

public List<Map<String, String>> getLocalNodes(String filter) {
String lcFilter = Strings.isNullOrEmpty(filter) ? null : filter.toLowerCase();
List<Map<String, String>> list = new ArrayList<>();
for (SimpleName sn : BaseNode.getNodes().keySet()) {
if (Strings.isNullOrEmpty(lcFilter) || sn.getOriginalName().toLowerCase().contains(lcFilter)) {
Map<String, String> item = new HashMap<>();
item.put("name", sn.getOriginalName());
item.put("node", sn.getReducedName());
list.add(item);
}
}
return list;
}

/**
* Permanently shuts down this nodel host
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ public BaseNode get(Object key) {
public Map<SimpleName, BaseNode> getNodes() {
return BaseNode.getNodes();
}

@Service(name = "locals", order = 1.5, title = "Locals", desc = "All the managed local nodes.")
public List<Map<String, String>> getLocalNodes(@Param(name = "filter", title = "Filter", desc = "Optional string filter.") String filter) {
return _nodelHost.getLocalNodes(filter);
}

@Service(name = "recipes", order = 1, title = "Recipes", desc = "Recipes that new nodes can be based on", genericClassA = String.class)
public RecipesEndPoint recipes() {
Expand Down
4 changes: 4 additions & 0 deletions nodel-webui-js/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ module.exports = function(grunt) {
src: 'src/nodes.xml',
dest: 'build/grunt/nodes.xml'
},
{
src: 'src/locals.xml',
dest: 'build/grunt/locals.xml'
},
{
src: 'src/toolkit.xml',
dest: 'build/grunt/toolkit.xml'
Expand Down
15 changes: 15 additions & 0 deletions nodel-webui-js/src/locals.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="v1/index.xsl"?>
<pages core="true" theme="default" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="index.xsd">
<header destination="diagnostics.xml">
<nodel type="hosticon"/>
</header>
<page title='Locals'>
<row>
<column>
<nodel type="add"/>
<nodel type="locals"/>
</column>
</row>
</page>
</pages>
41 changes: 28 additions & 13 deletions nodel-webui-js/src/nodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,23 +844,38 @@ var getNodeList = function(filterstr){

var getLocalsList = function(filterstr){
if(!_.isUndefined(filterstr)) $.observable(localsList['flt'] = filterstr);
filter = {'filter': localsList['flt']};
var fltstr = localsList['flt'];
var d = $.Deferred();
if(localsListreq) localsListreq.abort();
var localhost = 'localhost';
localsListreq = $.postJSON(proto+'//'+host+'/REST/locals', JSON.stringify(filter), function(data) {
for (i=0; i<data.length; i++) {
data[i].host = localhost;
data[i].address = '/nodes/' + encodeURIComponent(data[i].node) + '/nodel.xml';
if(_.isUndefined(localsList['hosts'][encodr(localhost)])) {
var hosts = updateHost(data[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);
}
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(data);
$.observable(localsList['lst']).refresh(filtered);
}).always(function(){
d.resolve();
});
Expand Down
8 changes: 0 additions & 8 deletions nodel-webui-js/src/nodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@
<page title='List'>
<row>
<column>
<nodel type="add"/>
<nodel type="list"/>
</column>
</row>
</page>
<page title='Locals'>
<row>
<column>
<nodel type="locals"/>
</column>
</row>
</page>
</pages>

0 comments on commit dae1832

Please sign in to comment.