1 |
c197eb02
|
Jaroslav Hrubý
|
import { Badge, Button, Checkbox, Dropdown, List, Modal, Space, Table } from 'antd';
|
2 |
9bfa1e39
|
Jaroslav Hrubý
|
import 'antd/dist/antd.css';
|
3 |
|
|
import React, { useContext, useEffect, useState } from 'react';
|
4 |
c197eb02
|
Jaroslav Hrubý
|
import { DocumentListInfo, UserInfo } from '../../api';
|
5 |
|
|
import {
|
6 |
|
|
annotationController,
|
7 |
|
|
documentController,
|
8 |
|
|
userController,
|
9 |
|
|
} from '../../controllers';
|
10 |
9bfa1e39
|
Jaroslav Hrubý
|
import { useUnauthRedirect } from '../../hooks';
|
11 |
|
|
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
|
12 |
669ffe38
|
Jaroslav Hrubý
|
import { ShowToast } from '../../utils/alerts';
|
13 |
c197eb02
|
Jaroslav Hrubý
|
import { getColumnSearchProps, getLocaleProps } from '../../utils/tableUtils';
|
14 |
|
|
import { TableUserInfo } from '../types/TableUserInfo';
|
15 |
|
|
import { TableDocInfo } from '../types/TableDocInfo';
|
16 |
fabfbe32
|
Jaroslav Hrubý
|
import { ABadge, BadgeStyle } from '../common/ABadge';
|
17 |
|
|
import { ok } from 'assert';
|
18 |
9bfa1e39
|
Jaroslav Hrubý
|
|
19 |
|
|
interface ModalProps {
|
20 |
fabfbe32
|
Jaroslav Hrubý
|
onCancel: (ok: boolean) => void;
|
21 |
9bfa1e39
|
Jaroslav Hrubý
|
documentsIds: (string | undefined)[];
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
function AssignDocumentModal({ onCancel, documentsIds }: ModalProps) {
|
25 |
|
|
const redirecting = useUnauthRedirect('/login');
|
26 |
|
|
const { role } = useContext(LoggedUserContext);
|
27 |
c197eb02
|
Jaroslav Hrubý
|
const [users, setUsers] = useState<TableUserInfo[]>([]);
|
28 |
9bfa1e39
|
Jaroslav Hrubý
|
const [selectedUsers, setSelectedUsers] = useState<string[]>([]);
|
29 |
|
|
|
30 |
|
|
const handleOk = () => {
|
31 |
fabfbe32
|
Jaroslav Hrubý
|
onCancel(true);
|
32 |
9bfa1e39
|
Jaroslav Hrubý
|
};
|
33 |
|
|
|
34 |
|
|
const handleCancel = () => {
|
35 |
fabfbe32
|
Jaroslav Hrubý
|
onCancel(false);
|
36 |
9bfa1e39
|
Jaroslav Hrubý
|
};
|
37 |
|
|
|
38 |
c197eb02
|
Jaroslav Hrubý
|
async function fetchData() {
|
39 |
9bfa1e39
|
Jaroslav Hrubý
|
if (!redirecting && role === 'ADMINISTRATOR') {
|
40 |
c197eb02
|
Jaroslav Hrubý
|
const usrs = (await userController.usersGet()).data.users;
|
41 |
|
|
// @ts-ignore
|
42 |
|
|
const tableUsers: TableUserInfo[] = usrs?.map((usr, index) => {
|
43 |
|
|
return { key: index, ...usr };
|
44 |
9bfa1e39
|
Jaroslav Hrubý
|
});
|
45 |
c197eb02
|
Jaroslav Hrubý
|
setUsers(tableUsers || []);
|
46 |
9bfa1e39
|
Jaroslav Hrubý
|
}
|
47 |
c197eb02
|
Jaroslav Hrubý
|
}
|
48 |
|
|
|
49 |
|
|
useEffect(() => {
|
50 |
|
|
fetchData();
|
51 |
54a1e077
|
Dominik Poch
|
}, [documentsIds, redirecting, role]);
|
52 |
9bfa1e39
|
Jaroslav Hrubý
|
|
53 |
43d49a98
|
Jaroslav Hrubý
|
const handleUpload = async () => {
|
54 |
9bfa1e39
|
Jaroslav Hrubý
|
// console.log(documentsIds, selectedUsers);
|
55 |
|
|
if (documentsIds && documentsIds.length !== 0) {
|
56 |
669ffe38
|
Jaroslav Hrubý
|
await annotationController
|
57 |
|
|
.annotationsPost({
|
58 |
|
|
// @ts-ignore
|
59 |
|
|
documentIdList: documentsIds,
|
60 |
|
|
userIdList: selectedUsers,
|
61 |
|
|
})
|
62 |
|
|
.then((r) => {
|
63 |
|
|
ShowToast(
|
64 |
|
|
'Přiřazení dokumentů proběhlo úspěšně',
|
65 |
|
|
'success',
|
66 |
|
|
3000,
|
67 |
|
|
'top-end'
|
68 |
|
|
);
|
69 |
fabfbe32
|
Jaroslav Hrubý
|
onCancel(true);
|
70 |
669ffe38
|
Jaroslav Hrubý
|
});
|
71 |
9bfa1e39
|
Jaroslav Hrubý
|
}
|
72 |
|
|
};
|
73 |
|
|
|
74 |
c197eb02
|
Jaroslav Hrubý
|
const rowSelection = {
|
75 |
|
|
onChange: (selectedRowKeys: React.Key[], selectedRows: UserInfo[]) => {
|
76 |
|
|
// @ts-ignore
|
77 |
|
|
setSelectedUsers(selectedRows.map((row) => row.id));
|
78 |
|
|
},
|
79 |
|
|
};
|
80 |
|
|
|
81 |
|
|
const columns = [
|
82 |
|
|
{
|
83 |
|
|
title: 'Jméno',
|
84 |
|
|
dataIndex: 'name',
|
85 |
|
|
key: 'name',
|
86 |
|
|
...getColumnSearchProps('name', 'jméno'),
|
87 |
|
|
// @ts-ignore
|
88 |
|
|
sorter: (a, b) => a.name.localeCompare(b.name),
|
89 |
|
|
},
|
90 |
|
|
{
|
91 |
|
|
title: 'Příjmení',
|
92 |
|
|
dataIndex: 'surname',
|
93 |
|
|
key: 'surname',
|
94 |
|
|
...getColumnSearchProps('surname', 'příjmení'),
|
95 |
|
|
// @ts-ignore
|
96 |
|
|
sorter: (a, b) => a.surname.localeCompare(b.surname),
|
97 |
|
|
},
|
98 |
|
|
{
|
99 |
|
|
title: 'Uživatelské jméno',
|
100 |
|
|
dataIndex: 'username',
|
101 |
|
|
key: 'username',
|
102 |
|
|
...getColumnSearchProps('username', 'uživatelské jméno'),
|
103 |
|
|
// @ts-ignore
|
104 |
|
|
sorter: (a, b) => a.username.localeCompare(b.username),
|
105 |
|
|
},
|
106 |
|
|
{
|
107 |
|
|
title: 'Role',
|
108 |
|
|
dataIndex: 'role',
|
109 |
|
|
key: 'role',
|
110 |
|
|
filters: [
|
111 |
|
|
{
|
112 |
|
|
text: 'Administrátor',
|
113 |
|
|
value: 'ADMINISTRATOR',
|
114 |
|
|
},
|
115 |
|
|
{
|
116 |
|
|
text: 'Anotátor',
|
117 |
|
|
value: 'ANNOTATOR',
|
118 |
|
|
},
|
119 |
|
|
],
|
120 |
|
|
// @ts-ignore
|
121 |
|
|
onFilter: (value, record) => record.role.indexOf(value) === 0,
|
122 |
|
|
// @ts-ignore
|
123 |
|
|
sorter: (a, b) => a.username.localeCompare(b.username),
|
124 |
|
|
render: (role: string) => {
|
125 |
|
|
let label = '';
|
126 |
|
|
if (role === 'ANNOTATOR') {
|
127 |
|
|
label = 'Anotátor';
|
128 |
|
|
}
|
129 |
|
|
if (role === 'ADMINISTRATOR') {
|
130 |
|
|
label = 'Administrátor';
|
131 |
|
|
}
|
132 |
|
|
return label;
|
133 |
|
|
},
|
134 |
|
|
},
|
135 |
|
|
{
|
136 |
fabfbe32
|
Jaroslav Hrubý
|
title: 'Aktivní | Hotovo | Celkem',
|
137 |
c197eb02
|
Jaroslav Hrubý
|
key: 'docCounts',
|
138 |
|
|
align: 'center' as 'center',
|
139 |
|
|
dataIndex: 'assignedDocumentsCount',
|
140 |
|
|
// @ts-ignore
|
141 |
fabfbe32
|
Jaroslav Hrubý
|
render: (text, row) => (
|
142 |
c197eb02
|
Jaroslav Hrubý
|
<div>
|
143 |
fabfbe32
|
Jaroslav Hrubý
|
<ABadge style={BadgeStyle.WARNING}>
|
144 |
|
|
{row.newDocumentsCount + row.inProgressDocumentsCount}
|
145 |
|
|
</ABadge>
|
146 |
|
|
{' | '}
|
147 |
|
|
<ABadge style={BadgeStyle.SUCCESS}>
|
148 |
|
|
{row.finalizedDocumentsCount}
|
149 |
|
|
</ABadge>
|
150 |
|
|
{' | '}
|
151 |
|
|
<ABadge style={BadgeStyle.GENERAL}>
|
152 |
|
|
{row.finalizedDocumentsCount +
|
153 |
|
|
row.newDocumentsCount +
|
154 |
|
|
row.inProgressDocumentsCount}
|
155 |
|
|
</ABadge>
|
156 |
c197eb02
|
Jaroslav Hrubý
|
</div>
|
157 |
|
|
),
|
158 |
|
|
// @ts-ignore
|
159 |
fabfbe32
|
Jaroslav Hrubý
|
sorter: (a, b) =>
|
160 |
|
|
a.newDocumentsCount +
|
161 |
|
|
a.inProgressDocumentsCount -
|
162 |
|
|
(b.newDocumentsCount + b.inProgressDocumentsCount),
|
163 |
c197eb02
|
Jaroslav Hrubý
|
},
|
164 |
|
|
];
|
165 |
9bfa1e39
|
Jaroslav Hrubý
|
|
166 |
|
|
return (
|
167 |
|
|
<Modal
|
168 |
|
|
title="Přiřadit dokumenty"
|
169 |
|
|
onOk={handleOk}
|
170 |
|
|
visible={true}
|
171 |
|
|
onCancel={handleCancel}
|
172 |
fabfbe32
|
Jaroslav Hrubý
|
width={1100}
|
173 |
9bfa1e39
|
Jaroslav Hrubý
|
footer={[
|
174 |
|
|
<Button key="back" onClick={handleCancel}>
|
175 |
|
|
Storno
|
176 |
|
|
</Button>,
|
177 |
|
|
<Button key="submit" type="primary" onClick={handleUpload}>
|
178 |
|
|
Přiřadit
|
179 |
|
|
</Button>,
|
180 |
|
|
]}
|
181 |
|
|
>
|
182 |
c197eb02
|
Jaroslav Hrubý
|
<Table
|
183 |
|
|
locale={{ ...getLocaleProps() }}
|
184 |
|
|
rowSelection={{
|
185 |
|
|
type: 'checkbox',
|
186 |
|
|
...rowSelection,
|
187 |
|
|
}}
|
188 |
|
|
// @ts-ignore
|
189 |
|
|
columns={columns}
|
190 |
9bfa1e39
|
Jaroslav Hrubý
|
dataSource={users}
|
191 |
c197eb02
|
Jaroslav Hrubý
|
pagination={false}
|
192 |
|
|
scroll={{ y: 400 }}
|
193 |
9bfa1e39
|
Jaroslav Hrubý
|
/>
|
194 |
|
|
</Modal>
|
195 |
|
|
);
|
196 |
|
|
}
|
197 |
|
|
|
198 |
|
|
export default AssignDocumentModal;
|