Bug 32807: Fetch count instead of all entries for agreements and licenses
To list agreements and licenses we are retrieving the whole list to
simply know if at least one exists (and display the table that will
fetch the X first elements to display).
We should call count instead.
Test plan:
List agreements and licenses.
If none exists, the table is not displayed but a "There are no...
defined" message instead.
If at least one exists the table must be there
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit f781fdb4a2)
Signed-off-by: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
This commit is contained in:
parent
cebf8ec141
commit
59daae2ebc
|
|
@ -1,8 +1,8 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else-if="agreements" id="agreements_list">
|
||||
<div v-else-if="agreement_count" id="agreements_list">
|
||||
<Toolbar v-if="before_route_entered" />
|
||||
<fieldset v-if="agreements.length" class="filters">
|
||||
<fieldset v-if="agreement_count > 0" class="filters">
|
||||
<label for="expired_filter">{{ $__("Filter by expired") }}:</label>
|
||||
<input
|
||||
type="checkbox"
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
:value="$__('Filter')"
|
||||
/>
|
||||
</fieldset>
|
||||
<div v-if="agreements.length" class="page-section">
|
||||
<div v-if="agreement_count > 0" class="page-section">
|
||||
<table :id="table_id"></table>
|
||||
</div>
|
||||
<div v-else-if="initialized" class="dialog message">
|
||||
|
|
@ -67,7 +67,7 @@ export default {
|
|||
data: function () {
|
||||
return {
|
||||
fp_config: flatpickr_defaults,
|
||||
agreements: [],
|
||||
agreement_count: null,
|
||||
initialized: false,
|
||||
filters: {
|
||||
by_expired: this.$route.query.by_expired || false,
|
||||
|
|
@ -83,7 +83,7 @@ export default {
|
|||
vm.before_route_entered = true // FIXME This is ugly, but we need to distinguish when it's used as main component or child component (from EHoldingsEBSCOPAckagesShow for instance)
|
||||
if (!vm.building_table) {
|
||||
vm.building_table = true
|
||||
vm.getAgreements().then(() => vm.build_datatable())
|
||||
vm.getAgreementCount().then(() => vm.build_datatable())
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
@ -97,11 +97,11 @@ export default {
|
|||
},
|
||||
},
|
||||
methods: {
|
||||
async getAgreements() {
|
||||
async getAgreementCount() {
|
||||
const client = APIClient.erm
|
||||
await client.agreements.getAll().then(
|
||||
agreements => {
|
||||
this.agreements = agreements
|
||||
await client.agreements.count().then(
|
||||
count => {
|
||||
this.agreement_count = count
|
||||
this.initialized = true
|
||||
},
|
||||
error => {}
|
||||
|
|
@ -463,7 +463,7 @@ export default {
|
|||
mounted() {
|
||||
if (!this.building_table) {
|
||||
this.building_table = true
|
||||
this.getAgreements().then(() => this.build_datatable())
|
||||
this.getAgreementCount().then(() => this.build_datatable())
|
||||
}
|
||||
},
|
||||
components: { flatPickr, Toolbar },
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export default {
|
|||
},
|
||||
data: function () {
|
||||
return {
|
||||
package_count: [],
|
||||
package_count: null,
|
||||
initialized: false,
|
||||
filters: {
|
||||
package_name: this.$route.query.package_name || "",
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export default {
|
|||
},
|
||||
data: function () {
|
||||
return {
|
||||
title_count: undefined,
|
||||
title_count: null,
|
||||
initialized: false,
|
||||
filters: {
|
||||
publication_title: this.$route.query.publication_title || "",
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<template>
|
||||
<div v-if="!initialized">{{ $__("Loading") }}</div>
|
||||
<div v-else-if="licenses" id="licenses_list">
|
||||
<div v-else-if="license_count" id="licenses_list">
|
||||
<Toolbar />
|
||||
<div v-if="licenses.length" class="page-section">
|
||||
<div v-if="license_count > 0" class="page-section">
|
||||
<table :id="table_id"></table>
|
||||
</div>
|
||||
<div v-else-if="initialized" class="dialog message">
|
||||
|
|
@ -42,21 +42,21 @@ export default {
|
|||
},
|
||||
data: function () {
|
||||
return {
|
||||
licenses: [],
|
||||
license_count: null,
|
||||
initialized: false,
|
||||
}
|
||||
},
|
||||
beforeRouteEnter(to, from, next) {
|
||||
next(vm => {
|
||||
vm.getLicenses().then(() => vm.build_datatable())
|
||||
vm.getLicenseCount().then(() => vm.build_datatable())
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
async getLicenses() {
|
||||
async getLicenseCount() {
|
||||
const client = APIClient.erm
|
||||
await client.licenses.getAll().then(
|
||||
licenses => {
|
||||
this.licenses = licenses
|
||||
await client.licenses.count().then(
|
||||
count => {
|
||||
this.license_count = count
|
||||
this.initialized = true
|
||||
},
|
||||
error => {}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,16 @@ export class ERMAPIClient extends HttpClient {
|
|||
endpoint: "agreements/" + id,
|
||||
body: agreement,
|
||||
}),
|
||||
//count: () => this.count("agreements"), //TODO: Implement count method
|
||||
count: (query = {}) =>
|
||||
this.count({
|
||||
endpoint:
|
||||
"agreements?" +
|
||||
new URLSearchParams({
|
||||
_page: 1,
|
||||
_per_page: 1,
|
||||
...(query && { q: JSON.stringify(query) }),
|
||||
}),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +79,16 @@ export class ERMAPIClient extends HttpClient {
|
|||
endpoint: "licenses/" + id,
|
||||
body: license,
|
||||
}),
|
||||
count: (query = {}) =>
|
||||
this.count({
|
||||
endpoint:
|
||||
"licenses?" +
|
||||
new URLSearchParams({
|
||||
_page: 1,
|
||||
_per_page: 1,
|
||||
...(query && { q: JSON.stringify(query) }),
|
||||
}),
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue