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 |
bae9fbba
|
Jaroslav Hrubý
|
import { Button, 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 |
8c45ccb0
|
hrubyjar
|
|
14 |
|
|
function UserDocumentPage() {
|
15 |
|
|
const redirecting = useUnauthRedirect('/login');
|
16 |
|
|
const { logout, role } = useContext(LoggedUserContext);
|
17 |
|
|
const router = useRouter();
|
18 |
06d1aa21
|
Jaroslav Hrubý
|
const [documents, setDocuments] = useState<AnnotationListInfo[]>([]);
|
19 |
8c45ccb0
|
hrubyjar
|
|
20 |
|
|
useEffect(() => {
|
21 |
bae9fbba
|
Jaroslav Hrubý
|
async function fetchData() {
|
22 |
|
|
let docs = (await userController.userAnnotationsGet()).data.annotations;
|
23 |
06d1aa21
|
Jaroslav Hrubý
|
if (!docs) {
|
24 |
|
|
setDocuments([]);
|
25 |
|
|
} else {
|
26 |
|
|
setDocuments(docs);
|
27 |
|
|
}
|
28 |
bae9fbba
|
Jaroslav Hrubý
|
}
|
29 |
87fd0356
|
Lukáš Vlček
|
|
30 |
|
|
if (!redirecting /* && role === 'ANNOTATOR'*/) {
|
31 |
|
|
// admin can also fetch data if he likes so
|
32 |
bae9fbba
|
Jaroslav Hrubý
|
fetchData();
|
33 |
8c45ccb0
|
hrubyjar
|
}
|
34 |
|
|
}, [logout, redirecting, role, router]);
|
35 |
|
|
|
36 |
bae9fbba
|
Jaroslav Hrubý
|
const columns = [
|
37 |
|
|
{
|
38 |
|
|
title: 'Název dokumentu',
|
39 |
|
|
dataIndex: 'documentName',
|
40 |
|
|
key: 'documentName',
|
41 |
|
|
},
|
42 |
|
|
{
|
43 |
|
|
title: 'Stav anotace',
|
44 |
|
|
key: 'state',
|
45 |
|
|
dataIndex: 'state',
|
46 |
|
|
render: (state: string) => {
|
47 |
|
|
let color = 'green';
|
48 |
|
|
let label = 'Hotovo';
|
49 |
|
|
if (state === 'NEW') {
|
50 |
|
|
color = 'volcano';
|
51 |
|
|
label = 'Nový';
|
52 |
|
|
}
|
53 |
|
|
if (state === 'IN_PROGRESS') {
|
54 |
|
|
color = 'orange';
|
55 |
|
|
label = 'Rozpracováno';
|
56 |
|
|
}
|
57 |
|
|
return (
|
58 |
|
|
<Tag color={color} key={label}>
|
59 |
|
|
{label.toUpperCase()}
|
60 |
|
|
</Tag>
|
61 |
|
|
);
|
62 |
|
|
},
|
63 |
|
|
},
|
64 |
|
|
{
|
65 |
|
|
title: '',
|
66 |
|
|
key: 'action',
|
67 |
|
|
dataIndex: 'annotationId',
|
68 |
|
|
render: (anotationId: number) => (
|
69 |
06d1aa21
|
Jaroslav Hrubý
|
<Button
|
70 |
|
|
key={anotationId}
|
71 |
|
|
type={'primary'}
|
72 |
|
|
onClick={() => router.push('/annotation/' + anotationId)}
|
73 |
|
|
>
|
74 |
bae9fbba
|
Jaroslav Hrubý
|
Anotovat
|
75 |
|
|
</Button>
|
76 |
|
|
),
|
77 |
|
|
},
|
78 |
|
|
];
|
79 |
|
|
|
80 |
87fd0356
|
Lukáš Vlček
|
return redirecting /*|| role !== 'ANNOTATOR' */ ? null : (
|
81 |
8c45ccb0
|
hrubyjar
|
<MainLayout>
|
82 |
|
|
<Typography.Title level={2}>
|
83 |
|
|
<FontAwesomeIcon icon={faFileLines} /> Dokumenty
|
84 |
|
|
</Typography.Title>
|
85 |
06d1aa21
|
Jaroslav Hrubý
|
<Table
|
86 |
|
|
columns={columns}
|
87 |
|
|
dataSource={documents}
|
88 |
|
|
size="small"
|
89 |
|
|
scroll={{ y: 500 }}
|
90 |
|
|
/>
|
91 |
8c45ccb0
|
hrubyjar
|
</MainLayout>
|
92 |
|
|
);
|
93 |
|
|
}
|
94 |
|
|
|
95 |
|
|
export default UserDocumentPage;
|