AW-6046 Angular improvement
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
import { Component, OnInit, OnDestroy, Inject, Optional, ViewEncapsulation, RendererFactory2, PLATFORM_ID, ChangeDetectionStrategy, HostListener, Input } from '@angular/core';
|
||||
import { Router, NavigationStart, NavigationEnd, RouteConfigLoadStart, RouteConfigLoadEnd, ActivatedRoute, PRIMARY_OUTLET } from '@angular/router';
|
||||
import { Meta, Title, MetaDefinition } from '@angular/platform-browser'; import { DOCUMENT } from "@angular/common";
|
||||
import { Subscription, Observable } from 'rxjs';
|
||||
import { ChangeDetectionStrategy, Component, HostListener, Inject, Input, OnDestroy, OnInit, Optional, ViewEncapsulation } from '@angular/core';
|
||||
import { NavigationEnd, NavigationStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router } from '@angular/router';
|
||||
import { Action, Store } from '@ngrx/store';
|
||||
import { OAuthErrorEvent, OAuthService } from 'angular-oauth2-oidc';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { distinctUntilChanged } from 'rxjs/operators';
|
||||
import { Store, Action } from '@ngrx/store';
|
||||
import { IUser } from '../../models/user';
|
||||
import { OAuthService, OAuthErrorEvent } from 'angular-oauth2-oidc';
|
||||
import { FM_COMMON_STARTPAGE } from '../../common.module';
|
||||
import { IUser } from '../../models/user';
|
||||
|
||||
//AppCommon
|
||||
import * as commonActions from '../../actions/app-common.actions';
|
||||
import { IEventMessage } from '../../models/event.message';
|
||||
import { IListItem } from '../../models/list.item';
|
||||
import { EventService } from '../../services/event.service';
|
||||
import { ItemTypeService } from '../../services/itemtype.service';
|
||||
import * as commonActions from '../../actions/app-common.actions';
|
||||
import { HealthCheckService } from '../../services/healthcheck.service';
|
||||
import { AppConfig } from '../../shared/app.config';
|
||||
|
||||
import * as appReducers from '../../reducers/app-common.reducer';
|
||||
|
||||
@@ -27,12 +24,6 @@ import * as appReducers from '../../reducers/app-common.reducer';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush
|
||||
})
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
|
||||
// This will go at the END of your title for example "Home - Angular Universal..." <-- after the dash (-)
|
||||
private endPageTitle = 'Farmmaps';
|
||||
// If no Title is provided, we'll use a default one before the dash(-)
|
||||
private defaultPageTitle = 'Farmmaps';
|
||||
|
||||
private routerSub$: Subscription;
|
||||
private eventSub$: Subscription;
|
||||
|
||||
@@ -54,19 +45,12 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
constructor(
|
||||
@Optional() @Inject(FM_COMMON_STARTPAGE) public startPage: string,
|
||||
public router: Router,
|
||||
private activatedRoute$: ActivatedRoute,
|
||||
private title$: Title,
|
||||
private meta$: Meta,
|
||||
private store$: Store<appReducers.State>,
|
||||
private eventService$: EventService,
|
||||
private healthCheckService$: HealthCheckService,
|
||||
private itemTypeService$: ItemTypeService,
|
||||
private oauthService$: OAuthService,
|
||||
private appConfig$: AppConfig
|
||||
) {
|
||||
private oauthService$: OAuthService) {
|
||||
}
|
||||
|
||||
|
||||
getActionFromEvent(event: IEventMessage): Action {
|
||||
let action: Action = null;
|
||||
//console.debug(`${event.eventType} Event received`);
|
||||
@@ -163,30 +147,28 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private InstallRouteEventHandler() {
|
||||
const other = this;
|
||||
this.routerSub$ = this.router.events.subscribe(event => {
|
||||
if (event instanceof RouteConfigLoadStart) {
|
||||
other.store$.dispatch(new commonActions.StartRouteLoading());
|
||||
this.store$.dispatch(new commonActions.StartRouteLoading());
|
||||
}
|
||||
if (event instanceof NavigationEnd && (event.url == "/" || event.url.startsWith("/content"))) {
|
||||
other.store$.dispatch(new commonActions.SetPageMode(true));
|
||||
this.store$.dispatch(new commonActions.SetPageMode(true));
|
||||
} else if (event instanceof NavigationEnd) {
|
||||
other.store$.dispatch(new commonActions.SetPageMode(false));
|
||||
this.store$.dispatch(new commonActions.SetPageMode(false));
|
||||
}
|
||||
if (event instanceof RouteConfigLoadEnd) {
|
||||
other.store$.dispatch(new commonActions.EndRouteLoading());
|
||||
this.store$.dispatch(new commonActions.EndRouteLoading());
|
||||
}
|
||||
if (event instanceof NavigationStart) {
|
||||
other.store$.dispatch(new commonActions.SetMenuVisible(false));
|
||||
this.store$.dispatch(new commonActions.SetMenuVisible(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private InstallEventServiceEventHandler() {
|
||||
const other = this;
|
||||
this.eventSub$ = this.eventService$.event.subscribe(event => {
|
||||
const action = other.getActionFromEvent(event);
|
||||
if (action) other.store$.dispatch(action);
|
||||
const action = this.getActionFromEvent(event);
|
||||
if (action) this.store$.dispatch(action);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -201,7 +183,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
handleClick(event: MouseEvent) {
|
||||
handleClick() {
|
||||
this.store$.dispatch(new commonActions.Escape(false, true));
|
||||
}
|
||||
|
||||
@@ -214,7 +196,7 @@ export class AppComponent implements OnInit, OnDestroy {
|
||||
this.store$.dispatch(new commonActions.ToggleMenu());
|
||||
}
|
||||
|
||||
handleHome(event: MouseEvent) {
|
||||
handleHome() {
|
||||
this.router.navigate(['/']);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user