Skip to content
Snippets Groups Projects
Commit fc14b3c2 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

add user to idgo catalog request & handle error

parent aba2f5ee
No related branches found
No related tags found
4 merge requests!295Version 3.0.0,!247REDMINE_ISSUE-12787,!245REDMINE_ISSUE-12786,!233REDMINE_ISSUE-12378
...@@ -6,18 +6,22 @@ const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE; ...@@ -6,18 +6,22 @@ const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE;
const miscAPI = { const miscAPI = {
async getIdgoCatalog() { async getIdgoCatalog(username) {
const response = await axios.get( try {
`${baseUrl}idgo-catalog/` const response = await axios.get(
); `${baseUrl}idgo-catalog/?user=${username}`
if ( );
response.status === 200 && if (
response.data response.status === 200 &&
) { response.data
return response.data; ) {
} else { return response.data;
return null; } else {
} return null;
}
} catch (err) {
return err;
}
}, },
async getExternalGeojson(queryParams) { async getExternalGeojson(queryParams) {
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
<div>Dataset</div> <div>Dataset</div>
<div>Ressource</div> <div>Ressource</div>
</div> </div>
<div> <div v-if="resources && resources.length > 0" >
<div <div
v-for="(resource, index) in paginatedRessources" v-for="(resource, index) in paginatedResources"
:key="`${resource.resource_name}-${index}`" :key="`${resource.resource_name}-${index}`"
@click="selectResource(resource)" @click="selectResource(resource)"
:class="[ :class="[
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<div>{{ resource.resource_name }}</div> <div>{{ resource.resource_name }}</div>
</div> </div>
</div> </div>
<div class="no-response" v-else>Pas de données trouvées pour l'utilisateur {{this.user.username}}</div>
</div> </div>
<div class="pagination_wrapper"> <div class="pagination_wrapper">
...@@ -39,7 +40,7 @@ ...@@ -39,7 +40,7 @@
> >
Affichage de l'élément {{ pagination.start + 1 }} à Affichage de l'élément {{ pagination.start + 1 }} à
{{ displayedPageEnd }} {{ displayedPageEnd }}
sur {{ ressources.length }} éléments sur {{ resources.length }} éléments
</div> </div>
<div <div
v-if="nbPages.length > 1" v-if="nbPages.length > 1"
...@@ -96,7 +97,7 @@ ...@@ -96,7 +97,7 @@
</template> </template>
<script> <script>
import { mapGetters } from "vuex"; import { mapGetters, mapState } from "vuex";
import miscAPI from "@/services/misc-api"; import miscAPI from "@/services/misc-api";
export default { export default {
...@@ -104,7 +105,7 @@ export default { ...@@ -104,7 +105,7 @@ export default {
data() { data() {
return { return {
ressources: [], resources: [],
pagination: { pagination: {
currentPage: 1, currentPage: 1,
pagesize: 15, pagesize: 15,
...@@ -116,15 +117,16 @@ export default { ...@@ -116,15 +117,16 @@ export default {
}, },
computed: { computed: {
...mapState(["user"]),
...mapGetters(["project", "permissions"]), ...mapGetters(["project", "permissions"]),
...mapGetters("feature_type", ["feature_type"]), ...mapGetters("feature_type", ["feature_type"]),
paginatedRessources() { paginatedResources() {
return this.ressources.slice(this.pagination.start, this.pagination.end); return this.resources.slice(this.pagination.start, this.pagination.end);
}, },
nbPages() { nbPages() {
let N = Math.ceil(this.ressources.length / this.pagination.pagesize); let N = Math.ceil(this.resources.length / this.pagination.pagesize);
const arr = [...Array(N).keys()].map(function (x) { const arr = [...Array(N).keys()].map(function (x) {
++x; ++x;
return x; return x;
...@@ -133,8 +135,8 @@ export default { ...@@ -133,8 +135,8 @@ export default {
}, },
displayedPageEnd() { displayedPageEnd() {
return this.ressources.length <= this.pagination.end return this.resources.length <= this.pagination.end
? this.ressources.length ? this.resources.length
: this.pagination.end; : this.pagination.end;
}, },
}, },
...@@ -160,7 +162,7 @@ export default { ...@@ -160,7 +162,7 @@ export default {
}, },
toNextPage() { toNextPage() {
if (this.pagination.end < this.ressources.length) { if (this.pagination.end < this.resources.length) {
this.pagination.start += this.pagination.pagesize; this.pagination.start += this.pagination.pagesize;
this.pagination.end += this.pagination.pagesize; this.pagination.end += this.pagination.pagesize;
this.pagination.currentPage += 1; this.pagination.currentPage += 1;
...@@ -192,9 +194,9 @@ export default { ...@@ -192,9 +194,9 @@ export default {
mounted() { mounted() {
this.$store.commit("DISPLAY_LOADER", "Interrogation du catologue datasud."); this.$store.commit("DISPLAY_LOADER", "Interrogation du catologue datasud.");
this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug); this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug);
miscAPI.getIdgoCatalog().then((data) => { miscAPI.getIdgoCatalog(this.user.username).then((data) => {
if (data && data.layers) this.resources = data.layers;
this.$store.commit("DISCARD_LOADER"); this.$store.commit("DISCARD_LOADER");
this.ressources = data.layers;
}); });
}, },
}; };
...@@ -237,6 +239,12 @@ h1 { ...@@ -237,6 +239,12 @@ h1 {
background-color: #e0e0e0; background-color: #e0e0e0;
} }
.no-response {
padding: 1rem;
text-align: center;
color: #585858;
}
.import { .import {
display: flex; display: flex;
align-items: center; align-items: center;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment