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

(-)a/admin/record_sources.pl (+37 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2023 Theke Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI        qw ( -utf8 );
23
use C4::Auth   qw( get_template_and_user );
24
use C4::Output qw( output_html_with_http_headers );
25
26
my $query = CGI->new;
27
28
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
29
    {
30
        template_name => "admin/record_sources.tt",
31
        query         => $query,
32
        type          => "intranet",
33
        flagsrequired => { parameters => 'manage_record_sources' },
34
    }
35
);
36
37
output_html_with_http_headers $query, $cookie, $template->output;
(-)a/debian/templates/apache-shared-intranet.conf (+2 lines)
Lines 13-18 ScriptAlias /search "/usr/share/koha/intranet/cgi-bin/catalogue/search.pl" Link Here
13
13
14
# Protect dev package install
14
# Protect dev package install
15
RewriteEngine on
15
RewriteEngine on
16
16
RewriteRule ^/cgi-bin/koha/(C4|debian|etc|installer/data|install_misc|Koha|misc|selenium|t|test|tmp|xt)/|\.PL$ /notfound [PT]
17
RewriteRule ^/cgi-bin/koha/(C4|debian|etc|installer/data|install_misc|Koha|misc|selenium|t|test|tmp|xt)/|\.PL$ /notfound [PT]
17
18
18
RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/catalogue/detail.pl?biblionumber=$1 [PT]
19
RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/catalogue/detail.pl?biblionumber=$1 [PT]
Lines 23-28 RewriteRule ^(.*)_[0-9]{2}\.[0-9]{7}\.(js|css)$ $1.$2 [L] Link Here
23
RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT]
24
RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT]
24
RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/preservation/.*.pl$
25
RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/preservation/.*.pl$
25
RewriteRule ^/cgi-bin/koha/preservation/.*$ /cgi-bin/koha/preservation/home.pl [PT]
26
RewriteRule ^/cgi-bin/koha/preservation/.*$ /cgi-bin/koha/preservation/home.pl [PT]
27
RewriteRule ^/cgi-bin/koha/admin/record_sources(.*)?$ /cgi-bin/koha/admin/record_sources.pl$1 [PT]
26
28
27
Alias "/api" "/usr/share/koha/api"
29
Alias "/api" "/usr/share/koha/api"
28
<Directory "/usr/share/koha/api">
30
<Directory "/usr/share/koha/api">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+4 lines)
Lines 209-214 Link Here
209
                        <dt><a href="/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl">Search engine configuration (Elasticsearch)</a></dt>
209
                        <dt><a href="/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl">Search engine configuration (Elasticsearch)</a></dt>
210
                        <dd>Manage indexes, facets, and their mappings to MARC fields and subfields</dd>
210
                        <dd>Manage indexes, facets, and their mappings to MARC fields and subfields</dd>
211
                    [% END %]
211
                    [% END %]
212
                    [% IF ( CAN_user_parameters_manage_record_sources ) %]
213
                        <dt><a href="/cgi-bin/koha/admin/record_sources">Record sources</a></dt>
214
                        <dd>Define record sources to import from</dd>
215
                    [% END %]
212
                </dl>
216
                </dl>
213
            [% END %]
217
            [% END %]
214
218
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/record_sources.tt (+34 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE To %]
3
[% USE Asset %]
4
[% USE KohaDates %]
5
[% USE TablesSettings %]
6
[% USE AuthorisedValues %]
7
[% SET footerjs = 1 %]
8
[% PROCESS 'i18n.inc' %]
9
[% INCLUDE 'doc-head-open.inc' %]
10
<title>
11
    Record sources &rsaquo; Koha
12
</title>
13
[% INCLUDE 'doc-head-close.inc' %]
14
</head>
15
16
<body id="record_sources" class="record_sources">
17
[% WRAPPER 'header.inc' %]
18
    [% INCLUDE 'prefs-admin-search.inc' %]
19
[% END %]
20
21
<div id="record-source"> <!-- this is closed in intranet-bottom.inc -->
22
23
[% MACRO jsinclude BLOCK %]
24
    [% INCLUDE 'calendar.inc' %] <!-- FIXME: this shouldn't be needed -->
25
    [% INCLUDE 'datatables.inc' %]
26
    [% INCLUDE 'columns_settings.inc' %]
27
    [% INCLUDE 'js-patron-format.inc' %]
28
    [% INCLUDE 'js-date-format.inc' %]
29
30
    [% Asset.js("js/vue/dist/admin/record_sources.js") | $raw %]
31
32
[% END %]
33
34
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/RecordSources/Edit.vue (+111 lines)
Line 0 Link Here
1
<template>
2
    <div v-if="!initialized">{{ $__("Loading") }}</div>
3
    <div v-else id="record_source_edit">
4
        <h1>{{ title }}</h1>
5
        <form @submit="processSubmit">
6
            <fieldset class="rows">
7
                <ol>
8
                    <li>
9
                        <label class="required" for="name">
10
                            {{ $__("Name") }}:
11
                        </label>
12
                        <input id="name" v-model="row.name" required />
13
                        <span class="required">{{ $__("Required") }}</span>
14
                    </li>
15
                    <li>
16
                        <label :for="`user_id`">
17
                            {{ $__("Can be edited") }}:
18
                        </label>
19
                        <input
20
                            id="can_be_edited"
21
                            type="checkbox"
22
                            v-model="row.can_be_edited"
23
                        />
24
                    </li>
25
                </ol>
26
            </fieldset>
27
            <fieldset class="action">
28
                <input type="submit" :value="$__('Submit')" />
29
                <router-link
30
                    to="../record_sources"
31
                    role="button"
32
                    class="cancel"
33
                    >{{ $__("Cancel") }}</router-link
34
                >
35
            </fieldset>
36
        </form>
37
    </div>
38
</template>
39
40
<script>
41
import { inject } from "vue"
42
import { RecordSourcesAPIClient } from "../../../fetch/record_sources-api-client"
43
44
export default {
45
    name: "Edit",
46
    setup() {
47
        const { record_source } = new RecordSourcesAPIClient()
48
        const { setMessage } = inject("mainStore")
49
        return {
50
            setMessage,
51
            api: record_source,
52
        }
53
    },
54
    data() {
55
        return {
56
            row: {
57
                name: "",
58
            },
59
            initialized: false,
60
        }
61
    },
62
    methods: {
63
        processSubmit(event) {
64
            event.preventDefault()
65
            const _hasValue = value => {
66
                return value !== undefined && value !== null && value !== ""
67
            }
68
            if (!_hasValue(this.row.name)) return false
69
            let response
70
            if (this.row.record_source_id) {
71
                const { record_source_id: id, ...row } = this.row
72
                response = this.api
73
                    .update({ id, row })
74
                    .then(() => this.$__("Record source updated!"))
75
            } else {
76
                response = this.api
77
                    .create({ row: this.row })
78
                    .then(() => this.$__("Record source created!"))
79
            }
80
            return response.then(responseMessage => {
81
                this.setMessage(responseMessage)
82
                return this.$router.push({ path: "../record_sources" })
83
            })
84
        },
85
    },
86
    created() {
87
        const { id } = this.$route.params
88
        if (id !== undefined) {
89
            this.api
90
                .get({
91
                    id,
92
                })
93
                .then(response => {
94
                    Object.keys(response).forEach(key => {
95
                        this.row[key] = response[key]
96
                    })
97
                    this.initialized = true
98
                })
99
        } else {
100
            this.initialized = true
101
        }
102
    },
103
    computed: {
104
        title() {
105
            if (!this.row || !this.row.record_source_id)
106
                return this.$__("Add record source")
107
            return this.$__("Edit '%s'").format(this.row.name)
108
        },
109
    },
110
}
111
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/RecordSources/List.vue (+139 lines)
Line 0 Link Here
1
<template>
2
    <div v-if="!initialized">{{ $__("Loading") }}</div>
3
    <div v-else id="record_sources_list">
4
        <Toolbar>
5
            <ToolbarButton
6
                :to="{ name: 'Add' }"
7
                icon="plus"
8
                :title="$__('New record source')"
9
            />
10
        </Toolbar>
11
        <h1>{{ title }}</h1>
12
        <div v-if="record_sources_count > 0" class="page-section">
13
            <KohaTable
14
                ref="table"
15
                v-bind="tableOptions"
16
                @edit="doEdit"
17
                @delete="doDelete"
18
            ></KohaTable>
19
        </div>
20
        <div v-else class="dialog message">
21
            {{ $__("There are no record sources defined") }}
22
        </div>
23
    </div>
24
</template>
25
26
<script>
27
import Toolbar from "../../Toolbar.vue"
28
import ToolbarButton from "../../ToolbarButton.vue"
29
import { inject } from "vue"
30
import { RecordSourcesAPIClient } from "../../../fetch/record_sources-api-client"
31
import KohaTable from "../../KohaTable.vue"
32
export default {
33
    name: "List",
34
    data() {
35
        return {
36
            title: this.$__("Record sources"),
37
            tableOptions: {
38
                columns: [
39
                    {
40
                        title: this.$__("ID"),
41
                        data: "record_source_id",
42
                        searchable: true,
43
                    },
44
                    {
45
                        title: this.$__("Name"),
46
                        data: "name",
47
                        searchable: true,
48
                    },
49
                    {
50
                        title: __("Can be edited"),
51
                        data: "can_be_edited",
52
                        searchable: true,
53
                        orderable: true,
54
                        render: function (data, type, row, meta) {
55
                            return escape_str(
56
                                row.can_be_edited ? __("Yes") : __("No")
57
                            )
58
                        },
59
                    },
60
                ],
61
                actions: {
62
                    "-1": ["edit", "delete"],
63
                },
64
                url: "/api/v1/record_sources",
65
            },
66
            initialized: false,
67
            record_sources_count: 0,
68
        }
69
    },
70
    setup() {
71
        const { setWarning, setMessage, setError, setConfirmationDialog } =
72
            inject("mainStore")
73
        const { record_source } = new RecordSourcesAPIClient()
74
        return {
75
            setWarning,
76
            setMessage,
77
            setError,
78
            setConfirmationDialog,
79
            api: record_source,
80
        }
81
    },
82
    beforeRouteEnter(to, from, next) {
83
        next(vm => {
84
            vm.getRecordSourcesCount().then(() => (vm.initialized = true))
85
        })
86
    },
87
    methods: {
88
        async getRecordSourcesCount() {
89
            const count = await this.api.count()
90
            this.record_sources_count = count
91
        },
92
        newRecordSource() {
93
            this.$router.push({ path: "record_sources/add" })
94
        },
95
        doEdit(data) {
96
            this.$router.push({
97
                path: `record_sources/${data.record_source_id}`,
98
                props: {
99
                    data,
100
                },
101
            })
102
        },
103
        doDelete(data, dt) {
104
            this.setConfirmationDialog(
105
                {
106
                    title: this.$__(
107
                        "Are you sure you want to remove this record source?"
108
                    ),
109
                    message: data.name,
110
                    accept_label: this.$__("Yes, remove"),
111
                    cancel_label: this.$__("No, do not remove"),
112
                },
113
                () => {
114
                    this.api
115
                        .delete({
116
                            id: data.record_source_id,
117
                        })
118
                        .then(response => {
119
                            if (response) {
120
                                this.setMessage(
121
                                    this.$__(
122
                                        "Record source '%s' removed"
123
                                    ).format(data.name),
124
                                    true
125
                                )
126
                                dt.draw()
127
                            }
128
                        })
129
                }
130
            )
131
        },
132
    },
133
    components: {
134
        KohaTable,
135
        Toolbar,
136
        ToolbarButton,
137
    },
138
}
139
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Admin/RecordSources/Main.vue (+34 lines)
Line 0 Link Here
1
<template>
2
    <div>
3
        <div id="sub-header">
4
            <Breadcrumbs></Breadcrumbs>
5
            <Help />
6
        </div>
7
        <div class="main container-fluid">
8
            <div class="row">
9
                <div class="col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2">
10
                    <main>
11
                        <Dialog></Dialog>
12
                        <router-view />
13
                    </main>
14
                </div>
15
            </div>
16
        </div>
17
    </div>
18
</template>
19
20
<script>
21
import Breadcrumbs from "../../Breadcrumbs.vue"
22
import Help from "../../Help.vue"
23
import Dialog from "../../Dialog.vue"
24
25
export default {
26
    components: {
27
        Breadcrumbs,
28
        Dialog,
29
        Help,
30
    },
31
}
32
</script>
33
34
<style></style>
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/fetch/record_sources-api-client.js (+59 lines)
Line 0 Link Here
1
import HttpClient from "./http-client";
2
3
export class RecordSourcesAPIClient extends HttpClient {
4
    constructor() {
5
        super({
6
            baseURL: "/api/v1/record_sources",
7
        });
8
    }
9
10
    get record_source() {
11
        return {
12
            create: ({ row, headers = {} }) => {
13
                const requestHeaders = {
14
                    ...headers,
15
                    "Content-Type": "application/json",
16
                };
17
                return this.post({
18
                    endpoint: "",
19
                    headers: requestHeaders,
20
                    body: JSON.stringify(row),
21
                });
22
            },
23
            delete: ({ id, headers = {} }) => {
24
                return this.delete({
25
                    endpoint: "/" + id,
26
                    headers,
27
                });
28
            },
29
            update: ({ id, headers = {}, row }) => {
30
                const requestHeaders = {
31
                    ...headers,
32
                    "Content-Type": "application/json",
33
                };
34
                return this.put({
35
                    endpoint: "/" + id,
36
                    headers: requestHeaders,
37
                    body: JSON.stringify(row),
38
                });
39
            },
40
            get: ({ id, headers = {} }) => {
41
                return this.get({
42
                    endpoint: "/" + id,
43
                    headers,
44
                });
45
            },
46
            count: (query = {}) => {
47
                return this.count({
48
                    endpoint:
49
                        "?" +
50
                        new URLSearchParams({
51
                            _page: 1,
52
                            _per_page: 1,
53
                            ...(query && { q: JSON.stringify(query) }),
54
                        }),
55
                });
56
            },
57
        };
58
    }
59
}
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/record_sources.ts (+54 lines)
Line 0 Link Here
1
import { createApp } from "vue";
2
import { createPinia } from "pinia";
3
import { createWebHistory, createRouter } from "vue-router";
4
5
import { library } from "@fortawesome/fontawesome-svg-core";
6
import {
7
    faPlus,
8
    faMinus,
9
    faPencil,
10
    faTrash,
11
    faSpinner,
12
} from "@fortawesome/free-solid-svg-icons";
13
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
14
import vSelect from "vue-select";
15
import { useNavigationStore } from "../../stores/navigation";
16
import { useMainStore } from "../../stores/main";
17
import routesDef from "../../routes/admin/record_sources";
18
19
library.add(faPlus, faMinus, faPencil, faTrash, faSpinner);
20
21
const pinia = createPinia();
22
const navigationStore = useNavigationStore(pinia);
23
const mainStore = useMainStore(pinia);
24
const { removeMessages } = mainStore;
25
const { setRoutes } = navigationStore;
26
const routes = setRoutes(routesDef);
27
28
const router = createRouter({
29
    history: createWebHistory(),
30
    linkExactActiveClass: "current",
31
    routes,
32
});
33
34
import App from "../../components/Admin/RecordSources/Main.vue";
35
import i18n from "../../i18n";
36
37
const app = createApp(App);
38
39
const rootComponent = app
40
    .use(i18n)
41
    .use(pinia)
42
    .use(router)
43
    .component("font-awesome-icon", FontAwesomeIcon)
44
    .component("v-select", vSelect);
45
46
app.config.unwrapInjectedRef = true;
47
app.provide("mainStore", mainStore);
48
app.provide("navigationStore", navigationStore);
49
app.mount("#record-source");
50
51
router.beforeEach(to => {
52
    navigationStore.$patch({ current: to.matched, params: to.params || {} });
53
    removeMessages(); // This will actually flag the messages as displayed already
54
});
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/routes/admin/record_sources.js (+40 lines)
Line 0 Link Here
1
import { markRaw } from "vue";
2
import Edit from "../../components/Admin/RecordSources/Edit.vue";
3
import List from "../../components/Admin/RecordSources/List.vue";
4
import { $__ } from "../../i18n";
5
6
export default {
7
    title: $__("Administration"),
8
    path: "",
9
    href: "/cgi-bin/koha/admin/admin-home.pl",
10
    BeforeUnloadEvent() {
11
        window.location.href = "/cgi-bin/koha/admin/admin-home.pl";
12
    },
13
    is_base: true,
14
    is_default: true,
15
    children: [
16
        {
17
            title: $__("Record sources"),
18
            path: "/cgi-bin/koha/admin/record_sources",
19
            children: [
20
                {
21
                    title: $__("List"),
22
                    path: "",
23
                    component: markRaw(List),
24
                },
25
                {
26
                    title: $__("Add record source"),
27
                    path: "add",
28
                    name: "Add",
29
                    component: markRaw(Edit),
30
                },
31
                {
32
                    title: $__("Edit record source"),
33
                    path: ":id",
34
                    name: "Edit",
35
                    component: markRaw(Edit),
36
                },
37
            ],
38
        },
39
    ],
40
};
(-)a/webpack.config.js (-1 / +1 lines)
Lines 7-12 module.exports = { Link Here
7
  entry: {
7
  entry: {
8
    erm: "./koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts",
8
    erm: "./koha-tmpl/intranet-tmpl/prog/js/vue/modules/erm.ts",
9
    preservation: "./koha-tmpl/intranet-tmpl/prog/js/vue/modules/preservation.ts",
9
    preservation: "./koha-tmpl/intranet-tmpl/prog/js/vue/modules/preservation.ts",
10
    "admin/record_sources": "./koha-tmpl/intranet-tmpl/prog/js/vue/modules/admin/record_sources.ts",
10
  },
11
  },
11
  output: {
12
  output: {
12
    filename: "[name].js",
13
    filename: "[name].js",
13
- 

Return to bug 35919