add machine serialler;render test list data;
authorHongyuan Ma <CS_MaleicAcid@163.com>
Fri, 8 Jun 2018 18:14:43 +0000 (02:14 +0800)
committerHongyuan Ma <CS_MaleicAcid@163.com>
Fri, 8 Jun 2018 18:14:43 +0000 (02:14 +0800)
13 files changed:
front-end/src/component/client-box/index.css [new file with mode: 0644]
front-end/src/component/client-box/index.jsx [new file with mode: 0644]
front-end/src/component/result-filter/index.jsx
front-end/src/image/client-icon/1.png [new file with mode: 0644]
front-end/src/image/client-icon/2.png [new file with mode: 0644]
front-end/src/image/client-icon/4.png [new file with mode: 0644]
front-end/src/image/client-icon/5.png [new file with mode: 0644]
front-end/src/page/status/index.jsx
front-end/src/util/util.jsx
web/apps/test_records/serializer.py
web/apps/test_records/views.py
web/apps/user_operation/models.py
web/apps/users/serializer.py [new file with mode: 0644]

diff --git a/front-end/src/component/client-box/index.css b/front-end/src/component/client-box/index.css
new file mode 100644 (file)
index 0000000..b96f59e
--- /dev/null
@@ -0,0 +1,6 @@
+.improve{
+    background-color: #d9f7be;
+}
+.decline{
+    background-color: #ffccc7;
+}
\ No newline at end of file
diff --git a/front-end/src/component/client-box/index.jsx b/front-end/src/component/client-box/index.jsx
new file mode 100644 (file)
index 0000000..5fc6599
--- /dev/null
@@ -0,0 +1,32 @@
+import React from 'react';
+import './index.css';
+import classNames from 'classnames';
+class ClientBox extends React.Component {
+    constructor(props) {
+        super(props);
+
+        this.state = {
+            isImprove: true,
+        };
+
+    }
+
+    render() {
+        let imgSrc = require('image/client-icon/' + this.props.clientNum + '.png');
+        let std = this.props.std;
+        let median = this.props.median;
+        let boxClass = classNames({
+            'client-box': true,
+            'improve': median > std,
+            'decline': (median <= std)
+        });
+
+        return (
+            <div className={boxClass}>
+                <img src={imgSrc} alt=""/>
+            </div>
+        );
+    }
+}
+
+export default ClientBox;
\ No newline at end of file
index fbbc4cf413e730aa78310d39efb31c742236800c..77bfe282e4ddc207127519bfdda1b47aa7219fe5 100644 (file)
@@ -76,14 +76,9 @@ class ResultFilter extends React.Component {
             // selected: newArr,
             isClear: false
         });
-        this.handleIsLoading();
-
-        console.log(this.props.isLoading)
-    }
-
-    handleIsLoading(e) {
-        // console.log(e.target.value)
         this.props.onIsLoadingChange(true);
+        this.props.onApplyBtnClick(true);
+        console.log('isLoading:' + this.props.isLoading)
     }
 
     resetButtonClick() {
diff --git a/front-end/src/image/client-icon/1.png b/front-end/src/image/client-icon/1.png
new file mode 100644 (file)
index 0000000..0103459
Binary files /dev/null and b/front-end/src/image/client-icon/1.png differ
diff --git a/front-end/src/image/client-icon/2.png b/front-end/src/image/client-icon/2.png
new file mode 100644 (file)
index 0000000..daa4f06
Binary files /dev/null and b/front-end/src/image/client-icon/2.png differ
diff --git a/front-end/src/image/client-icon/4.png b/front-end/src/image/client-icon/4.png
new file mode 100644 (file)
index 0000000..b7d7463
Binary files /dev/null and b/front-end/src/image/client-icon/4.png differ
diff --git a/front-end/src/image/client-icon/5.png b/front-end/src/image/client-icon/5.png
new file mode 100644 (file)
index 0000000..2779f13
Binary files /dev/null and b/front-end/src/image/client-icon/5.png differ
index 366905555f275e24492dcb51ef88ec54881e39c7..4bb74a06428a7bc6fd2f4d8ae4f48a0b77464506 100644 (file)
@@ -1,6 +1,7 @@
 import React from 'react';
 // import './index.css';
 import ResultFilter from 'component/result-filter/index.jsx';
+import ClientBox from 'component/client-box/index.jsx';
 import Pagination from 'util/pagination/index.jsx';
 import RateBar from 'util/rate-bar/index.jsx';
 import TableList    from 'util/table-list/index.jsx';
@@ -8,7 +9,7 @@ import BasicTable    from 'util/basic-table/index.jsx';
 import Record      from 'service/record-service.jsx'
 import PGUtil        from 'util/util.jsx'
 
-const _util           = new PGUtil();
+const _util = new PGUtil();
 const _record = new Record();
 class Status extends React.Component {
     constructor(props) {
@@ -32,33 +33,45 @@ class Status extends React.Component {
             ]
 
         },
-        this.onPageChange = this.onPageChange.bind(this);
-        this.handleIsLoading = this.handleIsLoading.bind(this);
+            this.onPageChange = this.onPageChange.bind(this);
+        this.onIsLoadingChange = this.onIsLoadingChange.bind(this);
+        this.handleApplyBtnClick = this.handleApplyBtnClick.bind(this);
     }
 
     componentDidMount() {
         this.loadRecordList();
     }
 
+    handleApplyBtnClick() {
+        console.log('apply btn clicked!')
+        this.loadRecordList()
+    }
+
     // load record list
     loadRecordList() {
+        let _this = this;
         let listParam = {};
         listParam.filter = this.state.filter;
         // listParam.pageNum = this.state.pageNum;
 
         _record.getRecordList(listParam).then(res => {
-            console.log('res is:'+ res)
+            console.log('res is:' + res)
             this.setState({
-                list: res.result
+                list: res.results,
+                isLoading: false
             });
+            _this.changeIsLoading(false);
         }, errMsg => {
             this.setState({
                 list: []
             });
             _util.errorTips(errMsg);
+
             console.log(errMsg)
+            _this.changeIsLoading(false);
         });
 
+
         console.log(this.state.list)
     }
 
@@ -70,10 +83,18 @@ class Status extends React.Component {
         });
     }
 
-    handleIsLoading(isLoading) {
+    changeIsLoading(flag) {
+        this.setState({
+            isLoading: flag
+        });
+    }
+
+    onIsLoadingChange(flag) {
+        console.log('flag:' + flag)
         this.setState({
-            isLoading: isLoading
-        })
+            isLoading: flag
+        });
+        console.log('status isLoading:' + this.state.isLoading)
     }
 
     render() {
@@ -83,13 +104,27 @@ class Status extends React.Component {
         };
 
         let listBody = this.state.list.map((machine, index) => {
+            let info = machine.machine_info[0];
+            let info_str = info.os_name + ' ' + info.os_version + ' ' + info.comp_name + ' ' + info.comp_version;
+            let client_max = machine.client_max_num
             return (
+
                 <tr key={index}>
 
-                    <td>{machine.alias}</td>
-                    <td><a href={'mailto:' + machine.email}>{machine.email}</a></td>
+                    <td><a href={'#'}>{info.alias}</a></td>
+
+                    <td><a href={'#'}>{info_str}</a></td>
+
                     <td>
-                        {machine.clients}
+                        <div>
+                            <ClientBox clientNum="1" std="100" median="200">1</ClientBox>
+                            <ClientBox clientNum="2" std="100" median="200">2</ClientBox>
+                            <ClientBox clientNum="4" std={100} median={2}>4</ClientBox>
+                        </div>
+
+                    </td>
+                    <td>
+                        1111
                         {/*<th rowspan="3"></th>*/}
                         {/*<th rowspan="3">1-2</th>*/}
                         {/*<th rowspan="2">1-3</th>*/}
@@ -97,11 +132,16 @@ class Status extends React.Component {
                         {/*<th rowspan="3">1-5</th>*/}
                     </td>
 
+                    <td rowSpan="2">
+                        {machine.clients}
+                        {/*<th rowspan="3"></th>*/}
+                        {/*<th rowspan="3">1-2</th>*/}
+                        {/*<th rowspan="2">1-3</th>*/}
+                        {/*<th rowspan="1">1-4</th>*/}
+                        {/*<th rowspan="3">1-5</th>*/}
+                    </td>
                     <td>
-                        <div>
-                            <p>..</p>
-                            {/*<RateBar style={{float: 'right', zIndex: 999}} std={this.state.std} curMark={this.state.curMark2}/>*/}
-                        </div>
+
                         {/*<div style={{float: 'left'}}> <p>{machine.mark}</p></div>*/}
                     </td>
                     <td>{new Date().toDateString()}</td>
@@ -119,9 +159,10 @@ class Status extends React.Component {
                 </p>
 
 
-                <ResultFilter isLoading={this.state.isLoading} onIsLoadingChange={this.handleIsLoading}/>
+                <ResultFilter isLoading={this.state.isLoading} onIsLoadingChange={this.onIsLoadingChange}
+                              onApplyBtnClick={this.handleApplyBtnClick}/>
 
-                <TableList tableHeads={['alias', 'email', 'clients', 'mark', 'date']}>
+                <TableList tableHeads={['alias', 'System', 'ro', 'rw', 'date']}>
                     {listBody}
                 </TableList>
                 {/*<BasicTable></BasicTable>*/}
index 6022a940cc6c5907c2e98665dc895ce830e7010d..2c0ae904633700e4ca70d6da5a827598a9f3ba25 100644 (file)
@@ -9,16 +9,18 @@ class PGUtil {
                 data: param.data || null,
                 success: res => {
                     // request success
-                    if (0 === res.status) {
-                        typeof resolve === 'function' && resolve(res.data, res.msg);
-                    }
-                    // nologin force to login
-                    else if (10 === res.status) {
-                        this.doLogin();
-                    }
-                    else {
-                        typeof reject === 'function' && reject(res.msg || res.data);
-                    }
+
+                    typeof resolve === 'function' && resolve(res, res.msg);
+                    // if (0 === res.status) {
+                    //     typeof resolve === 'function' && resolve(res.data, res.msg);
+                    // }
+                    // // nologin force to login
+                    // else if (10 === res.status) {
+                    //     this.doLogin();
+                    // }
+                    // else {
+                    //     typeof reject === 'function' && reject(res.msg || res.data);
+                    // }
                 },
                 error: err => {
                     typeof reject === 'function' && reject(err.statusText);
index 1c8de2be8f5d477d73fc45353bd79332fd3480a7..ae0711ae83df503ae3a61623bb7fe23eb24174e6 100644 (file)
@@ -1,5 +1,7 @@
 from rest_framework import serializers
 from test_records.models import TestRecord, TestResult, PGInfo, LinuxInfo ,MetaInfo
+from users.serializer import UserMachineSerializer
+from users.models import UserMachine
 from django.db.models import Q
 class PGInfoSerializer(serializers.ModelSerializer):
 
@@ -47,9 +49,11 @@ class TestRecordSerializer(serializers.ModelSerializer):
     meta_info = MetaInfoSerializer()
     ro_info = serializers.SerializerMethodField()
     rw_info = serializers.SerializerMethodField()
+    machine_info = serializers.SerializerMethodField()
+    client_max_num = serializers.SerializerMethodField()
     class Meta:
         model = TestRecord
-        fields = "__all__"
+        fields = ('add_time', 'machine_info', 'pg_info', 'linux_info', 'meta_info', 'ro_info', 'rw_info', 'client_max_num')
 
     def get_ro_info(self, obj):
         all_data = TestResult.objects.filter(Q(test_record_id=obj.id ) ,test_cate_id=1)
@@ -63,6 +67,17 @@ class TestRecordSerializer(serializers.ModelSerializer):
         rw_info_serializer = TestResultSerializer(all_data, many=True, context={'request': self.context['request']})
         return rw_info_serializer.data
 
+    def get_machine_info(self, obj):
+        machine_data = UserMachine.objects.filter(Q(id=obj.test_machine_id.id))
+
+        machine_info_serializer = UserMachineSerializer(machine_data,many=True, context={'request': self.context['request']})
+        return machine_info_serializer.data
+
+    def get_client_max_num(self, obj):
+        ro_client_num = TestResult.objects.filter(Q(test_record_id=obj.id ) ,test_cate_id=1).order_by('clients').distinct('clients').count()
+        rw_client_num = TestResult.objects.filter(Q(test_record_id=obj.id ) ,test_cate_id=2).order_by('clients').distinct('clients').count()
+        return max(ro_client_num,rw_client_num)
+
 class TestRecordDetailSerializer(serializers.ModelSerializer):
 
     '''
index 5b0d852f582b2e61b96559b09271ac4399ebf101..741856f371c9e1b3fc25dfaef8af13888dfc654c 100644 (file)
@@ -27,24 +27,6 @@ class TestRecordListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     queryset = TestRecord.objects.all()
     serializer_class = TestRecordSerializer
     pagination_class = StandardResultsSetPagination
-    # authentication_classes = None
-    # def get(self, request, *args, **kwargs):
-    #     return self.list(request, *args, **kwargs)
-
-    # def post(self, request, *args, **kwargs):
-    #     return self.create(request, *args, **kwargs)
-    # def get(self, request, format=None):
-    #     testRecords = TestRecord.objects.all()
-    #     records_serializer = TestRecordSerializer(testRecords, many=True)
-    #     return Response(records_serializer.data)
-    #
-    # def post(self, request, format=None):
-    #     serializer = TestRecordSerializer(data=request.data)
-    #     if serializer.is_valid():
-    #         serializer.save()
-    #         return Response(serializer.data, status=status.HTTP_201_CREATED)
-    #     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
-
 
 class TestRecordDetailViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, viewsets.GenericViewSet):
     """
index 861ffe9328841424b491f39821150277edff3f48..804118add8c5ce7818d23d41e1a902871534d0c1 100644 (file)
@@ -2,6 +2,4 @@ from datetime import datetime
 from django.db import models
 
 from users.models import UserMachine
-# Create your models here.
-
-
+# Create your models here.
\ No newline at end of file
diff --git a/web/apps/users/serializer.py b/web/apps/users/serializer.py
new file mode 100644 (file)
index 0000000..251e023
--- /dev/null
@@ -0,0 +1,13 @@
+from rest_framework import serializers
+from users.models import UserMachine
+from django.db.models import Q
+
+class UserMachineSerializer(serializers.ModelSerializer):
+
+    '''
+    use UserMachineSerializer
+    '''
+    class Meta:
+        model = UserMachine
+        # fields = "__all__"
+        fields = ('alias', 'os_name', 'os_version' ,'comp_name', 'comp_version')
\ No newline at end of file