Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option: "Download as pdf" #538

Merged
merged 44 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
911477c
Add pdf download format management
volterra79 Jan 9, 2024
afc6868
Merge branch 'dev' into issue_537
Raruto Jan 16, 2024
6e7a2ba
jsdoc
Raruto Jan 16, 2024
0ac49ef
Update src/app/core/layers/mixins/download.js
volterra79 Jan 16, 2024
4f7ff91
Merge branch 'dev' into issue_537
volterra79 Jan 17, 2024
a72aae5
Merge branch 'issue_537' of https://github.com/g3w-suite/g3w-client i…
volterra79 Jan 17, 2024
301d3dd
Merge branch 'dev' into issue_537
volterra79 Jan 29, 2024
74a4b5c
Clean code
volterra79 Jan 29, 2024
b530a38
Clean code
volterra79 Jan 29, 2024
b3fdbce
Add getLayerDownloads to filter download formats enable of layer level
volterra79 Jan 29, 2024
b1b5615
Clean code
volterra79 Jan 29, 2024
03090d8
Filter 'pdf' downloadformats config attribute, because it used only f…
volterra79 Jan 29, 2024
f4624c0
Clean code
volterra79 Jan 29, 2024
fa3ae39
Clean code
volterra79 Jan 29, 2024
59422ca
Clean code
volterra79 Jan 29, 2024
00bcc77
change from v-if to v-show to pass all html dom element for pdf downl…
volterra79 Jan 29, 2024
3aa81f9
Add i18n translation
volterra79 Jan 29, 2024
bd2a98d
Add feature-html-content attribute to estract contento of single hmtl…
volterra79 Jan 29, 2024
ecda233
Clean code
volterra79 Jan 30, 2024
73ed3a0
Clean code
volterra79 Jan 30, 2024
72c3d96
Change pdf api url
volterra79 Jan 30, 2024
a76ba6f
Chnage pdf POST parameter name to html
volterra79 Jan 30, 2024
0ec9f92
Merge branch 'dev' into issue_537
volterra79 Jan 31, 2024
28f4f5e
DEV: Force download_pdf config layer to true. Fox Development only pu…
volterra79 Jan 31, 2024
a15816f
Merge branch 'dev' into issue_537
volterra79 Jan 31, 2024
38a75c2
Merge branch 'dev' into issue_537
Raruto Feb 1, 2024
b66d246
Merge branch 'dev' into issue_537
volterra79 Feb 7, 2024
b3abf5a
Merge branch 'issue_537' of https://github.com/g3w-suite/g3w-client i…
volterra79 Feb 7, 2024
e0aa8de
Merge branch 'dev' into issue_537
Raruto Feb 14, 2024
e7e127a
Merge branch 'dev' into issue_537
volterra79 Mar 18, 2024
a0ad6fe
Merge branch 'issue_537' of https://github.com/g3w-suite/g3w-client i…
volterra79 Mar 18, 2024
06c3ac8
Merge branch 'dev' into issue_537
Raruto Apr 15, 2024
800467c
Merge branch 'dev' into issue_537
volterra79 May 6, 2024
404382e
Fix delete feature-html-content attr after merging with dev brach
volterra79 May 6, 2024
30595a8
Remove DEV code
volterra79 May 6, 2024
6ffa38a
Merge branch 'dev' into issue_537
volterra79 May 8, 2024
7e0270a
Merge branch 'dev' into issue_537
volterra79 May 13, 2024
3e39f4c
Clean code - spaces
volterra79 May 13, 2024
5c55c44
Add parameter for POST method request
volterra79 May 13, 2024
8ca79bc
Use downloadFile utils intead $.fileDownload jquery plugin to downloa…
volterra79 May 13, 2024
bb7a365
simplify `layer.config` and `getDownloadFilefromDownloadDataType`
Raruto May 14, 2024
2011be4
Clean code - Spaces
volterra79 May 14, 2024
900ec21
:bug: download pdf format in case of single format
volterra79 May 14, 2024
471b75f
Filter pdf format from layer.downloads format array.
volterra79 May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/app/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const DOWNLOAD_FORMATS = {
download_raster: {
format: 'geotiff',
url: 'geotiff'
}
},
download_pdf: {
format: 'pdf',
url: 'pdf'
},
};

/**
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const deprecate = require('util-deprecate');

// Base Class of all Layer
function Layer(config={}, options={}) {
//DEV CODE
config.download_pdf = true;
Raruto marked this conversation as resolved.
Show resolved Hide resolved

this.config = config;

Expand Down Expand Up @@ -62,6 +64,7 @@ function Layer(config={}, options={}) {
this.config.urls.xls = `${vectorUrl}xls/${suffixUrl}`;
this.config.urls.gpx = `${vectorUrl}gpx/${suffixUrl}`;
this.config.urls.gpkg = `${vectorUrl}gpkg/${suffixUrl}`;
this.config.urls.pdf = `/html2pdf/`; //@since 3.10.0
this.config.urls.geotiff = `${rasterUrl}geotiff/${suffixUrl}`;
this.config.urls.editing = `${vectorUrl}editing/${suffixUrl}`;
this.config.urls.commit = `${vectorUrl}commit/${suffixUrl}`;
Expand Down
18 changes: 9 additions & 9 deletions src/app/core/layers/map/maplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const { base, inherit } = require('utils');
const G3WObject = require('core/g3wobject');

function MapLayer(config={}) {
this.config = config;
this.id = config.id;
this.iframe_internal = config.iframe_internal || false;
this.extent = config.extent;
this.projection = config.projection;
this.layer = null;
this.layers = config.layers || []; // store all enabled layers
this.allLayers = []; // store all layers
this.config = config;
this.id = config.id;
this.iframe_internal = config.iframe_internal || false;
this.extent = config.extent;
this.projection = config.projection;
this.layer = null;
this.layers = config.layers || []; // store all enabled layers
this.allLayers = []; // store all layers
this.showSpinnerWhenLoading = true;
base(this);
}
Expand Down Expand Up @@ -40,7 +40,7 @@ proto.checkLayersDisabled = function(resolution, mapUnits) {
this.allLayers.forEach(layer => this.checkLayerDisabled(layer, resolution, mapUnits));
};

proto.setupCustomMapParamsToLegendUrl = function(params={}){
proto.setupCustomMapParamsToLegendUrl = function(params={}) {
//to owerwrite for each map layer subclass
};

Expand Down
18 changes: 18 additions & 0 deletions src/app/core/layers/mixins/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default {
case 'gpx': return this.getGpx({data, options});
case 'gpkg': return this.getGpkg({data, options});
case 'geotiff': return this.getGeoTIFF({ data, options });
case 'pdf': return this.getPdf({ data, options });
}
},

Expand Down Expand Up @@ -110,6 +111,23 @@ export default {
httpMethod: "POST"
})
},
/**
* Get csv layer format
*
* @param data
*
* @returns {Promise | Promise<unknown>}
*
* @since 3.10.0
*/
getPdf({ data = {} } = {}) {
data.filtertoken = this.getFilterToken();
return XHR.fileDownload({
url: this.getUrl('pdf'),
data,
httpMethod: "POST"
})
},

/**
* Check if it has a format to download
Expand Down
22 changes: 17 additions & 5 deletions src/app/gui/queryresults/queryresultsservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,13 @@ class QueryResultsService extends G3WObject {
this.setLayerActionTool({
layer,
component: layer[name].active ? DownloadFormats : null,
config: layer[name].active ? this.state.actiontools[name][layer.id] : null
config: layer[name].active
? {
...this.state.actiontools[name][layer.id],
//for download layer need to filter pdf format because it works only for a single feature
downloads: this.state.actiontools[name][layer.id].downloads.filter(d => 'pdf' !== d.format)
}
: null
})
}

Expand All @@ -1502,8 +1508,9 @@ class QueryResultsService extends G3WObject {
* @param features
* @param action
* @param index
* @param html
*/
async downloadFeatures(type, layer, features = [], action, index) {
async downloadFeatures(type, layer, features = [], action, index, html) {

if (features && !Array.isArray(features)) {
features = [features];
Expand All @@ -1514,6 +1521,11 @@ class QueryResultsService extends G3WObject {
fids: features.map(f => f.attributes[G3W_FID]).join(',')
};

//In case of pdf type need to add html element
if ('pdf' === type) {
data.html = html;
}

/**
* A function that che be called in case of querybypolygon
*
Expand Down Expand Up @@ -2096,12 +2108,12 @@ class QueryResultsService extends G3WObject {
format,
class: GUI.getFontClass(format),
hint: `sdk.tooltips.download_${format}`,
cbk: (layer, feature, action, index) => {
cbk: (layer, feature, action, index, html) => {
// un-toggle downloads action
this.downloadFeatures(format, layer, feature, action, index);
this.downloadFeatures(format, layer, feature, action, index, html);
volterra79 marked this conversation as resolved.
Show resolved Hide resolved
if ('polygon' !== this.state.query.type) {
const downloadsaction = this.state.layersactions[layer.id].find(action => 'downloads' === action.id);
downloadsaction.cbk(layer, feature, downloadsaction, index);
downloadsaction.cbk(layer, feature, downloadsaction, index, html);
}
}
});
Expand Down
29 changes: 23 additions & 6 deletions src/components/QueryResults.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
></span>
</span>
</template>
<!-- DOWNLOAD -->
<!-- END DOWNLOAD -->
</template>
<span
v-if = "layer.external || (layer.source && 'wms' !== layer.source.type )"
Expand Down Expand Up @@ -273,11 +273,14 @@
</td>
</tr>
<tr
v-show="!collapsedFeatureBox(layer,feature) || hasOneLayerAndOneFeature(layer)"
:id = "`${layer.id}_${index}`"
class = "featurebox-body"
v-show = "!collapsedFeatureBox(layer,feature) || hasOneLayerAndOneFeature(layer)"
:id = "`${layer.id}_${index}`"
class = "featurebox-body"
>
<td :colspan="getColSpan(layer)">
<td
:colspan = "getColSpan(layer)"
:feature-html-content = "`${layer.id}_${index}`"
> <!-- @since v3.10.0 Reference to content of feature html response -->
<tabs
:fields = "getQueryFields(layer, feature)"
:layerid = "layer.id"
Expand Down Expand Up @@ -380,7 +383,10 @@
:id = "`${layer.id}_${index}`"
class = "featurebox-body"
>
<td :colspan="getColSpan(layer)">
<td
:colspan = "getColSpan(layer)"
:feature-html-content = "`${layer.id}_${index}`"
><!--@since v3.10.0 Reference to content of feature html response-->
<table class="feature_attributes">
<template v-for="attribute in layer.attributes.filter(attribute => attribute.show)">
<template v-if="isJSON(getLayerField({layer, feature, fieldName: attribute.name}))">
Expand Down Expand Up @@ -546,6 +552,17 @@
},
methods: {

/**
* @since v3.10.0
*
* @param { Array.<string> } downloads
*
* return {Array} return array of download formats enable of layer features
*/
getLayerDownloads(downloads=[]) {
return downloads.filter(d => 'pdf' !== d);
},

/**
* @param { Object } layer
*
Expand Down
2 changes: 1 addition & 1 deletion src/components/QueryResultsAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}
},
async created() {
if (this.action.init){
if (this.action.init) {
this.action.init({layer: this.layer, feature: this.feature, index:this.featureIndex, action:this.action});
}
if (typeof this.action.condition === 'function') {
Expand Down
16 changes: 13 additions & 3 deletions src/components/QueryResultsActionDownloadFormats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,20 @@ export default {
},
},
methods: {
async download(){
async download() {
try {
const download = this.config.downloads.find(a => a.format === this.download_format);
await download.cbk(this.layer, this.feature ? this.feature : this.layer.features, download, this.featureIndex);
const download = this.config.downloads.find(action => action.format === this.download_format);
await download.cbk(
this.layer,
this.feature
? this.feature
: this.layer.features,
download,
this.featureIndex,
'pdf' === download.format
? document.querySelector(`[feature-html-content="${this.layer.id}_${this.featureIndex}"]`).innerHTML
: null
);
}
catch(e) {console.warn(e) }
}
Expand Down
4 changes: 4 additions & 0 deletions src/locales/de.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default {
download_gpkg: "GPKG herunterladen",
download_csv: "CSV herunterladen",
download_xls: "XLS herunterladen",
download_pdf: "PDF herunterladen",
show_chart: "Diagramm anzeigen",
atlas: "Atlas drucken"
},
Expand Down Expand Up @@ -248,6 +249,9 @@ export default {
download_xls: {
hint: "Feature XLS herunterladen"
},
download_pdf: {
hint: "Feature PDF herunterladen"
},
atlas: {
hint: "Atlas drucken"
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default {
download_gpkg: "Download GPKG",
download_csv: "Download CSV",
download_xls: "Download XLS",
download_pdf: "Download PDF",
show_chart: "Show Chart",
atlas: "Print Atlas"
},
Expand Down Expand Up @@ -248,6 +249,9 @@ export default {
download_xls: {
hint: "Download feature XLS"
},
download_pdf: {
hint: "Download feature PDF"
},
atlas: {
hint: "Print Atlas"
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/fi.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default {
download_gpkg: "Lataa GPKG-tiedosto",
download_csv: "Lataa CSV-tiedosto",
download_xls: "Lataa XLS-tiedosto",
download_pdf: "Lataa PDF-tiedosto",
show_chart: "Näytä kaavio",
atlas: "Tulosta Atlas"
},
Expand Down Expand Up @@ -248,6 +249,9 @@ export default {
download_xls: {
hint: "Lataa ominaisuuden XLS-tiedosto"
},
download_pdf: {
hint: "Lataa ominaisuuden PDF-tiedosto"
},
atlas: {
hint: "Tulosta Atlas"
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ export default {
download_gpkg: "Télécharger GPKG",
download_csv: "Télécharger CSV",
download_xls: "Télécharger XLS",
download_pdf: "Télécharger PDF",
show_chart: "Montrer graphique",
atlas: "Imprimer l'Atlas"
},
Expand Down Expand Up @@ -247,6 +248,9 @@ export default {
download_xls: {
hint: "Télécharger le XLS"
},
download_pdf: {
hint: "Télécharger le PDF"
},
atlas: {
hint: "Imprimer l'Atlas"
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/it.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export default {
download_gpkg: "Scarica GPKG",
download_csv: "Scarica CSV",
download_xls: "Scarica XLS",
download_pdf: "Scarica PDF",
show_chart: "Mostra Grafico",
atlas: "Stampa Atlas"
},
Expand Down Expand Up @@ -249,6 +250,9 @@ export default {
download_xls: {
hint: "Scarica la feature in XLS"
},
download_pdf: {
hint: "Scarica la feature in PDF"
},
atlas: {
hint: "Stampa Atlas"
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/ro.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default {
download_gpkg: "Descarcă GPKG",
download_csv: "Descarcă CSV",
download_xls: "Descarcă XLS",
download_pdf: "Descarcă PDF",
show_chart: "Arată Diagrama",
atlas: "Tipărire Atlas"
},
Expand Down Expand Up @@ -248,6 +249,9 @@ export default {
download_xls: {
hint: "Descarcă entitate în XLS"
},
download_pdf: {
hint: "Descarcă entitate în PDF"
},
atlas: {
hint: "Tipărire Atlas"
},
Expand Down
4 changes: 4 additions & 0 deletions src/locales/se.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export default {
download_gpkg: "Ladda GPKG-fil",
download_csv: "Ladda CSV-fil",
download_xls: "Ladda XLS-fil",
download_pdf: "Ladda PDF-fil",
show_chart: "Visa diagram", //Tero 9.12.2020
atlas: "Skriv ut Atlas"
},
Expand Down Expand Up @@ -248,6 +249,9 @@ export default {
download_xls: {
hint: "Ladda egenskapens XLS-fil"
},
download_pdf: {
hint: "Ladda egenskapens PDF-fil"
},
atlas: {
hint: "Skriv ut Atlas"
},
Expand Down
12 changes: 6 additions & 6 deletions src/mixins/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

export default {
methods: {
getFieldService(){
getFieldService() {
if (undefined === this._fieldsService) {
this._fieldsService = require('gui/fields/fieldsservice');
}
Expand All @@ -14,19 +14,19 @@ export default {
getFieldType(field) {
return this.getFieldService().getType(field);
},
isSimple(field){
isSimple(field) {
return this.getFieldService().isSimple(field);
},
isLink(field){
isLink(field) {
return this.getFieldService().isLink(field);
},
isImage(field){
isImage(field) {
return this.getFieldService().isImage(field);
},
isPhoto(field){
isPhoto(field) {
return this.getFieldService().isPhoto(field);
},
isVue(field){
isVue(field) {
return this.getFieldService().isVue(field);
},
sanitizeFieldValue(value) {
Expand Down
Loading