Bug 32030: Add documents to license
Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
5234bc22f4
commit
e8222d6074
5 changed files with 72 additions and 2 deletions
|
@ -22,6 +22,7 @@ use Koha::Database;
|
|||
use base qw(Koha::Object);
|
||||
|
||||
use Koha::Acquisition::Bookseller;
|
||||
use Koha::ERM::Documents;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
@ -33,6 +34,21 @@ Koha::ERM::License - Koha ERM License Object class
|
|||
|
||||
=cut
|
||||
|
||||
=head3 documents
|
||||
|
||||
Returns or updates the documents for this license
|
||||
|
||||
=cut
|
||||
|
||||
sub documents {
|
||||
my ( $self, $documents ) = @_;
|
||||
if ($documents) {
|
||||
$self->documents->replace_with($documents, $self);
|
||||
}
|
||||
my $documents_rs = $self->_result->erm_documents;
|
||||
return Koha::ERM::Documents->_new_from_dbic($documents_rs);
|
||||
}
|
||||
|
||||
=head3 vendor
|
||||
|
||||
Return the vendor for this license
|
||||
|
|
|
@ -91,7 +91,10 @@ sub add {
|
|||
|
||||
my $body = $c->validation->param('body');
|
||||
|
||||
my $documents = delete $body->{documents} // [];
|
||||
|
||||
my $license = Koha::ERM::License->new_from_api($body)->store;
|
||||
$license->documents($documents);
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
|
||||
return $c->render(
|
||||
|
@ -163,7 +166,10 @@ sub update {
|
|||
|
||||
my $body = $c->validation->param('body');
|
||||
|
||||
my $documents = delete $body->{documents} // [];
|
||||
|
||||
$license->set_from_api($body)->store;
|
||||
$license->documents($documents);
|
||||
|
||||
$c->res->headers->location($c->req->url->to_string . '/' . $license->license_id);
|
||||
return $c->render(
|
||||
|
|
|
@ -108,6 +108,7 @@
|
|||
:config="fp_config"
|
||||
/>
|
||||
</li>
|
||||
<Documents :documents="license.documents" />
|
||||
</ol>
|
||||
</fieldset>
|
||||
<fieldset class="action">
|
||||
|
@ -127,6 +128,7 @@
|
|||
<script>
|
||||
import { inject } from 'vue'
|
||||
import flatPickr from 'vue-flatpickr-component'
|
||||
import Documents from './Documents.vue'
|
||||
import { setMessage, setError } from "../../messages"
|
||||
import { fetchLicense } from '../../fetch'
|
||||
import { storeToRefs } from "pinia"
|
||||
|
@ -162,6 +164,7 @@ export default {
|
|||
status: '',
|
||||
started_on: undefined,
|
||||
ended_on: undefined,
|
||||
documents: [],
|
||||
},
|
||||
initialized: false,
|
||||
}
|
||||
|
@ -209,6 +212,8 @@ export default {
|
|||
license.started_on = license.started_on ? $date_to_rfc3339(license.started_on) : null
|
||||
license.ended_on = license.ended_on ? $date_to_rfc3339(license.ended_on) : null
|
||||
|
||||
license.documents = license.documents.map(({ file_type, uploaded_on, ...keepAttrs }) => keepAttrs)
|
||||
|
||||
const options = {
|
||||
method: method,
|
||||
body: JSON.stringify(license),
|
||||
|
@ -234,7 +239,8 @@ export default {
|
|||
},
|
||||
},
|
||||
components: {
|
||||
flatPickr
|
||||
flatPickr,
|
||||
Documents,
|
||||
},
|
||||
name: "LicensesFormAdd",
|
||||
}
|
||||
|
|
|
@ -66,6 +66,42 @@
|
|||
<label>{{ $t("Ended on") }}:</label>
|
||||
<span>{{ format_date(license.ended_on) }}</span>
|
||||
</li>
|
||||
<li v-if="license.documents.length">
|
||||
<label>{{ $t("Documents") }}</label>
|
||||
<div id="license_documents">
|
||||
<ul>
|
||||
<li
|
||||
v-for="document in license.documents"
|
||||
v-bind:key="document.document_id"
|
||||
>
|
||||
<div v-if="document.file_name">
|
||||
<span v-if="document.file_description"
|
||||
>{{ document.file_description }} -
|
||||
</span>
|
||||
<a
|
||||
download
|
||||
:href="`/api/v1/erm/documents/${document.document_id}/file/content`"
|
||||
>
|
||||
{{ document.file_name }}
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
({{ document.file_type }}) Uploaded on:
|
||||
{{ format_date(document.uploaded_on) }}
|
||||
</div>
|
||||
<div v-if="document.physical_location">
|
||||
{{ $t("Physical location") }}:
|
||||
{{ document.physical_location }}
|
||||
</div>
|
||||
<div v-if="document.uri">
|
||||
{{ $t("URI") }}: {{ document.uri }}
|
||||
</div>
|
||||
<div v-if="document.notes">
|
||||
{{ $t("Notes") }}: {{ document.notes }}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</fieldset>
|
||||
<fieldset class="action">
|
||||
|
@ -134,4 +170,10 @@ export default {
|
|||
padding-left: 0.2em;
|
||||
font-size: 11px;
|
||||
}
|
||||
#license_documents {
|
||||
padding-left: 10rem;
|
||||
}
|
||||
#license_documents ul {
|
||||
padding-left: 0;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -44,7 +44,7 @@ export const fetchLicense = async function (license_id) {
|
|||
let license;
|
||||
await fetch(apiUrl, {
|
||||
headers: {
|
||||
"x-koha-embed": "vendor",
|
||||
"x-koha-embed": "vendor,documents",
|
||||
},
|
||||
})
|
||||
.then(checkError)
|
||||
|
|
Loading…
Reference in a new issue