DataTable.tsx 5.68 KB
Newer Older
Maxym Borodenko's avatar
Maxym Borodenko committed
1
2
import * as React from 'react';
import { Link } from 'react-router-dom';
Matija Obreza's avatar
Matija Obreza committed
3
4
5
6
7
8
9
10
11
12
import {withStyles} from '@material-ui/core/styles';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableFooter from '@material-ui/core/TableFooter';
import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';

import Paper from '@material-ui/core/Paper';
import Button from '@material-ui/core/Button';
Maxym Borodenko's avatar
Maxym Borodenko committed
13
14
import * as moment from 'moment';

Matija Obreza's avatar
Subsets    
Matija Obreza committed
15
import Page from 'model/Page';
Maxym Borodenko's avatar
Maxym Borodenko committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

interface IDataTableProps extends React.ClassAttributes<any> {
    classes: any;
    pageObj: Page<any>;
    path: string;
    showStatus: boolean;
}

const styles = (theme) => ({
    root: {
        backgroundColor: '#fff',
    },
    btnEdit: theme.buttons.edit,
    tableHead: {
        fontSize: '1rem',
        fontWeight: 'bold' as 'bold',
        color: '#b4b4b2',
    },
    tableCell: {
        border: '2px solid #fff',
    },
    tableRow: {
        background: '#f3f2ee',
    },
    tableRow2: {
        background: '#f8f7f5',
    },
    numerationHead: {
        padding: '4px 0 4px 0',
Matija Obreza's avatar
Matija Obreza committed
45
        textAlign: 'center' as 'center',
Maxym Borodenko's avatar
Maxym Borodenko committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
        maxWidth: '25px',
    },
    numeration: {
        padding: '4px 16px',
        fontWeight: 'bold' as 'bold',
        color: '#4d4c46',
        fontSize: '1rem',
        width: '50px',
    },
    title: {
        fontWeight: 'bold' as 'bold',
        fontSize: '1rem',
        /*color: '#006db4',*/
    },
    footer: {
        height: '30px',
    },
    fake: {
        background: '#fff',
        padding: '0',
        width: '20px',
    },
    creationDate: {
        fontSize: '1rem',
        color: '#4d4c46',
    },
    edit: {
        width: '100px',
        padding: '4px 20px',
    },
});

class DataTable extends React.Component<IDataTableProps, any> {

    public render() {
        const {classes, pageObj, path, showStatus} = this.props;
        return (
            <Paper className={ classes.root }>
                <Table>
                    <TableHead>
                        <TableRow>
                            <TableCell className={ classes.fake } padding="none"/>
                            <TableCell className={ `${ classes.tableHead } ${ classes.numerationHead }` }>No</TableCell>
                            <TableCell className={ classes.tableHead }>Title</TableCell>
                            <TableCell className={ classes.tableHead }>Created</TableCell>
                            { showStatus && <TableCell className={ classes.tableHead }>Status</TableCell> }
                            <TableCell className={ `${ classes.tableHead } ${ classes.edit }` }/>
                            <TableCell className={ classes.fake } padding="none"/>
                        </TableRow>
                    </TableHead>
                    <TableBody>
                        { pageObj.content.map((e, i) =>
                            (
                                <TableRow key={ i } className={ i % 2 === 0 ? classes.tableRow : classes.tableRow2 }>
                                    <TableCell className={ `${ classes.tableCell } ${ classes.fake }` } padding="none"/>
                                    <TableCell className={ `${ classes.tableCell } ${ classes.numeration }` }>{ i + 1 }</TableCell>
                                    <TableCell className={ `${ classes.tableCell } ${ classes.title }` }>
                                        { e.published && (
                                        <Link to={ `${path}/${e.uuid}` }>
                                            { e.title }
                                        </Link>
                                        ) }
                                        { ! e.published && e.title }
                                    </TableCell>
                                    <TableCell className={ `${ classes.tableCell } ${ classes.creationDate }` }>{ e.createdDate && moment(e.createdDate).format('YYYY-DD-MM h:mm') }</TableCell>
                                    { showStatus && <TableCell className={ `${ classes.tableCell }` }>{ e.published ? 'published' : 'ongoing' }</TableCell> }
                                    <TableCell className={ `${ classes.tableCell } ${ classes.edit }` }>
                                        { ! e.published && e._permissions && e._permissions.write && (
                                        <Link to={ `${path}/${e.uuid}/edit` }>
Matija Obreza's avatar
Matija Obreza committed
115
                                            <Button variant="raised" className={ classes.btnEdit }>
Maxym Borodenko's avatar
Maxym Borodenko committed
116
117
118
119
120
121
                                                EDIT
                                            </Button>
                                        </Link>
                                        ) }
                                        { e.published && (
                                        <Link to={ `${path}/${e.uuid}` }>
Matija Obreza's avatar
Matija Obreza committed
122
                                            <Button variant="raised" className={ classes.btnEdit }>
Maxym Borodenko's avatar
Maxym Borodenko committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
                                                VIEW
                                            </Button>
                                        </Link>
                                        ) }
                                    </TableCell>
                                    <TableCell className={ `${ classes.tableCell } ${ classes.fake }` } padding="none"/>
                                </TableRow>
                            ),
                         ) }
                    </TableBody>
                    <TableFooter>
                        <TableRow className={ classes.footer }/>
                    </TableFooter>
                </Table>
            </Paper>
        );
139
    }
Maxym Borodenko's avatar
Maxym Borodenko committed
140
141
142
143

}

export default withStyles(styles)(DataTable);