Projekt

Obecné

Profil

Stáhnout (4.23 KB) Statistiky
| Větev: | Tag: | Revize:
1 8c45ccb0 hrubyjar
import 'antd/dist/antd.css';
2 bae9fbba Jaroslav Hrubý
import React, { useContext, useEffect, useState } from 'react';
3 8c45ccb0 hrubyjar
4
import { useUnauthRedirect } from '../../../hooks';
5
import { useRouter } from 'next/router';
6 0db53e25 Jaroslav Hrubý
import { Button, Input, Space, Table, Tag, Typography } from 'antd';
7 8c45ccb0 hrubyjar
import { faFileLines } from '@fortawesome/free-solid-svg-icons';
8
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
9
import { LoggedUserContext } from '../../../contexts/LoggedUserContext';
10 bae9fbba Jaroslav Hrubý
import { MainLayout } from '../../../layouts/MainLayout';
11
import { userController } from '../../../controllers';
12
import { AnnotationListInfo } from '../../../api';
13 0db53e25 Jaroslav Hrubý
import {
14
    CheckCircleOutlined,
15
    ClockCircleOutlined,
16
    SyncOutlined,
17
} from '@ant-design/icons';
18 669ffe38 Jaroslav Hrubý
import { getColumnSearchProps, getLocaleProps } from '../../../utils/tableUtils';
19 8c45ccb0 hrubyjar
20
function UserDocumentPage() {
21
    const redirecting = useUnauthRedirect('/login');
22
    const { logout, role } = useContext(LoggedUserContext);
23 06d1aa21 Jaroslav Hrubý
    const [documents, setDocuments] = useState<AnnotationListInfo[]>([]);
24 0db53e25 Jaroslav Hrubý
    const router = useRouter();
25 8c45ccb0 hrubyjar
26
    useEffect(() => {
27 bae9fbba Jaroslav Hrubý
        async function fetchData() {
28
            let docs = (await userController.userAnnotationsGet()).data.annotations;
29 06d1aa21 Jaroslav Hrubý
            if (!docs) {
30
                setDocuments([]);
31
            } else {
32
                setDocuments(docs);
33
            }
34 bae9fbba Jaroslav Hrubý
        }
35 87fd0356 Lukáš Vlček
36
        if (!redirecting /* && role === 'ANNOTATOR'*/) {
37
            // admin can also fetch data if he likes so
38 bae9fbba Jaroslav Hrubý
            fetchData();
39 8c45ccb0 hrubyjar
        }
40
    }, [logout, redirecting, role, router]);
41
42 bae9fbba Jaroslav Hrubý
    const columns = [
43
        {
44
            title: 'Název dokumentu',
45
            dataIndex: 'documentName',
46
            key: 'documentName',
47 0db53e25 Jaroslav Hrubý
            ...getColumnSearchProps('documentName', 'název'),
48 669ffe38 Jaroslav Hrubý
            // @ts-ignore
49
            sorter: (a, b) => a.documentName.localeCompare(b.documentName),
50 bae9fbba Jaroslav Hrubý
        },
51
        {
52
            title: 'Stav anotace',
53
            key: 'state',
54
            dataIndex: 'state',
55
            render: (state: string) => {
56
                let color = 'green';
57
                let label = 'Hotovo';
58 0db53e25 Jaroslav Hrubý
                let icon = <CheckCircleOutlined />;
59 bae9fbba Jaroslav Hrubý
                if (state === 'NEW') {
60
                    color = 'volcano';
61
                    label = 'Nový';
62 0db53e25 Jaroslav Hrubý
                    icon = <ClockCircleOutlined />;
63 bae9fbba Jaroslav Hrubý
                }
64
                if (state === 'IN_PROGRESS') {
65
                    color = 'orange';
66
                    label = 'Rozpracováno';
67 41a82611 Jaroslav Hrubý
                    icon = <SyncOutlined />;
68 bae9fbba Jaroslav Hrubý
                }
69
                return (
70 0db53e25 Jaroslav Hrubý
                    <Tag icon={icon} color={color} key={label}>
71 bae9fbba Jaroslav Hrubý
                        {label.toUpperCase()}
72
                    </Tag>
73
                );
74
            },
75 0db53e25 Jaroslav Hrubý
            filters: [
76
                {
77
                    text: 'Nový',
78
                    value: 'NEW',
79
                },
80
                {
81
                    text: 'Rozpracováno',
82
                    value: 'IN_PROGRESS',
83
                },
84
                {
85
                    text: 'Hotovo',
86
                    value: 'DONE',
87
                },
88
            ],
89
            // @ts-ignore
90
            onFilter: (value, record) => record.state.indexOf(value) === 0,
91
            // @ts-ignore
92
            sorter: (a, b) => a.state.length - b.state.length,
93
            sortDirections: ['descend', 'ascend'],
94 bae9fbba Jaroslav Hrubý
        },
95
        {
96
            title: '',
97
            key: 'action',
98
            dataIndex: 'annotationId',
99
            render: (anotationId: number) => (
100 06d1aa21 Jaroslav Hrubý
                <Button
101
                    key={anotationId}
102
                    type={'primary'}
103
                    onClick={() => router.push('/annotation/' + anotationId)}
104
                >
105 bae9fbba Jaroslav Hrubý
                    Anotovat
106
                </Button>
107
            ),
108
        },
109
    ];
110
111 87fd0356 Lukáš Vlček
    return redirecting /*|| role !== 'ANNOTATOR' */ ? null : (
112 8c45ccb0 hrubyjar
        <MainLayout>
113
            <Typography.Title level={2}>
114
                <FontAwesomeIcon icon={faFileLines} /> Dokumenty
115
            </Typography.Title>
116 06d1aa21 Jaroslav Hrubý
            <Table
117 669ffe38 Jaroslav Hrubý
                locale={{ ...getLocaleProps() }}
118 0db53e25 Jaroslav Hrubý
                // @ts-ignore
119 06d1aa21 Jaroslav Hrubý
                columns={columns}
120 0db53e25 Jaroslav Hrubý
                // @ts-ignore
121 06d1aa21 Jaroslav Hrubý
                dataSource={documents}
122
                size="small"
123
                scroll={{ y: 500 }}
124
            />
125 8c45ccb0 hrubyjar
        </MainLayout>
126
    );
127
}
128
129
export default UserDocumentPage;