Projekt

Obecné

Profil

Stáhnout (23.7 KB) Statistiky
| Větev: | Tag: | Revize:
1 8c45ccb0 hrubyjar
import 'antd/dist/antd.css';
2 3396af93 Dominik Poch
import React, { FocusEvent, useContext, useEffect, useState } from 'react';
3 8c45ccb0 hrubyjar
4
import { useUnauthRedirect } from '../../../hooks';
5
import { useRouter } from 'next/router';
6 937bfbee Jaroslav Hrubý
import { Button, Dropdown, Input, Menu, Row, Space, Table, Tag, Typography } from 'antd';
7 99a58334 Jaroslav Hrubý
import { faArrowsRotate, faFileLines, faUser } from '@fortawesome/free-solid-svg-icons';
8 8c45ccb0 hrubyjar
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
9
import { LoggedUserContext } from '../../../contexts/LoggedUserContext';
10 bae9fbba Jaroslav Hrubý
import { MainLayout } from '../../../layouts/MainLayout';
11 4a7bae81 Jaroslav Hrubý
import AddDocumentModal from '../../../components/modals/AddDocumentModal';
12 ff61085f Lukáš Vlček
import {
13 99a58334 Jaroslav Hrubý
    DeleteDocumentsRequest,
14 ff61085f Lukáš Vlček
    DocumentListInfo,
15 87a3d8d1 Lukáš Vlček
    DocumentListResponse,
16 ff61085f Lukáš Vlček
    DocumentUserInfo,
17
    EState,
18 99a58334 Jaroslav Hrubý
    ExportRequest,
19 ff61085f Lukáš Vlček
} from '../../../api';
20 c6109e2d Lukáš Vlček
import { documentController, userController } from '../../../controllers';
21 9bfa1e39 Jaroslav Hrubý
import AssignDocumentModal from '../../../components/modals/AssignDocumentModal';
22 99a58334 Jaroslav Hrubý
import { ShowConfirm, ShowConfirmDelete, ShowToast } from '../../../utils/alerts';
23 43d49a98 Jaroslav Hrubý
import { TableDocInfo } from '../../../components/types/TableDocInfo';
24 ff61085f Lukáš Vlček
import {
25
    getAnnotationStateColor,
26 c4f198c3 Jaroslav Hrubý
    getAnnotationStateString,
27 ff61085f Lukáš Vlček
    getNameTruncated,
28
    getUserInfoAlt,
29
} from '../../../utils/strings';
30 87a3d8d1 Lukáš Vlček
import { ABadge, BadgeStyle } from '../../../components/common/ABadge';
31 e7eca311 Lukáš Vlček
import SetRequiredAnnotationsCountModal from '../../../components/modals/SetRequiredAnnotationsCountModal';
32 d7167305 Jaroslav Hrubý
import DocPreviewModal from '../../../components/modals/DocPreviewModal';
33 0db53e25 Jaroslav Hrubý
import { UserFilter } from '../../../components/types/UserFilter';
34 669ffe38 Jaroslav Hrubý
import { getColumnSearchProps, getLocaleProps } from '../../../utils/tableUtils';
35 c4f198c3 Jaroslav Hrubý
import { SweetAlertIcon } from 'sweetalert2';
36 3396af93 Dominik Poch
import { Stack } from 'react-bootstrap';
37 fa93df26 Dominik Poch
38
import { faCircleCheck, faClock } from '@fortawesome/free-regular-svg-icons';
39
import styles from '/styles/Icon.module.scss';
40 937bfbee Jaroslav Hrubý
import { FileSearchOutlined, UserDeleteOutlined } from '@ant-design/icons';
41 fa93df26 Dominik Poch
42 8c45ccb0 hrubyjar
function AdminDocumentPage() {
43
    const redirecting = useUnauthRedirect('/login');
44
    const { logout, role } = useContext(LoggedUserContext);
45 c4f198c3 Jaroslav Hrubý
    const [finalizing, setFinalizing] = React.useState(false);
46 9bfa1e39 Jaroslav Hrubý
    const [visibleAdd, setVisibleAdd] = React.useState(false);
47
    const [visibleAssign, setVisibleAssign] = React.useState(false);
48 d7167305 Jaroslav Hrubý
    const [visiblePreview, setVisiblePreview] = React.useState(false);
49 e7eca311 Lukáš Vlček
    const [visibleSetCount, setVisibleSetCount] = React.useState(false);
50
51 8c45ccb0 hrubyjar
    const router = useRouter();
52
53 43d49a98 Jaroslav Hrubý
    const [documents, setDocuments] = useState<TableDocInfo[]>([]);
54 0db53e25 Jaroslav Hrubý
    const [userFilters, setUserFilters] = useState<UserFilter[]>([]);
55 cca0bfa0 Lukáš Vlček
    const [selectedDocs, setSelectedDocs] = useState<string[]>([]);
56 db3fa00e Jaroslav Hrubý
    const [selectedRows, setSelectedRows] = useState([]);
57 d7167305 Jaroslav Hrubý
    const [previewDocContent, setPreviewDocContent] = useState<string>();
58
    const [previewDocName, setPreviewDocName] = useState<string>();
59 3396af93 Dominik Poch
    const [annotationCount, setAnnotationCount] = useState<number>();
60 c6109e2d Lukáš Vlček
61 43d49a98 Jaroslav Hrubý
    async function fetchData() {
62 ef5792a8 Lukáš Vlček
        const docs = (await documentController.documentsGet()).data.documents;
63 43d49a98 Jaroslav Hrubý
        // @ts-ignore
64
        const tableDocs: TableDocInfo[] = docs?.map((doc, index) => {
65
            return { key: index, ...doc };
66
        });
67 9bfa1e39 Jaroslav Hrubý
68 0db53e25 Jaroslav Hrubý
        const users = (await userController.usersGet()).data.users;
69
        // @ts-ignore
70
        const filters: UserFilter[] = users?.map((user) => {
71
            return {
72 99a58334 Jaroslav Hrubý
                text: user.surname + ' ' + user.name,
73 0db53e25 Jaroslav Hrubý
                value: user.username,
74
            };
75
        });
76
        setUserFilters(filters);
77
78 3396af93 Dominik Poch
        let annotationCountRes =
79
            await documentController.documentsRequiredAnnotationsGlobalGet();
80
        setAnnotationCount(annotationCountRes.data.requiredAnnotationsGlobal);
81
82 43d49a98 Jaroslav Hrubý
        if (!docs) {
83
            setDocuments([]);
84
        } else {
85
            setDocuments(tableDocs);
86 c6109e2d Lukáš Vlček
        }
87 43d49a98 Jaroslav Hrubý
    }
88 c6109e2d Lukáš Vlček
89 43d49a98 Jaroslav Hrubý
    useEffect(() => {
90 06d1aa21 Jaroslav Hrubý
        if (!redirecting && role === 'ADMINISTRATOR') {
91 c6109e2d Lukáš Vlček
            fetchData();
92 8c45ccb0 hrubyjar
        }
93
    }, [logout, redirecting, role, router]);
94
95 c4f198c3 Jaroslav Hrubý
    const finalizeDocumentConfirm = async (
96
        document: DocumentListInfo,
97
        recreate: boolean
98
    ) => {
99
        let desc = recreate ? 'Dosavadní změny finální verze budou smazány' : '';
100
        let icon: SweetAlertIcon = recreate ? 'warning' : 'question';
101
102
        const doneAnnotations = document.annotatingUsers?.filter(
103
            (usr) => usr.state === EState.Done
104
        ).length;
105
106
        if (
107
            doneAnnotations !== undefined &&
108
            document.requiredAnnotations !== undefined &&
109
            doneAnnotations < document.requiredAnnotations
110
        ) {
111
            icon = 'warning';
112
            desc =
113
                'Není dokončen požadovaný počet anotací <br /> (dokončeno ' +
114
                doneAnnotations +
115
                ' z ' +
116
                document.requiredAnnotations +
117
                ')';
118
        }
119
        recreate
120
            ? ShowConfirm(
121
                  () => finalizeDocument(document.id),
122
                  'vytvořit novou finální verzi dokumentu',
123
                  desc,
124
                  icon
125
              )
126
            : ShowConfirm(
127
                  () => finalizeDocument(document.id),
128
                  'vytvořit finální verzi dokumentu',
129
                  desc,
130
                  icon
131
              );
132
    };
133
134
    const finalizeDocument = async (documentId: string | undefined) => {
135
        setFinalizing(true);
136
        const finalAnnotationId = (
137
            await documentController.documentDocumentIdFinalPost(
138
                documentId ? documentId : ''
139
            )
140
        ).data.finalAnnotationId;
141
        if (!finalAnnotationId) {
142
            ShowToast('Finální verzi se nepovedlo vytvořit', 'error');
143
        } else {
144
            router.push({
145
                pathname: '/annotation/[annotationId]',
146
                query: { annotationId: finalAnnotationId, final: true },
147
            });
148
        }
149
        setFinalizing(false);
150
    };
151
152
    const editFinalizedDocument = async (finalAnnotationId: string) => {
153
        setFinalizing(true);
154
        if (!finalAnnotationId) {
155
            ShowToast('Finální verze dosud neexistuje', 'warning');
156
        } else {
157
            router.push({
158
                pathname: '/annotation/[annotationId]',
159
                query: { annotationId: finalAnnotationId, final: true },
160
            });
161
        }
162
        setFinalizing(false);
163
    };
164
165 ef5792a8 Lukáš Vlček
    async function removeUserFromDocument(documentID: string, annotatorID: string) {
166
        const res =
167
            await documentController.documentsDocumentIdAnnotatorsAnnotatorIdDelete(
168
                documentID,
169
                annotatorID
170
            );
171
172
        if (res.status === 200) {
173
            ShowToast('Uživatel byl úspěšně odebrán z dokumentu');
174
        }
175
        await fetchData();
176
    }
177
178 c4f198c3 Jaroslav Hrubý
    const getFinalizationStateIcon = (state: EState) => {
179
        const color = getAnnotationStateColor(state);
180
        const label = getAnnotationStateString(state);
181 fa93df26 Dominik Poch
        let icon = <FontAwesomeIcon icon={faCircleCheck} className={styles.iconLeft} />;
182 c4f198c3 Jaroslav Hrubý
        if (state === 'NEW') {
183 fa93df26 Dominik Poch
            icon = <FontAwesomeIcon icon={faClock} className={styles.iconLeft} />;
184 c4f198c3 Jaroslav Hrubý
        }
185
        if (state === 'IN_PROGRESS') {
186 fa93df26 Dominik Poch
            icon = <FontAwesomeIcon icon={faArrowsRotate} className={styles.iconLeft} />;
187 c4f198c3 Jaroslav Hrubý
        }
188
189
        return (
190
            <Tag icon={icon} color={color} key={label}>
191
                {label.toUpperCase()}
192
            </Tag>
193
        );
194
    };
195
196 9bfa1e39 Jaroslav Hrubý
    const showAssignModal = () => {
197
        if (selectedDocs.length == 0) {
198
            ShowToast('Vyberte dokument pro přiřazení', 'warning', 3000, 'top-end');
199
        } else {
200
            setVisibleAssign(true);
201
        }
202
    };
203 e7eca311 Lukáš Vlček
    const showRequiredAnnotationsCountModal = () => {
204
        if (selectedDocs.length == 0) {
205
            ShowToast(
206
                'Vyberte dokument, pro které chcete nastavit požadovaný počet anotací',
207
                'warning',
208
                3000,
209
                'top-end'
210
            );
211
        } else {
212
            setVisibleSetCount(true);
213
        }
214
    };
215 9bfa1e39 Jaroslav Hrubý
    const showAddModal = () => {
216
        setVisibleAdd(true);
217 4a7bae81 Jaroslav Hrubý
    };
218
219 d7167305 Jaroslav Hrubý
    const showPreviewModal = async (id: string, name: string) => {
220
        const documentContent = (await documentController.documentDocumentIdGet(id)).data
221
            .content;
222 e97b42bc Jaroslav Hrubý
        if (documentContent) {
223
            setPreviewDocName(name);
224
            setPreviewDocContent(documentContent);
225
            setVisiblePreview(true);
226
        }
227 d7167305 Jaroslav Hrubý
    };
228
229 99a58334 Jaroslav Hrubý
    const deleteDocuments = () => {
230
        const req: DeleteDocumentsRequest = { documentIds: selectedDocs };
231
232
        ShowConfirmDelete(() => {
233
            documentController.documentsDelete(req).then(() => {
234
                ShowToast('Dokumenty byly úspěšně odstraněny');
235
                fetchData();
236 db3fa00e Jaroslav Hrubý
                clearSelection();
237 99a58334 Jaroslav Hrubý
            });
238
        }, 'dokumenty');
239
    };
240
241 9e60bee1 Lukáš Vlček
    const exportDocuments = async () => {
242 99a58334 Jaroslav Hrubý
        const req: ExportRequest = { documentIds: selectedDocs };
243 9e60bee1 Lukáš Vlček
        const res = await documentController.documentsExportPost(req);
244
        if (res?.data) {
245
            download(res.data, 'export.zip');
246 db3fa00e Jaroslav Hrubý
            clearSelection();
247 9e60bee1 Lukáš Vlček
        }
248 99a58334 Jaroslav Hrubý
    };
249
250 9e60bee1 Lukáš Vlček
    function download(baseData: string, filename: string) {
251
        if (!baseData) {
252
            console.log('base data null');
253
            return;
254
        }
255
256
        const linkSource = `data:application/zip;base64,${baseData}`;
257
        const downloadLink = document.createElement('a');
258
259
        downloadLink.href = linkSource;
260
        downloadLink.download = filename;
261
        downloadLink.click();
262
263
        // Clean up and remove the link
264
        // downloadLink.parentNode.removeChild(downloadLink);
265
    }
266
267 3396af93 Dominik Poch
    const changeDefaultAnotationCount = (e: FocusEvent<HTMLInputElement>) => {
268
        documentController.documentsRequiredAnnotationsGlobalPost({
269
            requiredAnnotations: parseInt(e.currentTarget.value),
270
        });
271
    };
272
273 db3fa00e Jaroslav Hrubý
    const hideModalWithClear = () => {
274 43d49a98 Jaroslav Hrubý
        fetchData();
275 9bfa1e39 Jaroslav Hrubý
        setVisibleAssign(false);
276 e7eca311 Lukáš Vlček
        setVisibleSetCount(false);
277 db3fa00e Jaroslav Hrubý
        clearSelection();
278
    };
279
280
    const hideModal = () => {
281
        fetchData();
282
        setVisibleAdd(false);
283 d7167305 Jaroslav Hrubý
        setVisiblePreview(false);
284 8c45ccb0 hrubyjar
    };
285
286 937bfbee Jaroslav Hrubý
    const removeUserDocument = (user: DocumentUserInfo, record: DocumentListInfo) => {
287
        ShowConfirm(
288
            async () => {
289
                if (!record.id || !user?.id) {
290
                    return;
291
                }
292
                await removeUserFromDocument(record.id, user.id);
293
            },
294
            'odebrat uživatele ' +
295
                user.name +
296
                ' ' +
297
                user.surname +
298
                ' (' +
299
                user.username +
300
                ') z tohoto dokumentu',
301
            'Dosavadní postup tohoto anotátora na daném dokumentu bude nenávratně smazán'
302
        );
303
    };
304
305
    const menu = (user: DocumentUserInfo, record: DocumentListInfo) => {
306
        return (
307
            <Menu>
308 1eaf63cd Jaroslav Hrubý
                <Menu.ItemGroup
309
                    title={
310
                        <div>
311
                            <Row>
312
                                <Typography.Text>
313
                                    {getNameTruncated(user) + ' (' + user.username + ')'}
314
                                </Typography.Text>
315
                            </Row>
316
                            <Row>
317
                                <Typography.Text>
318
                                    {user.state
319
                                        ? 'stav anotace: ' +
320
                                          getAnnotationStateString(user.state)
321
                                        : ''}
322
                                </Typography.Text>
323
                            </Row>
324
                        </div>
325
                    }
326
                >
327 937bfbee Jaroslav Hrubý
                    <Menu.Item
328
                        icon={<FileSearchOutlined />}
329
                        onClick={() =>
330
                            router.push({
331
                                pathname: '/annotation/[annotationId]',
332
                                query: { annotationId: user.annotationId, final: false },
333
                            })
334
                        }
335
                    >
336
                        Zobrazit anotaci
337
                    </Menu.Item>
338
                    <Menu.Item
339
                        icon={<UserDeleteOutlined />}
340
                        onClick={() => removeUserDocument(user, record)}
341
                    >
342
                        Odebrat
343
                    </Menu.Item>
344
                </Menu.ItemGroup>
345
            </Menu>
346
        );
347
    };
348
349 ef5792a8 Lukáš Vlček
    function getUserTag(user: DocumentUserInfo, record: DocumentListInfo) {
350
        return (
351 937bfbee Jaroslav Hrubý
            <Dropdown overlay={menu(user, record)}>
352
                <Space
353
                    size={2}
354 ef5792a8 Lukáš Vlček
                    style={{
355 937bfbee Jaroslav Hrubý
                        paddingRight: 10,
356 ef5792a8 Lukáš Vlček
                        color: getAnnotationStateColor(user.state),
357
                    }}
358
                >
359
                    <FontAwesomeIcon
360
                        icon={faUser}
361
                        title={getUserInfoAlt(user)}
362
                        className={'me-2'}
363
                    />
364
                    {record.finalAnnotations?.some(
365
                        (annot) => annot.userId === user.id
366
                    ) ? (
367
                        <u>{getNameTruncated(user)}</u>
368
                    ) : (
369
                        getNameTruncated(user)
370
                    )}
371 937bfbee Jaroslav Hrubý
                </Space>
372
            </Dropdown>
373 ef5792a8 Lukáš Vlček
        );
374
    }
375
376 c6109e2d Lukáš Vlček
    const columns = [
377
        {
378
            title: 'Název dokumentu',
379
            dataIndex: 'name',
380
            key: 'name',
381 eba090c1 Lukáš Vlček
            width: '30%',
382 0db53e25 Jaroslav Hrubý
            ...getColumnSearchProps('name', 'název'),
383 669ffe38 Jaroslav Hrubý
            sorter: {
384
                // @ts-ignore
385
                compare: (a, b) => a.name.localeCompare(b.name),
386
                multiple: 2,
387
            },
388 c6109e2d Lukáš Vlček
        },
389
        {
390
            title: 'Délka',
391
            dataIndex: 'length',
392
            key: 'length',
393 eba090c1 Lukáš Vlček
            width: '5%',
394 c4f198c3 Jaroslav Hrubý
            align: 'center' as 'center',
395 0db53e25 Jaroslav Hrubý
            sorter: {
396
                // @ts-ignore
397
                compare: (a, b) => a.length - b.length,
398
                multiple: 1,
399
            },
400 c6109e2d Lukáš Vlček
        },
401 87a3d8d1 Lukáš Vlček
        {
402
            title: 'Dokončeno | přiřazeno | vyžadováno',
403
            key: 'annotationCounts',
404 c4f198c3 Jaroslav Hrubý
            width: '15%',
405
            align: 'center' as 'center',
406 87a3d8d1 Lukáš Vlček
            render: (
407
                columnData: DocumentListResponse,
408
                record: DocumentListInfo,
409
                index: number
410
            ) => {
411
                const finished =
412
                    record.annotatingUsers?.filter((d) => d.state === EState.Done)
413
                        .length ?? 0;
414
415
                return (
416
                    <div>
417
                        <ABadge
418
                            style={
419
                                finished === record.annotatingUsers?.length
420
                                    ? BadgeStyle.SUCCESS
421
                                    : BadgeStyle.WARNING
422
                            }
423
                        >
424
                            {finished}
425
                        </ABadge>
426
                        {' | '}
427
                        <ABadge
428
                            style={
429 ef2143b8 Lukáš Vlček
                                (record.annotatingUsers?.length ?? 0) >=
430
                                (record.requiredAnnotations ?? 0)
431 87a3d8d1 Lukáš Vlček
                                    ? BadgeStyle.SUCCESS
432
                                    : BadgeStyle.WARNING
433
                            }
434
                        >
435
                            {record.annotatingUsers?.length}
436
                        </ABadge>
437
                        {' | '}
438
                        <ABadge style={BadgeStyle.GENERAL}>
439
                            {record.requiredAnnotations}
440
                        </ABadge>
441
                    </div>
442
                );
443
            },
444
        },
445 c6109e2d Lukáš Vlček
        {
446
            title: 'Anotátoři',
447
            dataIndex: 'annotatingUsers',
448
            key: 'annotatingUsers',
449 c4f198c3 Jaroslav Hrubý
            width: '20%',
450 ff61085f Lukáš Vlček
            render: (
451
                columnData: DocumentUserInfo[],
452
                record: DocumentListInfo,
453
                index: number
454
            ) => {
455 ef5792a8 Lukáš Vlček
                return <div>{columnData.map((e) => getUserTag(e, record))}</div>;
456 c6109e2d Lukáš Vlček
            },
457 0db53e25 Jaroslav Hrubý
            filters: userFilters,
458
            filterSearch: true,
459
            // @ts-ignore
460
            onFilter: (value, record) =>
461
                // @ts-ignore
462
                record.annotatingUsers.find((user) => user['username'] === value),
463
            sorter: {
464
                // @ts-ignore
465
                compare: (a, b) => a.annotatingUsers.length - b.annotatingUsers.length,
466 669ffe38 Jaroslav Hrubý
                multiple: 3,
467 0db53e25 Jaroslav Hrubý
            },
468 c6109e2d Lukáš Vlček
        },
469 d7167305 Jaroslav Hrubý
        {
470
            title: '',
471
            key: 'action',
472
            dataIndex: ['id', 'name'],
473 c4f198c3 Jaroslav Hrubý
            align: 'center' as 'center',
474 4eaee414 Lukáš Vlček
            width: '10%',
475 d7167305 Jaroslav Hrubý
            // @ts-ignore
476
            render: (text, row) => (
477 eba090c1 Lukáš Vlček
                <Button
478
                    style={{ width: '80px' }}
479
                    key={row.id}
480
                    onClick={() => showPreviewModal(row.id, row.name)}
481
                >
482 d7167305 Jaroslav Hrubý
                    Náhled
483
                </Button>
484
            ),
485
        },
486 c4f198c3 Jaroslav Hrubý
        {
487
            title: 'Finální verze dokumentu',
488
            key: 'final',
489
            dataIndex: ['id', 'finalizedExists'],
490 4eaee414 Lukáš Vlček
            width: '20%',
491 c4f198c3 Jaroslav Hrubý
            // @ts-ignore
492
            render: (text, row) =>
493
                row.finalizedExists ? (
494 eba090c1 Lukáš Vlček
                    <>
495
                        <Row>
496
                            <Space>
497
                                <Button
498
                                    disabled={finalizing}
499 8b02c5d8 Jaroslav Hrubý
                                    onClick={() => finalizeDocumentConfirm(row, true)}
500 eba090c1 Lukáš Vlček
                                >
501
                                    Znovu vytvořit
502
                                </Button>
503
                            </Space>
504
                        </Row>
505
                        <Row style={{ marginTop: '5px' }}>
506
                            <Space>
507
                                <Button
508
                                    disabled={finalizing}
509
                                    onClick={() =>
510
                                        editFinalizedDocument(row.finalizedAnnotationId)
511
                                    }
512
                                >
513
                                    Upravit
514
                                </Button>
515
                                {getFinalizationStateIcon(row.finalizedState)}
516
                            </Space>
517
                        </Row>
518
                    </>
519 c4f198c3 Jaroslav Hrubý
                ) : (
520
                    <Button
521
                        disabled={finalizing}
522
                        onClick={() => finalizeDocumentConfirm(row, false)}
523
                    >
524
                        Finalizovat
525
                    </Button>
526
                ),
527
            filters: [
528
                {
529
                    text: 'Nefinalizováno',
530
                    value: null,
531
                },
532
                {
533
                    text: 'Nový',
534
                    value: 'NEW',
535
                },
536
                {
537
                    text: 'Rozpracováno',
538
                    value: 'IN_PROGRESS',
539
                },
540
                {
541
                    text: 'Hotovo',
542
                    value: 'DONE',
543
                },
544
            ],
545
            // @ts-ignore
546
            onFilter: (value, record) => record.finalizedState === value,
547
        },
548 c6109e2d Lukáš Vlček
    ];
549
550 db3fa00e Jaroslav Hrubý
    const clearSelection = () => {
551
        setSelectedRows([]);
552
    };
553
554
    const onSelectChange = (
555
        selectedRowKeys: React.Key[],
556
        selectedRows: DocumentListInfo[]
557
    ) => {
558
        // @ts-ignore
559
        setSelectedDocs(selectedRows.map((row) => row.id));
560
        // @ts-ignore
561
        setSelectedRows(selectedRowKeys);
562
    };
563
564 9bfa1e39 Jaroslav Hrubý
    const rowSelection = {
565 db3fa00e Jaroslav Hrubý
        selectedRowKeys: selectedRows,
566
        onChange: onSelectChange,
567 9bfa1e39 Jaroslav Hrubý
    };
568
569 8c45ccb0 hrubyjar
    return redirecting || role !== 'ADMINISTRATOR' ? null : (
570
        <MainLayout>
571 c3b99cdb Lukáš Vlček
            <div
572
                style={{
573
                    display: 'flex',
574
                    flexDirection: 'row',
575
                    justifyContent: 'space-between',
576
                    flexWrap: 'wrap',
577
                }}
578
            >
579
                <Typography.Title level={2}>
580
                    <FontAwesomeIcon icon={faFileLines} /> Dokumenty
581
                </Typography.Title>
582
583
                <Stack
584
                    style={{
585
                        width: '400px',
586
                        border: '1px solid lightgray',
587
                        borderRadius: 3,
588
                        padding: 10,
589
                        marginBottom: 30,
590
                        display: 'flex',
591
                        flexDirection: 'row',
592
                        justifyContent: 'space-between',
593
                    }}
594
                    direction="horizontal"
595
                    key={annotationCount}
596
                >
597
                    <span>Výchozí požadovaný počet anotací:</span>
598
                    <Input
599
                        style={{ width: '100px' }}
600
                        defaultValue={annotationCount}
601
                        onBlur={changeDefaultAnotationCount}
602
                    />
603
                </Stack>
604
            </div>
605
606
            <div
607
                style={{
608
                    padding: '10px',
609
                    display: 'flex',
610
                    flexDirection: 'row',
611
                    justifyContent: 'flex-start',
612
                    gap: '20px',
613 99a58334 Jaroslav Hrubý
                    marginBottom: '20px',
614 c3b99cdb Lukáš Vlček
                }}
615
            >
616
                <Button type={'primary'} onClick={showAddModal}>
617
                    Nahrát dokument
618
                </Button>
619
620 9e60bee1 Lukáš Vlček
                <div style={{ display: 'flex', gap: '3px', flexWrap: 'wrap' }}>
621 792f82f0 Lukáš Vlček
                    <Button
622
                        danger
623
                        disabled={!(selectedDocs?.length > 0)}
624
                        onClick={() => deleteDocuments()}
625
                    >
626
                        Smazat dokumenty
627
                    </Button>
628 99a58334 Jaroslav Hrubý
629 792f82f0 Lukáš Vlček
                    <Button
630
                        disabled={!(selectedDocs?.length > 0)}
631
                        onClick={() => exportDocuments()}
632
                    >
633
                        Export
634
                    </Button>
635 c3b99cdb Lukáš Vlček
                    <Button
636
                        onClick={showAssignModal}
637
                        disabled={!(selectedDocs?.length > 0)}
638
                    >
639
                        Přiřadit vybrané dokumenty uživatelům
640
                    </Button>
641
                    <Button
642
                        onClick={showRequiredAnnotationsCountModal}
643
                        disabled={!(selectedDocs?.length > 0)}
644
                    >
645
                        Nastavit požadovaný počet anotací vybraným dokumentům
646
                    </Button>
647
                </div>
648
            </div>
649 3396af93 Dominik Poch
650 9bfa1e39 Jaroslav Hrubý
            {visibleAdd && <AddDocumentModal onCancel={hideModal} />}
651
            {visibleAssign && (
652 db3fa00e Jaroslav Hrubý
                <AssignDocumentModal
653
                    documentsIds={selectedDocs}
654
                    onCancel={hideModalWithClear}
655
                />
656 9bfa1e39 Jaroslav Hrubý
            )}
657 d7167305 Jaroslav Hrubý
            {visiblePreview && (
658
                <DocPreviewModal
659
                    onCancel={hideModal}
660 329a602d Jaroslav Hrubý
                    documentName={previewDocName ?? ''}
661
                    content={
662
                        previewDocContent ?? 'Nastala chyba při načítání obsahu dokumentu'
663 cca0bfa0 Lukáš Vlček
                    }
664
                />
665 d8873409 Vojtěch Bartička
            )}
666 e7eca311 Lukáš Vlček
            {visibleSetCount && (
667
                <SetRequiredAnnotationsCountModal
668
                    documentsIds={selectedDocs}
669 db3fa00e Jaroslav Hrubý
                    onCancel={hideModalWithClear}
670 d7167305 Jaroslav Hrubý
                />
671
            )}
672 c6109e2d Lukáš Vlček
673
            <Table
674 669ffe38 Jaroslav Hrubý
                locale={{ ...getLocaleProps() }}
675 db3fa00e Jaroslav Hrubý
                rowSelection={rowSelection}
676 0db53e25 Jaroslav Hrubý
                // @ts-ignore
677 c6109e2d Lukáš Vlček
                columns={columns}
678
                dataSource={documents}
679 9bfa1e39 Jaroslav Hrubý
                size="middle"
680 99a58334 Jaroslav Hrubý
                scroll={{ y: 'calc(65vh - 4em)' }}
681
                pagination={false}
682 c6109e2d Lukáš Vlček
            />
683 8c45ccb0 hrubyjar
        </MainLayout>
684
    );
685
}
686
687
export default AdminDocumentPage;