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/occtac fix counting form problem #3257

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

93 changes: 56 additions & 37 deletions contrib/occtax/frontend/app/occtax-form/occtax-form.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { Injectable } from '@angular/core';
import { UntypedFormControl } from '@angular/forms';
import { BehaviorSubject, Observable, of } from 'rxjs';
import { filter, tap, skip, distinctUntilChanged, switchMap } from 'rxjs/operators';

import { HttpClient, HttpParams } from '@angular/common/http';
import { Router } from '@angular/router';
import { AuthService, User } from '@geonature/components/auth/auth.service';
import { CommonService } from '@geonature_common/service/common.service';
import { DataFormService } from '@geonature_common/form/data-form.service';
import { ModuleService } from '@geonature/services/module.service';
import { OcctaxDataService } from '../services/occtax-data.service';
import { ConfigService } from '@geonature/services/config.service';
import { Injectable } from "@angular/core";
import { UntypedFormControl } from "@angular/forms";
import { BehaviorSubject, Observable, of } from "rxjs";
import {
filter,
tap,
skip,
distinctUntilChanged,
switchMap,
} from "rxjs/operators";

import { HttpClient, HttpParams } from "@angular/common/http";
import { Router } from "@angular/router";
import { AuthService, User } from "@geonature/components/auth/auth.service";
import { CommonService } from "@geonature_common/service/common.service";
import { DataFormService } from "@geonature_common/form/data-form.service";
import { ModuleService } from "@geonature/services/module.service";
import { OcctaxDataService } from "../services/occtax-data.service";
import { ConfigService } from "@geonature/services/config.service";

@Injectable()
export class OcctaxFormService {
Expand All @@ -31,7 +37,7 @@ export class OcctaxFormService {
// public datasetOccurrenceAddFields: Array<any>= [];
public datasetCountingAddFields: Array<any> = [];
public idTaxonList: number;
public currentTab: 'releve' | 'taxons';
public currentTab: "releve" | "taxons";

get observerFromCurrentUser() {
return;
Expand Down Expand Up @@ -73,78 +79,89 @@ export class OcctaxFormService {
}
},
(error) => {
this._commonService.translateToaster('error', 'Releve.DoesNotExist');
this._router.navigate(['occtax/form']);
this._commonService.translateToaster("error", "Releve.DoesNotExist");
this._router.navigate(["occtax/form"]);
}
);
}

getDefaultValues(idOrg?: number, regne?: string, group2_inpn?: string) {
let params = new HttpParams();
if (idOrg) {
params = params.set('organism', idOrg.toString());
params = params.set("organism", idOrg.toString());
}
if (group2_inpn) {
params = params.append('regne', regne);
params = params.append("regne", regne);
}
if (regne) {
params = params.append('group2_inpn', group2_inpn);
params = params.append("group2_inpn", group2_inpn);
}
return this._http.get<any>(`${this.config.API_ENDPOINT}/occtax/defaultNomenclatures`, {
params: params,
});
return this._http.get<any>(
`${this.config.API_ENDPOINT}/occtax/defaultNomenclatures`,
{
params: params,
}
);
}

getAdditionnalFields(object_code: Array<string>, idDataset?: string): Observable<any> {
getAdditionnalFields(
object_code: Array<string>,
idDataset?: string
): Observable<any> {
return this.dataFormService
.getadditionalFields({
id_dataset: idDataset || 'null',
id_dataset: idDataset || "null",
module_code: [this._moduleService.currentModule.module_code],
object_code: object_code,
})
.catch((error) => {
console.error('error while get addional fields', error);
console.error("error while get addional fields", error);
return of([]);
});
}

onEditReleve(id) {
this._router.navigate(['occtax/form', id]);
this._router.navigate(["occtax/form", id]);
}
backToList() {
this._router.navigate(['occtax']);
this._router.navigate(["occtax"]);
}

formDisabled() {
if (this.disabled) {
this._commonService.translateToaster('warning', 'Releve.FillGeometryFirst');
this._commonService.translateToaster(
"warning",
"Releve.FillGeometryFirst"
);
}
}

addOccurrenceData(occurrence): void {
let occtaxData = this.occtaxData.getValue();
const occtaxData = this.occtaxData.getValue();

if (!occtaxData.releve.properties.t_occurrences_occtax) {
occtaxData.releve.properties.t_occurrences_occtax = [];
}
occtaxData.releve.properties.t_occurrences_occtax.push(occurrence);
this.occtaxData.next(occtaxData);
}

removeOccurrenceData(id_occurrence): void {
let occtaxData = this.occtaxData.getValue();
const occtaxData = this.occtaxData.getValue();
if (occtaxData.releve.properties.t_occurrences_occtax) {
for (let i = 0; i < occtaxData.releve.properties.t_occurrences_occtax.length; i++) {
for (
let i = 0;
i < occtaxData.releve.properties.t_occurrences_occtax.length;
i++
) {
if (
occtaxData.releve.properties.t_occurrences_occtax[i].id_occurrence_occtax ===
id_occurrence
occtaxData.releve.properties.t_occurrences_occtax[i]
.id_occurrence_occtax === id_occurrence
) {
occtaxData.releve.properties.t_occurrences_occtax.splice(i, 1);
break;
}
}
}
this.occtaxData.next(occtaxData);
}

replaceOccurrenceData(occurrence): void {
Expand All @@ -159,7 +176,7 @@ export class OcctaxFormService {
}

formatDate(strDate) {
const date = new Date(strDate + 'T00:00:00');
const date = new Date(strDate + "T00:00:00");
return {
year: date.getFullYear(),
month: date.getMonth() + 1,
Expand All @@ -172,7 +189,9 @@ export class OcctaxFormService {
let inter = Object.assign([], globalAddFields);
// remove formde dataset additional field from globalAddfield
inter = globalAddFields.filter((globalField) => {
return !formerDatasetAddFields.map((f) => f.id_field).includes(globalField.id_field);
return !formerDatasetAddFields
.map((f) => f.id_field)
.includes(globalField.id_field);
});

return inter;
Expand Down
2 changes: 1 addition & 1 deletion frontend/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"tabWidth": 2,
"semi": true,
"bracketSpacing": true,
"trailingComma": "es5",
"trailingComma": "none",
"singleAttributePerLine": true,
"bracketSameLine": false,
"htmlWhitespaceSensitivity": "ignore"
Expand Down
4 changes: 2 additions & 2 deletions frontend/cypress/e2e/import/constants/common.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const VIEWPORTS = [
{
width: 1920,
height: 1080,
},
height: 1080
}
];

export const TIMEOUT_WAIT = 2000;
16 changes: 8 additions & 8 deletions frontend/cypress/e2e/import/constants/fieldsContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@ export const FIELDS_CONTENT_STEP_UPLOAD = {
datasetField: {
defaultValue: 'JDD-TEST-IMPORT-ADMIN',
newValue: 'JDD-TEST-IMPORT-2',
selector: 'ng-select',
selector: 'ng-select'
},
fileUploadField: {
defaultValue: 'import/synthese/valid_file_test_link_list_import_synthese.csv',
newValue: 'import/synthese/valid_file_import_synthese_test_changed.csv',
parentSelector: '[data-qa="import-new-upload-file"]',
selector: '[data-qa="import-new-upload-file-label"]',
},
selector: '[data-qa="import-new-upload-file-label"]'
}
};

export const FIELDS_CONTENT_STEP_FILE_DECODE = {
encodeField: {
defaultValue: 'utf-8 (auto-détecté)',
newValue: 'iso-8859-15',
selector: '[data-qa="import-new-decode-encode"]',
selector: '[data-qa="import-new-decode-encode"]'
},
formatField: {
defaultValue: 'csv (auto-détecté)',
newValue: 'geojson',
selector: '[data-qa="import-new-decode-format"]',
selector: '[data-qa="import-new-decode-format"]'
},
delimiterField: {
defaultValue: '; (auto-détecté)',
newValue: ',',
selector: '[data-qa="import-new-decode-delimiter"]',
selector: '[data-qa="import-new-decode-delimiter"]'
},
sridField: {
defaultValue: 'WGS84',
newValue: 'Lambert93',
selector: '[data-qa="import-new-decode-srid"]',
},
selector: '[data-qa="import-new-decode-srid"]'
}
};
16 changes: 8 additions & 8 deletions frontend/cypress/e2e/import/constants/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@ export const FILES = {
valid: {
fixture: 'import/synthese/valid_file_test_link_list_import_synthese.csv',
toast: '',
formErrorElement: '',
formErrorElement: ''
},
bad: {
fixture: 'import/synthese/bad.csv',
toast: '',
formErrorElement: '[data-qa="import-new-upload-error-empty"]',
formErrorElement: '[data-qa="import-new-upload-error-empty"]'
},
empty: {
fixture: 'import/synthese/empty.csv',
toast: 'File must start with columns',
formErrorElement: '[data-qa="import-new-upload-error-firstColumn"]',
formErrorElement: '[data-qa="import-new-upload-error-firstColumn"]'
},
bad_extension: {
fixture: 'import/synthese/bad_extension.pdf',
toast: '',
formErrorElement: '',
},
formErrorElement: ''
}
},
occhab: {
valid: {
fixture: 'import/occhab/valid_file.csv',
toast: '',
formErrorElement: '',
},
},
formErrorElement: ''
}
}
};
8 changes: 4 additions & 4 deletions frontend/cypress/e2e/import/constants/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ export const FILTERS_TABLE = [
{
columnName: 'Jeu de données',
searchTerm: ['JDD-TEST', 'JDD-TEST-IMPORT-ADMIN', 'JDD-INVALID'],
expectedRowsCount: [4, 1, 0],
expectedRowsCount: [4, 1, 0]
},
{
columnName: 'Fichier',
searchTerm: ['valid_file_test_import', 'invalid_file.csv'],
expectedRowsCount: [2, 0],
expectedRowsCount: [2, 0]
},
{
columnName: 'Auteur',
searchTerm: ['Administrateur-test-import', 'Agent-test-import'],
expectedRowsCount: [4, 1],
},
expectedRowsCount: [4, 1]
}
];
2 changes: 1 addition & 1 deletion frontend/cypress/e2e/import/constants/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export const DEFAULT_FIELDMAPPINGS = ['Synthese GeoNature', 'Format DEE (champs

export const DEFAULT_CONTENTMAPPINGS = [
'Nomenclatures SINP (labels)',
'Nomenclatures SINP (codes)',
'Nomenclatures SINP (codes)'
];
16 changes: 8 additions & 8 deletions frontend/cypress/e2e/import/constants/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ export const SELECTORS_NAVIGATION = {
step: {
upload: {
back_btn_selector: '',
next_btn_selector: '[data-qa="import-new-upload-validate"]',
next_btn_selector: '[data-qa="import-new-upload-validate"]'
},
decode: {
back_btn_selector: '[data-qa="import-file-decode-back-btn"]',
step_btn_selector: '[data-qa="import-file-decode-step-btn"]',
next_btn_selector: '[data-qa="import-new-decode-validate"]',
next_btn_selector: '[data-qa="import-new-decode-validate"]'
},
fieldmapping: {
back_btn_selector: '[data-qa="import-fieldmapping-model-back-btn"]',
step_btn_selector: '[data-qa="import-fieldmapping-step-btn"]',
next_btn_selector: '[data-qa="import-new-fieldmapping-model-validate"]',
next_btn_selector: '[data-qa="import-new-fieldmapping-model-validate"]'
},
contentmapping: {
back_btn_selector: '[data-qa="import-contentmapping-back-btn"]',
step_btn_selector: '[data-qa="import-contentmapping-step-btn"]',
next_btn_selector: '[data-qa="import-new-contentmapping-model-validate"]',
next_btn_selector: '[data-qa="import-new-contentmapping-model-validate"]'
},
import: {
back_btn_selector: '[data-qa="import-data-back-btn"]',
step_btn_selector: '[data-qa="import-data-step-btn"]',
next_btn_selector: '[data-qa="import-new-verification-start"]',
},
next_btn_selector: '[data-qa="import-new-verification-start"]'
}
},
general: {
save_and_quit_btn_selector: '[data-qa="import-new-footer-save"]',
cancel_and_delete_import_btn_selector: '[data-qa="import-new-footer-delete"]',
'delete-import-modal-btn-selector': '[data-qa="modal-delete-validate"]',
},
'delete-import-modal-btn-selector': '[data-qa="modal-delete-validate"]'
}
};

export const getSelectorsForStep = (stepName) => {
Expand Down
Loading
Loading