MCSM: отображение реального списка серверов
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
group = 'asys'
|
group = 'asys'
|
||||||
version = '0.8-SNAPSHOT'
|
version = '0.8.1-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'osgi'
|
apply plugin: 'osgi'
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class Activator implements BundleActivator, ServiceListener {
|
|||||||
|
|
||||||
Manager manager = new Manager();
|
Manager manager = new Manager();
|
||||||
|
|
||||||
module = new MCSM_WebModule();
|
module = new MCSM_WebModule(manager);
|
||||||
|
|
||||||
logger.debug("Get service: {}", Webinterface.class);
|
logger.debug("Get service: {}", Webinterface.class);
|
||||||
serviceTracker = new ServiceTracker<>(context, Webinterface.class, null);
|
serviceTracker = new ServiceTracker<>(context, Webinterface.class, null);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
package asys.mcsmanager;
|
package asys.mcsmanager;
|
||||||
|
|
||||||
import asys.webinterface.api.WebModule;
|
import asys.webinterface.api.WebModule;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.sun.net.httpserver.HttpExchange;
|
import com.sun.net.httpserver.HttpExchange;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -15,8 +17,15 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MCSM_WebModule extends WebModule {
|
public class MCSM_WebModule extends WebModule {
|
||||||
|
private static final Gson GSON = new Gson();
|
||||||
|
private Manager manager;
|
||||||
private final String MODULE_NAME = "mcsmanager";
|
private final String MODULE_NAME = "mcsmanager";
|
||||||
private final Pattern URL_PATTERN_JS = Pattern.compile("/"+MODULE_NAME+"/(\\w+)\\.js");
|
private final String MODULE_URL = "/"+MODULE_NAME;
|
||||||
|
private final Pattern URL_PATTERN_JS = Pattern.compile(MODULE_URL+"/(\\w+)\\.js");
|
||||||
|
|
||||||
|
MCSM_WebModule(Manager manager) {
|
||||||
|
this.manager = manager;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -38,18 +47,31 @@ public class MCSM_WebModule extends WebModule {
|
|||||||
@Override
|
@Override
|
||||||
public boolean handle(HttpExchange httpExchange) throws IOException {
|
public boolean handle(HttpExchange httpExchange) throws IOException {
|
||||||
String urlPath = httpExchange.getRequestURI().getPath();
|
String urlPath = httpExchange.getRequestURI().getPath();
|
||||||
Matcher matcher = URL_PATTERN_JS.matcher(urlPath);
|
if (urlPath.equals(MODULE_URL+"/servers.json")) {
|
||||||
if (matcher.find()) {
|
return handleServersJson(httpExchange);
|
||||||
InputStream stream = getClass().getResourceAsStream("/"+matcher.group(1)+".js");
|
} else {
|
||||||
if (stream == null) {
|
Matcher matcher = URL_PATTERN_JS.matcher(urlPath);
|
||||||
this.sendHttpCode(httpExchange, 404, "not found");
|
if (matcher.find()) {
|
||||||
|
InputStream stream = getClass().getResourceAsStream("/" + matcher.group(1) + ".js");
|
||||||
|
if (stream == null) {
|
||||||
|
this.sendHttpCode(httpExchange, 404, "not found");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
httpExchange.getResponseHeaders().add("Content-Type", "text/javascript;charset=utf-8");
|
||||||
|
this.sendContent(httpExchange, 0, stream);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
httpExchange.getResponseHeaders().add("Content-Type", "text/javascript;charset=utf-8");
|
|
||||||
this.sendContent(httpExchange, 0, stream);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean handleServersJson(HttpExchange httpExchange) throws IOException {
|
||||||
|
this.sendJson(httpExchange, serverList());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonElement serverList() {
|
||||||
|
return GSON.toJsonTree(manager.getServerList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,21 +55,13 @@ var NvLineChart = React.createClass({
|
|||||||
|
|
||||||
var ServerListItem = React.createClass({
|
var ServerListItem = React.createClass({
|
||||||
render: function(){
|
render: function(){
|
||||||
var status;
|
|
||||||
if (this.props.stopped) {
|
|
||||||
status = ce('span', {className: 'label label-danger'}, 'остановлен');
|
|
||||||
} else {
|
|
||||||
status = ce('span', {className: 'label label-primary'}, this.props.players);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(
|
return(
|
||||||
ce('a', {className: 'list-group-item clearfix' + (this.props.active ? ' active' : ''), href: '#'},
|
ce('a', {className: 'list-group-item clearfix' + (this.props.active ? ' active' : ''), href: '#'},
|
||||||
ce('span', {style: {'padding-top': '15px'}},
|
ce('span', {style: {'padding-top': '15px'}},
|
||||||
ce('span', {className: 'glyphicon glyphicon-tasks'}),
|
ce('span', {className: 'glyphicon glyphicon-tasks'}),
|
||||||
nbsp,
|
nbsp,
|
||||||
this.props.title
|
this.props.title
|
||||||
),
|
)
|
||||||
ce('span', {className: 'pull-right'}, status)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -77,12 +69,6 @@ var ServerListItem = React.createClass({
|
|||||||
|
|
||||||
var ServerList = React.createClass({
|
var ServerList = React.createClass({
|
||||||
render: function(){return(
|
render: function(){return(
|
||||||
ce('div', {className: 'list-group'},
|
ce('div', {className: 'list-group'}, this.props.children)
|
||||||
ce(ServerListItem, {title: 'Server 1 [hub-1]', players: 42}),
|
|
||||||
ce(ServerListItem, {title: 'Server 2 [skywars-1]', players: 6, active: true}),
|
|
||||||
ce(ServerListItem, {title: 'Server 3 [bedwars-3]', players: 23}),
|
|
||||||
ce(ServerListItem, {title: 'Server 4', stopped: true}),
|
|
||||||
ce(ServerListItem, {title: 'Server 5', stopped: true})
|
|
||||||
)
|
|
||||||
)}
|
)}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,8 +14,22 @@ var ContentModule = React.createClass({
|
|||||||
style.onerror = fnError;
|
style.onerror = fnError;
|
||||||
document.body.appendChild(style);
|
document.body.appendChild(style);
|
||||||
},
|
},
|
||||||
|
requestServerList: function() {
|
||||||
|
var _this = this;
|
||||||
|
fetch('/mcsmanager/servers.json')
|
||||||
|
.then(function(response) {
|
||||||
|
response.json().then(function(data) {
|
||||||
|
console.debug(data);
|
||||||
|
_this.setState({serverList: data})
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(err){
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
getInitialState: function(){return{
|
getInitialState: function(){return{
|
||||||
nvScriptReady: 0
|
nvScriptReady: 0,
|
||||||
|
serverList: []
|
||||||
}},
|
}},
|
||||||
componentWillMount: function(){
|
componentWillMount: function(){
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@@ -36,12 +50,19 @@ var ContentModule = React.createClass({
|
|||||||
},
|
},
|
||||||
function(){ _this.setState({nvScriptReady: -5}); console.error('d3 - error'); }
|
function(){ _this.setState({nvScriptReady: -5}); console.error('d3 - error'); }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.requestServerList();
|
||||||
},
|
},
|
||||||
render: function(){
|
render: function(){
|
||||||
var element;
|
var element;
|
||||||
if (this.state.nvScriptReady === 3) {
|
if (this.state.nvScriptReady === 3) {
|
||||||
|
var serverListItems = [];
|
||||||
|
this.state.serverList.forEach(function(item){
|
||||||
|
serverListItems.push(ce(ServerListItem, {title: item}));
|
||||||
|
});
|
||||||
|
|
||||||
element = ce('div', {className: 'row'},
|
element = ce('div', {className: 'row'},
|
||||||
ce('div', {className: 'col-md-4'}, ce(ServerList)),
|
ce('div', {className: 'col-md-4'}, ce(ServerList, null, serverListItems)),
|
||||||
ce('div', {className: 'col-md-8'},
|
ce('div', {className: 'col-md-8'},
|
||||||
ce('div', {className: 'pull-right'},
|
ce('div', {className: 'pull-right'},
|
||||||
ce('div', {className: 'btn-group'},
|
ce('div', {className: 'btn-group'},
|
||||||
|
|||||||
Reference in New Issue
Block a user