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

feat(export): added possibility of exporting merged CSV files #949

Merged
merged 19 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e946efc
feat(export): export unique CSVs
LAMM26 Oct 18, 2021
5f3962d
added toggle to combine layers
LAMM26 Oct 26, 2021
97f8672
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Oct 27, 2021
262db67
added empty row toggle
LAMM26 Oct 28, 2021
c2c458e
refactor(export): change label of toggle and add column when exportin…
LAMM26 Nov 19, 2021
ea1796d
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Nov 24, 2021
c8e8790
refactor(remove zone when exporting results from spatial filter tool)
LAMM26 Nov 24, 2021
39bd4d4
fix(demo): fix import-export lib demo
PhilippeLafreniere18 Dec 3, 2021
e9da836
Merge remote-tracking branch 'origin/next' into export_csv_unique
PhilippeLafreniere18 Dec 3, 2021
1f9b774
lint
PhilippeLafreniere18 Dec 3, 2021
b3bced3
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Dec 6, 2021
70cfc66
refactor(export): translated filename and csv adjustments
LAMM26 Dec 6, 2021
bd4cc63
Merge branch 'export_csv_unique' of https://github.com/infra-geo-ouve…
LAMM26 Dec 6, 2021
fa304a2
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Dec 8, 2021
29b04b0
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Dec 9, 2021
440d694
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Dec 9, 2021
ac7ae0c
Merge remote-tracking branch 'origin/next' into export_csv_unique
LAMM26 Dec 10, 2021
1cd1144
fix(export): fix hang
LAMM26 Dec 10, 2021
2166573
fix(export): add arrow in divider
LAMM26 Dec 10, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ <h4>{{'igo.geo.importExportForm.exportNoLayersExportable' | translate}}</h4>
</mat-form-field>
</div>

<div class="export-combine-layers mat-typography" *ngIf="layers.length > 1 && (form.value.format === 'CSVcomma' || form.value.format === 'CSVsemicolon')">
<mat-slide-toggle
formControlName="combineLayers"
[labelPosition]="'before'">
{{'igo.geo.importExportForm.exportCombineResults' | translate}}
</mat-slide-toggle>
</div>

<div class="export-separator mat-typography" *ngIf="layers.length > 1 && (form.value.format === 'CSVcomma' || form.value.format === 'CSVsemicolon') && form.value.combineLayers">
<mat-slide-toggle
formControlName="separator"
[labelPosition]="'before'">
{{'igo.geo.importExportForm.exportSeparator' | translate}}
</mat-slide-toggle>
</div>

<div class="export-options mat-typography" *ngIf="form.value.format !== 'URL'">
<mat-slide-toggle
formControlName="featureInMapExtent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ igo-spinner {
padding-left: 10px;
}

.export-options {
.export-options, .export-combine-layers, .export-separator {
overflow-x: hidden;

mat-slide-toggle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,19 @@ export class ImportExportComponent implements OnDestroy, OnInit {
this.handlePopup();
}

data.layers.forEach((layer) => {
let geomTypesCSV: { geometryType: string, features: any[] }[] = [];
let featuresCSV: any[] = [];
let filename: string = "";

for (const [layerIndex, layer] of data.layers.entries()) {
const lay = this.map.getLayerById(layer);
let filename = lay.title;
if (data.name !== undefined) {
filename = data.name;
if (!(data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) || ! data.combineLayers) {
filename = lay.title;
if (data.name) {
filename = data.name;
}
} else {
filename = "combinedLayers";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translation would be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
const dSOptions: DataSourceOptions = lay.dataSource.options;
if (data.format === ExportFormat.URL && dSOptions.download && (dSOptions.download.url || dSOptions.download.dynamicUrl)) {
Expand Down Expand Up @@ -530,6 +538,8 @@ export class ImportExportComponent implements OnDestroy, OnInit {

geomTypes.forEach(geomType => {
geomType.features.forEach(feature => {
const re = new RegExp('^\\D+');
feature.set('couche', lay.title.match(re)[0].trim());
const radius: number = feature.get('rad');

if (radius) {
Expand All @@ -552,36 +562,88 @@ export class ImportExportComponent implements OnDestroy, OnInit {
}
}

if ((data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) && data.combineLayers) {
geomTypes.forEach(geomType => geomTypesCSV.push(geomType));

if (layerIndex !== data.layers.length - 1) {
continue;
} else {
let previousFeature = undefined;
geomTypesCSV.forEach(geomType => {
geomType.features.forEach(currentFeature => {
if (data.separator) {
if (previousFeature) {
if (currentFeature.get('type') !== previousFeature.get('type')) {
const emptyRowFeature = previousFeature.clone();
const previousFeatureKeys: Array<string> = previousFeature.getKeys();
previousFeatureKeys.forEach(key => {
emptyRowFeature.unset(key, true);
});
featuresCSV.push(emptyRowFeature);
}
}
}
featuresCSV.push(currentFeature);
previousFeature = currentFeature;
});
});
}
}

if (geomTypes.length === 0) {
this.loading$.next(false);
const title = translate.instant('igo.geo.export.nothing.title');
const message = translate.instant('igo.geo.export.nothing.text');
this.messageService.error(message, title, { timeOut: 20000 });

} else {
geomTypes.map(geomType =>
this.exportService.export(geomType.features, data.format, filename + geomType.geometryType, data.encoding, this.map.projection)
.subscribe(
() => {},
(error: Error) => this.onFileExportError(error),
() => {
this.onFileExportSuccess();

geomType.features.forEach(feature => {
const radius: number = feature.get('rad');

if (radius) {
const point = new olPoint([feature.get('longitude'), feature.get('latitude')]);
point.transform('EPSG:4326', feature.get('_projection'));
feature.setGeometry(point);
}
});

this.loading$.next(false);
if (!(data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) || !data.combineLayers) {
geomTypes.map(geomType =>
this.exportService.export(geomType.features, data.format, filename + geomType.geometryType, data.encoding, this.map.projection)
.subscribe(
() => {},
(error: Error) => this.onFileExportError(error),
() => {
this.onFileExportSuccess();

geomType.features.forEach(feature => {
const radius: number = feature.get('rad');

if (radius) {
const point = new olPoint([feature.get('longitude'), feature.get('latitude')]);
point.transform('EPSG:4326', feature.get('_projection'));
feature.setGeometry(point);
}
});

this.loading$.next(false);
}
));
));
}
}
});
};
if ((data.format === ExportFormat.CSVsemicolon || data.format === ExportFormat.CSVcomma) && data.combineLayers) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be put into else condition (line 561) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.exportService.export(featuresCSV, data.format, filename, data.encoding, this.map.projection)
.subscribe(
() => {},
(error: Error) => this.onFileExportError(error),
() => {
this.onFileExportSuccess();

featuresCSV.forEach(feature => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create method instead ? Could be also use for geomType at line 609

const radius: number = feature.get('rad');

if (radius) {
const point = new olPoint([feature.get('longitude'), feature.get('latitude')]);
point.transform('EPSG:4326', feature.get('_projection'));
feature.setGeometry(point);
}
});

this.loading$.next(false);
}
);
}
}

private buildForm() {
Expand All @@ -595,6 +657,8 @@ export class ImportExportComponent implements OnDestroy, OnInit {
layers: [[], [Validators.required]],
layersWithSelection: [[]],
encoding: [EncodingFormat.UTF8, [Validators.required]],
combineLayers: [true, [Validators.required]],
separator: [false, [Validators.required]],
featureInMapExtent: [false, [Validators.required]],
name: ['', [Validators.required]]
});
Expand All @@ -604,6 +668,8 @@ export class ImportExportComponent implements OnDestroy, OnInit {
layers: [[], [Validators.required]],
layersWithSelection: [[]],
encoding: [EncodingFormat.UTF8, [Validators.required]],
combineLayers: [true, [Validators.required]],
separator: [false, [Validators.required]],
featureInMapExtent: [false, [Validators.required]],
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface ExportOptions {
layers: string[];
layersWithSelection?: string[];
name?: string;
combineLayers?: boolean;
separator?: boolean;
featureInMapExtent?: boolean;
circlesToPolygons?: boolean;
}
7 changes: 4 additions & 3 deletions packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@
"exportButton": "Export",
"exportButtonLink": "Open the link",
"exportButtonLinks": "Open the links",
"exportCircleToPolygon": "Transform Circle entities in polygons",
"exportCombineResults": "Combine layers into one file",
"exportFormatPlaceholder": "Format",
"exportLayerPlaceholder": "Layer",
"exportFileNamePlaceholder": "Filename",
"exportSeparator": "Insert separator (empty row) between layers",
"encodingPlaceholder": "Encoding",
"exportTabTitle": "Export",
"exportFeatureInExtent": "Export only features in map extent",
Expand Down Expand Up @@ -382,8 +383,8 @@
"notification": "notification ...",
"uturnText": "Make u-turn and head {{translatedDirection}} on {{route}}",
"unknown": "???",
"cntSuffix": {

"cntSuffix": {
"first": "st",
"secondAndMore": "rd"
},
Expand Down
7 changes: 4 additions & 3 deletions packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@
"exportButton": "Exporter",
"exportButtonLink": "Ouvrir le lien",
"exportButtonLinks": "Ouvrir les liens",
"exportCircleToPolygon": "Transformer les entités de type Cercle en polygones",
"exportCombineResults": "Combiner les couches dans un seul fichier",
"exportFormatPlaceholder": "Format",
"exportLayerPlaceholder": "Couche(s)",
"exportFileNamePlaceholder": "Nom du fichier",
"exportSeparator": "Insérer un séparateur (ligne vide) entre les couches",
"encodingPlaceholder": "Encodage",
"exportTabTitle": "Exporter",
"exportFeatureInExtent": "Seulement les entités contenues dans la carte",
Expand Down Expand Up @@ -381,8 +382,8 @@
"notification": "notification ...",
"uturnText": "Faire demi-tour et continuer en direction {{translatedDirection}} sur {{route}}",
"unknown": "???",
"cntSuffix": {

"cntSuffix": {
"first": "ère",
"secondAndMore": "e"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ export class SpatialFilterToolComponent implements OnInit, OnDestroy {

activateExportTool() {
const ids = [];
const re = new RegExp('^Zone \\d+');
for (const layer of this.layers) {
ids.push(layer.id);
if (!layer.title.match(re)) {
ids.push(layer.id);
}
}
this.importExportState.setMode(ImportExportMode.export);
this.importExportState.setsExportOptions({ layers: ids } as ExportOptions);
Expand Down