Revize e7eca311
Přidáno uživatelem Lukáš Vlček před téměř 3 roky(ů)
webapp/components/modals/SetRequiredAnnotationsCountModal.tsx | ||
---|---|---|
1 |
import { Button, Form, Input, Modal } from 'antd'; |
|
2 |
import 'antd/dist/antd.css'; |
|
3 |
import React from 'react'; |
|
4 |
import { SetRequiredAnnotationsRequest } from '../../api'; |
|
5 |
import { documentController } from '../../controllers'; |
|
6 |
import { ShowToast } from '../../utils/alerts'; |
|
7 | ||
8 |
interface ModalProps { |
|
9 |
onCancel: () => void; |
|
10 |
documentsIds: string[]; |
|
11 |
} |
|
12 | ||
13 |
function SetRequiredAnnotationsCountModal({ onCancel, documentsIds }: ModalProps) { |
|
14 |
const handleOk = () => { |
|
15 |
onCancel(); |
|
16 |
}; |
|
17 | ||
18 |
const handleCancel = () => { |
|
19 |
onCancel(); |
|
20 |
}; |
|
21 | ||
22 |
const onFinish = async (values: any) => { |
|
23 |
if (documentsIds && documentsIds.length !== 0) { |
|
24 |
const req: SetRequiredAnnotationsRequest = { |
|
25 |
requiredAnnotations: values.annotationsCount, |
|
26 |
documentIds: documentsIds, |
|
27 |
}; |
|
28 | ||
29 |
await documentController.documentsRequiredAnnotationsPost(req); |
|
30 | ||
31 |
ShowToast( |
|
32 |
'Požadovaný počet anotací úspěšně nastaven', |
|
33 |
'success', |
|
34 |
3000, |
|
35 |
'top-end' |
|
36 |
); |
|
37 |
} |
|
38 | ||
39 |
handleOk(); |
|
40 |
}; |
|
41 | ||
42 |
const onFinishFailed = (errorInfo: any) => { |
|
43 |
ShowToast('Zadané údaje nejsou validní', 'error', 3000, 'top-end'); |
|
44 |
}; |
|
45 | ||
46 |
return ( |
|
47 |
<Modal |
|
48 |
title={'Nastavit požadovaný počet anotací'} |
|
49 |
onOk={handleOk} |
|
50 |
visible={true} |
|
51 |
onCancel={handleCancel} |
|
52 |
footer={null} |
|
53 |
width={400} |
|
54 |
centered |
|
55 |
> |
|
56 |
<Form |
|
57 |
onFinish={onFinish} |
|
58 |
onFinishFailed={onFinishFailed} |
|
59 |
autoComplete="off" |
|
60 |
labelCol={{ span: 4 }} |
|
61 |
layout="horizontal" |
|
62 |
> |
|
63 |
Požadovaný počet anotací: |
|
64 |
<Form.Item |
|
65 |
name="annotationsCount" |
|
66 |
rules={[ |
|
67 |
{ |
|
68 |
required: true, |
|
69 |
message: 'Zadejte počet anotací', |
|
70 |
}, |
|
71 |
]} |
|
72 |
> |
|
73 |
<Input placeholder="Počet anotací" /> |
|
74 |
</Form.Item> |
|
75 |
<Form.Item> |
|
76 |
<Button type="primary" htmlType="submit" className="w-100"> |
|
77 |
Změnit |
|
78 |
</Button> |
|
79 |
</Form.Item> |
|
80 |
</Form> |
|
81 |
</Modal> |
|
82 |
); |
|
83 |
} |
|
84 | ||
85 |
export default SetRequiredAnnotationsCountModal; |
webapp/pages/documents/admin/index.tsx | ||
---|---|---|
25 | 25 |
getUserInfoAlt, |
26 | 26 |
} from '../../../utils/strings'; |
27 | 27 |
import { ABadge, BadgeStyle } from '../../../components/common/ABadge'; |
28 |
import SetRequiredAnnotationsCountModal from '../../../components/modals/SetRequiredAnnotationsCountModal'; |
|
28 | 29 | |
29 | 30 |
function AdminDocumentPage() { |
30 | 31 |
const redirecting = useUnauthRedirect('/login'); |
31 | 32 |
const { logout, role } = useContext(LoggedUserContext); |
32 | 33 |
const [visibleAdd, setVisibleAdd] = React.useState(false); |
33 | 34 |
const [visibleAssign, setVisibleAssign] = React.useState(false); |
35 |
const [visibleSetCount, setVisibleSetCount] = React.useState(false); |
|
36 | ||
34 | 37 |
const router = useRouter(); |
35 | 38 | |
36 | 39 |
const [documents, setDocuments] = useState<TableDocInfo[]>([]); |
... | ... | |
64 | 67 |
setVisibleAssign(true); |
65 | 68 |
} |
66 | 69 |
}; |
67 | ||
70 |
const showRequiredAnnotationsCountModal = () => { |
|
71 |
if (selectedDocs.length == 0) { |
|
72 |
ShowToast( |
|
73 |
'Vyberte dokument, pro které chcete nastavit požadovaný počet anotací', |
|
74 |
'warning', |
|
75 |
3000, |
|
76 |
'top-end' |
|
77 |
); |
|
78 |
} else { |
|
79 |
setVisibleSetCount(true); |
|
80 |
} |
|
81 |
}; |
|
68 | 82 |
const showAddModal = () => { |
69 | 83 |
setVisibleAdd(true); |
70 | 84 |
}; |
... | ... | |
73 | 87 |
fetchData(); |
74 | 88 |
setVisibleAdd(false); |
75 | 89 |
setVisibleAssign(false); |
90 |
setVisibleSetCount(false); |
|
76 | 91 |
}; |
77 | 92 | |
78 | 93 |
const columns = [ |
... | ... | |
179 | 194 |
Nahrát dokument |
180 | 195 |
</Button> |
181 | 196 |
<Button onClick={showAssignModal}>Přiřadit dokumenty</Button> |
197 |
<Button onClick={showRequiredAnnotationsCountModal}> |
|
198 |
Nastavit požadovaný počet anotací |
|
199 |
</Button> |
|
182 | 200 |
{visibleAdd && <AddDocumentModal onCancel={hideModal} />} |
183 | 201 |
{visibleAssign && ( |
184 | 202 |
<AssignDocumentModal documentsIds={selectedDocs} onCancel={hideModal} /> |
185 | 203 |
)} |
204 |
{visibleSetCount && ( |
|
205 |
<SetRequiredAnnotationsCountModal |
|
206 |
documentsIds={selectedDocs} |
|
207 |
onCancel={hideModal} |
|
208 |
/> |
|
209 |
)} |
|
186 | 210 | |
187 | 211 |
<Table |
188 | 212 |
rowSelection={{ |
Také k dispozici: Unified diff
Required annotations count changing - modal - done