Parcourir la source

🚨 lint files

jmacura il y a 4 ans
Parent
commit
60e94aa9fa

+ 7 - 7
src/app/app.component.spec.ts

@@ -1,5 +1,5 @@
+import {AppComponent} from './app.component';
 import {HsConfig} from 'hslayers-ng';
-import {HslayersAppComponent} from './app.component';
 import {TestBed, waitForAsync} from '@angular/core/testing';
 class HsConfigMock {
   constructor() {}
@@ -8,26 +8,26 @@ describe('AppComponent', () => {
   beforeEach(
     waitForAsync(() => {
       TestBed.configureTestingModule({
-        declarations: [HslayersAppComponent],
+        declarations: [AppComponent],
         providers: [{provide: HsConfig, useValue: new HsConfigMock()}],
       }).compileComponents();
     })
   );
 
   it('should create the app', () => {
-    const fixture = TestBed.createComponent(HslayersAppComponent);
+    const fixture = TestBed.createComponent(AppComponent);
     const app = fixture.componentInstance;
     expect(app).toBeTruthy();
   });
 
-  it(`should have as title 'hslayers-workspace'`, () => {
-    const fixture = TestBed.createComponent(HslayersAppComponent);
+  it(`should have as title 'hslayers-application'`, () => {
+    const fixture = TestBed.createComponent(AppComponent);
     const app = fixture.componentInstance;
-    expect(app.title).toEqual('hslayers-workspace');
+    expect(app.title).toEqual('hslayers-application');
   });
 
   it('should render title', () => {
-    const fixture = TestBed.createComponent(HslayersAppComponent);
+    const fixture = TestBed.createComponent(AppComponent);
     fixture.detectChanges();
     const compiled = fixture.nativeElement;
     expect(compiled.querySelector('.content span').textContent).toContain(

+ 14 - 14
src/app/app.component.ts

@@ -1,18 +1,14 @@
 import {Component} from '@angular/core';
 
 import proj4 from 'proj4';
-import {get as getProjection, transform} from 'ol/proj';
-import {register} from 'ol/proj/proj4';
 import {GeoJSON} from 'ol/format';
-import {View} from 'ol';
 import {OSM, Vector as VectorSource} from 'ol/source';
 import {Tile, Vector as VectorLayer} from 'ol/layer';
+import {View} from 'ol';
+import {get as getProjection, transform} from 'ol/proj';
+import {register} from 'ol/proj/proj4';
 
-import {
-  HsConfig,
-  HsEventBusService,
-  HsToastService
-} from 'hslayers-ng';
+import {HsConfig, HsEventBusService, HsToastService} from 'hslayers-ng';
 
 import i18n from './translations.json';
 import {AppService} from './app.service';
@@ -43,7 +39,7 @@ export class AppComponent {
     /* Inject here all modules from HSLayers-NG which you intend to use */
     public hsConfig: HsConfig,
     private hsEventBusService: HsEventBusService,
-    private hsToastService: HsToastService,
+    private hsToastService: HsToastService
   ) {
     /* Define the polygon's style using SLD */
     const fieldSld = `<?xml version="1.0" encoding="ISO-8859-1"?>
@@ -152,9 +148,12 @@ export class AppComponent {
             //path: 'User generated',
           },
           source: new VectorSource({
-            features: [new GeoJSON().readFeature(this.calculatorService.field, {
-              dataProjection: 'EPSG:4326', featureProjection: 'EPSG:5514'
-            })]
+            features: [
+              new GeoJSON().readFeature(this.calculatorService.field, {
+                dataProjection: 'EPSG:4326',
+                featureProjection: 'EPSG:5514',
+              }),
+            ],
           }),
         }),
       ],
@@ -167,9 +166,10 @@ export class AppComponent {
         'READY!',
         'Your map is now ready to use.',
         {
-          toastStyleClasses: 'bg-success text-white' /* Use any Bootstrap class here, see https://getbootstrap.com/docs/4.0/utilities/colors/ */
+          toastStyleClasses:
+            'bg-success text-white' /* Use any Bootstrap class here, see https://getbootstrap.com/docs/4.0/utilities/colors/ */,
         }
       );
-    })
+    });
   }
 }

+ 1 - 1
src/app/app.module.ts

@@ -2,8 +2,8 @@ import {BrowserModule} from '@angular/platform-browser';
 import {NgModule} from '@angular/core';
 
 import {AppComponent} from './app.component';
-import {HslayersModule} from 'hslayers-ng';
 import {CalculatorModule} from './calculator/calculator.module';
+import {HslayersModule} from 'hslayers-ng';
 
 @NgModule({
   declarations: [AppComponent],

+ 4 - 5
src/app/app.service.ts

@@ -7,7 +7,7 @@ import {
   HsLayerManagerService,
   HsLayoutService,
   HsPanelContainerService,
-  HsSidebarService
+  HsSidebarService,
 } from 'hslayers-ng';
 
 import {CalculatorComponent} from './calculator/calculator.component';
@@ -27,8 +27,8 @@ export class AppService {
       panel: 'calculator',
       module: 'calculator',
       order: 0,
-      title: 'Field Calculator',//() =>
-        //this.hsLanguageService.getTranslation('ADJUSTER.adjustFactors'),
+      title: 'Field Calculator', //() =>
+      //this.hsLanguageService.getTranslation('ADJUSTER.adjustFactors'),
       description: 'Adjust factors for computation',
       icon: 'icon-analytics-piechart',
     });
@@ -38,5 +38,4 @@ export class AppService {
       this.hsLayoutService.setDefaultPanel('calculator');
     });
   }
-  
-}
+}

+ 8 - 8
src/app/calculator/calculator.component.ts

@@ -1,15 +1,12 @@
 import {Component, OnInit, ViewRef} from '@angular/core';
 
-import {
-  HsLayoutService,
-  HsPanelComponent
-} from 'hslayers-ng';
+import {HsLayoutService, HsPanelComponent} from 'hslayers-ng';
 
 import {CalculatorService, Index} from './calculator.service';
 
 @Component({
   selector: 'calculator-panel',
-  templateUrl: './calculator.component.html'
+  templateUrl: './calculator.component.html',
 })
 export class CalculatorComponent implements HsPanelComponent, OnInit {
   data: {
@@ -22,7 +19,7 @@ export class CalculatorComponent implements HsPanelComponent, OnInit {
   constructor(
     public calcService: CalculatorService,
     public hsLayoutService: HsLayoutService
-  ) { }
+  ) {}
 
   ngOnInit() {}
 
@@ -51,6 +48,9 @@ export class CalculatorComponent implements HsPanelComponent, OnInit {
   }
 
   getZones() {
-    this.calcService.getZones({product: this.data.selectedProduct, date: this.data.selectedDate});
+    this.calcService.getZones({
+      product: this.data.selectedProduct,
+      date: this.data.selectedDate,
+    });
   }
-}
+}

+ 45 - 24
src/app/calculator/calculator.service.ts

@@ -1,11 +1,13 @@
-import {catchError} from 'rxjs/operators';
 import {HttpClient} from '@angular/common/http';
 import {Injectable} from '@angular/core';
+import {catchError} from 'rxjs/operators';
 
 import {HsConfig} from 'hslayers-ng';
 
 import {ZonesService} from './zones.service';
 
+export type Index = 'EVI' | 'RVI4S1';
+
 @Injectable({providedIn: 'root'})
 export class CalculatorService {
   availableDates: Array<string>;
@@ -15,18 +17,32 @@ export class CalculatorService {
   //TODO: temporary hard-coded hack
   centroid = {type: 'Point', coordinates: [16.944, 49.228]};
   //TODO: temporarry hard-coded hack
-  field = {type: 'Polygon', coordinates: [[[17.008032903697003,49.259378350222214],[17.012346093160815,49.26055145480218],[17.01341275235608,49.25661998865008],[17.01578237120672,49.251834177355896],[17.01243531034079,49.24966645404407],[17.009126895621744,49.24897297823598],[17.003117114964958,49.253454830509305],[17.008032903697003,49.259378350222214]]]};
+  field = {
+    type: 'Polygon',
+    coordinates: [
+      [
+        [17.008032903697003, 49.259378350222214],
+        [17.012346093160815, 49.26055145480218],
+        [17.01341275235608, 49.25661998865008],
+        [17.01578237120672, 49.251834177355896],
+        [17.01243531034079, 49.24966645404407],
+        [17.009126895621744, 49.24897297823598],
+        [17.003117114964958, 49.253454830509305],
+        [17.008032903697003, 49.259378350222214],
+      ],
+    ],
+  };
   //[[[17.01403296191603, 49.24858329768389], [17.014029303734432, 49.24849340104692], [17.01389198448605, 49.2484957958039], [17.013754665219444, 49.24849819039773], [17.013751007554088, 49.248408293744056], [17.013613688518262, 49.24841068816722], [17.013476369464207, 49.24841308242727], [17.013469055184203, 49.248233289084894], [17.01333173660994, 49.24823568316671], [17.01319441801745, 49.24823807708539], [17.013183448228144, 49.24796838701452], [17.013320766073623, 49.24796599311847], [17.01331710926463, 49.247876096432506], [17.013729061944726, 49.24786891378824], [17.01373271950072, 49.24795881045155], [17.0138700372733, 49.24795641590298], [17.013873695096525, 49.24804631255717], [17.014285649051903, 49.24803912791008], [17.014281990481678, 49.247949231278554], [17.014419308181342, 49.247946836077475], [17.014422967000566, 49.24803673270145], [17.015246874309636, 49.24802235802403], [17.015384192130647, 49.24801996167353], [17.01540249521542, 49.24846944450495], [17.01526517614939, 49.248471840893245], [17.01526151574496, 49.24838194432262], [17.015124196909692, 49.24838434054022], [17.015127857065117, 49.248474237118394], [17.01457858054565, 49.248483820387705], [17.014582239723282, 49.248573716994485], [17.01403296191603, 49.24858329768389]]]};
 
   constructor(
     private hsConfig: HsConfig,
     private httpClient: HttpClient,
-    private zonesService: ZonesService,
-    ) {
+    private zonesService: ZonesService
+  ) {
     //TODO: temporary hard-coded hack
     this.selectedField = this.centroid;
   }
-  
+
   noFieldSelected(): boolean {
     return this.selectedField === undefined;
   }
@@ -40,43 +56,50 @@ export class CalculatorService {
       const data = await this.httpClient
         .get<{dates: string[]}>(
           (this.proxyEnabled() ? this.hsConfig.proxyPrefix : '') +
-          this.serviceBaseUrl +
-          'get_dates?' +
-          'product=' +
-          product +
-          '&centroid=' +
-          JSON.stringify(this.centroid)
-        ).toPromise();
+            this.serviceBaseUrl +
+            'get_dates?' +
+            'product=' +
+            product +
+            '&centroid=' +
+            JSON.stringify(this.centroid)
+        )
+        .toPromise();
       console.log('data received!');
       console.log(data);
       this.availableDates = data.dates;
       //TODO: temporary hard-coded hack
       this.selectedField = this.field;
-    } catch(err) {
+    } catch (err) {
       console.error('Somethin fucked up!');
       console.log(err);
     }
   }
-  
-  async getZones({product, date}: {product: Index, date: string}) {
+
+  async getZones({product, date}: {product: Index; date: string}) {
     try {
       const data = await this.httpClient
         .post(
           (this.proxyEnabled() ? this.hsConfig.proxyPrefix : '') +
-          this.serviceBaseUrl +
-          'get_zones', {
+            this.serviceBaseUrl +
+            'get_zones',
+          {
             product,
             date,
             format: 'geojson',
-            geometry: this.selectedField
-          }, {
-            headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}
+            geometry: this.selectedField,
+          },
+          {
+            headers: {
+              'Content-Type': 'application/json',
+              'Accept': 'application/json',
+            },
           }
-          ).toPromise();
+        )
+        .toPromise();
       console.log('data received!');
       console.log(data);
       this.zonesService.updateZones(data);
-    } catch(err) {
+    } catch (err) {
       console.error('Somethin fucked up!');
       console.log(err);
     }
@@ -86,5 +109,3 @@ export class CalculatorService {
     return this.hsConfig.useProxy === undefined || this.hsConfig.useProxy;
   }
 }
-
-export type Index = 'EVI' | 'RVI4S1';

+ 20 - 18
src/app/calculator/zones.service.ts

@@ -1,9 +1,9 @@
+import {Fill, Stroke, Style} from 'ol/style';
+import {GeoJSON} from 'ol/format';
+import {Geometry} from 'ol/geom';
 import {Injectable} from '@angular/core';
 import {Vector as VectorLayer} from 'ol/layer';
 import {Vector as VectorSource} from 'ol/source';
-import {Geometry} from 'ol/geom';
-import {GeoJSON} from 'ol/format';
-import {Fill, Stroke, Style} from 'ol/style';
 
 import {HsAddDataService} from 'hslayers-ng';
 
@@ -14,15 +14,14 @@ export class ZonesService {
   zonesStyle: (feature) => Style;
   quantileColors = ['#0000ff', '#0033cc', '#006666', '#00cc33', '#00ff00'];
 
-  constructor(
-    private hsAddDataService: HsAddDataService
-  ) {
-    this.zonesStyle = (feature) => new Style({
-      fill: new Fill({
-        color: this.quantileColors[feature.get('quantile')]
-      }),
-      stroke: new Stroke()
-    })
+  constructor(private hsAddDataService: HsAddDataService) {
+    this.zonesStyle = (feature) =>
+      new Style({
+        fill: new Fill({
+          color: this.quantileColors[feature.get('quantile')],
+        }),
+        stroke: new Stroke(),
+      });
   }
 
   updateZones(zones) {
@@ -30,16 +29,19 @@ export class ZonesService {
       this.zonesSource = new VectorSource();
       this.zonesLayer = new VectorLayer({
         properties: {
-          title: 'Zones'
+          title: 'Zones',
         },
         style: this.zonesStyle,
-        source: this.zonesSource
+        source: this.zonesSource,
       });
       this.hsAddDataService.addLayer(this.zonesLayer);
     }
     this.zonesSource.clear();
-    this.zonesSource.addFeatures(new GeoJSON().readFeatures(zones, {
-      dataProjection: 'EPSG:4326', featureProjection: 'EPSG:5514'
-    }));
+    this.zonesSource.addFeatures(
+      new GeoJSON().readFeatures(zones, {
+        dataProjection: 'EPSG:4326',
+        featureProjection: 'EPSG:5514',
+      })
+    );
   }
-}
+}