1 |
4e91ed40
|
Dominik Poch
|
import { Col, Container, Row, Stack } from 'react-bootstrap';
|
2 |
76242338
|
Dominik Poch
|
import { Tag } from '../types/tag';
|
3 |
b80a6919
|
Lukáš Vlček
|
import { useContext, useState } from 'react';
|
4 |
967f45fc
|
Dominik Poch
|
import 'antd/dist/antd.css';
|
5 |
b80a6919
|
Lukáš Vlček
|
import { Button, Select } from 'antd';
|
6 |
|
|
import { DownOutlined, PlusOutlined, TagOutlined } from '@ant-design/icons';
|
7 |
c73aecde
|
Dominik Poch
|
import { AnnotationContext } from '../../contexts/AnnotationContext';
|
8 |
b80a6919
|
Lukáš Vlček
|
import { AnnotationOccurrenceItem } from './AnnotationOccurrenceItem';
|
9 |
|
|
import { COLOR_ALL_OCCURRENCES_ACCEPTED, COLOR_HIGHLIGHTED_TAG } from '../../constants';
|
10 |
|
|
import { ABadge, BadgeStyle } from '../common/ABadge';
|
11 |
|
|
import { getNameTruncated } from '../../utils/strings';
|
12 |
|
|
import { ShowConfirm } from '../../utils/alerts';
|
13 |
bcbaa7d3
|
Dominik Poch
|
|
14 |
fa93df26
|
Dominik Poch
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
15 |
eee60de6
|
Dominik Poch
|
import { faTag } from '@fortawesome/free-solid-svg-icons';
|
16 |
fa93df26
|
Dominik Poch
|
import styles from '/styles/Icon.module.scss';
|
17 |
|
|
|
18 |
bcbaa7d3
|
Dominik Poch
|
const { Option } = Select;
|
19 |
967f45fc
|
Dominik Poch
|
|
20 |
acb8a961
|
Dominik Poch
|
/**
|
21 |
|
|
* Creates a single item in an annotation panel.
|
22 |
|
|
* @param props Properties should contain a tag that will be shown in this annotation.
|
23 |
|
|
* @returns The item that represents an annotation.
|
24 |
|
|
*/
|
25 |
c73aecde
|
Dominik Poch
|
export function AnnotationItem(props: { tag: Tag }) {
|
26 |
acb8a961
|
Dominik Poch
|
/**
|
27 |
|
|
* Should properties of this annotation be visible?
|
28 |
|
|
*/
|
29 |
b80a6919
|
Lukáš Vlček
|
const [detailsVisible, setDetailsVisible] = useState(false);
|
30 |
acb8a961
|
Dominik Poch
|
|
31 |
|
|
/**
|
32 |
|
|
* Context that manages annotations.
|
33 |
|
|
*/
|
34 |
c73aecde
|
Dominik Poch
|
const {
|
35 |
|
|
addOccurrence,
|
36 |
6973d036
|
Lukáš Vlček
|
selectedInstanceId,
|
37 |
|
|
setSelectedOccurrenceId,
|
38 |
|
|
setSelectedInstanceId,
|
39 |
b80a6919
|
Lukáš Vlček
|
isFinal,
|
40 |
|
|
makeOccurrenceFinal,
|
41 |
c73aecde
|
Dominik Poch
|
} = useContext(AnnotationContext);
|
42 |
967f45fc
|
Dominik Poch
|
|
43 |
acb8a961
|
Dominik Poch
|
/**
|
44 |
|
|
* Adds new occurrence of this annotation to the context.
|
45 |
|
|
*/
|
46 |
c73aecde
|
Dominik Poch
|
const onAddOccurrence = () => {
|
47 |
|
|
addOccurrence(props.tag);
|
48 |
4e91ed40
|
Dominik Poch
|
};
|
49 |
967f45fc
|
Dominik Poch
|
|
50 |
acb8a961
|
Dominik Poch
|
/**
|
51 |
|
|
* Changes visibility of properties of this annotation.
|
52 |
|
|
*/
|
53 |
c73aecde
|
Dominik Poch
|
const changePropertiesVisibility = () => {
|
54 |
b80a6919
|
Lukáš Vlček
|
setDetailsVisible(!detailsVisible);
|
55 |
c73aecde
|
Dominik Poch
|
};
|
56 |
|
|
|
57 |
b80a6919
|
Lukáš Vlček
|
function isAllAccepted() {
|
58 |
|
|
return props.tag.occurrences.filter((o) => !o.isFinal).length === 0;
|
59 |
|
|
}
|
60 |
|
|
function getBackgroundColor(): string {
|
61 |
|
|
if (selectedInstanceId === props.tag.instanceId) {
|
62 |
|
|
// highlighted tag
|
63 |
|
|
return COLOR_HIGHLIGHTED_TAG;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
if (isFinal) {
|
67 |
|
|
if (isAllAccepted()) {
|
68 |
|
|
return COLOR_ALL_OCCURRENCES_ACCEPTED;
|
69 |
|
|
} else {
|
70 |
|
|
return '#E4C8CC';
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
return 'white';
|
75 |
|
|
}
|
76 |
967f45fc
|
Dominik Poch
|
return (
|
77 |
b80a6919
|
Lukáš Vlček
|
<Container
|
78 |
|
|
className="border rounded"
|
79 |
|
|
style={{
|
80 |
|
|
backgroundColor: getBackgroundColor(),
|
81 |
|
|
}}
|
82 |
|
|
>
|
83 |
|
|
<Row className="">
|
84 |
76242338
|
Dominik Poch
|
<Col sm="auto" className="d-flex align-items-center">
|
85 |
6973d036
|
Lukáš Vlček
|
<Button
|
86 |
fa93df26
|
Dominik Poch
|
icon={
|
87 |
|
|
<FontAwesomeIcon icon={faTag} className={styles.iconLeft} />
|
88 |
|
|
}
|
89 |
6973d036
|
Lukáš Vlček
|
onClick={() => {
|
90 |
|
|
setSelectedInstanceId(props.tag.instanceId);
|
91 |
|
|
setSelectedOccurrenceId(null);
|
92 |
|
|
}}
|
93 |
|
|
style={{
|
94 |
|
|
border: 'none',
|
95 |
|
|
paddingLeft: 0,
|
96 |
b80a6919
|
Lukáš Vlček
|
backgroundColor: getBackgroundColor(),
|
97 |
6973d036
|
Lukáš Vlček
|
}}
|
98 |
|
|
title={'Zvýraznit značky'}
|
99 |
|
|
/>
|
100 |
76242338
|
Dominik Poch
|
</Col>
|
101 |
4bc99591
|
Lukáš Vlček
|
<Col className="d-flex align-items-center">
|
102 |
|
|
{props.tag.tagName}
|
103 |
|
|
{props.tag.subtagName ? ' (' + props.tag.subtagName + ')' : ''}
|
104 |
|
|
</Col>
|
105 |
4e91ed40
|
Dominik Poch
|
<Col sm="auto">
|
106 |
b80a6919
|
Lukáš Vlček
|
{props.tag.occurrences.length > 1 && (
|
107 |
|
|
<ABadge style={BadgeStyle.GENERAL}>
|
108 |
|
|
{props.tag.occurrences.length}
|
109 |
|
|
</ABadge>
|
110 |
|
|
)}
|
111 |
|
|
|
112 |
4e91ed40
|
Dominik Poch
|
<Button
|
113 |
|
|
type="text"
|
114 |
|
|
shape="circle"
|
115 |
|
|
icon={<PlusOutlined />}
|
116 |
c73aecde
|
Dominik Poch
|
onClick={onAddOccurrence}
|
117 |
4e91ed40
|
Dominik Poch
|
/>
|
118 |
|
|
<Button
|
119 |
|
|
type="text"
|
120 |
|
|
shape="circle"
|
121 |
|
|
icon={<DownOutlined />}
|
122 |
|
|
onClick={changePropertiesVisibility}
|
123 |
|
|
/>
|
124 |
|
|
</Col>
|
125 |
967f45fc
|
Dominik Poch
|
</Row>
|
126 |
b80a6919
|
Lukáš Vlček
|
{isFinal && !isAllAccepted() && (
|
127 |
|
|
<>
|
128 |
|
|
<Row
|
129 |
|
|
style={{
|
130 |
|
|
backgroundColor: getBackgroundColor(),
|
131 |
|
|
}}
|
132 |
|
|
>
|
133 |
|
|
<Col sm="12" className="d-flex align-items-center">
|
134 |
|
|
{props.tag.occurrences.length === 1 && (
|
135 |
|
|
<div
|
136 |
|
|
style={{
|
137 |
|
|
display: 'flex',
|
138 |
|
|
flexDirection: 'row',
|
139 |
|
|
width: '100%',
|
140 |
|
|
justifyContent: 'space-between',
|
141 |
|
|
}}
|
142 |
|
|
>
|
143 |
|
|
<div style={{ width: '60%' }}>
|
144 |
|
|
Anotovali:{' '}
|
145 |
|
|
{props.tag.occurrences[0].users?.map((u) => (
|
146 |
|
|
<span
|
147 |
|
|
title={
|
148 |
|
|
u.name +
|
149 |
|
|
' ' +
|
150 |
|
|
u.surname +
|
151 |
|
|
' (' +
|
152 |
|
|
u.username +
|
153 |
|
|
')'
|
154 |
|
|
}
|
155 |
|
|
key={
|
156 |
|
|
props.tag.occurrences[0].occurenceId +
|
157 |
|
|
'.' +
|
158 |
|
|
u.id
|
159 |
|
|
}
|
160 |
|
|
style={{ marginRight: 10 }}
|
161 |
bcbaa7d3
|
Dominik Poch
|
>
|
162 |
b80a6919
|
Lukáš Vlček
|
{getNameTruncated(u)}
|
163 |
|
|
</span>
|
164 |
|
|
))}
|
165 |
|
|
</div>
|
166 |
|
|
<div>
|
167 |
6973d036
|
Lukáš Vlček
|
<Button
|
168 |
|
|
onClick={() => {
|
169 |
b80a6919
|
Lukáš Vlček
|
ShowConfirm(() => {
|
170 |
|
|
makeOccurrenceFinal(
|
171 |
59714895
|
Lukáš Vlček
|
props.tag.occurrences[0],
|
172 |
|
|
true
|
173 |
b80a6919
|
Lukáš Vlček
|
);
|
174 |
|
|
}, 'označit toto řešení jako správné');
|
175 |
6973d036
|
Lukáš Vlček
|
}}
|
176 |
b80a6919
|
Lukáš Vlček
|
>
|
177 |
|
|
Přijmout toto řešení
|
178 |
|
|
</Button>
|
179 |
|
|
</div>
|
180 |
|
|
</div>
|
181 |
|
|
)}
|
182 |
|
|
</Col>
|
183 |
|
|
</Row>
|
184 |
|
|
</>
|
185 |
|
|
)}
|
186 |
|
|
|
187 |
|
|
{detailsVisible && (
|
188 |
|
|
<Stack gap={1} className="mb-2">
|
189 |
|
|
<div>Kategorie: {props.tag.category}</div>
|
190 |
|
|
<div>Výskyty (části):</div>
|
191 |
|
|
{props.tag.occurrences.map((occurrence, index) => {
|
192 |
|
|
return (
|
193 |
|
|
<AnnotationOccurrenceItem
|
194 |
|
|
occurrence={occurrence}
|
195 |
|
|
tag={props.tag}
|
196 |
|
|
key={'occ-' + occurrence.occurenceId}
|
197 |
|
|
/>
|
198 |
967f45fc
|
Dominik Poch
|
);
|
199 |
|
|
})}
|
200 |
4e91ed40
|
Dominik Poch
|
</Stack>
|
201 |
967f45fc
|
Dominik Poch
|
)}
|
202 |
c73aecde
|
Dominik Poch
|
</Container>
|
203 |
967f45fc
|
Dominik Poch
|
);
|
204 |
|
|
}
|