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

(-)a/Koha/REST/V1/Preservation.pm (+54 lines)
Line 0 Link Here
1
package Koha::REST::V1::Preservation;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Mojo::Base 'Mojolicious::Controller';
21
22
use Koha::Patrons;
23
24
use Try::Tiny qw( catch try );
25
26
=head1 NAME
27
28
Koha::REST::V1::Preservation
29
30
=head1 API
31
32
=head2 Class methods
33
34
=head3 config
35
36
Return the configuration options needed for the Preservation Vue app
37
38
=cut
39
40
sub config {
41
    my $c = shift->openapi->valid_input or return;
42
    return $c->render(
43
        status  => 200,
44
        openapi => {
45
            settings => {
46
                enabled                       => C4::Context->preference('PreservationModule'),
47
                not_for_loan_waiting_list_in  => C4::Context->preference('PreservationNotForLoanWaitingListIn'),
48
                not_for_loan_default_train_in => C4::Context->preference('PreservationNotForLoanDefaultTrainIn'),
49
            },
50
        },
51
    );
52
}
53
54
1;
(-)a/api/v1/swagger/definitions/preservation_config.yaml (+7 lines)
Line 0 Link Here
1
---
2
type: object
3
properties:
4
  settings:
5
    type: object
6
    description: List of sysprefs used for the Preservation module
7
additionalProperties: false
(-)a/api/v1/swagger/paths/preservation_config.yaml (+38 lines)
Line 0 Link Here
1
---
2
/preservation/config:
3
  get:
4
    x-mojo-to: Preservation#config
5
    operationId: getPreservationconfig
6
    description: This resource returns a list of options needed for the Preservation Vue app. EXPERIMENTAL - DO NOT RELY on this, it is subject to change!
7
    summary: get the Preservation config
8
    tags:
9
      - Preservation
10
    produces:
11
      - application/json
12
    responses:
13
      200:
14
        description: The Preservation module config
15
        schema:
16
          $ref: "../swagger.yaml#/definitions/preservation_config"
17
      400:
18
        description: Bad request
19
        schema:
20
          $ref: "../swagger.yaml#/definitions/error"
21
      403:
22
        description: Access forbidden
23
        schema:
24
          $ref: "../swagger.yaml#/definitions/error"
25
      500:
26
        description: |
27
          Internal server error. Possible `error_code` attribute values:
28
29
          * `internal_server_error`
30
        schema:
31
          $ref: "../swagger.yaml#/definitions/error"
32
      503:
33
        description: Under maintenance
34
        schema:
35
          $ref: "../swagger.yaml#/definitions/error"
36
    x-koha-authorization:
37
      permissions:
38
        preservation: 1
(-)a/api/v1/swagger/swagger.yaml (+4 lines)
Lines 90-95 definitions: Link Here
90
    $ref: ./definitions/patron_balance.yaml
90
    $ref: ./definitions/patron_balance.yaml
91
  patron_extended_attribute:
91
  patron_extended_attribute:
92
    $ref: ./definitions/patron_extended_attribute.yaml
92
    $ref: ./definitions/patron_extended_attribute.yaml
93
  preservation_config:
94
    $ref: ./definitions/preservation_config.yaml
93
  preservation_train:
95
  preservation_train:
94
    $ref: ./definitions/preservation_train.yaml
96
    $ref: ./definitions/preservation_train.yaml
95
  preservation_processing:
97
  preservation_processing:
Lines 321-326 paths: Link Here
321
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
323
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password"
322
  "/patrons/{patron_id}/password/expiration_date":
324
  "/patrons/{patron_id}/password/expiration_date":
323
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
325
    $ref: "./paths/patrons_password.yaml#/~1patrons~1{patron_id}~1password~1expiration_date"
326
  /preservation/config:
327
    $ref: ./paths/preservation_config.yaml#/~1preservation~1config
324
  /preservation/trains:
328
  /preservation/trains:
325
    $ref: ./paths/preservation_trains.yaml#/~1preservation~1trains
329
    $ref: ./paths/preservation_trains.yaml#/~1preservation~1trains
326
  "/preservation/trains/{train_id}":
330
  "/preservation/trains/{train_id}":
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/Main.vue (-34 / +18 lines)
Lines 1-5 Link Here
1
<template>
1
<template>
2
    <div v-if="initialized && PreservationModule == 1">
2
    <div v-if="initialized && config.settings.enabled == 1">
3
        <div id="sub-header">
3
        <div id="sub-header">
4
            <Breadcrumbs />
4
            <Breadcrumbs />
5
            <Help />
5
            <Help />
Lines 32-37 import LeftMenu from "../LeftMenu.vue" Link Here
32
import Dialog from "../Dialog.vue"
32
import Dialog from "../Dialog.vue"
33
import { APIClient } from "../../fetch/api-client.js"
33
import { APIClient } from "../../fetch/api-client.js"
34
import "vue-select/dist/vue-select.css"
34
import "vue-select/dist/vue-select.css"
35
import { storeToRefs } from "pinia"
35
36
36
export default {
37
export default {
37
    setup() {
38
    setup() {
Lines 42-103 export default { Link Here
42
        const { loading, loaded, setError } = mainStore
43
        const { loading, loaded, setError } = mainStore
43
44
44
        const PreservationStore = inject("PreservationStore")
45
        const PreservationStore = inject("PreservationStore")
46
47
        const { config } = storeToRefs(PreservationStore)
48
45
        return {
49
        return {
46
            AVStore,
50
            AVStore,
47
            loading,
51
            loading,
48
            loaded,
52
            loaded,
53
            config,
49
            setError,
54
            setError,
50
            PreservationStore,
51
        }
55
        }
52
    },
56
    },
53
    data() {
57
    data() {
54
        return {
58
        return {
55
            initialized: false,
59
            initialized: false,
56
            PreservationModule: null,
57
        }
60
        }
58
    },
61
    },
59
    beforeCreate() {
62
    beforeCreate() {
60
        this.loading()
63
        this.loading()
61
64
62
        const fetch_config = () => {
65
        const fetch_additional_config = () => {
63
            const sysprefs_client = APIClient.sysprefs
66
            let promises = []
64
            const av_client = APIClient.authorised_values
67
            const av_client = APIClient.authorised_values
65
            let promises = [
68
            promises.push(
66
                sysprefs_client.sysprefs
67
                    .get("PreservationNotForLoanWaitingListIn")
68
                    .then(
69
                        value => {
70
                            this.PreservationStore.settings.not_for_loan_waiting_list_in =
71
                                value.value
72
                        },
73
                        error => {}
74
                    ),
75
                sysprefs_client.sysprefs
76
                    .get("PreservationNotForLoanDefaultTrainIn")
77
                    .then(
78
                        value => {
79
                            this.PreservationStore.settings.not_for_loan_default_train_in =
80
                                value.value
81
                        },
82
                        error => {}
83
                    ),
84
                av_client.values.get("NOT_LOAN").then(
69
                av_client.values.get("NOT_LOAN").then(
85
                    values => {
70
                    values => {
86
                        this.AVStore.av_notforloan = values
71
                        this.AVStore.av_notforloan = values
87
                    },
72
                    },
88
                    error => {}
73
                    error => {}
89
                ),
74
                )
90
            ]
75
            )
91
92
            return Promise.all(promises)
76
            return Promise.all(promises)
93
        }
77
        }
94
78
95
        const sysprefs_client = APIClient.sysprefs
79
        const client = APIClient.preservation
96
        sysprefs_client.sysprefs
80
        client.config
97
            .get("PreservationModule")
81
            .get()
98
            .then(value => {
82
            .then(config => {
99
                this.PreservationModule = value.value
83
                this.config = config
100
                if (this.PreservationModule != 1) {
84
                if (this.config.settings.enabled != 1) {
101
                    return this.setError(
85
                    return this.setError(
102
                        this.$__(
86
                        this.$__(
103
                            'The preservation module is disabled, turn on <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=PreservationModule">PreservationModule</a> to use it'
87
                            'The preservation module is disabled, turn on <a href="/cgi-bin/koha/admin/preferences.pl?tab=&op=search&searchfield=PreservationModule">PreservationModule</a> to use it'
Lines 105-111 export default { Link Here
105
                        false
89
                        false
106
                    )
90
                    )
107
                }
91
                }
108
                return fetch_config()
92
                return fetch_additional_config()
109
            })
93
            })
110
            .then(() => {
94
            .then(() => {
111
                this.loaded()
95
                this.loaded()
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/Settings.vue (-7 / +13 lines)
Lines 21-27 Link Here
21
                            >
21
                            >
22
                            <v-select
22
                            <v-select
23
                                id="not_for_loan_waiting_list_in"
23
                                id="not_for_loan_waiting_list_in"
24
                                v-model="settings.not_for_loan_waiting_list_in"
24
                                v-model="
25
                                    config.settings.not_for_loan_waiting_list_in
26
                                "
25
                                label="description"
27
                                label="description"
26
                                :reduce="av => av.value"
28
                                :reduce="av => av.value"
27
                                :options="av_notforloan"
29
                                :options="av_notforloan"
Lines 29-35 Link Here
29
                                <template #search="{ attributes, events }">
31
                                <template #search="{ attributes, events }">
30
                                    <input
32
                                    <input
31
                                        :required="
33
                                        :required="
32
                                            !settings.not_for_loan_waiting_list_in
34
                                            !config.settings
35
                                                .not_for_loan_waiting_list_in
33
                                        "
36
                                        "
34
                                        class="vs__search"
37
                                        class="vs__search"
35
                                        v-bind="attributes"
38
                                        v-bind="attributes"
Lines 48-54 Link Here
48
                            >
51
                            >
49
                            <v-select
52
                            <v-select
50
                                id="not_for_loan_default_train_in"
53
                                id="not_for_loan_default_train_in"
51
                                v-model="settings.not_for_loan_default_train_in"
54
                                v-model="
55
                                    config.settings
56
                                        .not_for_loan_default_train_in
57
                                "
52
                                label="description"
58
                                label="description"
53
                                :reduce="av => av.value"
59
                                :reduce="av => av.value"
54
                                :options="av_notforloan"
60
                                :options="av_notforloan"
Lines 84-92 export default { Link Here
84
90
85
        const { setMessage, setWarning } = inject("mainStore")
91
        const { setMessage, setWarning } = inject("mainStore")
86
        const PreservationStore = inject("PreservationStore")
92
        const PreservationStore = inject("PreservationStore")
87
        const { settings } = storeToRefs(PreservationStore)
93
        const { config } = PreservationStore
88
94
89
        return { av_notforloan, setMessage, setWarning, settings }
95
        return { av_notforloan, setMessage, setWarning, config }
90
    },
96
    },
91
    data() {
97
    data() {
92
        return {
98
        return {
Lines 108-119 export default { Link Here
108
            client.sysprefs
114
            client.sysprefs
109
                .update(
115
                .update(
110
                    "PreservationNotForLoanWaitingListIn",
116
                    "PreservationNotForLoanWaitingListIn",
111
                    this.settings.not_for_loan_waiting_list_in
117
                    this.config.settings.not_for_loan_waiting_list_in
112
                )
118
                )
113
                .then(
119
                .then(
114
                    client.sysprefs.update(
120
                    client.sysprefs.update(
115
                        "PreservationNotForLoanDefaultTrainIn",
121
                        "PreservationNotForLoanDefaultTrainIn",
116
                        this.settings.not_for_loan_default_train_in || 0
122
                        this.config.settings.not_for_loan_default_train_in || 0
117
                    )
123
                    )
118
                )
124
                )
119
                .then(
125
                .then(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/TrainsFormAdd.vue (-3 / +4 lines)
Lines 103-111 export default { Link Here
103
        const { setMessage, setWarning } = inject("mainStore")
103
        const { setMessage, setWarning } = inject("mainStore")
104
104
105
        const PreservationStore = inject("PreservationStore")
105
        const PreservationStore = inject("PreservationStore")
106
        const { settings } = storeToRefs(PreservationStore)
106
        const { config } = PreservationStore
107
107
108
        return { av_notforloan, setMessage, setWarning, settings }
108
        return { av_notforloan, setMessage, setWarning, config }
109
    },
109
    },
110
    data() {
110
    data() {
111
        return {
111
        return {
Lines 113-119 export default { Link Here
113
                train_id: null,
113
                train_id: null,
114
                name: "",
114
                name: "",
115
                description: "",
115
                description: "",
116
                not_for_loan: this.settings.not_for_loan_default_train_in,
116
                not_for_loan:
117
                    this.config.settings.not_for_loan_default_train_in,
117
                default_processing_id: null,
118
                default_processing_id: null,
118
                created_on: null,
119
                created_on: null,
119
                closed_on: null,
120
                closed_on: null,
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/WaitingList.vue (-3 / +6 lines)
Lines 81-87 Link Here
81
        </div>
81
        </div>
82
    </transition>
82
    </transition>
83
    <div v-if="!initialized">{{ $__("Loading") }}</div>
83
    <div v-if="!initialized">{{ $__("Loading") }}</div>
84
    <div v-else-if="!settings.not_for_loan_waiting_list_in" id="waiting-list">
84
    <div
85
        v-else-if="!config.settings.not_for_loan_waiting_list_in"
86
        id="waiting-list"
87
    >
85
        {{ $__("You need to configure this module first.") }}
88
        {{ $__("You need to configure this module first.") }}
86
    </div>
89
    </div>
87
    <div v-else id="waiting-list">
90
    <div v-else id="waiting-list">
Lines 130-143 export default { Link Here
130
        const table = ref()
133
        const table = ref()
131
134
132
        const PreservationStore = inject("PreservationStore")
135
        const PreservationStore = inject("PreservationStore")
133
        const { settings } = storeToRefs(PreservationStore)
136
        const { config } = PreservationStore
134
137
135
        const { setMessage, setConfirmationDialog, loading, loaded } =
138
        const { setMessage, setConfirmationDialog, loading, loaded } =
136
            inject("mainStore")
139
            inject("mainStore")
137
140
138
        return {
141
        return {
139
            table,
142
            table,
140
            settings,
143
            config,
141
            setMessage,
144
            setMessage,
142
            setConfirmationDialog,
145
            setConfirmationDialog,
143
            loading,
146
            loading,
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/preservation-api-client.js (+9 lines)
Lines 7-12 export class PreservationAPIClient extends HttpClient { Link Here
7
        });
7
        });
8
    }
8
    }
9
9
10
    get config() {
11
        return {
12
            get: () =>
13
                this.get({
14
                    endpoint: "config",
15
                }),
16
        };
17
    }
18
10
    get trains() {
19
    get trains() {
11
        return {
20
        return {
12
            get: id =>
21
            get: id =>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/preservation.ts (-2 / +4 lines)
Lines 40-45 import i18n from "../i18n"; Link Here
40
const pinia = createPinia();
40
const pinia = createPinia();
41
41
42
const mainStore = useMainStore(pinia);
42
const mainStore = useMainStore(pinia);
43
const AVStore = useAVStore(pinia);
43
const navigationStore = useNavigationStore(pinia);
44
const navigationStore = useNavigationStore(pinia);
44
const routes = navigationStore.setRoutes(routesDef);
45
const routes = navigationStore.setRoutes(routesDef);
45
46
Lines 60-68 const rootComponent = app Link Here
60
61
61
app.config.unwrapInjectedRef = true;
62
app.config.unwrapInjectedRef = true;
62
app.provide("mainStore", mainStore);
63
app.provide("mainStore", mainStore);
63
app.provide("navigationStore", navigationStore);
64
app.provide("AVStore", useAVStore(pinia));
64
app.provide("AVStore", useAVStore(pinia));
65
app.provide("PreservationStore", usePreservationStore(pinia));
65
app.provide("navigationStore", navigationStore);
66
const PreservationStore = usePreservationStore(pinia);
67
app.provide("PreservationStore", PreservationStore);
66
68
67
app.mount("#preservation");
69
app.mount("#preservation");
68
70
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/preservation.js (-4 / +6 lines)
Lines 2-10 import { defineStore } from "pinia"; Link Here
2
2
3
export const usePreservationStore = defineStore("preservation", {
3
export const usePreservationStore = defineStore("preservation", {
4
    state: () => ({
4
    state: () => ({
5
        settings: {
5
        config: {
6
            not_for_loan_waiting_list_in: null,
6
            settings: {
7
            not_for_loan_default_train_in: 0,
7
                enabled: 0,
8
                not_for_loan_waiting_list_in: null,
9
                not_for_loan_default_train_in: 0,
10
            },
8
        },
11
        },
9
    }),
12
    }),
10
});
13
});
11
- 

Return to bug 30708