add MachineRecordListFilter;
authorHongyuan Ma <CS_MaleicAcid@163.com>
Wed, 11 Jul 2018 04:18:34 +0000 (12:18 +0800)
committerHongyuan Ma <CS_MaleicAcid@163.com>
Wed, 11 Jul 2018 04:18:34 +0000 (12:18 +0800)
front-end/src/component/history-records-pane1/index.css
front-end/src/component/history-records-pane1/index.jsx
front-end/src/page/machineInfo/index.jsx
front-end/src/service/record-service.jsx
front-end/src/util/machine-record-table/index.jsx
web/apps/test_records/filters.py
web/apps/test_records/views.py
web/apps/user_operation/filters.py [new file with mode: 0644]
web/apps/user_operation/views.py
web/pgperffarm/urls.py

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b8cdbf89cdc44933d3bfe6b9d7dce0551aaf9082 100644 (file)
@@ -0,0 +1,4 @@
+.active_branch{
+    color: #fff9f8 !important;
+    background-color: #40a9ff !important;
+}
\ No newline at end of file
index 4bd4e7483b8240c42e668ef7d29089b36c5b34d3..a93eedbfd1d4546daa9e1b8c87dbc30c6db1971d 100644 (file)
@@ -3,8 +3,11 @@ import Pagination from 'util/pagination/index.jsx';
 import {Tab, Divider, Icon, Label} from 'semantic-ui-react'
 
 import MachineRecordTable from 'util/machine-record-table/index.jsx'
+import Record      from 'service/record-service.jsx'
 import PGUtil        from 'util/util.jsx'
+
 const _util = new PGUtil();
+const _record = new Record();
 import './index.css';
 
 class HistoryRecordPane1 extends React.Component {
@@ -12,43 +15,73 @@ class HistoryRecordPane1 extends React.Component {
         super(props);
 
         this.state = {
-            list: [],
+            currentList: [],
+            currentTotal: 0,
+            currentPage:1,
+            machine_sn: props.machine_sn || '',
             branches: props.branches || [],
-            selected_branch: '',
-            restoreNum: 0,
-            selected: [{
-                'cate': 'Category 1',
-                'index': 0,
-                'key': 'date',
-                'data': [
-                    {'name': 'All', 'value': ''},
-                    {'name': '7 days', 'value': '7'},
-                    {'name': '30 days', 'value': '30'}
-                ],
-            }],
+            selected_branch: 1,
         }
-        console.log('br')
-        console.dir(this.state.branches)
+        // console.dir(this.state.branches)
+        this.loadMachineRecordListByBranch = this.loadMachineRecordListByBranch.bind(this);
+        // this.loadMachineRecordListByBranch
     }
 
     componentDidMount() {
         // this.loadHistoryRecordList();
     }
     componentWillReceiveProps(nextProps) {
-        this.setState({branches: nextProps.branches});
+        this.setState({
+            branches: nextProps.branches,
+            machine_sn: nextProps.machine_sn,
+        });
     }
-    reloadRecordTable(branch_id){
+    handleBranchTagClick(branch_id){
         console.log('new reload branch is: ' + branch_id)
+
+        this.setState({
+            selected_branch: branch_id,
+        },() => {
+            this.loadMachineRecordListByBranch()
+        });
+
     }
 
+    // load record list
+    loadMachineRecordListByBranch(page=1) {
+        let _this = this;
+        let listParam = {};
+
+        listParam.page = page;
+        listParam.test_machine__machine_sn = this.state.machine_sn;
+        listParam.branch__id = this.state.selected_branch;
+
+        _record.getMachineRecordListByBranch(listParam).then(res => {
+            _this.setState({
+                currentList: res.results,
+                currentTotal: res.count,
+                isLoading: false
+            });
+        }, errMsg => {
+            _this.setState({
+                curentList: []
+            });
+            _util.errorTips(errMsg);
+
+            console.log(errMsg)
+        });
+
+        console.log(this.state.list)
+    }
 
     render(){
         let _list = this.state.branches || [];
         console.log('list is')
         console.dir(_list)
         let branch_tags = _list.map((branchItem, index) => {
+            let className = branchItem.value == this.state.selected_branch ? 'active_branch' : '';
             return (
-                <Label onClick={() => this.reloadRecordTable(branchItem.value)}>
+                <Label className={className} onClick={() => this.handleBranchTagClick(branchItem.value)}>
                     <Icon name='usb' />{branchItem.branch}
                 </Label>
             );
@@ -62,7 +95,7 @@ class HistoryRecordPane1 extends React.Component {
                     {branch_tags}
                 </div>
 
-                    <MachineRecordTable list={this.state.list} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadRecordList}/>
+                    <MachineRecordTable list={this.state.currentList} total={this.state.currentTotal} current={this.state.currentPage} loadfunc={this.loadMachineRecordListByBranch}/>
 
             </div>
         );
index 8a076286677de49dcd696f4134e1190c39aaad66..4f59c382e32483de122e88d371d77940208decde 100644 (file)
@@ -22,8 +22,8 @@ class MachineInfo extends React.Component {
             list: [
             ]
         },
-        console.dir(this.props.match.params)
-        this.onPageChange = this.onPageChange.bind(this);
+        // console.dir(this.props.match.params)
+        // this.onPageChange = this.onPageChange.bind(this);
         this.handleApplyBtnClick = this.handleApplyBtnClick.bind(this);
         this.loadHistoryRecordList = this.loadHistoryRecordList.bind(this);
     }
@@ -75,18 +75,10 @@ class MachineInfo extends React.Component {
         console.log(this.state.list)
     }
 
-    onPageChange(page) {
-        console.log(page);
-        console.log(this);
-        this.setState({
-            current: page,
-        });
-    }
-
     render() {
         // let branches = this.state.branches;
         let panes = [
-            { menuItem: 'Tab 1', render: () => <Tab.Pane attached={true}><HistoryRecordsPane1 branches={this.state.branches}/></Tab.Pane> },
+            { menuItem: 'Review By Branches', render: () => <Tab.Pane attached={true}><HistoryRecordsPane1 machine_sn={this.state.machineInfo.machine_sn} branches={this.state.branches}/></Tab.Pane> },
         ]
 
         return (
@@ -116,7 +108,7 @@ class MachineInfo extends React.Component {
                         {/*<MachineRecordTable list={this.state.list} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadRecordList}/>*/}
 
 
-                        <Tab menu={{ attached: false }} panes={panes} />
+                        <Tab menu={{pointing: true }} panes={panes} />
                     {/*</div>*/}
 
                 </div>
index 6e79a217fec118724195334eaf1974bec26d2c20..1e5a9b42aab06169ed6bb80162304dc1dea5a9a7 100644 (file)
@@ -31,7 +31,7 @@ class Record{
         });
     }
 
-    // get history record list
+    // get machine info
     getHistoryRecordList(listParam){
         let url = PGConstant.base_url + '/machine-records/' + listParam.machine_sn;
 
@@ -46,6 +46,22 @@ class Record{
             data    : data
         });
     }
+
+
+    getMachineRecordListByBranch(listParam){
+        let url = PGConstant.base_url + '/machine-records-by-branch/';
+
+        let data = {};
+        data = listParam;
+
+        console.log('final data')
+        console.dir(listParam);
+        return _util.request({
+            type    : 'get',
+            url     : url,
+            data    : data
+        });
+    }
 }
 
 export default Record;
\ No newline at end of file
index 0e96f7b13f11a7106f76879831f3e976738e225b..89b5160d07f656b0470b59452e7b926678088dad 100644 (file)
@@ -17,41 +17,6 @@ function Bubble(props) {
     );
 }
 
-//todo
-// function TrendCell(trend) {
-//     const isNull = !list;
-//     const isEmpty = !isNull && !list.length;
-//     let improvedIconClassName = trend.improved > 0 ? 'improved' : 'anonymous'
-//     let quoIconClassName = trend.quo > 0 ? 'quo' : 'anonymous'
-//     let regressiveIconClassName = trend.regressive > 0 ? 'regressive' : 'anonymous'
-//     if (!trend.is_first) {
-//         return (
-//             <Table.Cell  textAlign='center'>
-//                 first report
-//             </Table.Cell>
-//         );
-//     } else {
-//         return (
-//             <div>
-//                 <Table.Cell textAlign='center'>
-//                     <Icon className={"bgc-clear " + improvedIconClassName} name='smile outline' size='large'/>
-//                     <Bubble num={trend.improved} name="improved"/>
-//                 </Table.Cell>
-//                 <Table.Cell textAlign='center'>
-//                     <Icon className={"bgc-clear " + quoIconClassName} name='meh outline' size='large'/>
-//                     <Bubble num={trend.quo} name="quo"/>
-//                 </Table.Cell>
-//                 <Table.Cell textAlign='center'>
-//                     <Icon className={"bgc-clear " + regressiveIconClassName} name='frown outline'
-//                           size='large'/>
-//                     <Bubble num={trend.regressive} name="regressive"/>
-//                 </Table.Cell>
-//             </div>
-//         );
-//     }
-//
-// }
-
 // general basic table
 class MachineRecordTable extends React.Component {
     constructor(props) {
@@ -64,18 +29,18 @@ class MachineRecordTable extends React.Component {
     }
 
 
-    // onPageNumChange(current) {
-    //     this.setState({
-    //         currentPage: current
-    //     }, () => {
-    //         this.props.loadfunc(current);
-    //     });
-    //     console.log('current:' + this.state.currentPage)
-    // }
+    onPageNumChange(current) {
+        this.setState({
+            currentPage: current
+        }, () => {
+            this.props.loadfunc(current);
+        });
+        console.log('current:' + this.state.currentPage)
+    }
 
     render() {
         // let branch = record.pg_info.pg_branch;
-        let _list = this.props.list.records || []
+        let _list = this.props.list || []
         let style = {
             display: 'show'
         };
@@ -132,8 +97,8 @@ class MachineRecordTable extends React.Component {
         });
 
         return (
-            <Table celled structured compact textAlign='center'>
-                <Table.Header>
+            <Table  basic='very' selectable structured compact textAlign='center'>
+                <Table.Header celled>
                     {/*<Table.Row>*/}
                     {/*<Table.HeaderCell rowSpan='9'>Branch: 10_STABLE</Table.HeaderCell>*/}
                     {/*</Table.Row>*/}
@@ -171,8 +136,8 @@ class MachineRecordTable extends React.Component {
                             {/*<Icon name='chevron right'/>*/}
                             {/*</Menu.Item>*/}
                             {/*</Menu>*/}
-                            {/*<Pagination style={style} onChange={(current) => this.onPageNumChange(current)} pageSize={2}*/}
-                                        {/*current={this.state.currentPage} total={this.props.total}/>*/}
+                            <Pagination style={style} onChange={(current) => this.onPageNumChange(current)} pageSize={2}
+                                        current={this.state.currentPage} total={this.props.total}/>
 
                         </Table.HeaderCell>
 
index f2e293ee48b5029d66fbad5b61a894b6500b9208..252e358de9e69fe29ccf7799d6d42bf0dc8f7c5d 100644 (file)
@@ -3,7 +3,7 @@
 import django_filters
 from django.db.models import Q
 
-from .models import TestRecord
+from test_records.models import TestRecord
 
 
 class TestRecordListFilter(django_filters.rest_framework.FilterSet):
index e76db5a63c8189abcbe0ffb26e6a4e977487fe71..5d13ae6c7895fe87080ee36f3a429cbace81de97 100644 (file)
@@ -8,7 +8,7 @@ from django.contrib.auth.hashers import make_password
 from rest_framework.pagination import PageNumberPagination
 
 from exception import TestDataUploadError
-from filters import TestRecordListFilter
+from test_records.filters import TestRecordListFilter
 from models import UserMachine, TestCategory
 from pgperffarm.settings import DB_ENUM
 from user_operation.views import UserMachinePermission
@@ -61,7 +61,6 @@ class MachineHistoryRecordViewSet( mixins.RetrieveModelMixin, viewsets.GenericVi
     serializer_class = MachineHistoryRecordSerializer
     # pagination_class = StandardResultsSetPagination
 
-
 @api_view(['POST'])
 @permission_classes((UserMachinePermission, ))
 def TestRecordCreate(request, format=None):
diff --git a/web/apps/user_operation/filters.py b/web/apps/user_operation/filters.py
new file mode 100644 (file)
index 0000000..743728b
--- /dev/null
@@ -0,0 +1,18 @@
+
+# -*- coding: utf-8 -*-
+import django_filters
+from django.db.models import Q
+
+from test_records.models import TestRecord
+
+
+class MachineRecordListFilter(django_filters.rest_framework.FilterSet):
+    """
+    TestRecordListFilter
+    """
+    branch__id = django_filters.NumberFilter(lookup_expr='icontains')
+    test_machine__machine_sn = django_filters.NumberFilter(lookup_expr='icontains')
+
+    class Meta:
+        model = TestRecord
+        fields = ['branch__id', 'test_machine__machine_sn']
\ No newline at end of file
index c8bdf4932558fff1d7488ce3ee8cd70e4693a63a..1683d67142dc33022e4733d5041f6045728bef09 100644 (file)
@@ -1,16 +1,39 @@
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
+import django_filters
 from django.shortcuts import render
 from rest_framework import mixins, viewsets, permissions, status
 
 from rest_framework import authentication
+from rest_framework.pagination import PageNumberPagination
 from rest_framework.response import Response
 from rest_framework.views import APIView
 from rest_framework_jwt.authentication import JSONWebTokenAuthentication
+
+from filters import MachineRecordListFilter
+from test_records.models import TestRecord
 from util.response import PGJsonResponse
 from users.models import UserMachine, UserProfile
-from serializer import UserMachineManageSerializer, UserPortalInfoSerializer
+from serializer import UserMachineManageSerializer, UserPortalInfoSerializer, TestRecordListSerializer
+
+class StandardResultsSetPagination(PageNumberPagination):
+    page_size = 2
+    page_size_query_param = 'page_size'
+    max_page_size = 100
+
+
+class UserMachineRecordByBranchListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
+    """
+    List machine records by branch
+    """
+
+    queryset = TestRecord.objects.all().order_by('add_time')
+    serializer_class = TestRecordListSerializer
+    pagination_class = StandardResultsSetPagination
+    filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
+    filter_class = MachineRecordListFilter
+
 
 
 class UserMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
index 7e4ff2023147e4c0f124ec3757065eec6dee3bf8..9106332ef6eb1a3016a0a884b3a59b7fae54167d 100644 (file)
@@ -31,13 +31,13 @@ from test_records.auth import MachineAuthToken
 #     'get': 'list',
 #     'post': 'create'
 # })
-from user_operation.views import UserMachineListViewSet, UserPortalInfoViewSet
+from user_operation.views import UserMachineListViewSet, UserPortalInfoViewSet, UserMachineRecordByBranchListViewSet
 
 router = DefaultRouter()
 router.register(r'records', TestRecordListViewSet, base_name="records")
 router.register(r'detail', TestRecordDetailViewSet, base_name="detail")
 router.register(r'machine-records', MachineHistoryRecordViewSet, base_name="machine-records")
-
+router.register(r'machine-records-by-branch', UserMachineRecordByBranchListViewSet, base_name="machine-records-by-branch")
 
 # user's machine manage list
 router.register(r'my-machine', UserMachineListViewSet, base_name="my-machine")