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