View | Details | Raw Unified | Return to bug 14962
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/api-client.js (+6 lines)
Lines 187-196 export const APIClient = { Link Here
187
        () => import("./authorised-values-api-client.js")
187
        () => import("./authorised-values-api-client.js")
188
    ),
188
    ),
189
    acquisition: createClientProxy(() => import("./acquisition-api-client.js")),
189
    acquisition: createClientProxy(() => import("./acquisition-api-client.js")),
190
    acquisition: createClientProxy(() => import("./acquisition-api-client.js")),
191
    biblio: createClientProxy(() => import("./biblio-api-client.js")),
190
    cataloguing: createClientProxy(() => import("./cataloguing-api-client.js")),
192
    cataloguing: createClientProxy(() => import("./cataloguing-api-client.js")),
191
    circulation: createClientProxy(() => import("./circulation-api-client.js")),
193
    circulation: createClientProxy(() => import("./circulation-api-client.js")),
192
    club: createClientProxy(() => import("./club-api-client.js")),
194
    club: createClientProxy(() => import("./club-api-client.js")),
193
    cover_image: createClientProxy(() => import("./cover-image-api-client.js")),
195
    cover_image: createClientProxy(() => import("./cover-image-api-client.js")),
196
    display: createClientProxy(() => import("./display-api-client.js")),
197
    item: createClientProxy(() => import("./item-api-client.js")),
198
    item_type: createClientProxy(() => import("./item-type-api-client.js")),
199
    library: createClientProxy(() => import("./library-api-client.js")),
194
    localization: createClientProxy(
200
    localization: createClientProxy(
195
        () => import("./localization-api-client.js")
201
        () => import("./localization-api-client.js")
196
    ),
202
    ),
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/biblio-api-client.js (+25 lines)
Line 0 Link Here
1
export class BiblioAPIClient {
2
    constructor(HttpClient) {
3
        this.httpClient = new HttpClient({
4
            baseURL: "/api/v1/",
5
        });
6
    }
7
8
    get biblios() {
9
        return {
10
            getAll: (query, params, headers) =>
11
                this.httpClient.getAll({
12
                    endpoint: "biblios",
13
                    query,
14
                    params,
15
                    headers,
16
                }),
17
            get: id =>
18
                this.httpClient.get({
19
                    endpoint: "items/" + id,
20
                }),
21
        };
22
    }
23
}
24
25
export default BiblioAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/display-api-client.js (+121 lines)
Line 0 Link Here
1
export class DisplayAPIClient {
2
    constructor(HttpClient) {
3
        this.httpClientDisplaysConfig = new HttpClient({
4
            baseURL: "/api/v1/displays/config/",
5
        });
6
7
        this.httpClientDisplays = new HttpClient({
8
            baseURL: "/api/v1/displays/",
9
        });
10
11
        this.httpClientDisplayItems = new HttpClient({
12
            baseURL: "/api/v1/display/items/",
13
        });
14
    }
15
16
    get config() {
17
        return {
18
            get: () =>
19
                this.httpClientDisplaysConfig.get({
20
                    endpoint: "",
21
                }),
22
        };
23
    }
24
25
    get displays() {
26
        return {
27
            create: display =>
28
                this.httpClientDisplays.post({
29
                    endpoint: "",
30
                    body: display,
31
                }),
32
            get: id =>
33
                this.httpClientDisplays.get({
34
                    endpoint: "" + id,
35
                    headers: {
36
                        "x-koha-embed": "display_items,library,item_type,+strings",
37
                    },
38
                }),
39
            getAll: (query, params) =>
40
                this.httpClientDisplays.getAll({
41
                    endpoint: "",
42
                    headers: {
43
                        "x-koha-embed": "display_items,library,item_type,+strings",
44
                    },
45
                    params,
46
                    query,
47
                }),
48
            update: (display, id) =>
49
                this.httpClientDisplays.put({
50
                    endpoint: "" + id,
51
                    body: display,
52
                }),
53
            delete: id =>
54
                this.httpClientDisplays.delete({
55
                    endpoint: "" + id,
56
                }),
57
            count: (query = {}) =>
58
                this.httpClientDisplays.count({
59
                    endpoint:
60
                        "?" +
61
                        new URLSearchParams({
62
                            _page: 1,
63
                            _per_page: 1,
64
                            ...(query && { q: JSON.stringify(query) }),
65
                        }),
66
                }),
67
        };
68
    }
69
70
    get displayItems() {
71
        return {
72
            create: displayItem =>
73
                this.httpClientDisplayItems.post({
74
                    endpoint: "",
75
                    body: displayItem,
76
                }),
77
            get: (display_id, itemnumber) =>
78
                this.httpClientDisplayItems.get({
79
                    endpoint: "" + display_id + "/" + itemnumber,
80
                }),
81
            getAll: (query, params) =>
82
                this.httpClientDisplayItems.getAll({
83
                    endpoint: "",
84
                    query,
85
                    params,
86
                }),
87
            update: (displayItem, display_id, itemnumber) =>
88
                this.httpClientDisplayItems.put({
89
                    endpoint: "" + display_id + "/" + itemnumber,
90
                    body: displayItem,
91
                }),
92
            delete: (display_id, itemnumber) =>
93
                this.httpClientDisplayItems.delete({
94
                    endpoint: "" + display_id + "/" + itemnumber,
95
                }),
96
            batchAdd: displayItems =>
97
                this.httpClientDisplayItems.post({
98
                    endpoint: "batch",
99
                    body: displayItems,
100
                }),
101
            batchDelete: displayItems =>
102
                this.httpClientDisplayItems.delete({
103
                    endpoint: "batch",
104
                    body: displayItems,
105
                    parseResponse: true,
106
                }),
107
            count: (query = {}) =>
108
                this.httpClientDisplayItems.count({
109
                    endpoint:
110
                        "?" +
111
                        new URLSearchParams({
112
                            _page: 1,
113
                            _per_page: 1,
114
                            ...(query && { q: JSON.stringify(query) }),
115
                        }),
116
                }),
117
        };
118
    }
119
}
120
121
export default DisplayAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/http-client.js (+6 lines)
Lines 184-189 class HttpClient { Link Here
184
    }
184
    }
185
185
186
    delete(params = {}) {
186
    delete(params = {}) {
187
        const body = params.body
188
            ? typeof params.body === "string"
189
                ? params.body
190
                : JSON.stringify(params.body)
191
            : undefined;
187
        let csrf_token = { "CSRF-TOKEN": this.csrf_token };
192
        let csrf_token = { "CSRF-TOKEN": this.csrf_token };
188
        let headers = { ...csrf_token, ...params.headers };
193
        let headers = { ...csrf_token, ...params.headers };
189
        return this._fetchJSON(
194
        return this._fetchJSON(
Lines 192-197 class HttpClient { Link Here
192
            {
197
            {
193
                parseResponse: false,
198
                parseResponse: false,
194
                ...params.options,
199
                ...params.options,
200
                body,
195
                method: "DELETE",
201
                method: "DELETE",
196
            },
202
            },
197
            params.return_response ?? true,
203
            params.return_response ?? true,
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/item-api-client.js (+12 lines)
Lines 14-19 export class ItemAPIClient { Link Here
14
                    params,
14
                    params,
15
                    headers,
15
                    headers,
16
                }),
16
                }),
17
            get: id =>
18
                this.httpClient.get({
19
                    endpoint: "items/" + id,
20
                }),
21
            getByExternalId: external_id =>
22
                this.httpClient.get({
23
                    endpoint: "items?" +
24
                    new URLSearchParams({
25
                        _match: 'starts_with',
26
                        external_id: external_id,
27
                    }),
28
                }),
17
        };
29
        };
18
    }
30
    }
19
31
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/item-type-api-client.js (+21 lines)
Line 0 Link Here
1
export class ItemTypeAPIClient {
2
    constructor(HttpClient) {
3
        this.httpClient = new HttpClient({
4
            baseURL: "/api/v1/",
5
        });
6
    }
7
8
    get item_types() {
9
        return {
10
            getAll: (query, params, headers) =>
11
                this.httpClient.getAll({
12
                    endpoint: "item_types",
13
                    query,
14
                    params,
15
                    headers,
16
                }),
17
        };
18
    }
19
}
20
21
export default ItemTypeAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/fetch/library-api-client.js (-1 / +21 lines)
Line 0 Link Here
0
- 
1
export class LibraryAPIClient {
2
    constructor(HttpClient) {
3
        this.httpClient = new HttpClient({
4
            baseURL: "/api/v1/",
5
        });
6
    }
7
8
    get libraries() {
9
        return {
10
            getAll: (query, params, headers) =>
11
                this.httpClient.getAll({
12
                    endpoint: "libraries",
13
                    query,
14
                    params,
15
                    headers,
16
                }),
17
        };
18
    }
19
}
20
21
export default LibraryAPIClient;

Return to bug 14962