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

(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/RecordSources/List.vue (-2 / +2 lines)
Lines 84-90 export default { Link Here
84
    },
84
    },
85
    methods: {
85
    methods: {
86
        async getRecordSourcesCount() {
86
        async getRecordSourcesCount() {
87
            const client = APIClient.record_sources
87
            const client = APIClient.admin
88
            await client.record_sources.count().then(
88
            await client.record_sources.count().then(
89
                count => {
89
                count => {
90
                    this.record_sources_count = count
90
                    this.record_sources_count = count
Lines 112-118 export default { Link Here
112
                    cancel_label: this.$__("No, do not delete"),
112
                    cancel_label: this.$__("No, do not delete"),
113
                },
113
                },
114
                () => {
114
                () => {
115
                    const client = APIClient.record_sources
115
                    const client = APIClient.admin
116
                    client.record_sources
116
                    client.record_sources
117
                        .delete(record_source.record_source_id)
117
                        .delete(record_source.record_source_id)
118
                        .then(
118
                        .then(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/admin-api-client.js (+10 lines)
Line 0 Link Here
1
import RecordSourcesAPIClient from './record-sources-api-client';
2
3
export class AdminAPIClient {
4
5
    get record_sources() {
6
        return new RecordSourcesAPIClient(); // maybe with some default embeds for the 'admin' context usage, etc
7
    }
8
}
9
10
export default AdminAPIClient;
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client-base.js (+76 lines)
Line 0 Link Here
1
import HttpClient from "./http-client";
2
3
export class APIClientBase extends HttpClient {
4
5
6
    // FIXME: All methods should accept:
7
    //        * 'embeds' and do the right thing (i.e. merge them with other headers)
8
    //        * custom headers (thinking of x-koha-override, Accept, etc) Even delete() should
9
    //          accept headers
10
    create(resource, ...params) {
11
        let headers = params.headers
12
13
        if ( params['embeds'] ) {
14
            headers = { headers, ...build_x_koha_embed(params['embeds']) }
15
        }
16
17
        return this.post({
18
            endpoint: this._baseURL,
19
            body: resource,
20
            headers: headers
21
        });
22
    }
23
24
    delete(id) {
25
        return this.delete({
26
            endpoint: this._baseURL + "/" + id,
27
        });
28
    }
29
30
    update( resource, id ) {
31
        return this.put({
32
            endpoint: this._baseURL + "/" + id,
33
            body: resource,
34
        });
35
    }
36
37
    patch( partial_resource, id ) {
38
        return this.patch({
39
            endpoint: this._baseURL + "/" + id,
40
            body: partial_resource,
41
        });
42
    }
43
44
    get(id) {
45
        return this.get({
46
            endpoint: this._baseURL + "/" + id,
47
        });
48
    }
49
50
    getAll(query, params) {
51
        return this.getAll({
52
            endpoint: this._baseURL,
53
            query,
54
            params,
55
            headers: {},
56
        });
57
    }
58
59
    count(query = {}) {
60
        return this.count({
61
            endpoint:
62
                "?" +
63
                new URLSearchParams({
64
                    _page: 1,
65
                    _per_page: 1,
66
                    ...(query && { q: JSON.stringify(query) }),
67
                }),
68
        });
69
    }
70
71
    build_x_koha_embed(embeds) {
72
        return { "x-koha-embed": embeds.join(",") };
73
    }
74
}
75
76
export default APIClientBase;
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/api-client.js (-2 / +2 lines)
Lines 3-11 import PatronAPIClient from "./patron-api-client"; Link Here
3
import AcquisitionAPIClient from "./acquisition-api-client";
3
import AcquisitionAPIClient from "./acquisition-api-client";
4
import AVAPIClient from "./authorised-values-api-client";
4
import AVAPIClient from "./authorised-values-api-client";
5
import ItemAPIClient from "./item-api-client";
5
import ItemAPIClient from "./item-api-client";
6
import RecordSourcesAPIClient from "./record-sources-api-client";
7
import SysprefAPIClient from "./system-preferences-api-client";
6
import SysprefAPIClient from "./system-preferences-api-client";
8
import PreservationAPIClient from "./preservation-api-client";
7
import PreservationAPIClient from "./preservation-api-client";
8
import AdminAPIClient from "./admin-api-client";
9
9
10
export const APIClient = {
10
export const APIClient = {
11
    erm: new ERMAPIClient(),
11
    erm: new ERMAPIClient(),
Lines 15-19 export const APIClient = { Link Here
15
    item: new ItemAPIClient(),
15
    item: new ItemAPIClient(),
16
    sysprefs: new SysprefAPIClient(),
16
    sysprefs: new SysprefAPIClient(),
17
    preservation: new PreservationAPIClient(),
17
    preservation: new PreservationAPIClient(),
18
    record_sources: new RecordSourcesAPIClient(),
18
    admin: new AdminAPIClient(),
19
};
19
};
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/http-client.js (-1 / +1 lines)
Lines 17-23 class HttpClient { Link Here
17
    ) {
17
    ) {
18
        let res, error;
18
        let res, error;
19
        if (mark_submitting) submitting();
19
        if (mark_submitting) submitting();
20
        await fetch(this._baseURL + endpoint, {
20
        await fetch( endpoint, {
21
            ...options,
21
            ...options,
22
            headers: { ...this._headers, ...headers },
22
            headers: { ...this._headers, ...headers },
23
        })
23
        })
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/record-sources-api-client.js (-43 / +2 lines)
Lines 1-51 Link Here
1
import HttpClient from "./http-client";
1
import APIClientBase from "./api-client-base";
2
2
3
export class RecordSourcesAPIClient extends HttpClient {
3
export class RecordSourcesAPIClient extends APIClientBase {
4
    constructor() {
4
    constructor() {
5
        super({
5
        super({
6
            baseURL: "/api/v1/record_sources",
6
            baseURL: "/api/v1/record_sources",
7
        });
7
        });
8
    }
8
    }
9
10
    get record_sources() {
11
        return {
12
            create: record_source =>
13
                this.post({
14
                    endpoint: "",
15
                    body: record_source,
16
                }),
17
            delete: id =>
18
                this.delete({
19
                    endpoint: "/" + id,
20
                }),
21
            update: (record_source, id) =>
22
                this.put({
23
                    endpoint: "/" + id,
24
                    body: record_source,
25
                }),
26
            get: id =>
27
                this.get({
28
                    endpoint: "/" + id,
29
                }),
30
            getAll: (query, params) =>
31
                this.getAll({
32
                    endpoint: "/",
33
                    query,
34
                    params,
35
                    headers: {},
36
                }),
37
            count: (query = {}) =>
38
                this.count({
39
                    endpoint:
40
                        "?" +
41
                        new URLSearchParams({
42
                            _page: 1,
43
                            _per_page: 1,
44
                            ...(query && { q: JSON.stringify(query) }),
45
                        }),
46
                }),
47
        };
48
    }
49
}
9
}
50
10
51
export default RecordSourcesAPIClient;
11
export default RecordSourcesAPIClient;
52
- 

Return to bug 36369