Projekt

Obecné

Profil

« Předchozí | Další » 

Revize afd6a1e8

Přidáno uživatelem Lukáš Vlček před asi 2 roky(ů)

AnnotationStrings refactor

Zobrazit rozdíly:

webapp/pages/documents/annotator/index.tsx
9 9
import { LoggedUserContext } from '../../../contexts/LoggedUserContext';
10 10
import { MainLayout } from '../../../layouts/MainLayout';
11 11
import { userController } from '../../../controllers';
12
import { AnnotationListInfo } from '../../../api';
12
import { AnnotationListInfo, EState } from '../../../api';
13
import {
14
    getAnnotationStateString,
15
    getAnnotationStateColor,
16
} from '../../../utils/strings';
13 17

  
14 18
function UserDocumentPage() {
15 19
    const redirecting = useUnauthRedirect('/login');
......
43 47
            title: 'Stav anotace',
44 48
            key: 'state',
45 49
            dataIndex: 'state',
46
            render: (state: string) => {
47
                let color = 'green';
48
                let label = 'Hotovo';
49
                if (state === 'NEW') {
50
                    color = 'volcano';
51
                    label = 'Nový';
52
                }
53
                if (state === 'IN_PROGRESS') {
54
                    color = 'orange';
55
                    label = 'Rozpracováno';
56
                }
50
            render: (state: EState) => {
51
                const color = getAnnotationStateColor(state);
52
                const label = getAnnotationStateString(state);
53

  
57 54
                return (
58 55
                    <Tag color={color} key={label}>
59 56
                        {label.toUpperCase()}
webapp/utils/strings.ts
1
import { EState, UserInfo } from '../api';
2

  
3
export function getName(user: UserInfo) {
4
    //return `${user.name} ${user.surname}`;
5
    return `${user.surname} ${user.name}`;
6
}
7

  
8
export function getNameTruncated(user: UserInfo, maxLength: number = 15) {
9
    const name = getName(user);
10
    if (name.length > maxLength) {
11
        return name.substring(0, maxLength - 3) + '...';
12
    } else {
13
        return name;
14
    }
15
}
16

  
17
export function getUserInfoAlt(user: UserInfo) {
18
    return `${getName(user)}\nUživatelské jméno: ${user.username}`;
19
}
20

  
21
export function getAnnotationStateString(state: EState) {
22
    switch (state) {
23
        case 'NEW':
24
            return 'Nový';
25
        case 'IN_PROGRESS':
26
            return 'Rozpracovaný';
27
        case 'DONE':
28
            return 'Hotovo';
29
    }
30
}
31

  
32
export function getAnnotationStateColor(state: EState | undefined) {
33
    switch (state) {
34
        case 'NEW':
35
            return 'indianred';
36
        case 'IN_PROGRESS':
37
            return 'orange';
38
        case 'DONE':
39
            return 'green';
40
    }
41
    return 'black';
42
}

Také k dispozici: Unified diff