diff --git a/src/main/java/fr/inra/oresing/persistence/ReferenceValueRepository.java b/src/main/java/fr/inra/oresing/persistence/ReferenceValueRepository.java index 29fb39b6b2cd8c52539ecf9878ce6a2ecaf01a07..4ab58a75fdd9a3cf3dfc684004d5b709b6b53f38 100644 --- a/src/main/java/fr/inra/oresing/persistence/ReferenceValueRepository.java +++ b/src/main/java/fr/inra/oresing/persistence/ReferenceValueRepository.java @@ -61,7 +61,24 @@ public class ReferenceValueRepository extends JsonTableInApplicationSchemaReposi * @return la liste qui satisfont aux criteres */ public List<ReferenceValue> findAllByReferenceType(String refType, MultiValueMap<String, String> params) { - MultiValueMap<String, String> toto = new LinkedMultiValueMap<>(); + int offset = Optional.of(params) + .map(m->m.remove("_offset_")) + .filter(l->l.size()>0) + .map(l->l.get(0)) + .map(o-> { + try { + return Integer.valueOf(o); + }catch (NumberFormatException e){ + return 0; + } + }) + .orElse(0); + String limit = Optional.of(params) + .map(m->m.remove("_limit_")) + .filter(l->l.size()>0) + .map(l->l.get(0)) + .filter(o->o.matches("[0-9]*|ALL")) + .orElse("ALL"); String query = "SELECT DISTINCT '" + ReferenceValue.class.getName() + "' as \"@class\", to_jsonb(t) as json FROM " + getTable().getSqlIdentifier() + " t, jsonb_each_text(t.refvalues) kv WHERE application=:applicationId::uuid AND referenceType=:refType"; MapSqlParameterSource paramSource = new MapSqlParameterSource("applicationId", getApplication().getId()) @@ -95,6 +112,7 @@ public class ReferenceValueRepository extends JsonTableInApplicationSchemaReposi if (StringUtils.isNotBlank(cond)) { cond = " AND (" + cond + ")"; } + cond = String .format("%s offset %d limit %s", cond, offset, limit); List result = getNamedParameterJdbcTemplate().query(query + cond, paramSource, getJsonRowMapper()); return (List<ReferenceValue>) result; diff --git a/ui/src/views/references/ReferenceTableView.vue b/ui/src/views/references/ReferenceTableView.vue index b87693e30382a2eae2a35be116d68a27ac25a100..7d37cccc93b12099ed231a25060023602d33de35 100644 --- a/ui/src/views/references/ReferenceTableView.vue +++ b/ui/src/views/references/ReferenceTableView.vue @@ -1,27 +1,27 @@ <template> <PageView class="with-submenu"> <SubMenu - :root="application.localName" - :paths="subMenuPaths" - role="navigation" - :aria-label="$t('menu.aria-sub-menu')" + :root="application.localName" + :paths="subMenuPaths" + role="navigation" + :aria-label="$t('menu.aria-sub-menu')" /> <h1 class="title main-title"> - {{ $t("titles.references-data", { refName: application.localRefName }) }} + {{ $t("titles.references-data", {refName: application.localRefName}) }} </h1> <div v-if="reference && columns"> <b-table - :data="tableValues" - :striped="true" - :isFocusable="true" - :isHoverable="true" - :sticky-header="true" - height="100%" - style="padding-bottom: 20px; position: relative; z-index: 1" - paginated - :current-page="currentPage" - :per-page="perPage" + :data="tableValues" + :striped="true" + :isFocusable="true" + :isHoverable="true" + :sticky-header="true" + height="100%" + style="padding-bottom: 20px; position: relative; z-index: 1" + paginated + :current-page="currentPage" + :per-page="perPage" > <template #pagination> <b-pagination @@ -38,26 +38,26 @@ range-after="3" range-before="3" :rounded="true" - /> - </template> + /> + </template> <b-table-column - v-for="column in columns" - :key="column.id" - :field="column.id" - :label="column.title" - sortable - :sticky="column.key" - v-slot="props" + v-for="column in columns" + :key="column.id" + :field="column.id" + :label="column.title" + sortable + :sticky="column.key" + v-slot="props" > <span v-if="info(column.id) || multiplicity(column.id, props.row[column.id])"> <b-button - size="is-small" - type="is-dark" - v-if="showBtnTablDynamicColumn(props.row[column.id])" - @click="showModal(column.id,props.row[column.id])" - icon-left="eye" - rounded - style="height: inherit" + size="is-small" + type="is-dark" + v-if="showBtnTablDynamicColumn(props.row[column.id])" + @click="showModal(column.id,props.row[column.id])" + icon-left="eye" + rounded + style="height: inherit" ></b-button> <p v-else></p> <b-modal v-model="isCardModalActive" class="modalCardRef" width="70%"> @@ -71,7 +71,7 @@ </div> <div class="card-content"> <div class="columns modalArrayObj" v-for="key in modalArrayObj" :key="key.id"> - <p class="column" v-if="key.column">{{ key.column }} {{ $t('ponctuation.colon')}}</p> + <p class="column" v-if="key.column">{{ key.column }} {{ $t('ponctuation.colon') }}</p> <p class="column" v-if="key.value">{{ key.value }}</p> </div> </div> @@ -84,9 +84,9 @@ <b-collapse v-else :open="false"> <template #trigger> <b-button - :label="'' + (tableValues.indexOf(props.row) + 1)" - type="is-small" - aria-controls="contentIdForA11y1" + :label="'' + (tableValues.indexOf(props.row) + 1)" + type="is-small" + aria-controls="contentIdForA11y1" /> </template> {{ referenceValues[tableValues.indexOf(props.row)].naturalKey }} @@ -98,17 +98,17 @@ </template> <script> -import SubMenu, { SubMenuPath } from "@/components/common/SubMenu.vue"; -import { ApplicationResult } from "@/model/ApplicationResult"; -import { AlertService } from "@/services/AlertService"; -import { ApplicationService } from "@/services/rest/ApplicationService"; -import { ReferenceService } from "@/services/rest/ReferenceService"; -import { Prop, Vue, Component } from "vue-property-decorator"; +import SubMenu, {SubMenuPath} from "@/components/common/SubMenu.vue"; +import {ApplicationResult} from "@/model/ApplicationResult"; +import {AlertService} from "@/services/AlertService"; +import {ApplicationService} from "@/services/rest/ApplicationService"; +import {ReferenceService} from "@/services/rest/ReferenceService"; +import {Prop, Vue, Component} from "vue-property-decorator"; import PageView from "../common/PageView.vue"; -import { InternationalisationService } from "@/services/InternationalisationService"; +import {InternationalisationService} from "@/services/InternationalisationService"; @Component({ - components: { PageView, SubMenu }, + components: {PageView, SubMenu}, }) export default class ReferenceTableView extends Vue { @Prop() applicationName; @@ -118,6 +118,8 @@ export default class ReferenceTableView extends Vue { applicationService = ApplicationService.INSTANCE; internationalisationService = InternationalisationService.INSTANCE; referenceService = ReferenceService.INSTANCE; + offset = 0; + limit = 15; application = new ApplicationResult(); subMenuPaths = []; @@ -138,28 +140,28 @@ export default class ReferenceTableView extends Vue { async showModal(columName, tablDynamicColumn) { this.isCardModalActive = true; this.modalArrayObj = Object.entries(tablDynamicColumn) - .filter((a) => a[1]) - .map(function (a) { - let obj = {}; - obj[a[0]] = a[1]; - return obj; - }); - if(this.referencesDynamic) { + .filter((a) => a[1]) + .map(function (a) { + let obj = {}; + obj[a[0]] = a[1]; + return obj; + }); + if (this.referencesDynamic) { for (let i = 0; i < this.referencesDynamic.referenceValues.length; i++) { let hierarchicalKey = this.referencesDynamic.referenceValues[i].hierarchicalKey; for (let j = 0; j < this.modalArrayObj.length; j++) { if (this.modalArrayObj[j][hierarchicalKey]) { let column = this.referencesDynamic.referenceValues[i].values[this.display] ? - this.referencesDynamic.referenceValues[i].values[this.display] : hierarchicalKey ; + this.referencesDynamic.referenceValues[i].values[this.display] : hierarchicalKey; let value = this.modalArrayObj[j][hierarchicalKey]; - this.modalArrayObj[j] = { ...this.modalArrayObj[j], column: column, value: value }; + this.modalArrayObj[j] = {...this.modalArrayObj[j], column: column, value: value}; } } - for(let j = 0; j < tablDynamicColumn.length; j++) { + for (let j = 0; j < tablDynamicColumn.length; j++) { if (tablDynamicColumn[j] === hierarchicalKey) { let value = this.referencesDynamic.referenceValues[i].values[this.display] ? - this.referencesDynamic.referenceValues[i].values[this.display] : columName ; - this.modalArrayObj[j] = { ...this.modalArrayObj[j], value: value }; + this.referencesDynamic.referenceValues[i].values[this.display] : columName; + this.modalArrayObj[j] = {...this.modalArrayObj[j], value: value}; } } } @@ -167,6 +169,7 @@ export default class ReferenceTableView extends Vue { } return this.modalArrayObj; } + info(refType) { let dynamicColumns = Object.entries(this.reference.dynamicColumns).filter((a) => a[1]); for (let i = 0; i < dynamicColumns.length; i++) { @@ -177,17 +180,17 @@ export default class ReferenceTableView extends Vue { showBtnTablDynamicColumn(tablDynamicColumn) { let showModal = Object.entries(tablDynamicColumn) - .filter((a) => a[1]) - .map(function (a) { - let obj = {}; - obj[a[0]] = a[1]; - return obj; - }); + .filter((a) => a[1]) + .map(function (a) { + let obj = {}; + obj[a[0]] = a[1]; + return obj; + }); return showModal.length !== 0; } multiplicity(column, arrayValues) { - for(let i = 0; i < this.tableValues.length ; i++) { + for (let i = 0; i < this.tableValues.length; i++) { let showModal = Object.entries(this.tableValues[i]) .filter((a) => a[1]); for (let j = 0; j < showModal.length; j++) { @@ -210,15 +213,19 @@ export default class ReferenceTableView extends Vue { this.application = { ...this.application, localName: this.internationalisationService.mergeInternationalization(this.application) - .localName, + .localName, localRefName: this.internationalisationService.localeReferenceName( - this.application.references[this.refId], - this.application + this.application.references[this.refId], + this.application ), }; const references = await this.referenceService.getReferenceValues( - this.applicationName, - this.refId + this.applicationName, + this.refId, + { + '_offset_': this.offset, + '_limit_': this.limit, + } ); if (references) { this.referenceValues = references.referenceValues; @@ -234,25 +241,25 @@ export default class ReferenceTableView extends Vue { } this.reference = Object.values(this.application.references).find( - (ref) => ref.id === this.refId + (ref) => ref.id === this.refId ); this.subMenuPaths = [ new SubMenuPath( - this.$t("referencesManagement.references").toLowerCase(), - () => this.$router.push(`/applications/${this.applicationName}/references`), - () => this.$router.push(`/applications`) + this.$t("referencesManagement.references").toLowerCase(), + () => this.$router.push(`/applications/${this.applicationName}/references`), + () => this.$router.push(`/applications`) ), new SubMenuPath( - this.reference.label, - () => this.$router.push(`/applications/${this.applicationName}/references/${this.refId}`), - () => this.$router.push(`/applications/${this.applicationName}/references`) + this.reference.label, + () => this.$router.push(`/applications/${this.applicationName}/references/${this.refId}`), + () => this.$router.push(`/applications/${this.applicationName}/references`) ), ]; if (this.reference && this.reference.columns) { this.columns = [ - { id: "#", title: "#id", key: false, linkedTo: null }, + {id: "#", title: "#id", key: false, linkedTo: null}, ...Object.values(this.reference.columns).sort((c1, c2) => { if (c1.title < c2.title) { return -1; @@ -279,15 +286,23 @@ export default class ReferenceTableView extends Vue { let dynamicColumns = Object.entries(this.reference.dynamicColumns).filter((a) => a[1]); for (let i = 0; i < dynamicColumns.length; i++) { this.referencesDynamic = await this.referenceService.getReferenceValues( - this.applicationName, - dynamicColumns[i][1].reference + this.applicationName, + dynamicColumns[i][1].reference, + { + '_offset_': this.offset, + '_limit_': this.limit, + } ); } for (let i = 0; i < this.columns.length; i++) { - if(this.application.references[this.columns[i].id]) { + if (this.application.references[this.columns[i].id]) { this.referencesDynamic = await this.referenceService.getReferenceValues( this.applicationName, - this.columns[i].id + this.columns[i].id, + { + '_offset_': this.offset, + '_limit_': this.limit, + } ); } }