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