From 8e1d0af68fae2fa9009884103ab5b7159a106da7 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Tue, 2 May 2017 21:07:51 +0300 Subject: [PATCH] =?UTF-8?q?MCSM:=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D0=B2=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D1=84=D0=B5=D0=B9=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mcserver-manager/build.gradle | 2 +- .../src/main/resources/components.js | 18 +++++------------- mcserver-manager/src/main/resources/module.js | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/mcserver-manager/build.gradle b/mcserver-manager/build.gradle index cfdfed1..71f61fc 100644 --- a/mcserver-manager/build.gradle +++ b/mcserver-manager/build.gradle @@ -1,5 +1,5 @@ group = 'asys' -version = '0.8.3-SNAPSHOT' +version = '0.8.4-SNAPSHOT' apply plugin: 'osgi' diff --git a/mcserver-manager/src/main/resources/components.js b/mcserver-manager/src/main/resources/components.js index 252ad1c..3b25067 100644 --- a/mcserver-manager/src/main/resources/components.js +++ b/mcserver-manager/src/main/resources/components.js @@ -54,6 +54,9 @@ var NvLineChart = React.createClass({ }); var ServerInfo = React.createClass({ + getInitialState: function(){return { + title: this.props.title + }}, render: function(){return( ce('div', null, ce('div', {className: 'pull-right'}, @@ -64,28 +67,17 @@ var ServerInfo = React.createClass({ ce('span', {className: 'glyphicon glyphicon-stop'}), nbsp+'остановка') ) ), - ce('h2', {style: {'margin-top': '0px'}}, this.props.title), + ce('h2', {style: {'margin-top': '0px'}}, this.state.title), this.props.children ) )} }); var ServerListItem = React.createClass({ - requestServerInfo: function() { - fetch('/mcsmanager/servers.json?clientid='+this.props.title) - .then(function(response){ - response.json().then(function(data){ - console.debug(data); - }); - }) - .catch(function(err){ - console.error(err); - }); - }, render: function(){ return( ce('a', {className: 'list-group-item clearfix' + (this.props.active ? ' active' : ''), href: '#', - onClick: this.requestServerInfo}, + onClick: this.props.onClick}, ce('span', {style: {'padding-top': '15px'}}, ce('span', {className: 'glyphicon glyphicon-tasks'}), nbsp, diff --git a/mcserver-manager/src/main/resources/module.js b/mcserver-manager/src/main/resources/module.js index 1a9eb15..b455fad 100644 --- a/mcserver-manager/src/main/resources/module.js +++ b/mcserver-manager/src/main/resources/module.js @@ -27,6 +27,19 @@ var ContentModule = React.createClass({ console.error(err); }); }, + clickServerListItem: function(title) { + var _this = this; + fetch('/mcsmanager/servers.json?clientid='+title) + .then(function(response){ + response.json().then(function(data){ + console.debug(data); + _this.refs.serverInfo.setState({ title: data.name }); + }); + }) + .catch(function(err){ + console.error(err); + }); + }, getInitialState: function(){return{ nvScriptReady: 0, serverList: [] @@ -56,14 +69,15 @@ var ContentModule = React.createClass({ render: function(){ var element; if (this.state.nvScriptReady === 3) { + var _this = this; var serverListItems = []; this.state.serverList.forEach(function(item){ - serverListItems.push(ce(ServerListItem, {title: item})); + serverListItems.push(ce(ServerListItem, {title: item, onClick: _this.clickServerListItem.bind(_this, item)})); }); element = ce('div', {className: 'row'}, ce('div', {className: 'col-md-4'}, ce(ServerList, null, serverListItems)), - ce('div', {className: 'col-md-8'}, ce(ServerInfo, {title: 'Server 2 [skywars-1]'}, ce(NvLineChart))) + ce('div', {className: 'col-md-8'}, ce(ServerInfo, {title: 'Server 2 [skywars-1]', ref: "serverInfo"}, ce(NvLineChart))) ); } else if (this.state.nvScriptReady < 0) { element = ce('span', null, 'error');