Projekt

Obecné

Profil

« Předchozí | Další » 

Revize acb8a961

Přidáno uživatelem Dominik Poch před více než 2 roky(ů)

Added comments

Zobrazit rozdíly:

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

  
5 4
import 'antd/dist/antd.css';
6 5
import { Button, Input } from 'antd';
7 6
import {
......
12 11
} from '@ant-design/icons';
13 12
import { AnnotationContext } from '../../contexts/AnnotationContext';
14 13

  
14
/**
15
 * Creates a single item in an annotation panel.
16
 * @param props Properties should contain a tag that will be shown in this annotation.
17
 * @returns The item that represents an annotation.
18
 */
15 19
export function AnnotationItem(props: { tag: Tag }) {
20
    /**
21
     * Should properties of this annotation be visible?
22
     */
16 23
    const [visibleProperties, setVisibleProperties] = useState(false);
24

  
25
    /**
26
     * Context that manages annotations.
27
     */
17 28
    const {
18 29
        addOccurrence,
19 30
        deleteOccurrence,
......
22 33
        changeLength,
23 34
    } = useContext(AnnotationContext);
24 35

  
36
    /**
37
     * Adds new occurrence of this annotation to the context.
38
     */
25 39
    const onAddOccurrence = () => {
26 40
        addOccurrence(props.tag);
27 41
    };
28 42

  
43
    /**
44
     * Removes an occurrence of this annotation from the context.
45
     * @param occurrence The occurrence that should be removed.
46
     */
29 47
    const onDeleteOccurrence = (occurrence: Occurrence) => (e: any) => {
30 48
        deleteOccurrence(occurrence);
31 49
    };
32 50

  
51
    /**
52
     * Changes visibility of this annotation in the context.
53
     */
33 54
    const onChangeVisibility = () => {
34 55
        changeVisibility(props.tag);
35 56
    };
36 57

  
58
    /**
59
     * Changes a position of an occurrence of this annotation in the context.
60
     * @param occurrence The occurrence that should be changed.
61
     */
37 62
    const onChangePosition =
38 63
        (occurrence: Occurrence) => (e: ChangeEvent<HTMLInputElement>) => {
39 64
            changePosition(occurrence, Number(e.currentTarget.value));
40 65
        };
41 66

  
67
    /**
68
     * Changes a length of an occurrence of this annotation in the context.
69
     * @param occurrence The occurrence that should be changed.
70
     */
42 71
    const onChangeLength =
43 72
        (occurrence: Occurrence) => (e: ChangeEvent<HTMLInputElement>) => {
44 73
            changeLength(occurrence, Number(e.currentTarget.value));
45 74
        };
46 75

  
76
    /**
77
     * Changes visibility of properties of this annotation.
78
     */
47 79
    const changePropertiesVisibility = () => {
48 80
        setVisibleProperties(!visibleProperties);
49 81
    };
webapp/components/annotation/AnnotationPanel.tsx
11 11
export function AnnotationPanel() {
12 12
    //const { tags } = useContext(AnnotationContext);
13 13

  
14
    /**
15
     * Temporary values of tags.
16
     * TODO: connect annotation panel to a context and use its tags.
17
     */
14 18
    const tags: Tag[] = [
15 19
        {
16 20
            name: 'tag a',
webapp/components/modals/AddDocument.tsx
39 39
    };
40 40

  
41 41
    /**
42
     * Handles successfull closing of the modal window.
42
     * Handles successful closing of the modal window.
43 43
     */
44 44
    const handleOk = () => {
45 45
        /**
webapp/contexts/AnnotationContext.tsx
1
import React, { createContext, useContext, useEffect, useState } from 'react';
1
import React, { createContext, useEffect, useState } from 'react';
2 2
import { TagInstanceInfo } from '../api';
3 3
import { Occurrence, Tag } from '../components/types/tag';
4 4

  
5
/**
6
 * Interface of an annotation context provider.
7
 */
5 8
interface IAnnotationContextProvider {
9
    /**
10
     * Tags managed by the context.
11
     */
6 12
    tags: TagInstanceInfo[] | null;
13

  
14
    /**
15
     * Sets new tags.
16
     * @param newTags An array of new tags.
17
     */
7 18
    setTags: (newTags: TagInstanceInfo[] | null) => void;
19

  
20
    /**
21
     * Adds occurrence to an annotation.
22
     * @param tag Tag whose occurrence should be added.
23
     */
8 24
    addOccurrence: (tag: Tag) => void;
25

  
26
    /**
27
     * Changes visibility of an annotation.
28
     * @param tag Tag whose visibility should be changed.
29
     */
9 30
    changeVisibility: (tag: Tag) => void;
31

  
32
    /**
33
     * Deletes an occurrence of an annotation.
34
     * @param occurrence Occurrence that should be deleted.
35
     */
10 36
    deleteOccurrence: (occurrence: Occurrence) => void;
37

  
38
    /**
39
     * Changes a position of an occurrence of an annotation.
40
     * @param occurrence Occurrence whose position should be changed.
41
     * @param newValue New value of the position.
42
     */
11 43
    changePosition: (occurrence: Occurrence, newValue: number) => void;
44

  
45
    /**
46
     * Changes a length of an occurrence of an annotation.
47
     * @param occurrence Occurrence whose length should be changed.
48
     * @param newValue New value of the length.
49
     */
12 50
    changeLength: (occurrence: Occurrence, newValue: number) => void;
13 51
}
14 52

  
53
/**
54
 * The annotation context that manages active annotations.
55
 */
15 56
export const AnnotationContext = createContext<IAnnotationContextProvider>({
57
    /**
58
     * Default tags.
59
     */
16 60
    tags: null,
61

  
62
    /**
63
     * Default implementation of setTags method.
64
     * @param v Array of new tags.
65
     */
17 66
    setTags: (v) => {
18 67
        return;
19 68
    },
69

  
70
    /**
71
     * Default implementation of addOccurrence method.
72
     * @param tag The tag with new occurrence.
73
     */
20 74
    addOccurrence: (tag: Tag) => {
21 75
        return;
22 76
    },
77

  
78
    /**
79
     * Default implementation of changeVisibility method.
80
     * @param tag The tag whose visibility should be changed.
81
     */
23 82
    changeVisibility: (tag: Tag) => {
24 83
        return;
25 84
    },
85

  
86
    /**
87
     * Default implementation of deleteOccurrence method.
88
     * @param occurrence Occurrence that should be deleted.
89
     */
26 90
    deleteOccurrence: (occurrence: Occurrence) => {
27 91
        return;
28 92
    },
93

  
94
    /**
95
     * Default implementation of changePosition method.
96
     * @param occurrence Occurrence whose position should be changed.
97
     * @param newValue A new position.
98
     */
29 99
    changePosition: (occurrence: Occurrence, newValue: number) => {
30 100
        return;
31 101
    },
102

  
103
    /**
104
     * Default implementation of changeLength method.
105
     * @param occurrence Occurrence whose length should be changed.
106
     * @param newValue A new length.
107
     */
32 108
    changeLength: (occurrence: Occurrence, newValue: number) => {
33 109
        return;
34 110
    },
35 111
});
36 112

  
113
/**
114
 * Provider of the annotation context.
115
 * @param props Children that should have access to the annotation context.
116
 * @returns Prepared html of the provider.
117
 */
37 118
const AnnotationProvider = (props: { children: React.ReactNode }) => {
119
    /**
120
     * Tags managed by the context.
121
     */
38 122
    const [tags, setTags] = useState<TagInstanceInfo[] | null>(null);
39
    const addOccurrence = (tag: Tag) => {};
40
    const changeVisibility = (tag: Tag) => {};
41
    const deleteOccurrence = (occurrence: Occurrence) => {};
42
    const changePosition = (occurrence: Occurrence, newValue: number) => {};
43
    const changeLength = (occurrence: Occurrence, newValue: number) => {};
44 123

  
124
    /**
125
     * Default implementation of addOccurrence method.
126
     * @param tag The tag with new occurrence.
127
     */
128
    const addOccurrence = (tag: Tag) => {
129
        //TODO: Implement method (should use objects from server API)
130
    };
131

  
132
    /**
133
     * Changes visibility of an annotation.
134
     * @param tag Tag whose visibility should be changed.
135
     */
136
    const changeVisibility = (tag: Tag) => {
137
        //TODO: Implement method (should use objects from server API)
138
    };
139

  
140
    /**
141
     * Deletes an occurrence of an annotation.
142
     * @param occurrence Occurrence that should be deleted.
143
     */
144
    const deleteOccurrence = (occurrence: Occurrence) => {
145
        //TODO: Implement method (should use objects from server API)
146
    };
147

  
148
    /**
149
     * Changes a position of an occurrence of an annotation.
150
     * @param occurrence Occurrence whose position should be changed.
151
     * @param newValue New value of the position.
152
     */
153
    const changePosition = (occurrence: Occurrence, newValue: number) => {
154
        //TODO: Implement method (should use objects from server API)
155
    };
156

  
157
    /**
158
     * Changes a length of an occurrence of an annotation.
159
     * @param occurrence Occurrence whose length should be changed.
160
     * @param newValue New value of the length.
161
     */
162
    const changeLength = (occurrence: Occurrence, newValue: number) => {
163
        //TODO: Implement method (should use objects from server API)
164
    };
165

  
166
    /**
167
     * Initializes the context.
168
     */
45 169
    useEffect(() => {
46
        // on context init
170
        //TODO: Implement initialization with values from the server
47 171
    }, []);
48 172

  
49 173
    return (
webapp/layouts/LoginLayout.tsx
5 5
import React from 'react';
6 6

  
7 7
/**
8
 * Creates layout of a login screen.
8
 * Creates a layout of a login screen.
9 9
 * @param props Html structure of a login form.
10 10
 * @returns The login screen.
11 11
 */
webapp/pages/annotation/index.tsx
4 4
import { MainLayout } from '../../layouts/MainLayout';
5 5
import 'antd/dist/antd.css';
6 6
import styles from '/styles/Annotation.module.scss';
7
import AnnotationProvider, { AnnotationContext } from '../../contexts/AnnotationContext';
7
import AnnotationProvider from '../../contexts/AnnotationContext';
8 8

  
9 9
/**
10 10
 * Creates an annotation screen.

Také k dispozici: Unified diff