From 6b11ab23b559361586e80105d9aecad9ab71bf41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr> Date: Mon, 27 Dec 2021 15:21:48 +0100 Subject: [PATCH] manage routing between two import types & fetch catalog --- src/router/index.js | 2 +- src/services/misc-api.js | 14 + src/views/Catalog.vue | 250 +----------------- .../feature_type/Feature_type_detail.vue | 5 +- src/views/feature_type/Feature_type_edit.vue | 1 - src/views/project/Project_detail.vue | 5 +- 6 files changed, 37 insertions(+), 240 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index 0b5919d5..224af0a5 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -125,7 +125,7 @@ const routes = [ }, { - path: '/projet/:slug/catalogue', + path: '/projet/:slug/catalog/:feature_type_slug', name: 'catalog-import', component: () => import('../views/Catalog.vue') }, diff --git a/src/services/misc-api.js b/src/services/misc-api.js index a8447446..5bce25aa 100644 --- a/src/services/misc-api.js +++ b/src/services/misc-api.js @@ -6,6 +6,20 @@ const baseUrl = store.state.configuration.VUE_APP_DJANGO_API_BASE; const miscAPI = { + async getIdgoCatalog(vector_by_user) { + const response = await axios.get( + `${baseUrl}idgo-catalog/?vector_by_user=${vector_by_user}` + ); + if ( + response.status === 200 && + response.data + ) { + return response.data; + } else { + return null; + } + }, + async getExternalGeojson(queryParams) { const response = await axios.get( `${baseUrl}external-geojson/${queryParams ? '?' + queryParams : ""}` diff --git a/src/views/Catalog.vue b/src/views/Catalog.vue index 42cc0a53..d841382e 100644 --- a/src/views/Catalog.vue +++ b/src/views/Catalog.vue @@ -13,7 +13,7 @@ </div> <div v-for="(resource, index) in paginatedRessources" - :key="`${resource.resource}-${index}`" + :key="`${resource.resource_name}-${index}`" @click="selectResource(resource)" :class="[ 'row', @@ -24,9 +24,9 @@ }, ]" > - <div>{{ resource.organisation }}</div> - <div>{{ resource.dataset }}</div> - <div>{{ resource.resource }}</div> + <div>{{ resource.organization_name }}</div> + <div>{{ resource.dataset_name }}</div> + <div>{{ resource.resource_name }}</div> </div> </div> @@ -103,231 +103,13 @@ export default { data() { return { - ressources: [ - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 1", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 2", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 3", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 4", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 11", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 12", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 13", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 14", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 21", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 22", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 23", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 24", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 31", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 32", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 33", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 34", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 41", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 42", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 43", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 44", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 51", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 52", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 53", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 54", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 61", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 62", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 63", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 64", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 71", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 72", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 73", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 74", - }, - { - organisation: "Organisation 1", - dataset: "Dataset 1", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 81", - }, - { - organisation: "Organisation 2", - dataset: "Dataset 2", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 82", - }, - { - organisation: "Organisation 3", - dataset: "Dataset 3", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 83", - }, - { - organisation: "Organisation 4", - dataset: "Dataset 4", - layerName: "travaux_ccpro_867f108", - resource: "Ressource 84", - }, - ], + ressources: [], pagination: { currentPage: 1, pagesize: 15, start: 0, end: 15, }, - geojson: null, selectedResource: null, }; }, @@ -384,32 +166,28 @@ export default { } }, - redirect() { - const routerHistory = this.$router.history.router.options.routerHistory - const name = routerHistory[routerHistory.length - 1].name === "details-type-signalement" ? "details-type-signalement" : "ajouter-type-signalement" + redirect(geojson) { + const name = this.$route.params.feature_type_slug === "create" ? "ajouter-type-signalement" : "details-type-signalement" this.$router.push({ - name, + name: name, params: { - geojson: this.geojson, + geojson, type: "external-geojson", }, }); }, launchImport() { - const user = "communaute-de-communes-du-pays-reuni-dorange"; - const paramsTest = `user=${user}&TYPENAME=${this.selectedResource.layerName}`; - miscAPI.getExternalGeojson(paramsTest).then((data) => { - this.geojson = data; - this.redirect(); + const queryParams = `typename=${this.selectedResource.layer}`; + miscAPI.getExternalGeojson(queryParams).then((data) => { + if (data) this.redirect(data); }); }, }, - created() { - console.log(this.$router) - console.log(this.$router.history.router.options.routerHistory[this.$router.history.router.options.routerHistory.length -1].name) + mounted() { this.$store.dispatch("GET_PROJECT_INFO", this.$route.params.slug); + miscAPI.getIdgoCatalog('mmeliani').then((data)=> this.ressources = data.layers); }, }; </script> diff --git a/src/views/feature_type/Feature_type_detail.vue b/src/views/feature_type/Feature_type_detail.vue index 8e663303..506fcc84 100644 --- a/src/views/feature_type/Feature_type_detail.vue +++ b/src/views/feature_type/Feature_type_detail.vue @@ -93,7 +93,10 @@ " :to="{ name: 'catalog-import', - params: { slug: project.slug }, + params: { + slug: project.slug, + feature_type_slug: $route.params.feature_type_slug + }, }" class="ui icon button import-catalog" >Créer un nouveau type de signalement à partir du catalogue Datasud diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue index 26bf6819..22b98958 100644 --- a/src/views/feature_type/Feature_type_edit.vue +++ b/src/views/feature_type/Feature_type_edit.vue @@ -604,7 +604,6 @@ export default { this.form.title.value = // * use the filename as title by default this.fileToImport.name.split(".")[0]; } else { //* case when the geojson comes from datasud catalog - console.log("external-geojson", this.geojson) this.form.title.value = this.geojson.name;// * use the typename as title by default } } diff --git a/src/views/project/Project_detail.vue b/src/views/project/Project_detail.vue index a24c49fc..604663b2 100644 --- a/src/views/project/Project_detail.vue +++ b/src/views/project/Project_detail.vue @@ -333,7 +333,10 @@ " :to="{ name: 'catalog-import', - params: { slug: project.slug }, + params: { + slug: project.slug, + feature_type_slug: 'create' + }, }" class="ui compact basic button button-hover-green button-align-left" > -- GitLab