Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 4e91ed40

Přidáno uživatelem Dominik Poch před asi 2 roky(ů)

Annotation panel events

Added events that propagate changes between panels in the annotation view

Zobrazit rozdíly:

webapp/components/annotation/annotationItem.tsx
1
import { Row } from 'react-bootstrap';
1
import { Col, Container, Row, Stack } from 'react-bootstrap';
2 2
import { Occurrence, Tag } from '../models/tag';
3
import { useState } from 'react';
3
import { ChangeEvent, ChangeEventHandler, useState } from 'react';
4 4

  
5 5
import 'antd/dist/antd.css';
6
import { Button } from 'antd';
6
import { Button, Input } from 'antd';
7 7
import {
8 8
    PlusOutlined,
9 9
    EyeOutlined,
......
11 11
    DeleteOutlined,
12 12
} from '@ant-design/icons';
13 13

  
14
function AnnotationItem(tag: Tag) {
14
type AnnotationItemProps = {
15
    tag: Tag;
16
    onAddOccurrence: (tag: Tag) => void;
17
    onDeleteOccurrence: (occurrence: Occurrence) => void;
18
    onChangeVisibility: (tag: Tag) => void;
19
    onChangePosition: (occurrence: Occurrence, newValue: number) => void;
20
    onChangeLength: (occurrence: Occurrence, newValue: number) => void;
21
};
22

  
23
export function AnnotationItem(props: AnnotationItemProps) {
15 24
    const [visibleProperties, setVisibleProperties] = useState(false);
16
    const [visible, setVisible] = useState(true);
17 25

  
18
    const addOccurrence = () => {};
26
    const addOccurrence = () => {
27
        props.onAddOccurrence(props.tag);
28
    };
19 29

  
20
    const deleteOccurrence = (occurrence: Occurrence) => (e: any) => {};
30
    const deleteOccurrence = (occurrence: Occurrence) => (e: any) => {
31
        props.onDeleteOccurrence(occurrence);
32
    };
21 33

  
22
    const changeVisibility = () => {};
34
    const changeVisibility = () => {
35
        props.onChangeVisibility(props.tag);
36
    };
23 37

  
24
    const changePropertiesVisiblity = () => {
38
    const changePropertiesVisibility = () => {
25 39
        setVisibleProperties(!visibleProperties);
26 40
    };
27 41

  
42
    const changePosition =
43
        (occurrence: Occurrence) => (e: ChangeEvent<HTMLInputElement>) => {
44
            props.onChangePosition(occurrence, Number(e.currentTarget.value));
45
        };
46

  
47
    const changeLength =
48
        (occurrence: Occurrence) => (e: ChangeEvent<HTMLInputElement>) => {
49
            props.onChangeLength(occurrence, Number(e.currentTarget.value));
50
        };
51

  
28 52
    return (
29 53
        <div>
30 54
            <Row>
31
                {tag.name}
32
                <Button
33
                    type="text"
34
                    shape="circle"
35
                    icon={<PlusOutlined />}
36
                    onClick={addOccurrence}
37
                />
38
                <Button
39
                    type="text"
40
                    shape="circle"
41
                    icon={<EyeOutlined />}
42
                    onClick={changeVisibility}
43
                />
44
                <Button
45
                    type="text"
46
                    shape="circle"
47
                    icon={<DownOutlined />}
48
                    onClick={changePropertiesVisiblity}
49
                />
55
                <Col className="d-flex align-items-center">{props.tag.name}</Col>
56
                <Col sm="auto">
57
                    <Button
58
                        type="text"
59
                        shape="circle"
60
                        icon={<PlusOutlined />}
61
                        onClick={addOccurrence}
62
                    />
63
                    <Button
64
                        type="text"
65
                        shape="circle"
66
                        icon={<EyeOutlined />}
67
                        onClick={changeVisibility}
68
                    />
69
                    <Button
70
                        type="text"
71
                        shape="circle"
72
                        icon={<DownOutlined />}
73
                        onClick={changePropertiesVisibility}
74
                    />
75
                </Col>
50 76
            </Row>
51 77
            {visibleProperties && (
52
                <Row>
53
                    {tag.category}
54
                    Výskyty
55
                    {tag.occurrences.map((occurrence, index) => {
78
                <Stack>
79
                    <div>Kategorie: {props.tag.category}</div>
80
                    <div>Výskyty:</div>
81
                    {props.tag.occurrences.map((occurrence, index) => {
56 82
                        return (
57
                            <div key={index}>
58
                                {occurrence.position}
59
                                {occurrence.length}
60
                                <Button
61
                                    icon={<DeleteOutlined />}
62
                                    onClick={deleteOccurrence(occurrence)}
63
                                ></Button>
83
                            <div key={index} id={props.tag.name + index}>
84
                                <Container>
85
                                    <Row>
86
                                        <Col>
87
                                            <Row>
88
                                                Pozice:
89
                                                <Input
90
                                                    value={occurrence.position}
91
                                                    onChange={changePosition(occurrence)}
92
                                                />
93
                                            </Row>
94
                                            <Row>
95
                                                Délka:
96
                                                <Input
97
                                                    value={occurrence.length}
98
                                                    onChange={changeLength(occurrence)}
99
                                                />
100
                                            </Row>
101
                                        </Col>
102
                                        <Col
103
                                            sm="auto"
104
                                            className="d-flex align-items-center"
105
                                        >
106
                                            <Button
107
                                                icon={<DeleteOutlined />}
108
                                                onClick={deleteOccurrence(occurrence)}
109
                                            ></Button>
110
                                        </Col>
111
                                    </Row>
112
                                </Container>
64 113
                            </div>
65 114
                        );
66 115
                    })}
67
                </Row>
116
                </Stack>
68 117
            )}
69 118
        </div>
70 119
    );
71 120
}
72

  
73
export default AnnotationItem;
webapp/components/annotation/annotationPanel.tsx
1
import AnnotationItem from './annotationItem';
1
import { Stack } from 'react-bootstrap';
2
import { AnnotationItem } from './annotationItem';
3
import { Occurrence, Tag } from '../models/tag';
4

  
5
type AnnotationPanelProps = {
6
    tags: Tag[];
7
    onAddOccurrence: (tag: Tag) => void;
8
    onDeleteOccurrence: (occurrence: Occurrence) => void;
9
    onChangeVisibility: (tag: Tag) => void;
10
    onChangePosition: (occurrence: Occurrence, newValue: number) => void;
11
    onChangeLength: (occurrence: Occurrence, newValue: number) => void;
12
};
2 13

  
3 14
/**
4 15
 * Creates a panel in the annotation screen that contains a list of annotations.
5 16
 * @returns Panel with a list of annotations.
6 17
 */
7
export function AnnotationPanel() {
18
export function AnnotationPanel(props: AnnotationPanelProps) {
8 19
    return (
9 20
        <div>
10 21
            <p>Panel with a list of annotations</p>
11
            <AnnotationItem name={'tag a'} category={'kategorie 1'} occurrences={[]} />
12
            <AnnotationItem name={'tag b'} category={'kategorie 2'} occurrences={[]} />
22
            <Stack>
23
                {props.tags.map((tag, index) => {
24
                    return (
25
                        <AnnotationItem
26
                            key={index}
27
                            tag={tag}
28
                            onAddOccurrence={props.onAddOccurrence}
29
                            onDeleteOccurrence={props.onDeleteOccurrence}
30
                            onChangeVisibility={props.onChangeVisibility}
31
                            onChangePosition={props.onChangePosition}
32
                            onChangeLength={props.onChangeLength}
33
                        />
34
                    );
35
                })}
36
            </Stack>
13 37
        </div>
14 38
    );
15 39
}
webapp/components/models/tag.tsx
1
import internal from 'stream';
2

  
3 1
export type Tag = {
4 2
    name: string;
5 3
    category: string;
4
    visible: boolean;
6 5
    occurrences: Occurrence[];
7 6
};
8 7

  

Také k dispozici: Unified diff