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