add machine page
authorHongyuan Ma <CS_MaleicAcid@163.com>
Tue, 31 Jul 2018 15:45:06 +0000 (23:45 +0800)
committerHongyuan Ma <CS_MaleicAcid@163.com>
Tue, 31 Jul 2018 15:45:06 +0000 (23:45 +0800)
15 files changed:
front-end/src/app.jsx
front-end/src/component/farmer-card/index.css [new file with mode: 0644]
front-end/src/component/farmer-card/index.jsx
front-end/src/component/farmer-detail-card/index.css [new file with mode: 0644]
front-end/src/component/farmer-detail-card/index.jsx
front-end/src/component/history-records-pane1/index.jsx
front-end/src/component/nav-top/index.jsx
front-end/src/page/detailInfo/index.jsx
front-end/src/page/machine/index.css [new file with mode: 0644]
front-end/src/page/machine/index.jsx [new file with mode: 0644]
front-end/src/page/portal/index.jsx
front-end/src/service/machine-service.jsx [new file with mode: 0644]
front-end/src/util/machine-table/index.jsx
web/apps/user_operation/views.py
web/pgperffarm/urls.py

index 6606564be510f0719f86a3c16051c5d6fd2d009c..cf10cfccb6029252c33809323bcd40c0975569bd 100644 (file)
@@ -9,9 +9,10 @@ import Layout from 'component/layout/index.jsx'
 // page
 import Login from './page/login/index.jsx'
 import Home from './page/home/index.jsx'
-
 import Status from './page/status/index.jsx'
+import Machine from './page/machine/index.jsx'
 import PPolicy from './page/ppolicy/index.jsx'
+
 import DetailInfo from './page/detailInfo/index.jsx'
 import MachinelInfo from './page/machineInfo/index.jsx'
 
@@ -66,6 +67,7 @@ class App extends React.Component {
 
                     <Route exact path="/home/" component={Home}/>
                     <Route exact path="/status/" component={Status}/>
+                    <Route exact path="/machine/" component={Machine}/>
                     <Route exact path="/ppolicy/" component={PPolicy}/>
 
                     <Route exact path="/portal/" component={Portal}/>
diff --git a/front-end/src/component/farmer-card/index.css b/front-end/src/component/farmer-card/index.css
new file mode 100644 (file)
index 0000000..cd3a3a8
--- /dev/null
@@ -0,0 +1,5 @@
+.flex-box{
+    display: flex;
+    justify-content:center;
+    align-items:center;
+}
\ No newline at end of file
index d4c8638541a8f340cbd7776ee1ff765f15893f81..e226e4fe9af761fbfaaa34094f80fa59cbb978fd 100644 (file)
@@ -1,5 +1,5 @@
 import React from 'react';
-
+import {Link}     from 'react-router-dom';
 import NavTop from 'component/nav-top/index.jsx';
 // import './index.css';
 import {Image, Card, Button, List, Icon} from 'semantic-ui-react'
@@ -32,12 +32,16 @@ class FarmerCard extends React.Component {
                             </List>
                         </Card.Description>
                     </Card.Content>
-                    <Card.Content extra>
+                    <Card.Content extra className='flex-box'>
                         <div className='ui buttons'>
                             {/*todo link to machine page*/}
-                            <Button basic color='blue'>
-                                Other records
-                            </Button>
+
+                                <Link color='linkedin' to={'/machineInfo/' + machine.machine_sn}>
+                                    <Button basic color='blue'>
+                                    Other records
+                                    </Button>
+                                </Link>
+
                         </div>
                     </Card.Content>
                 </Card>
diff --git a/front-end/src/component/farmer-detail-card/index.css b/front-end/src/component/farmer-detail-card/index.css
new file mode 100644 (file)
index 0000000..cd3a3a8
--- /dev/null
@@ -0,0 +1,5 @@
+.flex-box{
+    display: flex;
+    justify-content:center;
+    align-items:center;
+}
\ No newline at end of file
index bee5456feba68bbe8d20734cd91808fb92e2dadf..6fb4ff1a5d591e9d8d7a3787c0568e5a02d4a34f 100644 (file)
@@ -1,7 +1,7 @@
 import React from 'react';
 
 import NavTop from 'component/nav-top/index.jsx';
-// import './index.css';
+import './index.css';
 import {Image, Card, Button, List, Icon} from 'semantic-ui-react'
 class FarmerDetailCard extends React.Component {
     constructor(props){
@@ -33,13 +33,13 @@ class FarmerDetailCard extends React.Component {
                             </List>
                         </Card.Description>
                     </Card.Content>
-                    <Card.Content extra>
+                    <Card.Content extra className='flex-box'>
 
                         <div className='ui buttons'>
                             {/*todo link to machine page*/}
-                            <Button basic mini color='grey'>
-                                {branch_num} branches involved
-                            </Button>
+                                <Button basic mini color='grey'>
+                                    {branch_num} branches involved
+                                </Button>
                         </div>
                     </Card.Content>
                 </Card>
index bd92ac27fa4d16c04af48375efdffb13bfc43190..608b3d06fc733008890dd1ee8982730fb83a4bc6 100644 (file)
@@ -32,9 +32,15 @@ class HistoryRecordPane1 extends React.Component {
         this.loadMachineRecordListByBranch()
     }
     componentWillReceiveProps(nextProps) {
+        let _this = this
         this.setState({
             branches: nextProps.branches,
             machine_sn: nextProps.machine_sn,
+        },() => {
+            if(this.state.branches.length > 0) {
+                _this.handleBranchTagClick(_this.state.branches[0].value)
+            }
+
         });
     }
     handleBranchTagClick(branch_id){
@@ -96,6 +102,9 @@ class HistoryRecordPane1 extends React.Component {
             <div>
                 <div className="branch-tags-container">
                     {branch_tags}
+                    <div>
+                        current num: {this.state.currentTotal}
+                    </div>
                 </div>
 
                     <MachineRecordTable list={this.state.currentList} total={this.state.currentTotal} current={this.state.currentPage} loadfunc={this.loadMachineRecordListByBranch}/>
index 2fa02a2e4dd1e2e9f16a87de858a51407e67ac1d..08a4e8d3bb591418308d1bd6de43dca2cc092263 100644 (file)
@@ -87,9 +87,8 @@ class NavTop extends React.Component {
                     </li>
                     <li><Link to="/status"><span className="glyphicon glyphicon-tasks" aria-hidden="true"></span>Status</Link>
                     </li>
-                    {/*<li><Link to="/classifiedDisplay">分类展示</Link><a href="/status"> <span className="glyphicon glyphicon-tasks" aria-hidden="true"></span> Status</a>*/}
-                    {/*</li>*/}
-                    <li><a href="#"> <span className="glyphicon glyphicon-blackboard" aria-hidden="true"></span>Machine</a>
+
+                    <li><Link to="/machine"> <span className="glyphicon glyphicon-blackboard" aria-hidden="true"></span>Machine</Link>
                     </li>
 
                     <li className="dropdown">
index 419c70f020d0619360a0a5beb5054cc676f7a9a3..612331ba81299bfaf8233ba9b35e7e10ee437da7 100644 (file)
@@ -219,7 +219,7 @@ class DetailInfo extends React.Component {
                     <Segment vertical>Farmer Info</Segment>
                     <FarmerCard machine={machine}></FarmerCard>
                     {/*//todo add a catalog*/}
-                    <div className="affix">aaaa</div>
+                    {/*<div className="affix">aaaa</div>*/}
                 </div>
 
                 <div className="col-md-9">
diff --git a/front-end/src/page/machine/index.css b/front-end/src/page/machine/index.css
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/front-end/src/page/machine/index.jsx b/front-end/src/page/machine/index.jsx
new file mode 100644 (file)
index 0000000..be5914f
--- /dev/null
@@ -0,0 +1,60 @@
+import React from 'react';
+// import './index.css';
+import ResultFilter from 'component/result-filter/index.jsx';
+import RecordTable    from 'util/record-table/index.jsx';
+import MachineService      from 'service/machine-service.jsx'
+import MachineTable    from 'util/machine-table/index.jsx';
+import PGUtil        from 'util/util.jsx'
+
+const _util = new PGUtil();
+const _machine = new MachineService();
+class Machine extends React.Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+            isLoading: false,
+            currentPage: 1,
+            total: 3,
+            machines: [],
+        },
+
+        // this.onPageChange = this.onPageChange.bind(this);
+
+        this.loadMachineList = this.loadMachineList.bind(this);
+    }
+
+    componentDidMount(){
+        this.loadMachineList();
+    }
+
+    loadMachineList(page=1){
+        _machine.getMachineList().then(res => {
+            this.setState({
+                machines: res.results,
+                total: res.count,
+                isLoading: false
+            });
+        }, errMsg => {
+            _util.errorTips(errMsg);
+        });
+    }
+
+
+    render() {
+        return (
+            <div id="page-wrapper">
+                <h1>machine page</h1>
+                <p>
+                    Shown here is the latest status of each farm member for each branch it has reported on in the last
+                    30 days.
+                    Use the farm member link for history of that member on the relevant branch.
+                </p>
+
+                <MachineTable list={this.state.machines} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadRecordList}/>
+
+            </div>
+        )
+    }
+}
+
+export default Machine;
\ No newline at end of file
index 9e292c60908b93ff84d267b84dbdedeb3047174e..e6c968bed301d3b76b77cf09f4aa9c74f43c4c22 100644 (file)
@@ -68,11 +68,6 @@ class Portal extends React.Component {
     }
 
     render() {
-        let show = this.state.isLoading ? "none" : "block";
-        let style = {
-            display: show
-        };
-
         return (
             <div className="container-fluid detail-container">
 
diff --git a/front-end/src/service/machine-service.jsx b/front-end/src/service/machine-service.jsx
new file mode 100644 (file)
index 0000000..9b5188b
--- /dev/null
@@ -0,0 +1,19 @@
+import PGUtil    from 'util/util.jsx'
+import PGConstant from 'util/constant.jsx'
+// const _const = new PGConstant();
+const _util       = new PGUtil();
+
+class MachineService{
+    getMachineList(pageNum){
+        let url = PGConstant.base_url + '/machines';
+        return _util.request({
+            type    : 'get',
+            url     : url,
+            data    : {
+                pageNum : pageNum
+            }
+        });
+    }
+}
+
+export default MachineService;
\ No newline at end of file
index a5154bc69d2f0ef5f1eb08a7637753f6e5c20fe4..e18001f57a8e03024bc97a1949d789f3ec32a372 100644 (file)
@@ -63,10 +63,14 @@ class MachineTable extends React.Component {
             return (
                 <Table.Row key={index} className={color}>
                     {/*alias*/}
-                    <Table.Cell><a href="#">{machine.alias}</a></Table.Cell>
+                    <Table.Cell>
+                        <Link color='linkedin' to={'machineInfo/' + machine.machine_sn}>
+                            {machine.alias}
+                        </Link>
+                    </Table.Cell>
 
                     {/*system*/}
-                    <Table.Cell><a href="#">{system}</a></Table.Cell>
+                    <Table.Cell>{system}</Table.Cell>
 
                     {/*State*/}
                     <Table.Cell>
index 03aa40a9055c61e57785d379ab7454f1aa6b401a..ab38fc029247661ceb22952c5d779f4a3aac278c 100644 (file)
@@ -46,6 +46,13 @@ class UserMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     serializer_class = UserMachineManageSerializer
     # pagination_class = StandardResultsSetPagination
 
+class PublicMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
+    """
+    List all machines
+    """
+    queryset = UserMachine.objects.all().order_by('add_time')
+    serializer_class = UserMachineManageSerializer
+
 class UserPortalInfoViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
     """
      user info
index 904d055e9e73f7629780fe40a3297f9cb1722425..fac3b6dc1addfb91cac722a6f970666489ae55ee 100644 (file)
@@ -31,11 +31,12 @@ from test_records.auth import MachineAuthToken
 #     'get': 'list',
 #     'post': 'create'
 # })
-from user_operation.views import UserMachineListViewSet, UserPortalInfoViewSet, UserMachineRecordByBranchListViewSet
+from user_operation.views import UserMachineListViewSet, UserPortalInfoViewSet, UserMachineRecordByBranchListViewSet, \
+    PublicMachineListViewSet
 
 router = DefaultRouter()
 router.register(r'records', TestRecordListViewSet, base_name="records")
-
+router.register(r'machines', PublicMachineListViewSet, base_name="machines")
 router.register(r'branches', TestBranchListViewSet, base_name="branches")
 router.register(r'records-by-branch', TestRecordListByBranchViewSet, base_name="records-by-branch")
 # router.register(r'status-records', TestStatusRecordListViewSet, base_name="status-records")