Skip to content

Commit 470819e

Browse files
committed
fix: some lint issues and incorrect logic in the edition of geofields
1 parent ce45f9e commit 470819e

File tree

10 files changed

+137
-95
lines changed

10 files changed

+137
-95
lines changed

apps/back-office/src/environments/environment.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ import { AuthConfig } from 'angular-oauth2-oidc';
22
import { theme } from '../themes/default/default.local';
33
import { sharedEnvironment } from './environment.shared';
44

5+
// const authConfig: AuthConfig = {
6+
// issuer:
7+
// 'https://login.microsoftonline.com/fbacd48d-ccf4-480d-baf0-31048368055f/v2.0',
8+
// redirectUri: 'http://localhost:4200/',
9+
// postLogoutRedirectUri: 'http://localhost:4200/auth/',
10+
// clientId: 'd62083d8-fdc0-4a6a-8618-652380eebdb9',
11+
// scope: 'openid profile email offline_access',
12+
// responseType: 'code',
13+
// showDebugInformation: true,
14+
// strictDiscoveryDocumentValidation: false,
15+
// };
16+
517
/**
618
* Authentication configuration
719
*/

libs/safe/src/i18n/fr.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@
431431
"delete": {
432432
"confirmationMessage": "Voulez-vous vraiment supprimer la page {{name}}?"
433433
},
434-
"hide": "@TODO",
434+
"hide": "Cacher la page dans la barre latérale de navigation",
435435
"notReordered": {
436436
"plural": "Les pages n'ont pas été réorganisées. {{error}}",
437437
"singular": "La page n'a pas été réorganisée. {{error}}"
@@ -440,7 +440,7 @@
440440
"plural": "Les pages ont été réorganisées avec succès.",
441441
"singular": "La page a été réorganisée avec succès."
442442
},
443-
"show": "@TODO"
443+
"show": "Afficher la page dans la barre latérale de navigation"
444444
},
445445
"positionAttribute": {
446446
"delete": {
@@ -651,9 +651,9 @@
651651
"formMapProperties": {
652652
"geofields": {
653653
"editDialog": {
654-
"editGeofield": "@TODO",
655-
"label": "@TODO",
656-
"value": "@TODO"
654+
"editGeofield": "Éditer les champs",
655+
"label": "Label",
656+
"value": "Valeur"
657657
}
658658
}
659659
},

libs/safe/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export * from './lib/models/layout.model';
5353
export * from './lib/models/aggregation.model';
5454
export * from './lib/models/reference-data.model';
5555
export * from './lib/models/metadata.model';
56-
export * from './lib/models/geofield.model';
5756

5857
// === COMPONENTS ===
5958
export * from './lib/components/aggregation/edit-aggregation-modal/edit-aggregation-modal.component';
Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1-
<safe-modal size="small">
2-
<h1 mat-dialog-title>{{ 'components.formMapProperties.geofields.editDialog.editGeofield' | translate }}</h1>
3-
<div mat-dialog-content>
4-
<form [formGroup]="geoFieldForm" class="flex flex-col">
5-
<mat-form-field appearance="outline">
6-
<mat-label>{{ 'components.formMapProperties.geofields.editDialog.value' | translate }}</mat-label>
7-
<input
8-
matInput
9-
type="text"
10-
[disabled]="true"
11-
[value]="data.geofield.value"
12-
/>
13-
</mat-form-field>
14-
<mat-form-field appearance="outline">
15-
<mat-label>{{ 'components.formMapProperties.geofields.editDialog.label' | translate }}</mat-label>
16-
<input
17-
matInput
18-
formControlName="label"
19-
type="text"
20-
[value]="data.geofield.label"
21-
/>
22-
</mat-form-field>
23-
</form>
24-
</div>
25-
<div mat-dialog-actions align="end">
26-
<safe-button (click)="onClose()">{{
27-
'common.close' | translate
28-
}}</safe-button>
29-
<safe-button
30-
category="secondary"
31-
variant="primary"
32-
[mat-dialog-close]="geoFieldForm.value"
33-
cdkFocusInitial
34-
[disabled]="!geoFieldForm.valid"
35-
>
36-
{{ 'common.edit' | translate }}
37-
</safe-button>
38-
</div>
39-
</safe-modal>
40-
1+
<ui-dialog size="small">
2+
<!-- Header -->
3+
<ng-container ngProjectAs="header">
4+
{{
5+
'components.formMapProperties.geofields.editDialog.editGeofield'
6+
| translate
7+
}}
8+
</ng-container>
9+
<!-- Form -->
10+
<ng-container ngProjectAs="content">
11+
<form [formGroup]="geoFieldForm" class="flex flex-col">
12+
<div uiFormFieldDirective>
13+
<label>{{
14+
'components.formMapProperties.geofields.editDialog.value' | translate
15+
}}</label>
16+
<input type="text" [disabled]="true" [value]="data.geofield.value" />
17+
</div>
18+
<div uiFormFieldDirective>
19+
<label>{{
20+
'components.formMapProperties.geofields.editDialog.label' | translate
21+
}}</label>
22+
<input
23+
formControlName="label"
24+
type="text"
25+
[value]="data.geofield.label"
26+
/>
27+
</div>
28+
</form>
29+
</ng-container>
30+
<!-- Actions -->
31+
<ng-container ngProjectAs="actions">
32+
<ui-button (click)="onClose()">{{ 'common.close' | translate }}</ui-button>
33+
<ui-button
34+
category="secondary"
35+
variant="primary"
36+
[uiDialogClose]="geoFieldForm.value"
37+
cdkFocusInitial
38+
[disabled]="!geoFieldForm.valid"
39+
>
40+
{{ 'common.edit' | translate }}
41+
</ui-button>
42+
</ng-container>
43+
</ui-dialog>

libs/safe/src/lib/components/geofields-listbox/edit-geofield/edit-geofield.component.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
import { Component, OnInit, Inject } from '@angular/core';
2-
import {
3-
UntypedFormBuilder,
4-
UntypedFormGroup,
5-
Validators,
6-
} from '@angular/forms';
7-
import {
8-
MatLegacyDialogRef as MatDialogRef,
9-
MAT_LEGACY_DIALOG_DATA as MAT_DIALOG_DATA,
10-
} from '@angular/material/legacy-dialog';
11-
import { Geofield } from '../../../models/geofield.model';
2+
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
123
import { CommonModule } from '@angular/common';
13-
import { SafeModalModule } from '../../ui/modal/modal.module';
144
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
15-
import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field';
16-
import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input';
175
import { TranslateModule } from '@ngx-translate/core';
6+
import { ButtonModule, DialogModule, FormWrapperModule } from '@oort-front/ui';
7+
import { DIALOG_DATA, DialogRef } from '@angular/cdk/dialog';
8+
import { GeoField } from '../geofield.type';
189

10+
/**
11+
* GeoField editor dialog.
12+
* Enable to change the label of the geofields that appear next to map in forms.
13+
*/
1914
@Component({
2015
standalone: true,
2116
imports: [
2217
CommonModule,
23-
SafeModalModule,
2418
FormsModule,
2519
ReactiveFormsModule,
26-
MatFormFieldModule,
27-
MatInputModule,
2820
TranslateModule,
21+
DialogModule,
22+
FormWrapperModule,
23+
ButtonModule,
2924
],
3025
selector: 'safe-edit-geofield',
3126
templateUrl: './edit-geofield.component.html',
3227
styleUrls: ['./edit-geofield.component.scss'],
3328
})
3429
export class EditGeofieldComponent implements OnInit {
3530
// === REACTIVE FORM ===
36-
geoFieldForm: UntypedFormGroup = new UntypedFormGroup({});
31+
geoFieldForm!: FormGroup;
3732

3833
/**
3934
* edit GeoField component
@@ -44,11 +39,11 @@ export class EditGeofieldComponent implements OnInit {
4439
* @param data.geofield geofield to edit
4540
*/
4641
constructor(
47-
private formBuilder: UntypedFormBuilder,
48-
public dialogRef: MatDialogRef<EditGeofieldComponent>,
49-
@Inject(MAT_DIALOG_DATA)
42+
private formBuilder: FormBuilder,
43+
public dialogRef: DialogRef<EditGeofieldComponent>,
44+
@Inject(DIALOG_DATA)
5045
public data: {
51-
geofield: Geofield;
46+
geofield: GeoField;
5247
}
5348
) {}
5449

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Interface for GeoField object */
2+
export interface GeoField {
3+
id?: string;
4+
value?: string;
5+
label?: string;
6+
}

libs/safe/src/lib/components/geofields-listbox/geofields-listbox.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
<span>
1313
{{ dataItem.label }}
1414
</span>
15-
<safe-icon
15+
<ui-icon
1616
*ngIf="dataItem.value !== 'coordinates'"
1717
(click)="editLabel(dataItem)"
1818
class="hidden group-hover:block"
1919
icon="edit"
2020
>
21-
</safe-icon>
21+
</ui-icon>
2222
</div>
2323
</ng-template>
2424
</kendo-listbox>
@@ -33,13 +33,13 @@
3333
<span>
3434
{{ dataItem.label }}
3535
</span>
36-
<safe-icon
36+
<ui-icon
3737
*ngIf="dataItem.value !== 'coordinates'"
3838
(click)="editLabel(dataItem)"
3939
class="hidden group-hover:block"
4040
icon="edit"
4141
>
42-
</safe-icon>
42+
</ui-icon>
4343
</div>
4444
</ng-template>
4545
</kendo-listbox>

libs/safe/src/lib/components/geofields-listbox/geofields-listbox.component.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import {
1313
} from '@progress/kendo-angular-listbox';
1414
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
1515
import { GeoProperties } from '../../components/geospatial-map/geospatial-map.interface';
16-
import { MatLegacyDialogModule as MatDialogModule } from '@angular/material/legacy-dialog';
17-
import { MatLegacyDialog as MatDialog } from '@angular/material/legacy-dialog';
18-
import { Geofield } from '../../models/geofield.model';
19-
import { SafeIconModule } from '../ui/icon/icon.module';
16+
import { Dialog } from '@angular/cdk/dialog';
17+
import { GeoField } from './geofield.type';
18+
import { takeUntil } from 'rxjs';
19+
import { SafeUnsubscribeComponent } from '../utils/unsubscribe/unsubscribe.component';
20+
import { IconModule } from '@oort-front/ui';
2021

2122
/** All available fields */
2223
export const ALL_FIELDS: { value: keyof GeoProperties; label: string }[] = [
@@ -40,13 +41,15 @@ export const ALL_FIELDS: { value: keyof GeoProperties; label: string }[] = [
4041
ListBoxModule,
4142
FormsModule,
4243
ReactiveFormsModule,
43-
SafeIconModule,
44-
MatDialogModule,
44+
IconModule,
4545
],
4646
templateUrl: './geofields-listbox.component.html',
4747
styleUrls: ['./geofields-listbox.component.scss'],
4848
})
49-
export class GeofieldsListboxComponent implements OnInit, OnChanges {
49+
export class GeofieldsListboxComponent
50+
extends SafeUnsubscribeComponent
51+
implements OnInit, OnChanges
52+
{
5053
@Input() selectedFields: { value: keyof GeoProperties; label: string }[] = [];
5154
public availableFields = ALL_FIELDS;
5255
public toolbarSettings: ListBoxToolbarConfig = {
@@ -62,17 +65,25 @@ export class GeofieldsListboxComponent implements OnInit, OnChanges {
6265
};
6366
@Output() selectionChange = new EventEmitter();
6467

65-
constructor(public dialog: MatDialog) {}
68+
/**
69+
* Component for the selection of the interest fields from geospatial question
70+
*
71+
* @param dialog Dialog service
72+
*/
73+
constructor(public dialog: Dialog) {
74+
super();
75+
}
6676

6777
ngOnInit(): void {
78+
console.log(this.selectedFields);
6879
this.availableFields = ALL_FIELDS.filter(
69-
(x) => !this.selectedFields.some((obj) => obj.value.includes(x.value))
80+
(x) => !this.selectedFields.some((obj) => obj.value === x.value)
7081
);
7182
}
7283

7384
ngOnChanges(): void {
7485
this.availableFields = ALL_FIELDS.filter(
75-
(x) => !this.selectedFields.some((obj) => obj.value.includes(x.value))
86+
(x) => !this.selectedFields.some((obj) => obj.value === x.value)
7687
);
7788
}
7889

@@ -81,8 +92,12 @@ export class GeofieldsListboxComponent implements OnInit, OnChanges {
8192
this.selectionChange.emit(this.selectedFields);
8293
}
8394

84-
/** Open dialog to edit label */
85-
async editLabel(geofield: Geofield): Promise<void> {
95+
/**
96+
* Open dialog to edit label
97+
*
98+
* @param geofield Geofield to edit
99+
*/
100+
async editLabel(geofield: GeoField): Promise<void> {
86101
const { EditGeofieldComponent } = await import(
87102
'./edit-geofield/edit-geofield.component'
88103
);
@@ -91,7 +106,7 @@ export class GeofieldsListboxComponent implements OnInit, OnChanges {
91106
geofield,
92107
},
93108
});
94-
dialogRef.afterClosed().subscribe((value) => {
109+
dialogRef.closed.pipe(takeUntil(this.destroy$)).subscribe((value: any) => {
95110
if (value) {
96111
const modified_fields = this.availableFields.map((field) => {
97112
if (field.value === geofield.value) {

libs/safe/src/lib/models/geofield.model.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

libs/safe/src/lib/survey/components/geospatial.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ import {
77
GeofieldsListboxComponent,
88
} from '../../components/geofields-listbox/geofields-listbox.component';
99

10+
/**
11+
* Extract geofields from question ( to match with latest version of the available ones )
12+
*
13+
* @param question Geospatial question
14+
* @returns clean list of selected geofields
15+
*/
16+
const getGeoFields = (question: any) => {
17+
const rawSelectedFields: any[] = (question.geoFields || []).map(
18+
(field: any) =>
19+
typeof field === 'string'
20+
? {
21+
value: field,
22+
label: ALL_FIELDS.find((x) => x.value === field)?.label || field,
23+
}
24+
: field
25+
);
26+
return rawSelectedFields.filter((x) =>
27+
(ALL_FIELDS.map((field) => field.value) as string[]).includes(x.value)
28+
);
29+
};
30+
1031
/**
1132
* Inits the geospatial component.
1233
*
@@ -58,10 +79,7 @@ export const init = (Survey: any, domService: DomService): void => {
5879
htmlElement
5980
);
6081
const instance: GeofieldsListboxComponent = listbox.instance;
61-
instance.selectedFields = (question.geoFields || []).filter(
62-
(x: string) =>
63-
(ALL_FIELDS.map((field) => field.value) as string[]).includes(x)
64-
);
82+
instance.selectedFields = getGeoFields(question);
6583
instance.selectionChange.subscribe((fields) => {
6684
question.geoFields = fields || [];
6785
});
@@ -85,7 +103,7 @@ export const init = (Survey: any, domService: DomService): void => {
85103
if (question.value) instance.data = question.value;
86104

87105
// Set geo fields
88-
instance.fields = question.geoFields || [];
106+
instance.fields = getGeoFields(question);
89107

90108
// Listen to change on geofields
91109
question.registerFunctionOnPropertyValueChanged('geoFields', () => {

0 commit comments

Comments
 (0)