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 (+74 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
        if ( params['embeds'] ) {
13
14
        }
15
        return this.post({
16
            endpoint: "",
17
            body: resource,
18
            headers: headers
19
        });
20
    }
21
22
    delete(id) {
23
        return this.delete({
24
            endpoint: this._baseURL + "/" + id,
25
        });
26
    }
27
28
    update( resource, id ) {
29
        return this.put({
30
            endpoint: this._baseURL + "/" + id,
31
            body: resource,
32
        });
33
    }
34
35
    patch( partial_resource, id ) {
36
        return this.patch({
37
            endpoint: this._baseURL + "/" + id,
38
            body: partial_resource,
39
        });
40
    }
41
42
    get(id) {
43
        return this.get({
44
            endpoint: this._baseURL + "/" + id,
45
        });
46
    }
47
48
    getAll(query, params) {
49
        return this.getAll({
50
            endpoint: this._baseURL,
51
            query,
52
            params,
53
            headers: {},
54
        });
55
    }
56
57
    count(query = {}) {
58
        return this.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
    build_x_koha_embed(embeds) {
70
        return { "x-koha-embed": embeds.join(",") };
71
    }
72
}
73
74
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/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