diff --git a/lib/webInterface.js b/lib/webInterface.js index e47112a..8b1c15b 100644 --- a/lib/webInterface.js +++ b/lib/webInterface.js @@ -38,7 +38,7 @@ function webInterface(config){ }); app.get("/lastestLog",function(req,res){ - recorder.getRecords(null,60,function(err,docs){ + recorder.getRecords(null,120,function(err,docs){ if(err){ res.end(err.toString()); }else{ diff --git a/package.json b/package.json index d6e83bf..2c0f8af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anyproxy", - "version": "3.7.3Beta", + "version": "3.7.3Beta2", "description": "A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.", "main": "proxy.js", "bin": { diff --git a/web/build/index.js b/web/build/index.js index f11a0e6..946fae9 100644 --- a/web/build/index.js +++ b/web/build/index.js @@ -154,11 +154,6 @@ var recorder; //action bar (function(){ - //detect whether to show the filter and map btn - $.get("/filetree",function(){ - $(".J_filterSection").show(); - }); - //clear log function clearLogs(){ recordSet = []; @@ -194,22 +189,66 @@ var recorder; } }); - //filter + //preset button (function (){ + var TopBtn = React.createClass({displayName: "TopBtn", + getInitialState: function(){ + return { + inUse : false + }; + }, + render: function(){ + var self = this, + iconClass = self.state.inUse ? "uk-icon-check" : self.props.icon, + btnClass = self.state.inUse ? "topBtn topBtnInUse" : "topBtn"; + + return React.createElement("a", {href: "#"}, React.createElement("span", {className: btnClass, onClick: self.props.onClick}, React.createElement("i", {className: iconClass}), self.props.title)) + } + }); + + // filter + var filterBtn, + FilterPanel = PopupContent["filter"], + filterPanelEl; + + filterBtn = React.render(React.createElement(TopBtn, {icon: "uk-icon-filter", title: "Filter", onClick: filterBtnClick}), document.getElementById("J_filterBtnContainer")); + filterPanelEl = (React.createElement(FilterPanel, {onChangeKeyword: updateKeyword}) ); + function updateKeyword(key){ eventCenter.dispatchEvent("filterUpdated",key); + filterBtn.setState({inUse : !!key}); + } + function filterBtnClick(){ + showPop({ left:"60%", content:filterPanelEl }); } - $(".J_showFilter").on("click",function(){ - showPop({ left:"60%", content:React.createElement(PopupContent["filter"], {onChangeKeyword : updateKeyword})}); - }); - })(); + // map local + var mapBtn, + mapPanelEl; + function onChangeMapConfig(cfg){ + mapBtn.setState({inUse : cfg && cfg.length}); + } - //map local - (function(){ - $(".J_showMapPanel").on("click",function(){ - showPop({left:"60%", content:React.createElement(PopupContent["map"],null)}); + function mapBtnClick(){ + showPop({left:"60%", content:mapPanelEl }); + } + + //detect whether to show the map btn + require("./mapPanel").fetchConfig(function(initConfig){ + var MapPanel = PopupContent["map"]; + mapBtn = React.render(React.createElement(TopBtn, {icon: "uk-icon-shield", title: "Map Local", onClick: mapBtnClick}),document.getElementById("J_filterContainer")); + mapPanelEl = (React.createElement(MapPanel, {onChange: onChangeMapConfig})); + onChangeMapConfig(initConfig); }); + + var t = true; + setInterval(function(){ + t = !t; + // mapBtn && mapBtn.setState({inUse : t}) + },300); + + + })(); //other button diff --git a/web/build/mapList.js b/web/build/mapList.js index 3a9979a..cf7f949 100644 --- a/web/build/mapList.js +++ b/web/build/mapList.js @@ -1,3 +1,7 @@ +function fetchConfig(cb){ + return $.getJSON("/getMapConfig",cb); +} + function init(React){ var MapList = React.createClass({displayName: "MapList", getInitialState:function(){ @@ -19,7 +23,6 @@ function init(React){ ruleList: newState }); } - }, removeRecord:function(index){ @@ -52,7 +55,7 @@ function init(React){ }, componentDidMount :function(){ var self = this; - $.getJSON("/getMapConfig",function(data){ + fetchConfig(function(data){ self.setState({ ruleList : data }); @@ -60,8 +63,8 @@ function init(React){ }, componentDidUpdate:function(){ var self = this; - //sync config + //upload config to server var currentList = self.state.ruleList; $.ajax({ method : "POST", @@ -71,10 +74,13 @@ function init(React){ dataType : "json", success :function(res){} }); + + self.props.onChange && self.props.onChange(self.state.ruleList); } }); return MapList; } -module.exports.init = init; \ No newline at end of file +module.exports.init = init; +module.exports.fetchConfig = fetchConfig; \ No newline at end of file diff --git a/web/build/mapPanel.js b/web/build/mapPanel.js index 00b82af..63c6efd 100644 --- a/web/build/mapPanel.js +++ b/web/build/mapPanel.js @@ -17,7 +17,7 @@ function init(React){ return ( React.createElement("div", {className: "mapWrapper"}, React.createElement("h4", {className: "subTitle"}, "Current Config"), - React.createElement(MapList, {ref: "list"}), + React.createElement(MapList, {ref: "list", onChange: self.props.onChange}), React.createElement("h4", {className: "subTitle"}, "Add Map Rule"), React.createElement(MapForm, {onSubmit: self.appendRecord}) @@ -29,4 +29,5 @@ function init(React){ return MapPanel; } -module.exports.init = init; \ No newline at end of file +module.exports.init = init; +module.exports.fetchConfig = require("./mapList").fetchConfig; \ No newline at end of file diff --git a/web/css/page.css b/web/css/page.css index e0fb48a..1e2024b 100644 --- a/web/css/page.css +++ b/web/css/page.css @@ -7,7 +7,7 @@ body, html { } .topHead{ - height: 55px; + height: 53px; position: relative; border-bottom: 1px solid #333; } @@ -15,14 +15,14 @@ body, html { .topHead .logoWrapper{ float: left; width: 220px; - height: 55px; + height: 53px; overflow: hidden; position: relative; } .topHead .logoWrapper h1{ color: #333; - line-height: 55px; + line-height: 53px; text-align: center; margin: 0; } @@ -63,10 +63,11 @@ body, html { .topHead .ctrlWrapper{ height : 26px; - line-height : 26px; + line-height : 16px; overflow : hidden; text-overflow : ellipsis; white-space : nowrap; + margin-top : 1px; } .topHead .ctrlWrapper .sep{ @@ -76,10 +77,16 @@ body, html { } .topHead .topBtn{ - margin-right: 8px; + margin-right: 4px; transition:0.08s; padding: 4px; border-radius: 2px; + min-width: 50px; + display: inline-block; +} + +.topHead .topBtn.topBtnInUse{ + color: #30B630; } .topHead .topBtn:hover:not(.btn_disable){ @@ -94,6 +101,7 @@ body, html { .topHead i{ margin-right: 3px; + width: 12px; } .topHead .btn_disable{ diff --git a/web/index.html b/web/index.html index 689e34b..47a284a 100644 --- a/web/index.html +++ b/web/index.html @@ -30,12 +30,9 @@
- Filter - + + + | {@if customMenu.length} {@each customMenu as item} diff --git a/web/page.js b/web/page.js index 9e7769c..8ffa185 100644 --- a/web/page.js +++ b/web/page.js @@ -200,11 +200,6 @@ //action bar (function(){ - //detect whether to show the filter and map btn - $.get("/filetree",function(){ - $(".J_filterSection").show(); - }); - //clear log function clearLogs(){ recordSet = []; @@ -240,22 +235,66 @@ } }); - //filter + //preset button (function (){ + var TopBtn = React.createClass({displayName: "TopBtn", + getInitialState: function(){ + return { + inUse : false + }; + }, + render: function(){ + var self = this, + iconClass = self.state.inUse ? "uk-icon-check" : self.props.icon, + btnClass = self.state.inUse ? "topBtn topBtnInUse" : "topBtn"; + + return React.createElement("a", {href: "#"}, React.createElement("span", {className: btnClass, onClick: self.props.onClick}, React.createElement("i", {className: iconClass}), self.props.title)) + } + }); + + // filter + var filterBtn, + FilterPanel = PopupContent["filter"], + filterPanelEl; + + filterBtn = React.render(React.createElement(TopBtn, {icon: "uk-icon-filter", title: "Filter", onClick: filterBtnClick}), document.getElementById("J_filterBtnContainer")); + filterPanelEl = (React.createElement(FilterPanel, {onChangeKeyword: updateKeyword}) ); + function updateKeyword(key){ eventCenter.dispatchEvent("filterUpdated",key); + filterBtn.setState({inUse : !!key}); + } + function filterBtnClick(){ + showPop({ left:"60%", content:filterPanelEl }); } - $(".J_showFilter").on("click",function(){ - showPop({ left:"60%", content:React.createElement(PopupContent["filter"], {onChangeKeyword : updateKeyword})}); - }); - })(); + // map local + var mapBtn, + mapPanelEl; + function onChangeMapConfig(cfg){ + mapBtn.setState({inUse : cfg && cfg.length}); + } - //map local - (function(){ - $(".J_showMapPanel").on("click",function(){ - showPop({left:"60%", content:React.createElement(PopupContent["map"],null)}); + function mapBtnClick(){ + showPop({left:"60%", content:mapPanelEl }); + } + + //detect whether to show the map btn + __webpack_require__(1).fetchConfig(function(initConfig){ + var MapPanel = PopupContent["map"]; + mapBtn = React.render(React.createElement(TopBtn, {icon: "uk-icon-shield", title: "Map Local", onClick: mapBtnClick}),document.getElementById("J_filterContainer")); + mapPanelEl = (React.createElement(MapPanel, {onChange: onChangeMapConfig})); + onChangeMapConfig(initConfig); }); + + var t = true; + setInterval(function(){ + t = !t; + // mapBtn && mapBtn.setState({inUse : t}) + },300); + + + })(); //other button @@ -298,7 +337,7 @@ return ( React.createElement("div", {className: "mapWrapper"}, React.createElement("h4", {className: "subTitle"}, "Current Config"), - React.createElement(MapList, {ref: "list"}), + React.createElement(MapList, {ref: "list", onChange: self.props.onChange}), React.createElement("h4", {className: "subTitle"}, "Add Map Rule"), React.createElement(MapForm, {onSubmit: self.appendRecord}) @@ -311,6 +350,7 @@ } module.exports.init = init; + module.exports.fetchConfig = __webpack_require__(14).fetchConfig; /***/ }, /* 2 */ @@ -28057,6 +28097,10 @@ /* 14 */ /***/ function(module, exports, __webpack_require__) { + function fetchConfig(cb){ + return $.getJSON("/getMapConfig",cb); + } + function init(React){ var MapList = React.createClass({displayName: "MapList", getInitialState:function(){ @@ -28078,7 +28122,6 @@ ruleList: newState }); } - }, removeRecord:function(index){ @@ -28111,7 +28154,7 @@ }, componentDidMount :function(){ var self = this; - $.getJSON("/getMapConfig",function(data){ + fetchConfig(function(data){ self.setState({ ruleList : data }); @@ -28119,8 +28162,8 @@ }, componentDidUpdate:function(){ var self = this; - //sync config + //upload config to server var currentList = self.state.ruleList; $.ajax({ method : "POST", @@ -28130,6 +28173,8 @@ dataType : "json", success :function(res){} }); + + self.props.onChange && self.props.onChange(self.state.ruleList); } }); @@ -28137,6 +28182,7 @@ } module.exports.init = init; + module.exports.fetchConfig = fetchConfig; /***/ }, /* 15 */ diff --git a/web/src/index.js b/web/src/index.js index e9ee44a..f8d43fe 100644 --- a/web/src/index.js +++ b/web/src/index.js @@ -154,11 +154,6 @@ var recorder; //action bar (function(){ - //detect whether to show the filter and map btn - $.get("/filetree",function(){ - $(".J_filterSection").show(); - }); - //clear log function clearLogs(){ recordSet = []; @@ -194,22 +189,66 @@ var recorder; } }); - //filter + //preset button (function (){ + var TopBtn = React.createClass({ + getInitialState: function(){ + return { + inUse : false + }; + }, + render: function(){ + var self = this, + iconClass = self.state.inUse ? "uk-icon-check" : self.props.icon, + btnClass = self.state.inUse ? "topBtn topBtnInUse" : "topBtn"; + + return {self.props.title} + } + }); + + // filter + var filterBtn, + FilterPanel = PopupContent["filter"], + filterPanelEl; + + filterBtn = React.render(, document.getElementById("J_filterBtnContainer")); + filterPanelEl = ( ); + function updateKeyword(key){ eventCenter.dispatchEvent("filterUpdated",key); + filterBtn.setState({inUse : !!key}); + } + function filterBtnClick(){ + showPop({ left:"60%", content:filterPanelEl }); } - $(".J_showFilter").on("click",function(){ - showPop({ left:"60%", content:React.createElement(PopupContent["filter"], {onChangeKeyword : updateKeyword})}); - }); - })(); + // map local + var mapBtn, + mapPanelEl; + function onChangeMapConfig(cfg){ + mapBtn.setState({inUse : cfg && cfg.length}); + } - //map local - (function(){ - $(".J_showMapPanel").on("click",function(){ - showPop({left:"60%", content:React.createElement(PopupContent["map"],null)}); + function mapBtnClick(){ + showPop({left:"60%", content:mapPanelEl }); + } + + //detect whether to show the map btn + require("./mapPanel").fetchConfig(function(initConfig){ + var MapPanel = PopupContent["map"]; + mapBtn = React.render(,document.getElementById("J_filterContainer")); + mapPanelEl = (); + onChangeMapConfig(initConfig); }); + + var t = true; + setInterval(function(){ + t = !t; + // mapBtn && mapBtn.setState({inUse : t}) + },300); + + + })(); //other button diff --git a/web/src/mapList.js b/web/src/mapList.js index a3b85d9..39ce5a5 100644 --- a/web/src/mapList.js +++ b/web/src/mapList.js @@ -1,3 +1,7 @@ +function fetchConfig(cb){ + return $.getJSON("/getMapConfig",cb); +} + function init(React){ var MapList = React.createClass({ getInitialState:function(){ @@ -19,7 +23,6 @@ function init(React){ ruleList: newState }); } - }, removeRecord:function(index){ @@ -52,7 +55,7 @@ function init(React){ }, componentDidMount :function(){ var self = this; - $.getJSON("/getMapConfig",function(data){ + fetchConfig(function(data){ self.setState({ ruleList : data }); @@ -60,8 +63,8 @@ function init(React){ }, componentDidUpdate:function(){ var self = this; - //sync config + //upload config to server var currentList = self.state.ruleList; $.ajax({ method : "POST", @@ -71,10 +74,13 @@ function init(React){ dataType : "json", success :function(res){} }); + + self.props.onChange && self.props.onChange(self.state.ruleList); } }); return MapList; } -module.exports.init = init; \ No newline at end of file +module.exports.init = init; +module.exports.fetchConfig = fetchConfig; \ No newline at end of file diff --git a/web/src/mapPanel.js b/web/src/mapPanel.js index d367511..9864f7e 100644 --- a/web/src/mapPanel.js +++ b/web/src/mapPanel.js @@ -17,7 +17,7 @@ function init(React){ return (

Current Config

- +

Add Map Rule

@@ -29,4 +29,5 @@ function init(React){ return MapPanel; } -module.exports.init = init; \ No newline at end of file +module.exports.init = init; +module.exports.fetchConfig = require("./mapList").fetchConfig; \ No newline at end of file