Skip to content

Commit

Permalink
add unknown option to producer list
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Dec 20, 2023
1 parent 70fb4c6 commit 1768ee0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/app/pages/observations/observation-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</otp-operator-detail>
</otp-modal>

<form *ngIf="!loading" name="form" class="c-form" (ngSubmit)="!isDisabled() && f.valid && onSubmitForReview()" #f="ngForm" novalidate>
<form *ngIf="!loading" name="form" class="c-form" (ngSubmit)="!isDisabled() && !unknownOperatorSelected && f.valid && onSubmitForReview()" #f="ngForm" novalidate>
<div class="c-container -j-between -t-d-column -t-a-start">
<h2 *ngIf="isDisabled() && !isCopied">{{'Observation details' | translate}}</h2>
<h2 *ngIf="(!isDisabled() && !observation) || isCopied">{{'New observation' | translate}}</h2>
Expand Down Expand Up @@ -196,7 +196,7 @@ <h3>{{'Upload report' | translate}}</h3>
</div>

<!-- 3. Operator -->
<div class="form-group -required" [ngClass]="{ 'has-error': f.submitted && !operator_id.valid }">
<div class="form-group -required" [ngClass]="{ 'has-error': f.submitted && (!operator_id.valid || unknownOperatorSelected) }">
<label for="operator_id">{{'Operator' | translate}}</label>
<ss-multiselect-dropdown
[texts]="multiSelectTexts"
Expand All @@ -207,8 +207,10 @@ <h3>{{'Upload report' | translate}}</h3>
name="operator_id"
#operator_id="ngModel"
[disabled]="isDisabled()"
required
></ss-multiselect-dropdown>
<div *ngIf="f.submitted && !operator_id.valid" class="help-text">{{'Please select an operator' | translate}}</div>
<div *ngIf="unknownOperatorSelected" class="help-text">{{'You will not be able to submit this observation to review with unknown operator selected' | translate}}</div>
<div class="note" *ngIf="!isDisabled()">
<button type="button" class="c-button -primary" (click)="onClickAddOperator('operator')">{{'Add a new producer to the list' | translate}}</button>
</div>
Expand Down
20 changes: 17 additions & 3 deletions src/app/pages/observations/observation-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class ObservationDetailComponent implements OnDestroy {
subcategories: Subcategory[] = [];
severities: Severity[] = [];
_operators: Operator[] = []; // Ordered by name, filtered by country
unknownOperator: Operator = null; // Special unknown operator
governments: Government[] = [];
observers: Observer[] = []; // Ordered by name
fmus: Fmu[] = [];
Expand Down Expand Up @@ -349,9 +350,13 @@ export class ObservationDetailComponent implements OnDestroy {

get operators() { return this._operators; }
set operators(collection) {
this._operators = collection;
this.operatorsOptions = collection.map((o) => ({ id: o.id, name: o.name }));
this.relevantOperatorsOptions = this.operators.map((operator) => ({ id: operator.id, name: operator.name }));
if (this.unknownOperator) {
this._operators = [this.unknownOperator, ...collection];
} else {
this._operators = collection;
}
this.operatorsOptions = this._operators.map((o) => ({ id: o.id, name: o.name }));
this.relevantOperatorsOptions = collection.map((o) => ({ id: o.id, name: o.name }));
}

get operatorChoice() { return this.observation ? this.observation.operator : this._operatorChoice; }
Expand Down Expand Up @@ -387,6 +392,9 @@ export class ObservationDetailComponent implements OnDestroy {
this.operatorsSelection = [];
}
}
get unknownOperatorSelected() {
return this.operatorChoice && this.unknownOperator && +this.operatorChoice.id === +this.unknownOperator.id;
}

get fmu() { return this.observation ? this.observation.fmu : this._fmu; }
set fmu(fmu) {
Expand Down Expand Up @@ -758,6 +766,12 @@ export class ObservationDetailComponent implements OnDestroy {
this.updateTranslatedOptions(this.coordinatesFormats, 'coordinatesFormat');
});

this.operatorsService.getAll({ filter: { slug: 'unknown' }}).then((operators) => {
if (operators.length > 0) {
this.unknownOperator = operators[0];
}
});

this.observersService.getAll({ sort: 'name' })
.then((observers) => {
this.observers = observers;
Expand Down
3 changes: 2 additions & 1 deletion src/assets/locale/zu.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,6 @@
"Please pick sub-category first.": "Please pick sub-category first.",
"Add a new government entity to the list": "Add a new government entity to the list",
"Add a new producer to the list": "Add a new producer to the list",
"Please select an existing report or upload a new one": "Please select an existing report or upload a new one"
"Please select an existing report or upload a new one": "Please select an existing report or upload a new one",
"You will not be able to submit this observation to review with unknown operator selected": "You will not be able to submit this observation to review with unknown operator selected"
}

0 comments on commit 1768ee0

Please sign in to comment.