Bug 38201: Migrate record sources
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
b6c3b0a0c8
commit
e9fe68bfee
|
|
@ -1,129 +0,0 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else id="record_source_edit">
|
||||
<h1 v-if="record_source.record_source_id">
|
||||
{{
|
||||
$__("Edit record source #%s").format(
|
||||
record_source.record_source_id
|
||||
)
|
||||
}}
|
||||
</h1>
|
||||
<h1 v-else>{{ $__("Add record source") }}</h1>
|
||||
<form @submit="onSubmit($event)">
|
||||
<fieldset class="rows">
|
||||
<ol>
|
||||
<li>
|
||||
<label class="required" for="name">
|
||||
{{ $__("Name") }}:
|
||||
</label>
|
||||
<input
|
||||
id="name"
|
||||
v-model="record_source.name"
|
||||
required
|
||||
/>
|
||||
<span class="required">{{ $__("Required") }}</span>
|
||||
</li>
|
||||
<li>
|
||||
<label for="can_be_edited">
|
||||
{{ $__("Can be edited") }}:
|
||||
</label>
|
||||
<input
|
||||
id="can_be_edited"
|
||||
type="checkbox"
|
||||
v-model="record_source.can_be_edited"
|
||||
/>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
<fieldset class="action">
|
||||
<input
|
||||
type="submit"
|
||||
class="btn btn-primary"
|
||||
:value="$__('Submit')"
|
||||
/>
|
||||
<router-link
|
||||
:to="{ name: 'RecordSourcesList' }"
|
||||
role="button"
|
||||
class="cancel"
|
||||
>{{ $__("Cancel") }}</router-link
|
||||
>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { inject } from "vue";
|
||||
import { setMessage, setError, setWarning } from "../../../messages";
|
||||
import { APIClient } from "../../../fetch/api-client.js";
|
||||
|
||||
export default {
|
||||
setup() {
|
||||
const { setMessage } = inject("mainStore");
|
||||
return {
|
||||
setMessage,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
record_source: {
|
||||
record_source_id: null,
|
||||
name: "",
|
||||
can_be_edited: false,
|
||||
},
|
||||
initialized: false,
|
||||
};
|
||||
},
|
||||
beforeRouteEnter(to, from, next) {
|
||||
next(vm => {
|
||||
if (to.params.record_source_id) {
|
||||
vm.getRecordSource(to.params.record_source_id);
|
||||
} else {
|
||||
vm.initialized = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
async getRecordSource(record_source_id) {
|
||||
const client = APIClient.record_sources;
|
||||
client.record_sources.get(record_source_id).then(
|
||||
record_source => {
|
||||
this.record_source = record_source;
|
||||
this.record_source_id = record_source_id;
|
||||
this.initialized = true;
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
},
|
||||
onSubmit(e) {
|
||||
e.preventDefault();
|
||||
const client = APIClient.record_sources;
|
||||
let response;
|
||||
// RO attribute
|
||||
delete this.record_source.record_source_id;
|
||||
if (this.record_source_id) {
|
||||
// update
|
||||
response = client.record_sources
|
||||
.update(this.record_source, this.record_source_id)
|
||||
.then(
|
||||
success => {
|
||||
setMessage(this.$__("Record source updated!"));
|
||||
this.$router.push({ name: "RecordSourcesList" });
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
} else {
|
||||
response = client.record_sources
|
||||
.create(this.record_source)
|
||||
.then(
|
||||
success => {
|
||||
setMessage(this.$__("Record source created!"));
|
||||
this.$router.push({ name: "RecordSourcesList" });
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else id="record_sources_list">
|
||||
<Toolbar>
|
||||
<ToolbarButton
|
||||
:to="{ name: 'RecordSourcesFormAdd' }"
|
||||
icon="plus"
|
||||
:title="$__('New record source')"
|
||||
/>
|
||||
</Toolbar>
|
||||
<h1>{{ title }}</h1>
|
||||
<div v-if="record_sources_count > 0" class="page-section">
|
||||
<KohaTable
|
||||
ref="table"
|
||||
v-bind="tableOptions"
|
||||
@edit="doEdit"
|
||||
@delete="doDelete"
|
||||
></KohaTable>
|
||||
</div>
|
||||
<div v-else class="alert alert-info">
|
||||
{{ $__("There are no record sources defined") }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Toolbar from "../../Toolbar.vue";
|
||||
import ToolbarButton from "../../ToolbarButton.vue";
|
||||
import { inject } from "vue";
|
||||
import { APIClient } from "../../../fetch/api-client.js";
|
||||
import KohaTable from "../../KohaTable.vue";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
title: this.$__("Record sources"),
|
||||
tableOptions: {
|
||||
options: { embed: "usage_count" },
|
||||
columns: [
|
||||
{
|
||||
title: this.$__("ID"),
|
||||
data: "record_source_id",
|
||||
searchable: true,
|
||||
},
|
||||
{
|
||||
title: this.$__("Name"),
|
||||
data: "name",
|
||||
searchable: true,
|
||||
},
|
||||
{
|
||||
title: __("Can be edited"),
|
||||
data: "can_be_edited",
|
||||
searchable: true,
|
||||
orderable: true,
|
||||
render: function (data, type, row, meta) {
|
||||
return escape_str(
|
||||
row.can_be_edited ? __("Yes") : __("No")
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: {
|
||||
"-1": [
|
||||
"edit",
|
||||
{
|
||||
delete: {
|
||||
text: this.$__("Delete"),
|
||||
icon: "fa fa-trash",
|
||||
should_display: row => row.usage_count == 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
url: "/api/v1/record_sources",
|
||||
},
|
||||
initialized: false,
|
||||
record_sources_count: 0,
|
||||
};
|
||||
},
|
||||
setup() {
|
||||
const { setWarning, setMessage, setError, setConfirmationDialog } =
|
||||
inject("mainStore");
|
||||
return {
|
||||
setWarning,
|
||||
setMessage,
|
||||
setError,
|
||||
setConfirmationDialog,
|
||||
};
|
||||
},
|
||||
beforeRouteEnter(to, from, next) {
|
||||
next(vm => {
|
||||
vm.getRecordSourcesCount().then(() => (vm.initialized = true));
|
||||
});
|
||||
},
|
||||
methods: {
|
||||
async getRecordSourcesCount() {
|
||||
const client = APIClient.record_sources;
|
||||
await client.record_sources.count().then(
|
||||
count => {
|
||||
this.record_sources_count = count;
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
},
|
||||
newRecordSource() {
|
||||
this.$router.push({ name: "RecordSourcesFormAdd" });
|
||||
},
|
||||
doEdit: function ({ record_source_id }, dt, event) {
|
||||
this.$router.push({
|
||||
name: "RecordSourcesFormAddEdit",
|
||||
params: { record_source_id },
|
||||
});
|
||||
},
|
||||
doDelete: function (record_source, dt, event) {
|
||||
this.setConfirmationDialog(
|
||||
{
|
||||
title: this.$__(
|
||||
"Are you sure you want to delete this record source?"
|
||||
),
|
||||
message: record_source.name,
|
||||
accept_label: this.$__("Yes, delete"),
|
||||
cancel_label: this.$__("No, do not delete"),
|
||||
},
|
||||
() => {
|
||||
const client = APIClient.record_sources;
|
||||
client.record_sources
|
||||
.delete(record_source.record_source_id)
|
||||
.then(
|
||||
success => {
|
||||
this.setMessage(
|
||||
this.$__(
|
||||
"Record source '%s' deleted"
|
||||
).format(record_source.name),
|
||||
true
|
||||
);
|
||||
dt.draw();
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
},
|
||||
components: {
|
||||
KohaTable,
|
||||
Toolbar,
|
||||
ToolbarButton,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
<template>
|
||||
<ResourceList
|
||||
v-if="action === 'list'"
|
||||
v-bind="{
|
||||
apiClient,
|
||||
i18n,
|
||||
tableOptions,
|
||||
resourceName,
|
||||
goToResourceShow,
|
||||
goToResourceEdit,
|
||||
doResourceDelete,
|
||||
goToResourceAdd,
|
||||
doResourceSelect,
|
||||
tableFilters,
|
||||
getFilters,
|
||||
filterTable,
|
||||
tableUrl,
|
||||
}"
|
||||
@select-resource="$emit('select-resource', $event)"
|
||||
/>
|
||||
<ResourceShow
|
||||
v-if="action === 'show'"
|
||||
v-bind="{
|
||||
idAttr,
|
||||
apiClient,
|
||||
i18n,
|
||||
resourceAttrs,
|
||||
listComponent,
|
||||
goToResourceEdit,
|
||||
doResourceDelete,
|
||||
}"
|
||||
/>
|
||||
<ResourceFormAdd
|
||||
v-if="['add', 'edit'].includes(action)"
|
||||
v-bind="{
|
||||
idAttr,
|
||||
apiClient,
|
||||
i18n,
|
||||
resourceAttrs,
|
||||
listComponent,
|
||||
resource: newResource,
|
||||
onSubmit,
|
||||
}"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BaseResource from "../../BaseResource.vue";
|
||||
import { APIClient } from "../../../fetch/api-client.js";
|
||||
import ResourceShow from "../../ResourceShow.vue";
|
||||
import ResourceFormAdd from "../../ResourceFormAdd.vue";
|
||||
import ResourceList from "../../ResourceList.vue";
|
||||
|
||||
export default {
|
||||
components: { ResourceShow, ResourceFormAdd, ResourceList },
|
||||
extends: BaseResource,
|
||||
extends: BaseResource,
|
||||
props: {
|
||||
action: String,
|
||||
},
|
||||
setup(props) {
|
||||
return {
|
||||
...BaseResource.setup({
|
||||
resourceName: "record_source",
|
||||
nameAttr: "name",
|
||||
idAttr: "record_source_id",
|
||||
showComponent: null,
|
||||
listComponent: "RecordSourcesList",
|
||||
addComponent: "RecordSourcesFormAdd",
|
||||
editComponent: "RecordSourcesFormAddEdit",
|
||||
apiClient: APIClient.record_sources.record_sources,
|
||||
resourceTableUrl: APIClient.record_sources._baseURL,
|
||||
i18n: {
|
||||
displayName: __("Record source"),
|
||||
displayNameLc: __("record source"),
|
||||
displayNamePl: __("record sources"),
|
||||
},
|
||||
}),
|
||||
};
|
||||
},
|
||||
data() {
|
||||
const tableFilters = this.getTableFilters();
|
||||
const defaults = this.getFilters(this.$route.query, tableFilters);
|
||||
|
||||
return {
|
||||
record_source: {
|
||||
record_source_id: null,
|
||||
name: "",
|
||||
can_be_edited: false,
|
||||
},
|
||||
resourceAttrs: [
|
||||
{
|
||||
name: "name",
|
||||
required: true,
|
||||
type: "text",
|
||||
label: __("Name"),
|
||||
showInTable: true,
|
||||
},
|
||||
{
|
||||
name: "can_be_edited",
|
||||
type: "checkbox",
|
||||
label: __("Can be edited"),
|
||||
value: false,
|
||||
},
|
||||
],
|
||||
tableOptions: {
|
||||
options: { embed: "usage_count" },
|
||||
columns: this.getTableColumns(),
|
||||
url: this.getResourceTableUrl(),
|
||||
actions: {
|
||||
"-1": [
|
||||
"edit",
|
||||
{
|
||||
delete: {
|
||||
text: __("Delete"),
|
||||
icon: "fa fa-trash",
|
||||
should_display: row => row.usage_count == 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
tableFilters,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
tableUrl() {
|
||||
return this.getResourceTableUrl();
|
||||
},
|
||||
onSubmit(e, recordSourceToSave) {
|
||||
e.preventDefault();
|
||||
let response;
|
||||
// RO attribute
|
||||
const recordSource = JSON.parse(JSON.stringify(recordSourceToSave)); // copy
|
||||
const recordSourceId = recordSource.record_source_id;
|
||||
|
||||
delete recordSource.record_source_id;
|
||||
|
||||
if (recordSourceId) {
|
||||
// update
|
||||
response = this.apiClient
|
||||
.update(recordSource, recordSourceId)
|
||||
.then(
|
||||
success => {
|
||||
this.setMessage(this.$__("Record source updated!"));
|
||||
this.$router.push({ name: "RecordSourcesList" });
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
} else {
|
||||
response = this.apiClient.create(recordSource).then(
|
||||
success => {
|
||||
this.setMessage(this.$__("Record source created!"));
|
||||
this.$router.push({ name: "RecordSourcesList" });
|
||||
},
|
||||
error => {}
|
||||
);
|
||||
}
|
||||
},
|
||||
getTableColumns() {
|
||||
let escape_str = this.escape_str;
|
||||
|
||||
return [
|
||||
{
|
||||
title: __("ID"),
|
||||
data: "record_source_id",
|
||||
searchable: true,
|
||||
},
|
||||
{
|
||||
title: __("Name"),
|
||||
data: "name",
|
||||
searchable: true,
|
||||
},
|
||||
{
|
||||
title: __("Can be edited"),
|
||||
data: "can_be_edited",
|
||||
searchable: true,
|
||||
orderable: true,
|
||||
render: function (data, type, row, meta) {
|
||||
return escape_str(
|
||||
row.can_be_edited ? __("Yes") : __("No")
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
getTableFilters() {
|
||||
return [];
|
||||
},
|
||||
async filterTable(filters, table, embedded = false) {},
|
||||
},
|
||||
computed: {
|
||||
newResource() {
|
||||
return this[this.resourceName];
|
||||
},
|
||||
},
|
||||
created() {
|
||||
//IMPROVEME: We need this for now to assign the correct av array from setup to the attr options in data
|
||||
this.assignAVs(this.resourceAttrs);
|
||||
// FIXME: We should use this to get the table columns, replace the explicit method if possible
|
||||
this.getResourceTableColumns();
|
||||
},
|
||||
name: "RecordSourcesResource",
|
||||
};
|
||||
</script>
|
||||
|
|
@ -4,7 +4,6 @@ import { build_url } from "../composables/datatables";
|
|||
|
||||
export default {
|
||||
setup(props) {
|
||||
//global setup for all resource (list and show for now, but maybe others?) components here
|
||||
const { setConfirmationDialog, setMessage, setError, setWarning } =
|
||||
inject("mainStore");
|
||||
|
||||
|
|
@ -22,7 +21,7 @@ export default {
|
|||
setWarning,
|
||||
format_date,
|
||||
patron_to_html,
|
||||
logged_in_user,
|
||||
...(typeof logged_in_user !== "undefined" && { logged_in_user }),
|
||||
escape_str,
|
||||
get_lib_from_av,
|
||||
map_av_dt_filter,
|
||||
|
|
@ -90,7 +89,7 @@ export default {
|
|||
* @param {Object} callback - Callback to call after deletion (optional)
|
||||
* @return {void}
|
||||
*/
|
||||
doResourceDelete: function (resource, callback) {
|
||||
doResourceDelete: function (resource, callback, table) {
|
||||
let resourceId = resource
|
||||
? resource[this.idAttr]
|
||||
: this[this.resourceName][this.idAttr];
|
||||
|
|
@ -120,13 +119,7 @@ export default {
|
|||
if (typeof callback === "function") {
|
||||
callback();
|
||||
} else {
|
||||
if (this.$options.name === this.listComponent) {
|
||||
this.$refs.table.redraw(
|
||||
this.getResourceTableUrl()
|
||||
);
|
||||
} else {
|
||||
this.goToResourceList();
|
||||
}
|
||||
callback.ajax.reload();
|
||||
}
|
||||
},
|
||||
error => {}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ export default {
|
|||
getFilters: Function,
|
||||
filterTable: Function,
|
||||
tableUrl: Function,
|
||||
hasAdditionalFields: { type: Boolean, default: false },
|
||||
},
|
||||
data: function () {
|
||||
return {
|
||||
|
|
@ -92,13 +93,17 @@ export default {
|
|||
if (this.embedded) {
|
||||
this.getResourceCount().then(() => (this.initialized = true));
|
||||
} else {
|
||||
this.getResourceCount().then(() =>
|
||||
this.getSearchableAdditionalFields().then(() =>
|
||||
this.getSearchableAVOptions().then(
|
||||
() => (this.initialized = true)
|
||||
)
|
||||
)
|
||||
);
|
||||
this.getResourceCount().then(() => {
|
||||
if (this.hasAdditionalFields) {
|
||||
this.getSearchableAdditionalFields().then(() =>
|
||||
this.getSearchableAVOptions().then(
|
||||
() => (this.initialized = true)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
this.initialized = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { markRaw } from "vue";
|
||||
import RecordSourcesFormAdd from "../../components/Admin/RecordSources/FormAdd.vue";
|
||||
import RecordSourcesList from "../../components/Admin/RecordSources/List.vue";
|
||||
|
||||
import ResourceWrapper from "../../components/ResourceWrapper.vue";
|
||||
|
||||
import { $__ } from "../../i18n";
|
||||
|
||||
export default {
|
||||
|
|
@ -14,20 +15,21 @@ export default {
|
|||
title: $__("Record sources"),
|
||||
path: "/cgi-bin/koha/admin/record_sources",
|
||||
is_end_node: true,
|
||||
resource: "Admin/RecordSources/RecordSourcesResource.vue",
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
name: "RecordSourcesList",
|
||||
component: markRaw(RecordSourcesList),
|
||||
component: markRaw(ResourceWrapper),
|
||||
},
|
||||
{
|
||||
component: markRaw(RecordSourcesFormAdd),
|
||||
component: markRaw(ResourceWrapper),
|
||||
name: "RecordSourcesFormAdd",
|
||||
path: "add",
|
||||
title: $__("Add record source"),
|
||||
},
|
||||
{
|
||||
component: markRaw(RecordSourcesFormAdd),
|
||||
component: markRaw(ResourceWrapper),
|
||||
name: "RecordSourcesFormAddEdit",
|
||||
path: "edit/:record_source_id",
|
||||
title: $__("Edit record source"),
|
||||
|
|
|
|||
Loading…
Reference in New Issue