From 59331f9b1cd99fbd22a224ad71f40fd93a9fdfb3 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 10 Apr 2017 15:40:40 +0800 Subject: [PATCH] add locStatus with location --- public/js/admin_bundle.js | 210 ++++++++++++++++++ route/api/wristband.js | 21 +- .../AdminPage/Wristband/LocStatus/ListItem.js | 1 + .../AdminPage/Wristband/LocStatus/index.js | 6 + .../Wristband/LocStatusWloc/index.js | 93 ++++++++ src/components/AdminPage/Wristband/index.js | 6 + .../AdminPage/Wristband/LocStatusWloc.js | 19 ++ 7 files changed, 346 insertions(+), 10 deletions(-) create mode 100644 src/components/AdminPage/Wristband/LocStatusWloc/index.js create mode 100644 src/containers/AdminPage/Wristband/LocStatusWloc.js diff --git a/public/js/admin_bundle.js b/public/js/admin_bundle.js index adad645..375a074 100644 --- a/public/js/admin_bundle.js +++ b/public/js/admin_bundle.js @@ -87816,6 +87816,11 @@ var ListItem = function ListItem(_ref) { null, data.wristband ), + _react2.default.createElement( + _semanticUiReact.Table.Cell, + null, + data.name + ), _react2.default.createElement( _semanticUiReact.Table.Cell, null, @@ -88022,6 +88027,14 @@ var LocStatus = function (_React$Component) { '\u624B\u74B0ID', this.renderSortIcon('mac') ), + _react2.default.createElement( + _semanticUiReact.Table.HeaderCell, + { className: 'pointer', onClick: function onClick() { + _this2.handlerSort('name'); + } }, + '\u624B\u74B0\u540D\u7A31', + this.renderSortIcon('name') + ), _react2.default.createElement( _semanticUiReact.Table.HeaderCell, { className: 'pointer', onClick: function onClick() { @@ -88895,6 +88908,10 @@ var _Location = __webpack_require__(1110); var _Location2 = _interopRequireDefault(_Location); +var _LocStatusWloc = __webpack_require__(1149); + +var _LocStatusWloc2 = _interopRequireDefault(_LocStatusWloc); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } @@ -88929,6 +88946,8 @@ var WristbandPage = function (_React$Component) { switch (_this.state.page) { case 'locstatus': return _react2.default.createElement(_LocStatus2.default, null); + case 'locstatus_wloc': + return _react2.default.createElement(_LocStatusWloc2.default, null); case 'wristband': return _react2.default.createElement(_WristbandInfo2.default, null); case 'location': @@ -88989,6 +89008,13 @@ var WristbandPage = function (_React$Component) { _this2.changePage('locstatus'); } }, '\u4F4D\u7F6E\u8CC7\u8A0A' + ), + _react2.default.createElement( + _semanticUiReact.Menu.Item, + { active: this.state.page == 'locstatus_wloc', onClick: function onClick() { + _this2.changePage('locstatus_wloc'); + } }, + '\u4F4D\u7F6E\u8CC7\u8A0A - \u5730\u9EDE\u5206\u985E' ) ) ) @@ -93716,5 +93742,189 @@ var PageRoot = function (_React$Component) { _reactDom2.default.render(_react2.default.createElement(PageRoot, null), document.getElementById('app')); +/***/ }), +/* 1147 */, +/* 1148 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _react = __webpack_require__(0); + +var _react2 = _interopRequireDefault(_react); + +var _semanticUiReact = __webpack_require__(8); + +var _actions = __webpack_require__(20); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var LocStatusWloc = function (_React$Component) { + _inherits(LocStatusWloc, _React$Component); + + function LocStatusWloc() { + var _ref; + + var _temp, _this, _ret; + + _classCallCheck(this, LocStatusWloc); + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = LocStatusWloc.__proto__ || Object.getPrototypeOf(LocStatusWloc)).call.apply(_ref, [this].concat(args))), _this), _this.state = { + loc: [] + }, _this.getLocList = function () { + var _this$props = _this.props, + toggleLoading = _this$props.toggleLoading, + showDialog = _this$props.showDialog; + + toggleLoading(1); + fetch('/api/wristband/getlocationlist', (0, _actions.getRequest)()).then(function (response) { + return response.json(); + }).then(function (json) { + toggleLoading(0); + if (json.status != 1) return showDialog(json.message); + _this.setState({ + loc: json.data.record || [] + }, function () { + _this.getStatus(); + }); + }); + }, _this.getStatus = function () { + var _this$props2 = _this.props, + toggleLoading = _this$props2.toggleLoading, + showDialog = _this$props2.showDialog; + + fetch('/api/wristband/getstatus', (0, _actions.getRequest)()).then(function (response) { + return response.json(); + }).then(function (json) { + if (json.status != 1) return showDialog(json.message); + var record = json.data.record || []; + var locs = _this.state.loc; + for (var i in locs) { + locs[i].list = []; + } + for (var _i in record) { + var tmp = record[_i]; + if (!tmp.locid) continue; + for (var j in locs) { + if (locs[j].serialnumber == tmp.locid) { + locs[j].list.push(tmp); + } + } + } + + _this.setState({ + loc: locs + }); + }); + }, _temp), _possibleConstructorReturn(_this, _ret); + } + + _createClass(LocStatusWloc, [{ + key: 'componentDidMount', + value: function componentDidMount() { + this.getLocList(); + } + }, { + key: 'render', + value: function render() { + + return _react2.default.createElement( + _semanticUiReact.Container, + { fluid: true }, + _react2.default.createElement( + _semanticUiReact.Grid, + { columns: 3 }, + this.state.loc.map(function (t, idx) { + return _react2.default.createElement( + _semanticUiReact.Grid.Column, + { key: idx, className: 'clearfix' }, + _react2.default.createElement(_semanticUiReact.Header, { as: 'h5', content: t.name }), + _react2.default.createElement( + _semanticUiReact.Segment, + { style: { height: '400px', overflow: 'auto' } }, + _react2.default.createElement( + _semanticUiReact.List, + null, + t.list ? t.list.map(function (tt, idx) { + return _react2.default.createElement( + _semanticUiReact.List.Item, + { key: idx }, + tt.name ? _react2.default.createElement(_semanticUiReact.Label, { basic: true, color: 'blue', size: 'tiny', content: tt.name }) : null, + _react2.default.createElement(_semanticUiReact.Label, { basic: true, color: 'teal', size: 'tiny', content: tt.mac }) + ); + }) : null + ) + ) + ); + }) + ) + ); + } + }]); + + return LocStatusWloc; +}(_react2.default.Component); + +exports.default = LocStatusWloc; + +/***/ }), +/* 1149 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _reactRedux = __webpack_require__(24); + +var _actions = __webpack_require__(20); + +var _LocStatusWloc = __webpack_require__(1148); + +var _LocStatusWloc2 = _interopRequireDefault(_LocStatusWloc); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var mapStateToProps = function mapStateToProps(state) { + return { + i18n: state.i18n + }; +}; + +var mapDispatchToProps = function mapDispatchToProps(dispatch, ownProps) { + return { + showDialog: function showDialog(msg) { + dispatch((0, _actions.add_dialog_msg)(msg)); + }, + toggleLoading: function toggleLoading() { + var flag = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + dispatch((0, _actions.toggle_loading)(flag)); + } + }; +}; + +exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_LocStatusWloc2.default); + /***/ }) /******/ ]); \ No newline at end of file diff --git a/route/api/wristband.js b/route/api/wristband.js index 2b0fdc4..60bd981 100644 --- a/route/api/wristband.js +++ b/route/api/wristband.js @@ -128,26 +128,25 @@ router .post('/getstatus', (req, res, n) => { if (!config.permission.wristband) return n('ERR9000'); - let query = "select w.`name`, w.`mac` as wristband, coalesce(l.`name`, l2.`name`) as locname, ll.*\ + let query = "select w.`name`, w.`mac` as wristband, \ + coalesce(l.`name`, l2.`name`) as locname, \ + coalesce(case when tmp2.`wlocrtloc` = 'NG' then null else tmp2.`wlocrtloc` end, ll.`devid`) as locid, \ + ll.*\ from ??.?? w\ - left join ( \ - select * from ( \ - select * from ??.?? \ - where `timestamp` > unix_timestamp() - 30 order by conv(`val11`, 16, 10) desc limit 65535000\ - ) tmp group by `mac` \ - ) tmp2 \ - on tmp2.`mac` = w.`mac` \ + left join ??.?? tmp2 \ + on tmp2.`wlocrtmac` = w.`mac` \ left join ??.?? ll \ on ll.`mac` = w.`mac` \ left join ??.?? l \ on \ - l.`serialnumber` = tmp2.`devid` \ + l.`serialnumber` = tmp2.`wlocrtloc` \ + and tmp2.`wlocrtloc` != 'NG' \ left join ??.?? l2\ on \ l2.`serialnumber` = ll.`devid` \ where \ w.`switch` = 1 "; - let param = [config.db.db9, 'wristband', config.db.db9, 'rawdata', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location', ]; + let param = [config.db.db9, 'wristband', config.db.db9, 'wlocationrt', config.db.db9, 'lastdata', config.db.db9, 'location', config.db.db9, 'location', ]; let sortfield = ''; let sortorder = ''; @@ -177,6 +176,8 @@ router case 'time': query += 'order by ll.`timestamp` ' + sortorder; break; + case 'name': + query += `order by w.name ${sortorder}`; default: query += 'order by w.`uid`'; break; diff --git a/src/components/AdminPage/Wristband/LocStatus/ListItem.js b/src/components/AdminPage/Wristband/LocStatus/ListItem.js index f16eca0..65b8b00 100644 --- a/src/components/AdminPage/Wristband/LocStatus/ListItem.js +++ b/src/components/AdminPage/Wristband/LocStatus/ListItem.js @@ -7,6 +7,7 @@ const ListItem = ({i18n, data}) => { return ( {data.wristband} + {data.name} {data.locname} {data.val3 ? parseInt(data.val3, 16) : ''} {data.val4 ? `${parseInt(data.val4, 16)}%` : ''} diff --git a/src/components/AdminPage/Wristband/LocStatus/index.js b/src/components/AdminPage/Wristband/LocStatus/index.js index e204b82..b7a01d1 100644 --- a/src/components/AdminPage/Wristband/LocStatus/index.js +++ b/src/components/AdminPage/Wristband/LocStatus/index.js @@ -102,6 +102,12 @@ class LocStatus extends React.Component{ this.renderSortIcon('mac') } + { this.handlerSort('name') }}> + 手環名稱 + { + this.renderSortIcon('name') + } + {this.handlerSort('loc')}}> 地點 {this.renderSortIcon('loc')} diff --git a/src/components/AdminPage/Wristband/LocStatusWloc/index.js b/src/components/AdminPage/Wristband/LocStatusWloc/index.js new file mode 100644 index 0000000..480f05b --- /dev/null +++ b/src/components/AdminPage/Wristband/LocStatusWloc/index.js @@ -0,0 +1,93 @@ +import React from 'react'; +import {Grid, Header, Container, Segment, List, Label} from 'semantic-ui-react'; +import {getRequest} from '../../../../actions'; + +class LocStatusWloc extends React.Component { + state = { + loc: [] + } + + componentDidMount() { + this.getLocList(); + } + + getLocList = ()=>{ + let {toggleLoading, showDialog} = this.props; + toggleLoading(1); + fetch('/api/wristband/getlocationlist', getRequest()) + .then(response=>response.json()) + .then(json=>{ + toggleLoading(0); + if(json.status != 1) return showDialog(json.message); + this.setState({ + loc: json.data.record || [] + }, ()=>{ + this.getStatus(); + }) + }) + } + + getStatus = () => { + let {toggleLoading, showDialog} = this.props; + fetch('/api/wristband/getstatus', getRequest()) + .then(response=>response.json()) + .then(json => { + if(json.status != 1) return showDialog(json.message); + let record = json.data.record || []; + let locs = this.state.loc; + for(let i in locs){ + locs[i].list = []; + } + for(let i in record) { + let tmp = record[i]; + if(!tmp.locid) continue; + for(let j in locs) { + if(locs[j].serialnumber == tmp.locid) { + locs[j].list.push(tmp); + } + } + } + + this.setState({ + loc: locs + }) + }) + } + + render() { + + return ( + + + { + this.state.loc.map((t,idx) => ( + +
+ + + { + t.list ? + t.list.map((tt, idx) => ( + + { + tt.name ? ( + + )) + : null + } + + + + )) + } + + + ) + } +} + +export default LocStatusWloc; \ No newline at end of file diff --git a/src/components/AdminPage/Wristband/index.js b/src/components/AdminPage/Wristband/index.js index c1b155f..5b9c4ed 100644 --- a/src/components/AdminPage/Wristband/index.js +++ b/src/components/AdminPage/Wristband/index.js @@ -3,6 +3,7 @@ import {Grid, Container, Segment, Menu, List} from 'semantic-ui-react'; import LocStatus from '../../../containers/AdminPage/Wristband/LocStatus'; import WristbandInfo from '../../../containers/AdminPage/Wristband/WristbandInfo'; import Location from '../../../containers/AdminPage/Wristband/Location'; +import LocStatusWloc from '../../../containers/AdminPage/Wristband/LocStatusWloc'; class WristbandPage extends React.Component{ state = { @@ -20,6 +21,8 @@ class WristbandPage extends React.Component{ switch(this.state.page) { case 'locstatus': return ; + case 'locstatus_wloc': + return ; case 'wristband': return ; case 'location': @@ -48,6 +51,9 @@ class WristbandPage extends React.Component{ { this.changePage('locstatus'); }}> 位置資訊 + { this.changePage('locstatus_wloc'); }}> + 位置資訊 - 地點分類 + diff --git a/src/containers/AdminPage/Wristband/LocStatusWloc.js b/src/containers/AdminPage/Wristband/LocStatusWloc.js new file mode 100644 index 0000000..dd4184b --- /dev/null +++ b/src/containers/AdminPage/Wristband/LocStatusWloc.js @@ -0,0 +1,19 @@ +import { connect } from 'react-redux'; +import { add_dialog_msg, toggle_loading } from '../../../actions'; +import LocStatusPage from '../../../components/AdminPage/Wristband/LocStatusWloc'; + + +const mapStateToProps = (state) => ({ + i18n: state.i18n +}); + +const mapDispatchToProps = (dispatch, ownProps) => ({ + showDialog: (msg) => { + dispatch(add_dialog_msg(msg)); + }, + toggleLoading: (flag = false) => { + dispatch(toggle_loading(flag)); + } +}) + +export default connect(mapStateToProps, mapDispatchToProps)(LocStatusPage); \ No newline at end of file