From 0231ba20ddc3df66311c083ed3522475bd40c76e Mon Sep 17 00:00:00 2001 From: Tomasz Subik Date: Wed, 9 Oct 2024 16:36:11 +0200 Subject: [PATCH] add non concession activities --- src/app/models/draft_observation.interface.ts | 1 + src/app/models/observation.model.ts | 1 + .../observation-detail.component.html | 8 ++ .../observation-detail.component.ts | 81 +++++++++++++++---- 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/src/app/models/draft_observation.interface.ts b/src/app/models/draft_observation.interface.ts index 3929652a..fd8b03b7 100644 --- a/src/app/models/draft_observation.interface.ts +++ b/src/app/models/draft_observation.interface.ts @@ -25,6 +25,7 @@ export interface DraftObservation { evidenceAttachment?: string; // Base64 evidenceDocumentType?: string; + nonConcessionActivity?: boolean; isPhysicalPlace?: boolean; litigationStatus?: string; locationAccuracy?: string; diff --git a/src/app/models/observation.model.ts b/src/app/models/observation.model.ts index b3f6f356..951b20e6 100644 --- a/src/app/models/observation.model.ts +++ b/src/app/models/observation.model.ts @@ -40,6 +40,7 @@ export class Observation extends JsonApiModel { @Attribute() 'hidden': boolean; // Whether an observation is archived @Attribute() 'user-type'?: string; @Attribute() 'monitor-comment'?: string; + @Attribute() 'non-concession-activity': boolean; // if operator operates in another operator fmu @Attribute() 'locale': string; @BelongsTo() fmu?: Fmu; diff --git a/src/app/pages/observations/observation-detail.component.html b/src/app/pages/observations/observation-detail.component.html index 6afe9f28..875e988a 100644 --- a/src/app/pages/observations/observation-detail.component.html +++ b/src/app/pages/observations/observation-detail.component.html @@ -460,6 +460,14 @@

{{'List of evidence' | translate}}

+
+ + +

+ {{'When checking this checkbox you will be able to select any FMU within selected country' | translate}} +

+
+
diff --git a/src/app/pages/observations/observation-detail.component.ts b/src/app/pages/observations/observation-detail.component.ts index 49196c87..687e79d6 100644 --- a/src/app/pages/observations/observation-detail.component.ts +++ b/src/app/pages/observations/observation-detail.component.ts @@ -20,6 +20,7 @@ import { ObservationsService } from 'app/services/observations.service'; import { Severity } from 'app/models/severity.model'; import { Router, ActivatedRoute } from '@angular/router'; import { Operator } from 'app/models/operator.model'; +import { FmusService } from 'app/services/fmus.service'; import { OperatorsService } from 'app/services/operators.service'; import { ObserversService } from 'app/services/observers.service'; import { Observer } from 'app/models/observer.model'; @@ -73,7 +74,9 @@ export class ObservationDetailComponent implements OnDestroy { unknownOperator: Operator = null; // Special unknown operator governments: Government[] = []; observers: Observer[] = []; // Ordered by name - fmus: Fmu[] = []; + _fmus: Fmu[] = []; + operatorFmus: Fmu[] = []; + countryFmus: Fmu[] = []; reports: ObservationReport[] = []; // Ordered by title documents: ObservationDocument[] = []; // Sorted by name initially reportDocuments: ObservationDocument[] = []; // Documents of the selected report @@ -230,6 +233,7 @@ export class ObservationDetailComponent implements OnDestroy { _latitude: number; // Only for type operator _longitude: number; // Only for type operator _fmu: Fmu = null; // Only for type operator + _nonConcessionActivity: boolean = false; // Only for type operator _government: Government = null; // Only for type government _law: Law = null; // Only for type operator _actions: string; @@ -348,6 +352,11 @@ export class ObservationDetailComponent implements OnDestroy { } if (country) { + this.fmusService.getAll({ sort: 'name', filter: { country: country.id } }) + .then((fmus) => { + this.countryFmus = fmus; + }); + this.operatorsService.getAll({ sort: 'name', filter: { country: country.id } }) .then((operators) => { this.operators = operators; @@ -397,25 +406,15 @@ export class ObservationDetailComponent implements OnDestroy { if (operatorChoice) { this.operatorsService.getById(operatorChoice.id, { include: 'fmus' }) .then((op) => { - this.fmus = op.fmus ? op.fmus : []; - - // If we can restore the FMU of the observation, we do it, - // otherwise we just reset the fmu each time the user - // update the operator - if (this.draft && this.draft.operatorId === operatorChoice.id) { - this.fmu = this.fmus.find(fmu => fmu.id === this.draft.fmuId); - } else if (this.observation && this.observation.operator.id === operatorChoice.id && this.observation.fmu) { - this.fmu = this.fmus.find(fmu => fmu.id === this.observation.fmu.id); - } else { - this.fmu = null; - } + this.operatorFmus = op.fmus ? op.fmus : []; + this.resetFmus(); }) .catch(err => console.error(err)); // TODO: visual feedback this.operatorsSelection = [operatorChoice.id]; } else { - this.fmus = []; - this.fmu = null; + this.operatorFmus = []; + this.resetFmus(); this.operatorsSelection = []; } } @@ -423,6 +422,49 @@ export class ObservationDetailComponent implements OnDestroy { return this.operatorChoice && this.unknownOperator && +this.operatorChoice.id === +this.unknownOperator.id; } + get nonConcessionActivity() { return this.observation ? this.observation['non-concession-activity'] : this._nonConcessionActivity; } + set nonConcessionActivity(nonConcessionActivity) { + this._nonConcessionActivity = nonConcessionActivity; + if (this.observation) { + this.observation['non-concession-activity'] = nonConcessionActivity; + } + + this.resetFmus(); + this.fmu = null; + } + + resetFmus() { + this.fmus = this.nonConcessionActivity ? this.countryFmus : this.operatorFmus; + } + + resetFmu() { + let fmuId = null; + if (this.draft) { + fmuId = this.draft.fmuId; + } else if (this.observation && this.observation.fmu) { + fmuId = this.observation.fmu.id; + } + + if (fmuId) { + if (this.nonConcessionActivity && this.countryFmus.length + || (!this.nonConcessionActivity && this.operatorFmus.length)) { + this.fmu = this._fmus.find(fmu => fmu.id === fmuId); + } + } + } + + // get operatorFmus() { return this._operatorFmus; } + // set operatorFmus(collection) { this._operatorFmus = collection; } + + // get countryFmus() { return this._countryFmus; } + // set countryFmus(collection) { this._countryFmus = collection; } + + get fmus() { return this._fmus; } + set fmus(collection) { + this._fmus = collection; + this.resetFmu(); + } + get fmu() { return this.observation ? this.observation.fmu : this._fmu; } set fmu(fmu) { // We create the map layer for the FMU and store it @@ -447,6 +489,11 @@ export class ObservationDetailComponent implements OnDestroy { } if (this.observation) { + if (this.observation.fmu && this.observation.fmu.id !== fmu.id) { + // reset latitude and longitude + this.latitude = null; + this.longitude = null; + } this.observation.fmu = fmu; } else { this._fmu = fmu; @@ -822,6 +869,7 @@ export class ObservationDetailComponent implements OnDestroy { private governmentsService: GovernmentsService, private subcategoriesService: SubcategoriesService, private operatorsService: OperatorsService, + private fmusService: FmusService, private lawsService: LawsService, private datastoreService: DatastoreService, private router: Router, @@ -888,6 +936,7 @@ export class ObservationDetailComponent implements OnDestroy { this.reportDate = new Date(this.draft.reportDate); if (this.type === 'operator') { + this.nonConcessionActivity = this.draft.nonConcessionActivity; this.physicalPlace = this.draft.isPhysicalPlace; this.latitude = this.draft.lat; this.longitude = this.draft.lng; @@ -1077,6 +1126,7 @@ export class ObservationDetailComponent implements OnDestroy { draftModel.operatorId = this.operatorChoice && this.operatorChoice.id; } + draftModel.nonConcessionActivity = this.nonConcessionActivity; draftModel.isPhysicalPlace = this.physicalPlace; draftModel.lat = this.physicalPlace && decimalCoordinates ? decimalCoordinates[0] : null; draftModel.lng = this.physicalPlace && decimalCoordinates ? decimalCoordinates[1] : null; @@ -1870,6 +1920,7 @@ export class ObservationDetailComponent implements OnDestroy { const decimalCoordinates = this.getDecimalCoordinates(); model.operator = this.operatorChoice; + model['non-concession-activity'] = this.nonConcessionActivity; model['is-physical-place'] = this.physicalPlace; model.lat = this.physicalPlace && decimalCoordinates ? decimalCoordinates[0] : null; model.lng = this.physicalPlace && decimalCoordinates ? decimalCoordinates[1] : null;