-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(integration): add a new tool to report data issues (#1524)
* feat(integration): add a new tool to report data issues * wip * wip * refactor(integration): rename geometry-form-tool to data-issue-reporter-tool * refactor(data-issue-reporter-tool): review comments * wip
- Loading branch information
Showing
10 changed files
with
312 additions
and
1 deletion.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...on/src/lib/geometry-form/data-issue-reporter-tool/data-issue-reporter-tool.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<igo-form | ||
*ngIf="form$ | async as form" | ||
[form]="form" | ||
[formData]="data$ | async" | ||
(submitForm)="onSubmit($event)" | ||
> | ||
<div *ngIf="form.fields.length" class="form-container"> | ||
<igo-form-field | ||
*ngFor="let field of form.fields" | ||
[field]="field" | ||
></igo-form-field> | ||
</div> | ||
|
||
<div formButtons class="actions-container"> | ||
<button | ||
mat-stroked-button | ||
type="button" | ||
color="primary" | ||
(click)="clearForm()" | ||
> | ||
{{ 'igo.integration.dataIssueReporterTool.reset.button' | translate }} | ||
</button> | ||
<button | ||
mat-flat-button | ||
type="submit" | ||
color="primary" | ||
[disabled]="submitDisabled" | ||
> | ||
{{ 'igo.integration.dataIssueReporterTool.submit.button' | translate }} | ||
</button> | ||
</div> | ||
</igo-form> |
16 changes: 16 additions & 0 deletions
16
...on/src/lib/geometry-form/data-issue-reporter-tool/data-issue-reporter-tool.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
:host { | ||
.actions-container { | ||
button:not(:last-child) { | ||
margin-right: 8px; | ||
} | ||
} | ||
.form-container { | ||
width: 100%; | ||
padding: 10px; | ||
|
||
igo-form-field { | ||
display: block; | ||
height: auto; | ||
} | ||
} | ||
} |
201 changes: 201 additions & 0 deletions
201
...tion/src/lib/geometry-form/data-issue-reporter-tool/data-issue-reporter-tool.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; | ||
import { Validators } from '@angular/forms'; | ||
|
||
import { Form, FormService, ToolComponent } from '@igo2/common'; | ||
import { LanguageService, MessageService } from '@igo2/core'; | ||
import { IgoMap } from '@igo2/geo'; | ||
|
||
import * as olstyle from 'ol/style'; | ||
|
||
import { BehaviorSubject, combineLatest } from 'rxjs'; | ||
import type { Subscription } from 'rxjs'; | ||
|
||
import { MapState } from '../../map/map.state'; | ||
|
||
interface DataIssueReporterData { | ||
geometry: object; | ||
layer: string; | ||
desc: string; | ||
email: string; | ||
} | ||
|
||
@ToolComponent({ | ||
name: 'dataIssueReporter', | ||
title: 'igo.integration.tools.dataIssueReporter', | ||
icon: 'message-alert' | ||
}) | ||
@Component({ | ||
selector: 'igo-issue-reporter-tool', | ||
templateUrl: './data-issue-reporter-tool.component.html', | ||
styleUrls: ['./data-issue-reporter-tool.component.scss'] | ||
}) | ||
export class DataIssueReporterToolComponent implements OnInit, OnDestroy { | ||
/** | ||
* Url to report the data issue. Use the Post protocol to send the form. | ||
*/ | ||
@Input() url: string; | ||
|
||
/** | ||
* Map to link to the form | ||
* @internal | ||
*/ | ||
get map(): IgoMap { | ||
return this.mapState.map; | ||
} | ||
|
||
form$ = new BehaviorSubject<Form>(undefined); | ||
|
||
data$ = new BehaviorSubject<{ [key: string]: any }>(undefined); | ||
|
||
submitDisabled = true; | ||
|
||
private valueChanges$$: Subscription; | ||
|
||
constructor( | ||
private mapState: MapState, | ||
private formService: FormService, | ||
private languageService: LanguageService, | ||
private messageService: MessageService, | ||
private httpClient: HttpClient | ||
) {} | ||
|
||
ngOnInit() { | ||
combineLatest([this.languageService.language$, this.map.layers$]).subscribe( | ||
([language, layers]) => { | ||
const baseLayerOrShownInLayerList = layers | ||
.filter((l) => l.baseLayer || l.showInLayerList) | ||
.map((l) => { | ||
return { value: `${l.title}-${l.id}`, title: l.title }; | ||
}); | ||
const fieldConfigs = [ | ||
{ | ||
name: 'geometry', | ||
title: this.languageService.translate.instant( | ||
'igo.integration.dataIssueReporterTool.geometry' | ||
), | ||
type: 'geometry', | ||
inputs: { | ||
map: this.map, | ||
geometryTypeField: true, | ||
geometryType: 'Polygon', | ||
drawGuideField: false, | ||
drawGuide: 0, | ||
drawGuidePlaceholder: this.languageService.translate.instant( | ||
'igo.integration.dataIssueReporterTool.drawGuidePlaceholder' | ||
), | ||
drawStyle: new olstyle.Style({ | ||
stroke: new olstyle.Stroke({ | ||
color: [255, 0, 0, 1], | ||
width: 2 | ||
}), | ||
fill: new olstyle.Fill({ | ||
color: [255, 0, 0, 0.2] | ||
}), | ||
image: new olstyle.Circle({ | ||
radius: 8, | ||
stroke: new olstyle.Stroke({ | ||
color: [255, 0, 0, 1] | ||
}), | ||
fill: new olstyle.Fill({ | ||
color: [255, 0, 0, 0.2] | ||
}) | ||
}) | ||
}), | ||
overlayStyle: new olstyle.Style({ | ||
stroke: new olstyle.Stroke({ | ||
color: [0, 255, 0, 1], | ||
width: 2 | ||
}), | ||
fill: new olstyle.Fill({ | ||
color: [0, 255, 0, 0.2] | ||
}), | ||
image: new olstyle.Circle({ | ||
radius: 8, | ||
stroke: new olstyle.Stroke({ | ||
color: [0, 255, 0, 1] | ||
}), | ||
fill: new olstyle.Fill({ | ||
color: [0, 255, 0, 0.2] | ||
}) | ||
}) | ||
}) | ||
} | ||
}, | ||
{ | ||
name: 'layer', | ||
title: this.languageService.translate.instant( | ||
'igo.integration.dataIssueReporterTool.layer' | ||
), | ||
type: 'select', | ||
options: { | ||
cols: 2 | ||
}, | ||
inputs: { | ||
choices: baseLayerOrShownInLayerList | ||
} | ||
}, | ||
{ | ||
name: 'desc', | ||
title: this.languageService.translate.instant( | ||
'igo.integration.dataIssueReporterTool.description' | ||
), | ||
type: 'textarea', | ||
options: { | ||
validator: Validators.required | ||
} | ||
}, | ||
{ | ||
name: 'email', | ||
title: this.languageService.translate.instant( | ||
'igo.integration.dataIssueReporterTool.email' | ||
), | ||
options: { | ||
validator: Validators.email | ||
} | ||
} | ||
]; | ||
|
||
const fields = fieldConfigs.map((config) => | ||
this.formService.field(config) | ||
); | ||
const form = this.formService.form(fields, []); | ||
|
||
this.valueChanges$$ = form.control.valueChanges.subscribe(() => { | ||
this.submitDisabled = !form.control.valid; | ||
}); | ||
|
||
this.form$.next(form); | ||
} | ||
); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.valueChanges$$.unsubscribe(); | ||
} | ||
|
||
clearForm() { | ||
this.form$.value.control.reset(); | ||
} | ||
|
||
onSubmit(data: DataIssueReporterData) { | ||
const submitTitle = 'igo.integration.dataIssueReporterTool.submit.title'; | ||
if (!this.url) { | ||
this.messageService.alert( | ||
'igo.integration.dataIssueReporterTool.submit.setupMessage', | ||
submitTitle | ||
); | ||
alert(JSON.stringify(data)); | ||
} else { | ||
this.httpClient | ||
.post<DataIssueReporterData>(this.url, data) | ||
.subscribe(() => { | ||
this.messageService.success( | ||
'igo.integration.dataIssueReporterTool.submit.message', | ||
submitTitle | ||
); | ||
}); | ||
this.clearForm(); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/integration/src/lib/geometry-form/data-issue-reporter-tool/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './data-issue-reporter-tool.component'; |
22 changes: 22 additions & 0 deletions
22
packages/integration/src/lib/geometry-form/geometry-form.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
|
||
import { IgoFormModule } from '@igo2/common'; | ||
import { IgoLanguageModule, IgoMessageModule } from '@igo2/core'; | ||
|
||
import { DataIssueReporterToolComponent } from './data-issue-reporter-tool/data-issue-reporter-tool.component'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
MatButtonModule, | ||
IgoLanguageModule, | ||
IgoFormModule, | ||
IgoMessageModule | ||
], | ||
declarations: [DataIssueReporterToolComponent], | ||
exports: [DataIssueReporterToolComponent], | ||
schemas: [] | ||
}) | ||
export class IgoAppGeometryFormModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './data-issue-reporter-tool'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters