add MachineTable in portal page
authorHongyuan Ma <CS_MaleicAcid@163.com>
Sat, 7 Jul 2018 10:57:06 +0000 (18:57 +0800)
committerHongyuan Ma <CS_MaleicAcid@163.com>
Sat, 7 Jul 2018 10:57:06 +0000 (18:57 +0800)
front-end/src/page/portal/index.css
front-end/src/page/portal/index.jsx
front-end/src/service/user-service.jsx
front-end/src/util/machine-table/index.css [new file with mode: 0644]
front-end/src/util/machine-table/index.jsx [new file with mode: 0644]
front-end/src/util/util.jsx
web/apps/user_operation/views.py
web/pgperffarm/settings.py

index d53a1d51f103a3dbfb10924e7ff1b783ee114fca..efe47f7c09d73972d308e567c0f7922c663ea103 100644 (file)
@@ -1,3 +1,4 @@
 .panel-blue{
-    border-top: 3px solid #2497ba;
+    /*border-top: 3px solid #2497ba;*/
+    border-top: 3px solid  rgb(2,141,193);
 }
\ No newline at end of file
index 3f4ca8597b6c3f5c55ab098f60ccb186e6a69fca..fe4ecfed77278682299915019af24b58b93e5fce 100644 (file)
@@ -1,7 +1,7 @@
 import React from 'react';
 import './index.css';
 import ResultFilter from 'component/result-filter/index.jsx';
-import BasicTable    from 'util/basic-table/index.jsx';
+import MachineTable    from 'util/machine-table/index.jsx';
 import UserInfoCard from 'component/userinfo-card/index.jsx'
 import Record      from 'service/record-service.jsx'
 import PGUtil        from 'util/util.jsx'
@@ -15,15 +15,34 @@ class Portal extends React.Component {
         super(props);
         this.state = {
             isLoading: false,
+            machines:[],
+            userinfo: {}
         }
 
     }
     componentDidMount(){
+        let user = _util.getStorage('userInfo')
+        console.log(user.token)
         this.loadUserMachineManageList();
     }
-    loadUserMachineManageList(){
+
+    loadUserInfo(){
+        _user.getUserInfo().then(res => {
+            this.setState({
+                userinfo: res.userinfo,
+            });
+        }, errMsg => {
+            _mm.errorTips(errMsg);
+        });
+    }
+
+    loadUserMachineManageList(page=1){
         _user.getUserMachineManageList().then(res => {
-            this.setState(res);
+            this.setState({
+                machines: res.machines,
+                total: res.count,
+                isLoading: false
+            });
         }, errMsg => {
             _mm.errorTips(errMsg);
         });
@@ -65,7 +84,7 @@ class Portal extends React.Component {
                         <h2 >Welcome Back, {this.state.username}</h2>
                     </div>
 
-
+                    <MachineTable list={this.state.machines} total={this.state.total} current={this.state.currentPage} loadfunc={this.loadRecordList}/>
                 </div>
             </div>
 
index 1ca1f0d3fb9b0a19894f8c774a9463d5c996fe9a..bbb600e736a236394fc19b1e654a299044cd2488 100644 (file)
@@ -54,6 +54,16 @@ class User{
             }
         });
     }
+
+    getUserInfo(){
+        let url = PGConstant.base_url + '/userinfo';
+        return _util.request({
+            type    : 'get',
+            url     : url,
+            data    : {}
+        });
+    }
+
 }
 
 export default User;
\ No newline at end of file
diff --git a/front-end/src/util/machine-table/index.css b/front-end/src/util/machine-table/index.css
new file mode 100644 (file)
index 0000000..0fe34f8
--- /dev/null
@@ -0,0 +1,43 @@
+.ReactTable .rt-th{
+    background-color: #ffffff;
+}
+
+.ReactTable .-pagination{
+    background-color: #ffffff;
+}
+
+.ReactTable .rt-tr-group:nth-child(2n) {
+    background-color: #ffffff;
+}
+
+.bgc-clear{
+    background-color: #ffffff;
+}
+
+.anonymous {
+    color: #e8e8e8;
+}
+
+.anonymous :hover {
+    color: lightgrey;
+}
+.improved {
+    color: #7cb305;
+}
+
+.quo {
+    color: #40a9ff;
+}
+
+.regressive {
+    color: #fa541c;
+}
+
+.mini-label {
+    font-weight: 100!important;
+    font-size: 0.1em!important;
+    min-width: 1.3em!important;
+    min-height: 0.1em!important;
+    padding: .2em!important;
+    line-height: 0.5em!important;
+}
\ No newline at end of file
diff --git a/front-end/src/util/machine-table/index.jsx b/front-end/src/util/machine-table/index.jsx
new file mode 100644 (file)
index 0000000..356bc32
--- /dev/null
@@ -0,0 +1,133 @@
+import React from 'react';
+import {Link}     from 'react-router-dom';
+import {Icon, Table, Label, Message, Button} from 'semantic-ui-react'
+import Pagination from 'util/pagination/index.jsx'
+import './index.css';
+
+function Bubble(props) {
+
+    if (props.num <= 0) {
+        return null;
+    }
+    let className = props.name + 'IconClassName';
+    return (
+        <Label circular size="mini" className={"mini-label " + className}>
+            {props.num}
+        </Label>
+    );
+}
+
+// general basic table
+class MachineTable extends React.Component {
+    constructor(props) {
+        super(props);
+        this.state = {
+            isFirstLoading: true,
+            total: this.props.total,
+            currentPage: 1,
+        }
+    }
+
+
+    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 || []
+        let style = {
+            display: 'show'
+        };
+        let listBody = _list.map((record, index) => {
+            let machine = record.machine_info[0];
+            let system = machine.os_name + ' ' + machine.os_version + ' ' + machine.comp_name + ' ' + machine.comp_version;
+            let alias = machine.alias;
+
+
+            let trend = record.trend
+            let improvedIconClassName = trend.improved > 0 ? 'improved' : 'anonymous'
+            let quoIconClassName = trend.quo > 0 ? 'quo' : 'anonymous'
+            let regressiveIconClassName = trend.regressive > 0 ? 'regressive' : 'anonymous'
+            return (
+
+                <Table.Row key={index}>
+                    {/*alias*/}
+                    <Table.Cell><a href="#">{alias}</a></Table.Cell>
+
+                    {/*system*/}
+                    <Table.Cell><a href="#">{system}</a></Table.Cell>
+
+                    {/*State*/}
+                    <Table.Cell>acitve</Table.Cell>
+
+                    {/*lastest-records*/}
+
+                    <Table.Cell textAlign='center'>
+                        <Icon className={"bgc-clear " + improvedIconClassName} name='smile outline' size='large'/>
+                        <Bubble num={trend.improved} name="improved"/>
+                    </Table.Cell>
+
+                    {/*machine history*/}
+                    <Table.Cell textAlign='center'>
+                        <Link color='linkedin' to={'machineInfo/' + record.uuid}>
+                            <Icon name='linkify'/> Link
+                        </Link>
+                    </Table.Cell>
+
+                    {/*date*/}
+                    <Table.Cell>{record.add_time}</Table.Cell>
+                </Table.Row>
+            );
+        });
+
+        return (
+            <Table celled structured compact textAlign='center'>
+                <Table.Header>
+                    {/*<Table.Row>*/}
+                        {/*<Table.HeaderCell rowSpan='9'>Branch: 10_STABLE</Table.HeaderCell>*/}
+                    {/*</Table.Row>*/}
+                    <Table.Row>
+                        <Table.HeaderCell rowSpan='2'>Alias</Table.HeaderCell>
+                        <Table.HeaderCell rowSpan='2'>System</Table.HeaderCell>
+                        {/*<Table.HeaderCell rowSpan='2'>Branch</Table.HeaderCell>*/}
+                        <Table.HeaderCell rowSpan='2'>State</Table.HeaderCell>
+                        <Table.HeaderCell rowSpan='3'>Lastest</Table.HeaderCell>
+                        <Table.HeaderCell rowSpan='2'>History</Table.HeaderCell>
+                        <Table.HeaderCell rowSpan='2'>Date</Table.HeaderCell>
+                    </Table.Row>
+                    {/*<Table.Row>*/}
+                        {/*<Table.HeaderCell>improvement</Table.HeaderCell>*/}
+                        {/*<Table.HeaderCell>status quo</Table.HeaderCell>*/}
+                        {/*<Table.HeaderCell>regression</Table.HeaderCell>*/}
+                    {/*</Table.Row>*/}
+
+                </Table.Header>
+
+                <Table.Body>
+                    {listBody}
+                </Table.Body>
+                <Table.Footer>
+                    <Table.Row>
+                        <Table.HeaderCell colSpan='10'>
+
+                            <Pagination style={style} onChange={(current) => this.onPageNumChange(current)} pageSize={2}
+                                        current={this.state.currentPage} total={this.props.total}/>
+                        </Table.HeaderCell>
+
+                    </Table.Row>
+                </Table.Footer>
+            </Table>
+        );
+
+    }
+
+
+}
+
+export default MachineTable;
\ No newline at end of file
index 0af29a2ef8e8fc4167af4b57a709af8608d2bc34..3492750c7f0c12980f36b80035602ee8164ee88f 100644 (file)
@@ -4,11 +4,15 @@ import PGConstant from 'util/constant.jsx'
 class PGUtil {
     request(param) {
         return new Promise((resolve, reject) => {
+            let user = this.getStorage('userInfo')
             $.ajax({
                 type: param.type || 'get',
                 url: param.url || '',
                 dataType: param.dataType || 'json',
                 data: param.data || null,
+                headers:{
+                    'Authorization': 'Token ' + user.token
+                },
                 success: res => {
                     // request success
 
index 5e8ea8afe58261a285063c492ecf03be9efd7384..fb46d05f053561f5a3c3886b09bc57c6afb73e89 100644 (file)
@@ -16,6 +16,7 @@ class UserMachineListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
     List test records
     """
     authentication_classes = (JSONWebTokenAuthentication, authentication.SessionAuthentication )
+    permission_classes = (permissions.IsAuthenticated, )
     queryset = UserMachine.objects.all().order_by('add_time')
     serializer_class = UserMachineManageSerializer
     # pagination_class = StandardResultsSetPagination
index 8606f3940b7b2ba466525103504b00d328107c37..2a62143b2e6dc3041497b26a7f35086b4c5ffede 100644 (file)
@@ -1,4 +1,5 @@
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+import datetime
 import os
 import sys
 
@@ -192,4 +193,6 @@ ALLOWED_HOSTS = ['*']
 JWT_AUTH = {
     'JWT_RESPONSE_PAYLOAD_HANDLER':
     'users.jwt_handler.jwt_response_payload_handler',
+    'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=7200),
+    'JWT_AUTH_HEADER_PREFIX': 'Token',
 }
\ No newline at end of file