Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 43d49a98

Přidáno uživatelem Jaroslav Hrubý před asi 2 roky(ů)

Modal windows for user edit, delete and assigned documents were implemented

Zobrazit rozdíly:

webapp/api/api.ts
186 186
     */
187 187
    documentIdList?: Array<string> | null;
188 188
}
189
/**
190
 *
191
 * @export
192
 * @interface ChangeUserInfoRequest
193
 */
194
export interface ChangeUserInfoRequest {
195
    /**
196
     *
197
     * @type {string}
198
     * @memberof ChangeUserInfoRequest
199
     */
200
    password?: string | null;
201
    /**
202
     *
203
     * @type {string}
204
     * @memberof ChangeUserInfoRequest
205
     */
206
    username?: string | null;
207
    /**
208
     *
209
     * @type {string}
210
     * @memberof ChangeUserInfoRequest
211
     */
212
    name?: string | null;
213
    /**
214
     *
215
     * @type {string}
216
     * @memberof ChangeUserInfoRequest
217
     */
218
    surname?: string | null;
219
    /**
220
     *
221
     * @type {ERole}
222
     * @memberof ChangeUserInfoRequest
223
     */
224
    role?: ERole;
225
}
189 226
/**
190 227
 *
191 228
 * @export
......
211 248
     */
212 249
    ip?: string | null;
213 250
}
251
/**
252
 *
253
 * @export
254
 * @interface CreateUserRequest
255
 */
256
export interface CreateUserRequest {
257
    /**
258
     *
259
     * @type {string}
260
     * @memberof CreateUserRequest
261
     */
262
    username?: string | null;
263
    /**
264
     *
265
     * @type {string}
266
     * @memberof CreateUserRequest
267
     */
268
    password?: string | null;
269
    /**
270
     *
271
     * @type {string}
272
     * @memberof CreateUserRequest
273
     */
274
    name?: string | null;
275
    /**
276
     *
277
     * @type {string}
278
     * @memberof CreateUserRequest
279
     */
280
    surname?: string | null;
281
    /**
282
     *
283
     * @type {ERole}
284
     * @memberof CreateUserRequest
285
     */
286
    role?: ERole;
287
}
214 288
/**
215 289
 *
216 290
 * @export
......
255 329
 * @interface DocumentListInfo
256 330
 */
257 331
export interface DocumentListInfo {
258
    key?: string;
259 332
    /**
260 333
     *
261 334
     * @type {string}
......
702 775
 * @interface UserInfo
703 776
 */
704 777
export interface UserInfo {
705
    key?: string;
706 778
    /**
707 779
     *
708 780
     * @type {string}
......
1884 1956
                options: localVarRequestOptions,
1885 1957
            };
1886 1958
        },
1959
        /**
1960
         *
1961
         * @param {string} userId
1962
         * @param {*} [options] Override http request option.
1963
         * @throws {RequiredError}
1964
         */
1965
        userUserIdAnnotationsGet: async (
1966
            userId: string,
1967
            options: AxiosRequestConfig = {}
1968
        ): Promise<RequestArgs> => {
1969
            // verify required parameter 'userId' is not null or undefined
1970
            assertParamExists('userUserIdAnnotationsGet', 'userId', userId);
1971
            const localVarPath = `/user/{userId}/annotations`.replace(
1972
                `{${'userId'}}`,
1973
                encodeURIComponent(String(userId))
1974
            );
1975
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
1976
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
1977
            let baseOptions;
1978
            if (configuration) {
1979
                baseOptions = configuration.baseOptions;
1980
            }
1981

  
1982
            const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
1983
            const localVarHeaderParameter = {} as any;
1984
            const localVarQueryParameter = {} as any;
1985

  
1986
            setSearchParams(localVarUrlObj, localVarQueryParameter);
1987
            let headersFromBaseOptions =
1988
                baseOptions && baseOptions.headers ? baseOptions.headers : {};
1989
            localVarRequestOptions.headers = {
1990
                ...localVarHeaderParameter,
1991
                ...headersFromBaseOptions,
1992
                ...options.headers,
1993
            };
1994

  
1995
            return {
1996
                url: toPathString(localVarUrlObj),
1997
                options: localVarRequestOptions,
1998
            };
1999
        },
2000
        /**
2001
         *
2002
         * @param {string} userId
2003
         * @param {*} [options] Override http request option.
2004
         * @throws {RequiredError}
2005
         */
2006
        userUserIdDelete: async (
2007
            userId: string,
2008
            options: AxiosRequestConfig = {}
2009
        ): Promise<RequestArgs> => {
2010
            // verify required parameter 'userId' is not null or undefined
2011
            assertParamExists('userUserIdDelete', 'userId', userId);
2012
            const localVarPath = `/user/{userId}`.replace(
2013
                `{${'userId'}}`,
2014
                encodeURIComponent(String(userId))
2015
            );
2016
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
2017
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
2018
            let baseOptions;
2019
            if (configuration) {
2020
                baseOptions = configuration.baseOptions;
2021
            }
2022

  
2023
            const localVarRequestOptions = {
2024
                method: 'DELETE',
2025
                ...baseOptions,
2026
                ...options,
2027
            };
2028
            const localVarHeaderParameter = {} as any;
2029
            const localVarQueryParameter = {} as any;
2030

  
2031
            setSearchParams(localVarUrlObj, localVarQueryParameter);
2032
            let headersFromBaseOptions =
2033
                baseOptions && baseOptions.headers ? baseOptions.headers : {};
2034
            localVarRequestOptions.headers = {
2035
                ...localVarHeaderParameter,
2036
                ...headersFromBaseOptions,
2037
                ...options.headers,
2038
            };
2039

  
2040
            return {
2041
                url: toPathString(localVarUrlObj),
2042
                options: localVarRequestOptions,
2043
            };
2044
        },
2045
        /**
2046
         *
2047
         * @param {string} userId
2048
         * @param {ChangeUserInfoRequest} [changeUserInfoRequest]
2049
         * @param {*} [options] Override http request option.
2050
         * @throws {RequiredError}
2051
         */
2052
        userUserIdPut: async (
2053
            userId: string,
2054
            changeUserInfoRequest?: ChangeUserInfoRequest,
2055
            options: AxiosRequestConfig = {}
2056
        ): Promise<RequestArgs> => {
2057
            // verify required parameter 'userId' is not null or undefined
2058
            assertParamExists('userUserIdPut', 'userId', userId);
2059
            const localVarPath = `/user/{userId}`.replace(
2060
                `{${'userId'}}`,
2061
                encodeURIComponent(String(userId))
2062
            );
2063
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
2064
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
2065
            let baseOptions;
2066
            if (configuration) {
2067
                baseOptions = configuration.baseOptions;
2068
            }
2069

  
2070
            const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options };
2071
            const localVarHeaderParameter = {} as any;
2072
            const localVarQueryParameter = {} as any;
2073

  
2074
            localVarHeaderParameter['Content-Type'] = 'application/json';
2075

  
2076
            setSearchParams(localVarUrlObj, localVarQueryParameter);
2077
            let headersFromBaseOptions =
2078
                baseOptions && baseOptions.headers ? baseOptions.headers : {};
2079
            localVarRequestOptions.headers = {
2080
                ...localVarHeaderParameter,
2081
                ...headersFromBaseOptions,
2082
                ...options.headers,
2083
            };
2084
            localVarRequestOptions.data = serializeDataIfNeeded(
2085
                changeUserInfoRequest,
2086
                localVarRequestOptions,
2087
                configuration
2088
            );
2089

  
2090
            return {
2091
                url: toPathString(localVarUrlObj),
2092
                options: localVarRequestOptions,
2093
            };
2094
        },
1887 2095
        /**
1888 2096
         *
1889 2097
         * @param {*} [options] Override http request option.
......
1911 2119
                ...options.headers,
1912 2120
            };
1913 2121

  
2122
            return {
2123
                url: toPathString(localVarUrlObj),
2124
                options: localVarRequestOptions,
2125
            };
2126
        },
2127
        /**
2128
         *
2129
         * @param {CreateUserRequest} [createUserRequest]
2130
         * @param {*} [options] Override http request option.
2131
         * @throws {RequiredError}
2132
         */
2133
        usersPost: async (
2134
            createUserRequest?: CreateUserRequest,
2135
            options: AxiosRequestConfig = {}
2136
        ): Promise<RequestArgs> => {
2137
            const localVarPath = `/users`;
2138
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
2139
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
2140
            let baseOptions;
2141
            if (configuration) {
2142
                baseOptions = configuration.baseOptions;
2143
            }
2144

  
2145
            const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
2146
            const localVarHeaderParameter = {} as any;
2147
            const localVarQueryParameter = {} as any;
2148

  
2149
            localVarHeaderParameter['Content-Type'] = 'application/json';
2150

  
2151
            setSearchParams(localVarUrlObj, localVarQueryParameter);
2152
            let headersFromBaseOptions =
2153
                baseOptions && baseOptions.headers ? baseOptions.headers : {};
2154
            localVarRequestOptions.headers = {
2155
                ...localVarHeaderParameter,
2156
                ...headersFromBaseOptions,
2157
                ...options.headers,
2158
            };
2159
            localVarRequestOptions.data = serializeDataIfNeeded(
2160
                createUserRequest,
2161
                localVarRequestOptions,
2162
                configuration
2163
            );
2164

  
1914 2165
            return {
1915 2166
                url: toPathString(localVarUrlObj),
1916 2167
                options: localVarRequestOptions,
......
1949 2200
                configuration
1950 2201
            );
1951 2202
        },
2203
        /**
2204
         *
2205
         * @param {string} userId
2206
         * @param {*} [options] Override http request option.
2207
         * @throws {RequiredError}
2208
         */
2209
        async userUserIdAnnotationsGet(
2210
            userId: string,
2211
            options?: AxiosRequestConfig
2212
        ): Promise<
2213
            (
2214
                axios?: AxiosInstance,
2215
                basePath?: string
2216
            ) => AxiosPromise<AnnotationListResponse>
2217
        > {
2218
            const localVarAxiosArgs =
2219
                await localVarAxiosParamCreator.userUserIdAnnotationsGet(userId, options);
2220
            return createRequestFunction(
2221
                localVarAxiosArgs,
2222
                globalAxios,
2223
                BASE_PATH,
2224
                configuration
2225
            );
2226
        },
2227
        /**
2228
         *
2229
         * @param {string} userId
2230
         * @param {*} [options] Override http request option.
2231
         * @throws {RequiredError}
2232
         */
2233
        async userUserIdDelete(
2234
            userId: string,
2235
            options?: AxiosRequestConfig
2236
        ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
2237
            const localVarAxiosArgs = await localVarAxiosParamCreator.userUserIdDelete(
2238
                userId,
2239
                options
2240
            );
2241
            return createRequestFunction(
2242
                localVarAxiosArgs,
2243
                globalAxios,
2244
                BASE_PATH,
2245
                configuration
2246
            );
2247
        },
2248
        /**
2249
         *
2250
         * @param {string} userId
2251
         * @param {ChangeUserInfoRequest} [changeUserInfoRequest]
2252
         * @param {*} [options] Override http request option.
2253
         * @throws {RequiredError}
2254
         */
2255
        async userUserIdPut(
2256
            userId: string,
2257
            changeUserInfoRequest?: ChangeUserInfoRequest,
2258
            options?: AxiosRequestConfig
2259
        ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
2260
            const localVarAxiosArgs = await localVarAxiosParamCreator.userUserIdPut(
2261
                userId,
2262
                changeUserInfoRequest,
2263
                options
2264
            );
2265
            return createRequestFunction(
2266
                localVarAxiosArgs,
2267
                globalAxios,
2268
                BASE_PATH,
2269
                configuration
2270
            );
2271
        },
1952 2272
        /**
1953 2273
         *
1954 2274
         * @param {*} [options] Override http request option.
......
1965 2285
                configuration
1966 2286
            );
1967 2287
        },
2288
        /**
2289
         *
2290
         * @param {CreateUserRequest} [createUserRequest]
2291
         * @param {*} [options] Override http request option.
2292
         * @throws {RequiredError}
2293
         */
2294
        async usersPost(
2295
            createUserRequest?: CreateUserRequest,
2296
            options?: AxiosRequestConfig
2297
        ): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
2298
            const localVarAxiosArgs = await localVarAxiosParamCreator.usersPost(
2299
                createUserRequest,
2300
                options
2301
            );
2302
            return createRequestFunction(
2303
                localVarAxiosArgs,
2304
                globalAxios,
2305
                BASE_PATH,
2306
                configuration
2307
            );
2308
        },
1968 2309
    };
1969 2310
};
1970 2311

  
......
1989 2330
                .userAnnotationsGet(options)
1990 2331
                .then((request) => request(axios, basePath));
1991 2332
        },
2333
        /**
2334
         *
2335
         * @param {string} userId
2336
         * @param {*} [options] Override http request option.
2337
         * @throws {RequiredError}
2338
         */
2339
        userUserIdAnnotationsGet(
2340
            userId: string,
2341
            options?: any
2342
        ): AxiosPromise<AnnotationListResponse> {
2343
            return localVarFp
2344
                .userUserIdAnnotationsGet(userId, options)
2345
                .then((request) => request(axios, basePath));
2346
        },
2347
        /**
2348
         *
2349
         * @param {string} userId
2350
         * @param {*} [options] Override http request option.
2351
         * @throws {RequiredError}
2352
         */
2353
        userUserIdDelete(userId: string, options?: any): AxiosPromise<void> {
2354
            return localVarFp
2355
                .userUserIdDelete(userId, options)
2356
                .then((request) => request(axios, basePath));
2357
        },
2358
        /**
2359
         *
2360
         * @param {string} userId
2361
         * @param {ChangeUserInfoRequest} [changeUserInfoRequest]
2362
         * @param {*} [options] Override http request option.
2363
         * @throws {RequiredError}
2364
         */
2365
        userUserIdPut(
2366
            userId: string,
2367
            changeUserInfoRequest?: ChangeUserInfoRequest,
2368
            options?: any
2369
        ): AxiosPromise<void> {
2370
            return localVarFp
2371
                .userUserIdPut(userId, changeUserInfoRequest, options)
2372
                .then((request) => request(axios, basePath));
2373
        },
1992 2374
        /**
1993 2375
         *
1994 2376
         * @param {*} [options] Override http request option.
......
1999 2381
                .usersGet(options)
2000 2382
                .then((request) => request(axios, basePath));
2001 2383
        },
2384
        /**
2385
         *
2386
         * @param {CreateUserRequest} [createUserRequest]
2387
         * @param {*} [options] Override http request option.
2388
         * @throws {RequiredError}
2389
         */
2390
        usersPost(
2391
            createUserRequest?: CreateUserRequest,
2392
            options?: any
2393
        ): AxiosPromise<void> {
2394
            return localVarFp
2395
                .usersPost(createUserRequest, options)
2396
                .then((request) => request(axios, basePath));
2397
        },
2002 2398
    };
2003 2399
};
2004 2400

  
......
2021 2417
            .then((request) => request(this.axios, this.basePath));
2022 2418
    }
2023 2419

  
2420
    /**
2421
     *
2422
     * @param {string} userId
2423
     * @param {*} [options] Override http request option.
2424
     * @throws {RequiredError}
2425
     * @memberof UserApi
2426
     */
2427
    public userUserIdAnnotationsGet(userId: string, options?: AxiosRequestConfig) {
2428
        return UserApiFp(this.configuration)
2429
            .userUserIdAnnotationsGet(userId, options)
2430
            .then((request) => request(this.axios, this.basePath));
2431
    }
2432

  
2433
    /**
2434
     *
2435
     * @param {string} userId
2436
     * @param {*} [options] Override http request option.
2437
     * @throws {RequiredError}
2438
     * @memberof UserApi
2439
     */
2440
    public userUserIdDelete(userId: string, options?: AxiosRequestConfig) {
2441
        return UserApiFp(this.configuration)
2442
            .userUserIdDelete(userId, options)
2443
            .then((request) => request(this.axios, this.basePath));
2444
    }
2445

  
2446
    /**
2447
     *
2448
     * @param {string} userId
2449
     * @param {ChangeUserInfoRequest} [changeUserInfoRequest]
2450
     * @param {*} [options] Override http request option.
2451
     * @throws {RequiredError}
2452
     * @memberof UserApi
2453
     */
2454
    public userUserIdPut(
2455
        userId: string,
2456
        changeUserInfoRequest?: ChangeUserInfoRequest,
2457
        options?: AxiosRequestConfig
2458
    ) {
2459
        return UserApiFp(this.configuration)
2460
            .userUserIdPut(userId, changeUserInfoRequest, options)
2461
            .then((request) => request(this.axios, this.basePath));
2462
    }
2463

  
2024 2464
    /**
2025 2465
     *
2026 2466
     * @param {*} [options] Override http request option.
......
2032 2472
            .usersGet(options)
2033 2473
            .then((request) => request(this.axios, this.basePath));
2034 2474
    }
2475

  
2476
    /**
2477
     *
2478
     * @param {CreateUserRequest} [createUserRequest]
2479
     * @param {*} [options] Override http request option.
2480
     * @throws {RequiredError}
2481
     * @memberof UserApi
2482
     */
2483
    public usersPost(
2484
        createUserRequest?: CreateUserRequest,
2485
        options?: AxiosRequestConfig
2486
    ) {
2487
        return UserApiFp(this.configuration)
2488
            .usersPost(createUserRequest, options)
2489
            .then((request) => request(this.axios, this.basePath));
2490
    }
2035 2491
}
webapp/components/modals/AddUserModal.tsx
100 100
                    name="password"
101 101
                    rules={[{ required: true, message: 'Prosím zadejte heslo' }]}
102 102
                >
103
                    <Input placeholder="Heslo" />
103
                    <Input.Password placeholder="Heslo" />
104 104
                </Form.Item>
105 105

  
106 106
                <Form.Item
webapp/components/modals/AssignDocumentModal.tsx
34 34
        }
35 35
    }, [documentsIds, redirecting, role]);
36 36

  
37
    const handleUpload = () => {
37
    const handleUpload = async () => {
38 38
        // console.log(documentsIds, selectedUsers);
39 39
        if (documentsIds && documentsIds.length !== 0) {
40
            annotationController.annotationsPost({
40
            await annotationController.annotationsPost({
41
                // @ts-ignore
41 42
                documentIdList: documentsIds,
42 43
                userIdList: selectedUsers,
43 44
            });
webapp/components/modals/EditUserModal.tsx
1
import { Button, Form, Input, Modal, Radio } from 'antd';
2
import 'antd/dist/antd.css';
3
import React from 'react';
4
import { ChangeUserInfoRequest, ERole, UserInfo } from '../../api';
5
import { userController } from '../../controllers';
6
import { ShowToast } from '../../utils/alerts';
7

  
8
interface ModalProps {
9
    onCancel: () => void;
10
    userInfo: UserInfo;
11
}
12

  
13
/**
14
 * Creates a modal window that loads documents to the app.
15
 * @returns The modal window.
16
 */
17
const EditUserModal: React.FC<ModalProps> = ({ onCancel, userInfo }: ModalProps) => {
18
    /**
19
     * Handles successful closing of the modal window.
20
     */
21
    const handleOk = () => {
22
        onCancel();
23
    };
24

  
25
    /**
26
     * Handles cancelling of the model window.
27
     */
28
    const handleCancel = () => {
29
        onCancel();
30
    };
31

  
32
    const onFinish = async (values: any) => {
33
        const req: ChangeUserInfoRequest = {
34
            username: values.username,
35
            password: values.password,
36
            name: values.name,
37
            surname: values.surname,
38
            role: values.role,
39
        };
40
        if (userInfo.id) {
41
            await userController.userUserIdPut(userInfo.id, req);
42
        }
43
        onCancel();
44
    };
45

  
46
    const onFinishFailed = (errorInfo: any) => {
47
        ShowToast('Zadané údaje nejsou validní', 'error', 3000, 'top-end');
48
    };
49

  
50
    return (
51
        <Modal
52
            title="Upravit uživatele"
53
            onOk={handleOk}
54
            visible={true}
55
            onCancel={handleCancel}
56
            footer={null}
57
        >
58
            <Form
59
                onFinish={onFinish}
60
                onFinishFailed={onFinishFailed}
61
                autoComplete="off"
62
                labelCol={{ span: 4 }}
63
                layout="horizontal"
64
            >
65
                <Form.Item
66
                    label=""
67
                    name="role"
68
                    rules={[
69
                        {
70
                            required: true,
71
                            message: 'Prosím vyberte roli',
72
                        },
73
                    ]}
74
                >
75
                    <Radio.Group>
76
                        <Radio.Button value={ERole.Annotator}>Anotátor</Radio.Button>
77
                        <Radio.Button value={ERole.Administrator}>Admin</Radio.Button>
78
                    </Radio.Group>
79
                </Form.Item>
80
                <Form.Item
81
                    name="username"
82
                    initialValue={userInfo.username}
83
                    rules={[
84
                        {
85
                            required: true,
86
                            message: 'Prosím zadejte uživatelské jméno',
87
                        },
88
                    ]}
89
                >
90
                    <Input placeholder="Uživatelské jméno" />
91
                </Form.Item>
92
                <Form.Item
93
                    name="password"
94
                    rules={[{ required: true, message: 'Prosím zadejte heslo' }]}
95
                >
96
                    <Input.Password placeholder="Heslo" />
97
                </Form.Item>
98

  
99
                <Form.Item
100
                    name="name"
101
                    initialValue={userInfo.name}
102
                    rules={[
103
                        {
104
                            required: true,
105
                            message: 'Prosím zadejte jméno',
106
                        },
107
                    ]}
108
                >
109
                    <Input placeholder="Jméno" />
110
                </Form.Item>
111

  
112
                <Form.Item
113
                    name="surname"
114
                    initialValue={userInfo.surname}
115
                    rules={[
116
                        {
117
                            required: true,
118
                            message: 'Prosím zadejte příjmení',
119
                        },
120
                    ]}
121
                >
122
                    <Input placeholder="Příjmení" />
123
                </Form.Item>
124
                <Form.Item>
125
                    <Button type="primary" htmlType="submit" className="w-100">
126
                        Upravit
127
                    </Button>
128
                </Form.Item>
129
            </Form>
130
        </Modal>
131
    );
132
};
133

  
134
export default EditUserModal;
webapp/components/modals/UserDocumentsModal.tsx
1
import { List, Modal } from 'antd';
2
import 'antd/dist/antd.css';
3
import React, { useContext, useEffect, useState } from 'react';
4
import { AnnotationListInfo } from '../../api';
5
import { userController } from '../../controllers';
6
import { useUnauthRedirect } from '../../hooks';
7
import { LoggedUserContext } from '../../contexts/LoggedUserContext';
8

  
9
interface ModalProps {
10
    onCancel: () => void;
11
    userId: string | undefined;
12
}
13

  
14
function UserDocumentsModal({ onCancel, userId }: ModalProps) {
15
    const redirecting = useUnauthRedirect('/login');
16
    const { role } = useContext(LoggedUserContext);
17
    const [annotations, setAnnotations] = useState<AnnotationListInfo[]>([]);
18

  
19
    const handleOk = () => {
20
        onCancel();
21
    };
22

  
23
    const handleCancel = () => {
24
        onCancel();
25
    };
26

  
27
    useEffect(() => {
28
        if (!redirecting && role === 'ADMINISTRATOR' && userId) {
29
            userController
30
                .userUserIdAnnotationsGet(userId)
31
                .then(({ data: { annotations } }) => {
32
                    setAnnotations(annotations || []);
33
                });
34
        }
35
    }, [userId, redirecting, role]);
36

  
37
    return (
38
        <Modal
39
            title="Dokumenty uživatele"
40
            onOk={handleOk}
41
            visible={true}
42
            onCancel={handleCancel}
43
            footer={[null]}
44
        >
45
            <List
46
                dataSource={annotations}
47
                size={'small'}
48
                grid={{ gutter: 10, column: 1 }}
49
                style={{ maxHeight: 400, overflowY: 'auto', overflowX: 'hidden' }}
50
                renderItem={(item) => (
51
                    <List.Item key={item.annotationId}>
52
                        <List.Item.Meta title={item.documentName} />
53
                    </List.Item>
54
                )}
55
            />
56
        </Modal>
57
    );
58
}
59

  
60
export default UserDocumentsModal;
webapp/components/types/TableDocInfo.tsx
1
import { UserInfo } from '../../api';
2

  
3
export type TableDocInfo = {
4
    id?: string;
5
    key?: string;
6
    name?: string | null;
7
    length?: number;
8
    requiredAnnotations?: number;
9
    annotatingUsers?: Array<UserInfo> | null;
10
};
webapp/pages/documents/admin/index.tsx
13 13
import { documentController, userController } from '../../../controllers';
14 14
import AssignDocumentModal from '../../../components/modals/AssignDocumentModal';
15 15
import { ShowToast } from '../../../utils/alerts';
16
import { TableDocInfo } from '../../../components/types/TableDocInfo';
16 17

  
17 18
function AdminDocumentPage() {
18 19
    const redirecting = useUnauthRedirect('/login');
......
21 22
    const [visibleAssign, setVisibleAssign] = React.useState(false);
22 23
    const router = useRouter();
23 24

  
24
    const [documents, setDocuments] = useState<DocumentListInfo[]>([]);
25
    const [documents, setDocuments] = useState<TableDocInfo[]>([]);
25 26
    const [selectedDocs, setSelectedDocs] = useState<string[] | undefined[]>([]);
26 27

  
27
    useEffect(() => {
28
        async function fetchData() {
29
            let docs = (await documentController.documentsGet(0, 1000)).data.documents;
30
            docs?.forEach((doc) => (doc.key = doc.id));
28
    async function fetchData() {
29
        const docs = (await documentController.documentsGet(0, 1000)).data.documents;
30

  
31
        // @ts-ignore
32
        const tableDocs: TableDocInfo[] = docs?.map((doc, index) => {
33
            return { key: index, ...doc };
34
        });
31 35

  
32
            if (!docs) {
33
                setDocuments([]);
34
            } else {
35
                setDocuments(docs);
36
            }
36
        if (!docs) {
37
            setDocuments([]);
38
        } else {
39
            setDocuments(tableDocs);
37 40
        }
41
    }
38 42

  
43
    useEffect(() => {
39 44
        if (!redirecting && role === 'ADMINISTRATOR') {
40 45
            fetchData();
41 46
        }
......
54 59
    };
55 60

  
56 61
    const hideModal = () => {
62
        fetchData();
57 63
        setVisibleAdd(false);
58 64
        setVisibleAssign(false);
59 65
    };
......
96 102

  
97 103
    const rowSelection = {
98 104
        onChange: (selectedRowKeys: React.Key[], selectedRows: DocumentListInfo[]) => {
105
            // @ts-ignore
99 106
            setSelectedDocs(selectedRows.map((row) => row.id));
100 107
        },
101 108
    };
webapp/pages/users/index.tsx
11 11
import { UserInfo } from '../../api';
12 12
import { userController } from '../../controllers';
13 13
import AddUserModal from '../../components/modals/AddUserModal';
14
import UserDocumentsModal from '../../components/modals/UserDocumentsModal';
15
import { ShowConfirmDelete } from '../../utils/alerts';
16
import EditUserModal from '../../components/modals/EditUserModal';
14 17

  
15 18
function UsersPage() {
16 19
    const redirecting = useUnauthRedirect('/login');
17 20
    const { logout, role } = useContext(LoggedUserContext);
18 21
    const router = useRouter();
19 22

  
20
    const [visible, setVisible] = React.useState(false);
23
    const [addVisible, setAddVisible] = React.useState(false);
24
    const [editVisible, setEditVisible] = React.useState(false);
25
    const [docsVisible, setDocsVisible] = React.useState(false);
21 26
    const [users, setUsers] = useState<UserInfo[]>([]);
22 27

  
23
    useEffect(() => {
24
        async function fetchData() {
25
            let usrs = (await userController.usersGet()).data.users;
26
            if (!usrs) {
27
                setUsers([]);
28
            } else {
29
                setUsers(usrs);
30
            }
28
    const [user, setUser] = useState<UserInfo>({});
29

  
30
    async function fetchData() {
31
        let usrs = (await userController.usersGet()).data.users;
32
        if (!usrs) {
33
            setUsers([]);
34
        } else {
35
            setUsers(usrs);
31 36
        }
37
    }
32 38

  
39
    useEffect(() => {
33 40
        if (!redirecting && role === 'ADMINISTRATOR') {
34 41
            fetchData();
35 42
        }
36 43
    }, [logout, redirecting, role, router]);
37 44

  
38
    const showModal = () => {
39
        setVisible(true);
45
    const setUserInfo = (userId: string) => {
46
        const userInfo = users.find((user) => user.id === userId);
47
        if (userInfo) {
48
            setUser(userInfo);
49
        }
50
    };
51

  
52
    const deleteUser = (userId: string) => {
53
        ShowConfirmDelete(() => {
54
            userController.userUserIdDelete(userId).then(() => fetchData());
55
        }, 'uživatele');
56
    };
57

  
58
    const showAddModal = () => {
59
        setAddVisible(true);
60
    };
61
    const showEditModal = (userId: string) => {
62
        setUserInfo(userId);
63
        setEditVisible(true);
64
    };
65
    const showDocsModal = (userId: string) => {
66
        setUserInfo(userId);
67
        setDocsVisible(true);
40 68
    };
41 69

  
42
    const hideModal = () => {
43
        setVisible(false);
70
    const hideModals = () => {
71
        fetchData();
72
        setAddVisible(false);
73
        setDocsVisible(false);
74
        setEditVisible(false);
44 75
    };
45 76

  
46 77
    const columns = [
......
50 81
        {
51 82
            title: '',
52 83
            key: 'operation',
53
            render: () => (
84
            dataIndex: 'id',
85
            render: (id: string) => (
54 86
                <div>
55 87
                    <Space size={'middle'}>
56
                        <Button>Dokumenty</Button>
57
                        <Button>Upravit</Button>
58
                        <Button>Smazat</Button>
88
                        <Button onClick={() => showDocsModal(id)}>Dokumenty</Button>
89
                        <Button onClick={() => showEditModal(id)}>Upravit</Button>
90
                        <Button onClick={() => deleteUser(id)}>Smazat</Button>
59 91
                    </Space>
60 92
                </div>
61 93
            ),
......
67 99
            <Typography.Title level={2}>
68 100
                <FontAwesomeIcon icon={faUsers} /> Uživatelé
69 101
            </Typography.Title>
70
            <Button type={'primary'} onClick={showModal}>
102
            <Button type={'primary'} onClick={showAddModal}>
71 103
                Přidat uživatele
72 104
            </Button>
73
            {visible && <AddUserModal onCancel={hideModal} />}
105
            {addVisible && <AddUserModal onCancel={hideModals} />}
106
            {editVisible && <EditUserModal userInfo={user} onCancel={hideModals} />}
107
            {docsVisible && <UserDocumentsModal userId={user.id} onCancel={hideModals} />}
74 108

  
75 109
            <Table
76 110
                columns={columns}
webapp/utils/alerts.ts
1 1
import Swal, { SweetAlertIcon, SweetAlertPosition } from 'sweetalert2';
2 2
import withReactContent from 'sweetalert2-react-content';
3
import { AxiosResponse } from 'axios';
3 4

  
4 5
const MySwal = withReactContent(Swal);
5 6

  
......
26 27
        title: text,
27 28
    });
28 29
}
30

  
31
export function ShowConfirmDelete(deleteAction: () => void, deleteSubjectLabel: string) {
32
    Swal.fire({
33
        title: 'Opravdu si přejete smazat ' + deleteSubjectLabel + '?',
34
        showCancelButton: true,
35
        confirmButtonText: 'Smazat',
36
    }).then((result) => {
37
        if (result.isConfirmed) {
38
            deleteAction();
39
        }
40
    });
41
}

Také k dispozici: Unified diff