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 |
|
|
import { AnnotationListInfo } from '../../../api';
|
13 |
0db53e25
|
Jaroslav Hrubý
|
import {
|
14 |
|
|
CheckCircleOutlined,
|
15 |
|
|
ClockCircleOutlined,
|
16 |
|
|
SearchOutlined,
|
17 |
|
|
SyncOutlined,
|
18 |
|
|
} from '@ant-design/icons';
|
19 |
8c45ccb0
|
hrubyjar
|
|
20 |
|
|
function UserDocumentPage() {
|
21 |
|
|
const redirecting = useUnauthRedirect('/login');
|
22 |
|
|
const { logout, role } = useContext(LoggedUserContext);
|
23 |
06d1aa21
|
Jaroslav Hrubý
|
const [documents, setDocuments] = useState<AnnotationListInfo[]>([]);
|
24 |
0db53e25
|
Jaroslav Hrubý
|
const router = useRouter();
|
25 |
8c45ccb0
|
hrubyjar
|
|
26 |
|
|
useEffect(() => {
|
27 |
bae9fbba
|
Jaroslav Hrubý
|
async function fetchData() {
|
28 |
|
|
let docs = (await userController.userAnnotationsGet()).data.annotations;
|
29 |
06d1aa21
|
Jaroslav Hrubý
|
if (!docs) {
|
30 |
|
|
setDocuments([]);
|
31 |
|
|
} else {
|
32 |
|
|
setDocuments(docs);
|
33 |
|
|
}
|
34 |
bae9fbba
|
Jaroslav Hrubý
|
}
|
35 |
87fd0356
|
Lukáš Vlček
|
|
36 |
|
|
if (!redirecting /* && role === 'ANNOTATOR'*/) {
|
37 |
|
|
// admin can also fetch data if he likes so
|
38 |
bae9fbba
|
Jaroslav Hrubý
|
fetchData();
|
39 |
8c45ccb0
|
hrubyjar
|
}
|
40 |
|
|
}, [logout, redirecting, role, router]);
|
41 |
|
|
|
42 |
0db53e25
|
Jaroslav Hrubý
|
const handleSearch = (
|
43 |
|
|
selectedKeys: React.SetStateAction<string>[],
|
44 |
|
|
confirm: () => void
|
45 |
|
|
) => {
|
46 |
|
|
confirm();
|
47 |
|
|
};
|
48 |
|
|
|
49 |
|
|
const handleReset = (clearFilters: () => void) => {
|
50 |
|
|
clearFilters();
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
const getColumnSearchProps = (dataIndex: string, searchLabel: string) => ({
|
54 |
|
|
// @ts-ignore
|
55 |
|
|
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => (
|
56 |
|
|
<div style={{ padding: 8 }}>
|
57 |
|
|
<Input
|
58 |
|
|
placeholder={`Vyhledat ${searchLabel}`}
|
59 |
|
|
value={selectedKeys[0]}
|
60 |
|
|
onChange={(e) =>
|
61 |
|
|
setSelectedKeys(e.target.value ? [e.target.value] : [])
|
62 |
|
|
}
|
63 |
|
|
onPressEnter={() => handleSearch(selectedKeys, confirm)}
|
64 |
|
|
style={{ marginBottom: 8, display: 'block' }}
|
65 |
|
|
/>
|
66 |
|
|
<Space>
|
67 |
|
|
<Button
|
68 |
|
|
type="primary"
|
69 |
|
|
onClick={() => handleSearch(selectedKeys, confirm)}
|
70 |
|
|
icon={<SearchOutlined />}
|
71 |
|
|
style={{ width: 90 }}
|
72 |
|
|
>
|
73 |
|
|
Hledat
|
74 |
|
|
</Button>
|
75 |
|
|
<Button
|
76 |
|
|
onClick={() => handleReset(clearFilters)}
|
77 |
|
|
style={{ width: 90 }}
|
78 |
|
|
>
|
79 |
|
|
Smazat
|
80 |
|
|
</Button>
|
81 |
|
|
</Space>
|
82 |
|
|
</div>
|
83 |
|
|
),
|
84 |
|
|
filterIcon: (filtered: any) => (
|
85 |
|
|
<SearchOutlined style={{ color: filtered ? '#1890ff' : undefined }} />
|
86 |
|
|
),
|
87 |
|
|
onFilter: (value: string, record: { [x: string]: { toString: () => string } }) =>
|
88 |
|
|
record[dataIndex]
|
89 |
|
|
? record[dataIndex].toString().toLowerCase().includes(value.toLowerCase())
|
90 |
|
|
: '',
|
91 |
|
|
});
|
92 |
|
|
|
93 |
bae9fbba
|
Jaroslav Hrubý
|
const columns = [
|
94 |
|
|
{
|
95 |
|
|
title: 'Název dokumentu',
|
96 |
|
|
dataIndex: 'documentName',
|
97 |
|
|
key: 'documentName',
|
98 |
0db53e25
|
Jaroslav Hrubý
|
...getColumnSearchProps('documentName', 'název'),
|
99 |
bae9fbba
|
Jaroslav Hrubý
|
},
|
100 |
|
|
{
|
101 |
|
|
title: 'Stav anotace',
|
102 |
|
|
key: 'state',
|
103 |
|
|
dataIndex: 'state',
|
104 |
|
|
render: (state: string) => {
|
105 |
|
|
let color = 'green';
|
106 |
|
|
let label = 'Hotovo';
|
107 |
0db53e25
|
Jaroslav Hrubý
|
let icon = <CheckCircleOutlined />;
|
108 |
bae9fbba
|
Jaroslav Hrubý
|
if (state === 'NEW') {
|
109 |
|
|
color = 'volcano';
|
110 |
|
|
label = 'Nový';
|
111 |
0db53e25
|
Jaroslav Hrubý
|
icon = <ClockCircleOutlined />;
|
112 |
bae9fbba
|
Jaroslav Hrubý
|
}
|
113 |
|
|
if (state === 'IN_PROGRESS') {
|
114 |
|
|
color = 'orange';
|
115 |
|
|
label = 'Rozpracováno';
|
116 |
0db53e25
|
Jaroslav Hrubý
|
icon = <SyncOutlined spin />;
|
117 |
bae9fbba
|
Jaroslav Hrubý
|
}
|
118 |
|
|
return (
|
119 |
0db53e25
|
Jaroslav Hrubý
|
<Tag icon={icon} color={color} key={label}>
|
120 |
bae9fbba
|
Jaroslav Hrubý
|
{label.toUpperCase()}
|
121 |
|
|
</Tag>
|
122 |
|
|
);
|
123 |
|
|
},
|
124 |
0db53e25
|
Jaroslav Hrubý
|
filters: [
|
125 |
|
|
{
|
126 |
|
|
text: 'Nový',
|
127 |
|
|
value: 'NEW',
|
128 |
|
|
},
|
129 |
|
|
{
|
130 |
|
|
text: 'Rozpracováno',
|
131 |
|
|
value: 'IN_PROGRESS',
|
132 |
|
|
},
|
133 |
|
|
{
|
134 |
|
|
text: 'Hotovo',
|
135 |
|
|
value: 'DONE',
|
136 |
|
|
},
|
137 |
|
|
],
|
138 |
|
|
// @ts-ignore
|
139 |
|
|
onFilter: (value, record) => record.state.indexOf(value) === 0,
|
140 |
|
|
// @ts-ignore
|
141 |
|
|
sorter: (a, b) => a.state.length - b.state.length,
|
142 |
|
|
sortDirections: ['descend', 'ascend'],
|
143 |
bae9fbba
|
Jaroslav Hrubý
|
},
|
144 |
|
|
{
|
145 |
|
|
title: '',
|
146 |
|
|
key: 'action',
|
147 |
|
|
dataIndex: 'annotationId',
|
148 |
|
|
render: (anotationId: number) => (
|
149 |
06d1aa21
|
Jaroslav Hrubý
|
<Button
|
150 |
|
|
key={anotationId}
|
151 |
|
|
type={'primary'}
|
152 |
|
|
onClick={() => router.push('/annotation/' + anotationId)}
|
153 |
|
|
>
|
154 |
bae9fbba
|
Jaroslav Hrubý
|
Anotovat
|
155 |
|
|
</Button>
|
156 |
|
|
),
|
157 |
|
|
},
|
158 |
|
|
];
|
159 |
|
|
|
160 |
87fd0356
|
Lukáš Vlček
|
return redirecting /*|| role !== 'ANNOTATOR' */ ? null : (
|
161 |
8c45ccb0
|
hrubyjar
|
<MainLayout>
|
162 |
|
|
<Typography.Title level={2}>
|
163 |
|
|
<FontAwesomeIcon icon={faFileLines} /> Dokumenty
|
164 |
|
|
</Typography.Title>
|
165 |
06d1aa21
|
Jaroslav Hrubý
|
<Table
|
166 |
0db53e25
|
Jaroslav Hrubý
|
locale={{
|
167 |
|
|
triggerDesc: 'Seřadit sestupně',
|
168 |
|
|
triggerAsc: 'Seřadit vzestupně',
|
169 |
|
|
cancelSort: 'Vypnout řazení',
|
170 |
|
|
}}
|
171 |
|
|
// @ts-ignore
|
172 |
06d1aa21
|
Jaroslav Hrubý
|
columns={columns}
|
173 |
0db53e25
|
Jaroslav Hrubý
|
// @ts-ignore
|
174 |
06d1aa21
|
Jaroslav Hrubý
|
dataSource={documents}
|
175 |
|
|
size="small"
|
176 |
|
|
scroll={{ y: 500 }}
|
177 |
|
|
/>
|
178 |
8c45ccb0
|
hrubyjar
|
</MainLayout>
|
179 |
|
|
);
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
export default UserDocumentPage;
|