AW-6046 Angular improvement
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
2024-04-15 10:29:47 +02:00
parent ede75f63f5
commit 84a1a04b19
104 changed files with 592 additions and 796 deletions

View File

@@ -1,15 +1,14 @@
import { HttpClient, HttpParams } from "@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IItem } from '../models/item';
import { HttpClient, HttpParams } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
import {ItemTypeService} from './itemtype.service';
@Injectable({
providedIn: 'root',
})
export class AdminService {
constructor(public httpClient: HttpClient, public appConfig: AppConfig,private itemTypeService:ItemTypeService) {
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
}
ApiEndpoint() {

View File

@@ -1,21 +1,14 @@
import { Injectable } from '@angular/core';
import { Router, Route, ActivatedRouteSnapshot, RouterStateSnapshot, UrlSegment, UrlTree } from '@angular/router';
import { Store } from '@ngrx/store';
import { ActivatedRouteSnapshot, Route, RouterStateSnapshot, UrlSegment, UrlTree } from '@angular/router';
import { OAuthService } from 'angular-oauth2-oidc';
import { Observable } from 'rxjs';
import * as appCommonReducer from '../reducers/app-common.reducer';
@Injectable({
providedIn: 'root',
})
export class AuthGuard {
constructor(private oauthService: OAuthService, private router: Router, private store: Store<appCommonReducer.State>) { }
constructor(private oauthService: OAuthService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
//console.debug("AuthGuard->canActivate", route, state);
@@ -31,7 +24,8 @@ export class AuthGuard {
return this.checkLogin(url, childRoute);
}
canLoad(route: Route, segments: UrlSegment[]): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
canLoad(route: Route, _segments: UrlSegment[]): boolean | UrlTree | Observable<boolean | UrlTree> | Promise<boolean | UrlTree> {
//console.debug("AuthGuard->canLoad", route, segments);
return this.checkLogin(route.path, null);
}

View File

@@ -1,4 +1,4 @@
import { Component, Injectable } from '@angular/core';
import { Injectable } from '@angular/core';
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
@Injectable({

View File

@@ -1,15 +1,14 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { IItem } from '../models/item';
import { HttpClient } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
import {ItemTypeService} from './itemtype.service';
@Injectable({
providedIn: 'root',
})
export class DownloadService {
constructor(public httpClient: HttpClient, public appConfig: AppConfig,private itemTypeService:ItemTypeService) {
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
}
ApiEndpoint() {

View File

@@ -1,8 +1,8 @@
import { Injectable } from '@angular/core';
import { IEventMessage } from '../models/event.message';
import { Subject, timer } from 'rxjs';
import { HttpTransportType, HubConnection, HubConnectionBuilder, HubConnectionState, LogLevel } from '@microsoft/signalr';
import { OAuthService } from 'angular-oauth2-oidc';
import { HubConnection, HubConnectionBuilder, LogLevel ,HttpTransportType,HubConnectionState} from '@microsoft/signalr';
import { Subject } from 'rxjs';
import { IEventMessage } from '../models/event.message';
import { AppConfig } from "../shared/app.config";
@@ -17,7 +17,7 @@ export class EventService {
public authenticated = false;
constructor(private oauthService: OAuthService, private appConfig: AppConfig) {
this._apiEndPoint = appConfig.getConfig("apiEndPoint");
this._apiEndPoint = this.appConfig.getConfig("apiEndPoint");
this._connection = new HubConnectionBuilder().withUrl(`${ this._apiEndPoint}/eventHub`,
{ transport: HttpTransportType.WebSockets,
// accessTokenFactory: () => {
@@ -28,7 +28,7 @@ export class EventService {
this._connection.on('event', eventMessage => {
this.event.next(eventMessage);
});
this._connection.onreconnected( event => {
this._connection.onreconnected(() => {
this.Authenticate();
});
this.Start();
@@ -42,7 +42,6 @@ export class EventService {
}
private Authenticate() {
const accessToken = this.oauthService.getAccessToken();
if (this.oauthService.hasValidAccessToken()) {
this._connection.send('authenticate', this.oauthService.getAccessToken());
this.authenticated=true;

View File

@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
@@ -12,7 +13,6 @@ import * as appCommonActions from '../actions/app-common.actions';
})
export class FullScreenGuard {
private loginDispatched = false;
constructor(private store: Store<appCommonReducer.State> ) { }
setFullScreen():boolean {
@@ -20,11 +20,11 @@ export class FullScreenGuard {
return true;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
canActivate(_route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): boolean {
return this.setFullScreen();
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
canActivateChild(_route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): boolean {
return this.setFullScreen();
}
}

View File

@@ -1,7 +1,6 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IUser } from '../models/user';
import { HttpClient,HttpHeaders } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
@Injectable({

View File

@@ -16,7 +16,7 @@ export class GradientService {
gd += `rgba(${gs.color.red},${gs.color.green},${gs.color.blue},${gs.color.alpha/255})`;
gd +=` ${gs.relativestop*100}%`
}
gradient.forEach((gs) => {
gradient.forEach(() => {
});
gd+=')"}';

View File

@@ -21,7 +21,7 @@ import { AppConfig } from "../shared/app.config";
check(interval:number): Observable<boolean> {
const retval = new BehaviorSubject<boolean>(true);
setInterval(() => {
this.httpClient.get(`${this.ApiEndpoint()}/api/v1/healthcheck`).pipe(map(() => true),catchError((error) => of(false))).toPromise().then((status) => {
this.httpClient.get(`${this.ApiEndpoint()}/api/v1/healthcheck`).pipe(map(() => true),catchError(() => of(false))).toPromise().then((status) => {
retval.next(status);
});
},interval);

View File

@@ -1,7 +1,5 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IUser } from '../models/user';
import { HttpClient,HttpHeaders } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
@Injectable({

View File

@@ -1,16 +1,14 @@
import { HttpClient, HttpHeaders, HttpParams } from "@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { IItemType } from '../models/item.type';
import { IItemLinkType } from '../models/itemlink.type';
import { IUrlType } from '../models/url.type';
import { IItem } from '../models/item';
import { IJsonline } from '../models/json-line';
import { IItemType } from '../models/item.type';
import { IItemTask } from '../models/itemTask';
import { HttpClient, HttpParams,HttpHeaders } from "@angular/common/http";
import { IItemLinkType } from '../models/itemlink.type';
import { IJsonline } from '../models/json-line';
import { IListItem } from '../models/list.item';
import { AppConfig } from "../shared/app.config";
import {ItemTypeService} from './itemtype.service';
import {IListItem} from '../models/list.item';
import { ItemTypeService } from './itemtype.service';
@Injectable({
providedIn: 'root',

View File

@@ -63,7 +63,7 @@ export class ItemTypeService {
this.itemTypes = itemTypes;
//return data;
})
.catch(error => this.itemTypes = null);
.catch(() => this.itemTypes = null);
} else {
return new Promise<void>((resolve) => {resolve()});
}

View File

@@ -1,10 +1,11 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Injectable } from '@angular/core';
import { Route, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Store } from '@ngrx/store';
import * as appCommonReducer from '../reducers/app-common.reducer'
import * as appCommonActions from '../actions/app-common.actions';
import * as appCommonReducer from '../reducers/app-common.reducer';
@Injectable({
@@ -12,7 +13,6 @@ import * as appCommonActions from '../actions/app-common.actions';
})
export class NavBarGuard {
private loginDispatched = false;
constructor(private store: Store<appCommonReducer.State>) { }
setNavBar():boolean {
@@ -20,11 +20,11 @@ export class NavBarGuard {
return true;
}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
canActivate(_route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): boolean {
return this.setNavBar();
}
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
canActivateChild(_route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): boolean {
return this.setNavBar();
}
}

View File

@@ -9,7 +9,8 @@ export class PackageGuard {
constructor(private packageService: PackageService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
canActivate(route: ActivatedRouteSnapshot, _state: RouterStateSnapshot): boolean {
return route.data && route.data.package && this.hasPackageForRoute(route.data.package);
}

View File

@@ -1,14 +1,14 @@
import {Injectable} from '@angular/core';
import {Store} from '@ngrx/store';
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import { IPackage, IPackages } from '../models/package';
import * as appCommonReducer from '../reducers/app-common.reducer';
import {IPackage, IPackages} from '../models/package';
import {IItem} from '../models/item';
import {IItemTask} from '../models/itemTask';
import {HttpClient} from '@angular/common/http';
import {AppConfig} from '../shared/app.config';
import {Observable,iif,of} from 'rxjs';
import {switchMap} from 'rxjs/operators';
import { HttpClient } from '@angular/common/http';
import { Observable, iif } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { IItem } from '../models/item';
import { IItemTask } from '../models/itemTask';
import { AppConfig } from '../shared/app.config';
@Injectable({
providedIn: 'root',

View File

@@ -31,10 +31,8 @@ export class SchemaService {
Observable<{schemaJson: any, schemaLayout: any}> {
return this.getSchema(schemaUrl).pipe(
switchMap(
schemaJson => this.getSchemaLayout(schemaUrl, locale)
.pipe(catchError(err => {
return of(undefined);
})),
() => this.getSchemaLayout(schemaUrl, locale)
.pipe(catchError(() => of(undefined))),
(schemaJson, schemaLayout) => {
return ({schemaJson, schemaLayout});
}

View File

@@ -1,4 +1,4 @@
import { Injectable, Query } from '@angular/core';
import { Injectable } from '@angular/core';
import { IQueryState } from '../models/query.state';
@Injectable({

View File

@@ -1,7 +1,5 @@
import { Injectable } from '@angular/core';
import { DatePipe } from '@angular/common';
import { Observable , Observer } from 'rxjs';
import { ITypeaheadItem } from '../models/typeahead.item';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
@@ -14,7 +12,6 @@ export class TimespanService {
quarters: string[] = ['KW1', 'KW2', 'KW3', 'KW4'];
getStartEndCaption(date: Date, otherDate: Date, unitScale: number, suffix = false, extended = true): string {
const showSuffix = false;
otherDate = new Date(otherDate.getTime() - 1); // fix year edge case
if (unitScale == 3) {
let format = "HH:00";

View File

@@ -1,7 +1,7 @@
import { HttpClient } from "@angular/common/http";
import { Injectable } from '@angular/core';
import { Observable , Observer } from 'rxjs';
import { Observable } from 'rxjs';
import { ITypeaheadItem } from '../models/typeahead.item';
import { HttpClient, HttpParams } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
@Injectable({

View File

@@ -1,14 +1,14 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {GeoJSON} from 'ol/format';
import {map, switchMap} from 'rxjs/operators';
import {getCenter} from 'ol/extent';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import moment from 'moment';
import {AppConfig} from '../shared/app.config';
import {WeatherCurrentObservation} from '../models/weatherCurrentObservation';
import {IItem} from '../models/item';
import {HourlyWeatherData, WeatherData} from '../models/WeatherData';
import { getCenter } from 'ol/extent';
import { GeoJSON } from 'ol/format';
import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { HourlyWeatherData, WeatherData } from '../models/WeatherData';
import { IItem } from '../models/item';
import { WeatherCurrentObservation } from '../models/weatherCurrentObservation';
import { AppConfig } from '../shared/app.config';
@Injectable({
providedIn: 'root',
@@ -49,7 +49,7 @@ export class WeatherService {
return this.getWeatherRange(centroid, startDateString, endDateString);
}
public getDailyHistoricalObservations(centroid: number[], startDate: string, endDate: string): Observable<HourlyWeatherData[]> {
public getDailyHistoricalObservations(centroid: number[], startDate: string): Observable<HourlyWeatherData[]> {
const endpoint = this.appConfig.getConfig('weatherApiEndPoint');
const apiKey = this.appConfig.getConfig('weatherApiKey');