Skip to content

Commit

Permalink
feat(import-export) control the export format at the layer level (#814)
Browse files Browse the repository at this point in the history
* feat(import-export) control the export format at the layer level

* feat(import-export) allow the wfs being exported by url

* lint
  • Loading branch information
pelord authored Feb 18, 2021
1 parent 66feee3 commit b3ffee4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 28 deletions.
2 changes: 2 additions & 0 deletions packages/geo/src/lib/download/shared/download.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { DataSourceOptions } from '../../datasource/shared/datasources/datasource.interface';
import { ExportFormat } from '../../import-export/shared/export.type';

export interface DownloadOptions {
url: string;
dynamicUrl?: string;
extern?: boolean;
allowedFormats?: ExportFormat[];
}

export interface DownloadDataSourceOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/download/shared/download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class DownloadService {
);
const outputFormatDownload =
wfsOptions.outputFormatDownload === undefined
? 'outputformat=' + wfsOptions.outputFormat
? wfsOptions.outputFormat === undefined ? '' : 'outputformat=' + wfsOptions.outputFormat
: 'outputformat=' + wfsOptions.outputFormatDownload;

const baseurl = DSOptions.download.dynamicUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { WfsWorkspace } from '../../workspace/shared/wfs-workspace';
import { FeatureWorkspace } from '../../workspace/shared/feature-workspace';
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
import { InputProjections, ProjectionsLimitationsOptions } from './import-export.interface';
import { DownloadService } from '../../download/shared/download.service';

@Component({
selector: 'igo-import-export',
Expand Down Expand Up @@ -151,7 +152,8 @@ export class ImportExportComponent implements OnDestroy, OnInit {
private formBuilder: FormBuilder,
private config: ConfigService,
private cdRef: ChangeDetectorRef,
private storageService: StorageService
private storageService: StorageService,
private downloadService: DownloadService
) {
this.loadConfig();
this.buildForm();
Expand Down Expand Up @@ -483,11 +485,16 @@ export class ImportExportComponent implements OnDestroy, OnInit {
if (
data.format === ExportFormat.URL &&
dSOptions.download &&
dSOptions.download.url
(dSOptions.download.url || dSOptions.download.dynamicUrl)
) {
setTimeout(() => {
// better look an feel
window.open(dSOptions.download.url, '_blank');
const url = dSOptions.download.url || dSOptions.download.dynamicUrl;
if (url.match(/service=wfs/gi)) {
this.downloadService.open(lay);
} else {
window.open(url , '_blank');
}
this.loading$.next(false);
}, 500);
return;
Expand Down Expand Up @@ -669,25 +676,31 @@ export class ImportExportComponent implements OnDestroy, OnInit {
}

private computeFormats(layers?: AnyLayer[]) {
let appliedformats: string[] = Object.keys(ExportFormat);
const formatsType = {
onlyUrl: false,
onlyVector: false,
vectorAndUrl: false,
customList: false
};
const customList = [];
if (layers && layers.length) {
const formatsType = {
onlyUrl: false,
onlyVector: false,
vectorAndUrl: false
};
layers.forEach((layer) => {
if (!layer) {
return;
}
if (
if (layer.dataSource.options.download?.allowedFormats) {
formatsType.customList = true;
customList.push({layer: layer.title, formats: this.validateListFormat(layer.dataSource.options.download.allowedFormats)});
} else if (
!(layer instanceof VectorLayer) &&
layer.dataSource.options.download &&
layer.dataSource.options.download.url
) {
formatsType.onlyUrl = true;
} else if (
layer.dataSource.options.download &&
layer.dataSource.options.download.url
(layer.dataSource.options.download.url || layer.dataSource.options.download.dynamicUrl)
) {
formatsType.vectorAndUrl = true;
} else if (layer instanceof VectorLayer) {
Expand All @@ -696,7 +709,7 @@ export class ImportExportComponent implements OnDestroy, OnInit {
});

if (formatsType.onlyUrl === true && formatsType.onlyVector === false) {
this.formats$.next(strEnum(['URL']));
appliedformats = ['URL'];
} else if (
formatsType.onlyVector === true &&
formatsType.onlyUrl === false
Expand All @@ -706,7 +719,7 @@ export class ImportExportComponent implements OnDestroy, OnInit {
const keys = Object.keys(this.formats$.value).filter(
(key) => key !== 'URL'
);
this.formats$.next(strEnum(keys));
appliedformats = keys;
}
} else if (
formatsType.vectorAndUrl === true &&
Expand All @@ -717,29 +730,47 @@ export class ImportExportComponent implements OnDestroy, OnInit {
if (!(ExportFormat.URL in this.formats$.value)) {
const keys = Object.keys(this.formats$.value);
keys.push('URL');
this.formats$.next(strEnum(keys));
appliedformats = keys;
}
} else {
this.formats$.next([]);
this.messageService.alert(
this.languageService.translate.instant(
'igo.geo.export.noFormat.text'
),
this.languageService.translate.instant(
'igo.geo.export.noFormat.title'
)
);
}
return;
}

if (this.config.getConfig('importExport.formats') !== undefined) {
const validatedListFormat = this.validateListFormat(
this.config.getConfig('importExport.formats')
);
this.formats$.next(strEnum(validatedListFormat));
appliedformats = validatedListFormat;
}
if (formatsType.customList) {
let commonFormats;
const layersWithCustomFormats = [];
let previousCustomListFormats = customList[0].formats;
customList.map(list => {
layersWithCustomFormats.push(list.layer);
commonFormats = list.formats.filter(value => previousCustomListFormats.includes(value));
previousCustomListFormats = list.formats;
});
const finalFormats = commonFormats.filter(value => appliedformats.includes(value));
if (finalFormats.length > 0) {
this.formats$.next(strEnum(finalFormats));

if (layers && layers.length) {
if (layers.length > 1) {
this.messageService.alert(
this.languageService.translate.instant('igo.geo.export.customList.text', { value: layersWithCustomFormats.join() }),
this.languageService.translate.instant('igo.geo.export.customList.title')
);
}
}
} else {
this.formats$.next([]);
this.messageService.alert(
this.languageService.translate.instant('igo.geo.export.noFormat.text'),
this.languageService.translate.instant('igo.geo.export.noFormat.title')
);
}
return;
} else {
this.formats$.next(ExportFormat);
this.formats$.next(strEnum(appliedformats));
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
}
},
"export": {
"customList": {
"text": "Some of the selected layers ( {{value}} ) limit the format's list",
"title": "Restricted list of formats"
},
"nothing": {
"text": "No feature could be exported.",
"title": "Nothing to export"
Expand Down
4 changes: 4 additions & 0 deletions packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
}
},
"export": {
"customList": {
"text": "Certaines couches sélectionnées ( {{value}} ) réduisent la liste des formats possible",
"title": "Liste restreinte de formats"
},
"nothing": {
"text": "Impossible d’exporter, donnée non valide ou aucune donnée sélectionnée.",
"title": "Donnée non valide ou non présente"
Expand Down

0 comments on commit b3ffee4

Please sign in to comment.