فهرست منبع

🐛 clean dates when new field selected

jmacura 3 سال پیش
والد
کامیت
ef0c55b80f
3فایلهای تغییر یافته به همراه16 افزوده شده و 5 حذف شده
  1. 1 1
      src/app/calculator/calculator.component.html
  2. 11 4
      src/app/calculator/calculator.service.ts
  3. 4 0
      src/app/calculator/field.service.ts

+ 1 - 1
src/app/calculator/calculator.component.html

@@ -9,7 +9,7 @@
       <div>
         {{ 'CALCULATOR.selectIndex' | translate}}:&emsp;
         <select class="form-select" [(ngModel)]="data.selectedProduct">
-          <option *ngFor="let product of calcService.availableProducts" [ngValue]="product">{{product}}</option>
+          <option *ngFor="let product of calcService.AVAILABLE_PRODUCTS" [ngValue]="product">{{product}}</option>
         </select>
       </div>
       <div>

+ 11 - 4
src/app/calculator/calculator.service.ts

@@ -12,13 +12,13 @@ export type Index = 'EVI' | 'RVI4S1';
 
 @Injectable({providedIn: 'root'})
 export class CalculatorService {
+  AVAILABLE_PRODUCTS = ['EVI', 'RVI4S1'] as const;
+  SERVICE_BASE_URL = 'https://fieldcalc.lesprojekt.cz/' as const;
   availableDates: Array<string>;
-  availableProducts = ['EVI', 'RVI4S1'];
   dateRangeSelects: Subject<{date: string}> = new Subject();
   dateCalendarSelects: Subject<{date: string}> = new Subject();
   selectedDate;
   //selectedProduct;
-  serviceBaseUrl = 'https://fieldcalc.lesprojekt.cz/';
   private _datesLoading: boolean;
   private _zonesLoading: boolean;
 
@@ -31,6 +31,13 @@ export class CalculatorService {
     this.dateRangeSelects.subscribe(({date}) => {
       this.selectedDate = date;
     });
+    /**
+     * When new field is selected, clean all other params
+     */
+    this.fieldService.fieldSelects.subscribe(({feature}) => {
+      this.availableDates = undefined;
+      this.selectedDate = undefined;
+    });
   }
 
   noDates(): boolean {
@@ -47,7 +54,7 @@ export class CalculatorService {
       const data = await this.httpClient
         .get<{dates: string[]}>(
           (this.proxyEnabled() ? this.hsConfig.proxyPrefix : '') +
-            this.serviceBaseUrl +
+            this.SERVICE_BASE_URL +
             'get_dates?' +
             'product=' +
             product +
@@ -87,7 +94,7 @@ export class CalculatorService {
       const data = await this.httpClient
         .post(
           (this.proxyEnabled() ? this.hsConfig.proxyPrefix : '') +
-            this.serviceBaseUrl +
+            this.SERVICE_BASE_URL +
             'get_zones',
           {
             product,

+ 4 - 0
src/app/calculator/field.service.ts

@@ -1,5 +1,7 @@
 import {Injectable} from '@angular/core';
+import {Subject} from 'rxjs';
 
+import {Feature} from 'ol';
 import {Geometry, Polygon} from 'ol/geom';
 import {getCenter} from 'ol/extent';
 import {transform} from 'ol/proj';
@@ -9,6 +11,7 @@ import {HsEventBusService, HsMapService} from 'hslayers-ng';
 @Injectable({providedIn: 'root'})
 export class FieldService {
   SELECTABLE_LAYERS = ['LPIS'] as const;
+  fieldSelects: Subject<{feature: Feature<Polygon>}> = new Subject();
   selectedField;
 
   constructor(
@@ -23,6 +26,7 @@ export class FieldService {
         return;
       }
       this.selectedField = data.feature.getGeometry() as Polygon;
+      this.fieldSelects.next({feature: this.selectedField});
     });
   }