Projekt

Obecné

Profil

Stáhnout (4.23 KB) Statistiky
| Větev: | Tag: | Revize:
1
import 'antd/dist/antd.css';
2
import React, { useContext, useEffect, useState } from 'react';
3

    
4
import { useUnauthRedirect } from '../../../hooks';
5
import { useRouter } from 'next/router';
6
import { Button, Input, Space, Table, Tag, Typography } from 'antd';
7
import { faFileLines } from '@fortawesome/free-solid-svg-icons';
8
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
9
import { LoggedUserContext } from '../../../contexts/LoggedUserContext';
10
import { MainLayout } from '../../../layouts/MainLayout';
11
import { userController } from '../../../controllers';
12
import { AnnotationListInfo } from '../../../api';
13
import {
14
    CheckCircleOutlined,
15
    ClockCircleOutlined,
16
    SyncOutlined,
17
} from '@ant-design/icons';
18
import { getColumnSearchProps, getLocaleProps } from '../../../utils/tableUtils';
19

    
20
function UserDocumentPage() {
21
    const redirecting = useUnauthRedirect('/login');
22
    const { logout, role } = useContext(LoggedUserContext);
23
    const [documents, setDocuments] = useState<AnnotationListInfo[]>([]);
24
    const router = useRouter();
25

    
26
    useEffect(() => {
27
        async function fetchData() {
28
            let docs = (await userController.userAnnotationsGet()).data.annotations;
29
            if (!docs) {
30
                setDocuments([]);
31
            } else {
32
                setDocuments(docs);
33
            }
34
        }
35

    
36
        if (!redirecting /* && role === 'ANNOTATOR'*/) {
37
            // admin can also fetch data if he likes so
38
            fetchData();
39
        }
40
    }, [logout, redirecting, role, router]);
41

    
42
    const columns = [
43
        {
44
            title: 'Název dokumentu',
45
            dataIndex: 'documentName',
46
            key: 'documentName',
47
            ...getColumnSearchProps('documentName', 'název'),
48
            // @ts-ignore
49
            sorter: (a, b) => a.documentName.localeCompare(b.documentName),
50
        },
51
        {
52
            title: 'Stav anotace',
53
            key: 'state',
54
            dataIndex: 'state',
55
            render: (state: string) => {
56
                let color = 'green';
57
                let label = 'Hotovo';
58
                let icon = <CheckCircleOutlined />;
59
                if (state === 'NEW') {
60
                    color = 'volcano';
61
                    label = 'Nový';
62
                    icon = <ClockCircleOutlined />;
63
                }
64
                if (state === 'IN_PROGRESS') {
65
                    color = 'orange';
66
                    label = 'Rozpracováno';
67
                    icon = <SyncOutlined />;
68
                }
69
                return (
70
                    <Tag icon={icon} color={color} key={label}>
71
                        {label.toUpperCase()}
72
                    </Tag>
73
                );
74
            },
75
            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
        },
95
        {
96
            title: '',
97
            key: 'action',
98
            dataIndex: 'annotationId',
99
            render: (anotationId: number) => (
100
                <Button
101
                    key={anotationId}
102
                    type={'primary'}
103
                    onClick={() => router.push('/annotation/' + anotationId)}
104
                >
105
                    Anotovat
106
                </Button>
107
            ),
108
        },
109
    ];
110

    
111
    return redirecting /*|| role !== 'ANNOTATOR' */ ? null : (
112
        <MainLayout>
113
            <Typography.Title level={2}>
114
                <FontAwesomeIcon icon={faFileLines} /> Dokumenty
115
            </Typography.Title>
116
            <Table
117
                locale={{ ...getLocaleProps() }}
118
                // @ts-ignore
119
                columns={columns}
120
                // @ts-ignore
121
                dataSource={documents}
122
                size="small"
123
                scroll={{ y: 500 }}
124
            />
125
        </MainLayout>
126
    );
127
}
128

    
129
export default UserDocumentPage;
    (1-1/1)