From: Hongyuan Ma Date: Fri, 8 Jun 2018 18:14:43 +0000 (+0800) Subject: add machine serialler;render test list data; X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=c2e89c270e2869a6a0de5736db7295b236fe53b2;p=pgperffarm.git add machine serialler;render test list data; --- diff --git a/front-end/src/component/client-box/index.css b/front-end/src/component/client-box/index.css new file mode 100644 index 0000000..b96f59e --- /dev/null +++ b/front-end/src/component/client-box/index.css @@ -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 index 0000000..5fc6599 --- /dev/null +++ b/front-end/src/component/client-box/index.jsx @@ -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 ( +
+ +
+ ); + } +} + +export default ClientBox; \ No newline at end of file diff --git a/front-end/src/component/result-filter/index.jsx b/front-end/src/component/result-filter/index.jsx index fbbc4cf..77bfe28 100644 --- a/front-end/src/component/result-filter/index.jsx +++ b/front-end/src/component/result-filter/index.jsx @@ -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 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 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 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 index 0000000..2779f13 Binary files /dev/null and b/front-end/src/image/client-icon/5.png differ diff --git a/front-end/src/page/status/index.jsx b/front-end/src/page/status/index.jsx index 3669055..4bb74a0 100644 --- a/front-end/src/page/status/index.jsx +++ b/front-end/src/page/status/index.jsx @@ -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 ( + - {machine.alias} - {machine.email} + {info.alias} + + {info_str} + - {machine.clients} +
+ 1 + 2 + 4 +
+ + + + 1111 {/**/} {/*1-2*/} {/*1-3*/} @@ -97,11 +132,16 @@ class Status extends React.Component { {/*1-5*/} + + {machine.clients} + {/**/} + {/*1-2*/} + {/*1-3*/} + {/*1-4*/} + {/*1-5*/} + -
-

..

- {/**/} -
+ {/*

{machine.mark}

*/} {new Date().toDateString()} @@ -119,9 +159,10 @@ class Status extends React.Component {

- + - + {listBody} {/**/} diff --git a/front-end/src/util/util.jsx b/front-end/src/util/util.jsx index 6022a94..2c0ae90 100644 --- a/front-end/src/util/util.jsx +++ b/front-end/src/util/util.jsx @@ -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); diff --git a/web/apps/test_records/serializer.py b/web/apps/test_records/serializer.py index 1c8de2b..ae0711a 100644 --- a/web/apps/test_records/serializer.py +++ b/web/apps/test_records/serializer.py @@ -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): ''' diff --git a/web/apps/test_records/views.py b/web/apps/test_records/views.py index 5b0d852..741856f 100644 --- a/web/apps/test_records/views.py +++ b/web/apps/test_records/views.py @@ -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): """ diff --git a/web/apps/user_operation/models.py b/web/apps/user_operation/models.py index 861ffe9..804118a 100644 --- a/web/apps/user_operation/models.py +++ b/web/apps/user_operation/models.py @@ -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 index 0000000..251e023 --- /dev/null +++ b/web/apps/users/serializer.py @@ -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