Update to angular 8.2

This commit is contained in:
Willem Dantuma
2019-11-25 14:34:51 +01:00
parent 16db063339
commit 7bd5dada2b
22 changed files with 5929 additions and 4352 deletions

View File

@@ -1,129 +1,129 @@
import { Component, OnInit, OnDestroy, Inject, ViewEncapsulation, RendererFactory2, PLATFORM_ID, ChangeDetectionStrategy, HostListener } from '@angular/core';
import { Router, NavigationEnd, RouteConfigLoadStart, RouteConfigLoadEnd, ActivatedRoute, PRIMARY_OUTLET } from '@angular/router';
import { Meta, Title, DOCUMENT, MetaDefinition } from '@angular/platform-browser';
import { Subscription , Observable } from 'rxjs';
import { Store, Action } from '@ngrx/store';
//AppCommon
import { IEventMessage } from '../../models/event.message';
import { IListItem} from '../../models/list.item';
import { EventService } from '../../services/event.service';
import * as commonActions from '../../actions/app-common.actions';
import * as appReducers from '../../reducers/app-common.reducer';
@Component({
selector: 'fm-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None,
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: string = 'Farmmaps';
// If no Title is provided, we'll use a default one before the dash(-)
private defaultPageTitle: string = 'Farmmaps';
private routerSub$: Subscription;
private eventSub$: Subscription;
public currentFolder: Observable<IListItem>;
public folderParents: Observable<IListItem[]>;
public browseFileElement: any;
public browseDirectoryElement: any;
public fileDroptarget: any;
public fullScreen: Observable<boolean>;
public routeLoading: Observable<boolean>;
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private title: Title,
private meta: Meta,
private store: Store<appReducers.State>,
private eventService: EventService,
) {
}
getActionFromEvent(event: IEventMessage): Action {
var action: Action = null;
console.debug(`${event.eventType} Event received`);
switch (event.eventType) {
case "ItemChanged": {
action = new commonActions.ItemChangedEvent(event.itemCode, event.attributes);
break;
}
case "ItemAdded": {
action = new commonActions.ItemAddedEvent(event.itemCode, event.attributes);
break;
}
case "ItemDeleted": {
action = new commonActions.ItemDeletedEvent(event.itemCode, event.attributes);
break;
}
case "taskStart": {
action = new commonActions.TaskStartEvent(event.itemCode, event.attributes);
break;
}
case "taskEnd": {
action = new commonActions.TaskEndEvent(event.itemCode, event.attributes);
break;
}
case "taskError": {
action = new commonActions.TaskErrorEvent(event.itemCode, event.attributes);
break;
}
}
return action;
}
ngOnInit() {
this.fullScreen = this.store.select(appReducers.selectGetFullScreen);
this.routeLoading = this.store.select(appReducers.selectGetRouteLoading);
this.InstallRouteEventHandler();
this.InstallEventServiceEventHandler();
}
@HostListener('document:keyup', ['$event'])
keyUp(event: KeyboardEvent) {
let x = event.keyCode;
if (x === 27) {
this.store.dispatch(new commonActions.Escape(true,false));
}
}
ngOnDestroy() {
// Subscription clean-up
if(this.routerSub$) this.routerSub$.unsubscribe();
if(this.eventSub$) this.eventSub$.unsubscribe();
}
private InstallRouteEventHandler() {
var other = this;
this.routerSub$ = this.router.events.subscribe(event => {
if (event instanceof RouteConfigLoadStart) {
other.store.dispatch(new commonActions.StartRouteLoading());
}
if (event instanceof RouteConfigLoadEnd) {
other.store.dispatch(new commonActions.EndRouteLoading());
}
});
}
private InstallEventServiceEventHandler() {
var other = this;
this.eventSub$ = this.eventService.event.subscribe(event => {
var action = other.getActionFromEvent(event);
if (action) other.store.dispatch(action);
});
}
handleClick(event: MouseEvent) {
this.store.dispatch(new commonActions.Escape(false,true));
}
}
import { Component, OnInit, OnDestroy, Inject, ViewEncapsulation, RendererFactory2, PLATFORM_ID, ChangeDetectionStrategy, HostListener } from '@angular/core';
import { Router, 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 { Store, Action } from '@ngrx/store';
//AppCommon
import { IEventMessage } from '../../models/event.message';
import { IListItem} from '../../models/list.item';
import { EventService } from '../../services/event.service';
import * as commonActions from '../../actions/app-common.actions';
import * as appReducers from '../../reducers/app-common.reducer';
@Component({
selector: 'fm-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
encapsulation: ViewEncapsulation.None,
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: string = 'Farmmaps';
// If no Title is provided, we'll use a default one before the dash(-)
private defaultPageTitle: string = 'Farmmaps';
private routerSub$: Subscription;
private eventSub$: Subscription;
public currentFolder: Observable<IListItem>;
public folderParents: Observable<IListItem[]>;
public browseFileElement: any;
public browseDirectoryElement: any;
public fileDroptarget: any;
public fullScreen: Observable<boolean>;
public routeLoading: Observable<boolean>;
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private title: Title,
private meta: Meta,
private store: Store<appReducers.State>,
private eventService: EventService,
) {
}
getActionFromEvent(event: IEventMessage): Action {
var action: Action = null;
console.debug(`${event.eventType} Event received`);
switch (event.eventType) {
case "ItemChanged": {
action = new commonActions.ItemChangedEvent(event.itemCode, event.attributes);
break;
}
case "ItemAdded": {
action = new commonActions.ItemAddedEvent(event.itemCode, event.attributes);
break;
}
case "ItemDeleted": {
action = new commonActions.ItemDeletedEvent(event.itemCode, event.attributes);
break;
}
case "taskStart": {
action = new commonActions.TaskStartEvent(event.itemCode, event.attributes);
break;
}
case "taskEnd": {
action = new commonActions.TaskEndEvent(event.itemCode, event.attributes);
break;
}
case "taskError": {
action = new commonActions.TaskErrorEvent(event.itemCode, event.attributes);
break;
}
}
return action;
}
ngOnInit() {
this.fullScreen = this.store.select(appReducers.selectGetFullScreen);
this.routeLoading = this.store.select(appReducers.selectGetRouteLoading);
this.InstallRouteEventHandler();
this.InstallEventServiceEventHandler();
}
@HostListener('document:keyup', ['$event'])
keyUp(event: KeyboardEvent) {
let x = event.keyCode;
if (x === 27) {
this.store.dispatch(new commonActions.Escape(true,false));
}
}
ngOnDestroy() {
// Subscription clean-up
if(this.routerSub$) this.routerSub$.unsubscribe();
if(this.eventSub$) this.eventSub$.unsubscribe();
}
private InstallRouteEventHandler() {
var other = this;
this.routerSub$ = this.router.events.subscribe(event => {
if (event instanceof RouteConfigLoadStart) {
other.store.dispatch(new commonActions.StartRouteLoading());
}
if (event instanceof RouteConfigLoadEnd) {
other.store.dispatch(new commonActions.EndRouteLoading());
}
});
}
private InstallEventServiceEventHandler() {
var other = this;
this.eventSub$ = this.eventService.event.subscribe(event => {
var action = other.getActionFromEvent(event);
if (action) other.store.dispatch(action);
});
}
handleClick(event: MouseEvent) {
this.store.dispatch(new commonActions.Escape(false,true));
}
}

View File

@@ -1,85 +1,85 @@
import { Component, Input,ViewChild,ElementRef,OnChanges,SimpleChanges,HostListener,ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'fm-side-panel',
templateUrl: 'side-panel.component.html',
styleUrls: ['side-panel.component.scss']
})
export class SidePanelComponent implements OnChanges {
@Input() public visible: boolean;
@Input() public collapsed: boolean;
@Input() public collapsable: boolean;
@Input() public resizeable: boolean = false;
@ViewChild("resizeGrip") elementView: ElementRef;
public mobile:boolean = true;
private parentHeight:number = 0;
public top = "100%";
private resizeTop:number=50;
public resizing:boolean=false;
constructor(private element: ElementRef,private ref: ChangeDetectorRef) {
this.collapsable = false;
this.setTop();
}
checkMobile():boolean {
let size = parseFloat(getComputedStyle(document.documentElement).width);
let rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
let threshold = 44 * rem;
return !(size>threshold);
}
setTop() {
this.mobile = this.checkMobile();
this.resizeTop = this.mobile?50:0;
this.top = (this.visible?this.resizeTop: (this.mobile? 100:0)) + "%";
}
ngAfterViewInit() {
this.parentHeight = this.element.nativeElement.offsetParent.clientHeight;
}
handleToggleClick(event) {
if (this.collapsable) {
this.collapsed = !this.collapsed;
}
}
handleStartGripDrag(event:DragEvent|TouchEvent) {
this.resizing=true;
if(event instanceof DragEvent) {
var crt = new Image();
crt.style.display = "none";
document.body.appendChild(crt);
event.dataTransfer.setDragImage(crt,0,0);
}
}
handleEndGripDrag() {
this.resizing = false;
}
handleGripDrag(event:DragEvent|TouchEvent) {
var clientY = 0;
if((event instanceof TouchEvent)) {
clientY = (event as TouchEvent).changedTouches[0].clientY;
} else {
clientY=(event as DragEvent).clientY;
}
this.resizeTop = Math.min(98, Math.max(0, clientY / (this.parentHeight / 100)));
this.top = (this.visible? this.resizeTop:(this.mobile? 100:0)) + "%";
}
ngOnChanges(changes: SimpleChanges) {
if(changes.visible) {
this.top = (changes.visible.currentValue?this.resizeTop:(this.mobile? 100:0)) + "%";
}
}
@HostListener('window:resize', ['$event'])
onResize(event) {
this.setTop();
}
}
import { Component, Input,ViewChild,ElementRef,OnChanges,SimpleChanges,HostListener,ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'fm-side-panel',
templateUrl: 'side-panel.component.html',
styleUrls: ['side-panel.component.scss']
})
export class SidePanelComponent implements OnChanges {
@Input() public visible: boolean;
@Input() public collapsed: boolean;
@Input() public collapsable: boolean;
@Input() public resizeable: boolean = false;
@ViewChild("resizeGrip", { static: false }) elementView: ElementRef;
public mobile:boolean = true;
private parentHeight:number = 0;
public top = "100%";
private resizeTop:number=50;
public resizing:boolean=false;
constructor(private element: ElementRef,private ref: ChangeDetectorRef) {
this.collapsable = false;
this.setTop();
}
checkMobile():boolean {
let size = parseFloat(getComputedStyle(document.documentElement).width);
let rem = parseFloat(getComputedStyle(document.documentElement).fontSize);
let threshold = 44 * rem;
return !(size>threshold);
}
setTop() {
this.mobile = this.checkMobile();
this.resizeTop = this.mobile?50:0;
this.top = (this.visible?this.resizeTop: (this.mobile? 100:0)) + "%";
}
ngAfterViewInit() {
this.parentHeight = this.element.nativeElement.offsetParent.clientHeight;
}
handleToggleClick(event) {
if (this.collapsable) {
this.collapsed = !this.collapsed;
}
}
handleStartGripDrag(event:DragEvent|TouchEvent) {
this.resizing=true;
if(event instanceof DragEvent) {
var crt = new Image();
crt.style.display = "none";
document.body.appendChild(crt);
event.dataTransfer.setDragImage(crt,0,0);
}
}
handleEndGripDrag() {
this.resizing = false;
}
handleGripDrag(event:DragEvent|TouchEvent) {
var clientY = 0;
if((event instanceof TouchEvent)) {
clientY = (event as TouchEvent).changedTouches[0].clientY;
} else {
clientY=(event as DragEvent).clientY;
}
this.resizeTop = Math.min(98, Math.max(0, clientY / (this.parentHeight / 100)));
this.top = (this.visible? this.resizeTop:(this.mobile? 100:0)) + "%";
}
ngOnChanges(changes: SimpleChanges) {
if(changes.visible) {
this.top = (changes.visible.currentValue?this.resizeTop:(this.mobile? 100:0)) + "%";
}
}
@HostListener('window:resize', ['$event'])
onResize(event) {
this.setTop();
}
}

View File

@@ -1,104 +1,104 @@
import { Component, Input, forwardRef,ElementRef,ViewChild } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR,NgModel } from '@angular/forms';
import { Observable,of } from 'rxjs';
import { tap,catchError,debounceTime,distinctUntilChanged,switchMap } from 'rxjs/operators'
import { TypeaheadService } from '../../services/typeahead.service';
@Component({
selector: 'fm-tag-input',
templateUrl: 'tag-input.component.html',
styleUrls: ['tag-input.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => TagInputComponent),
multi: true
}
]
})
export class TagInputComponent implements ControlValueAccessor {
@Input() tags: string[]
@ViewChild('taginput') tagInputElement: ElementRef;
public tag: string;
searching = false;
searchFailed = false;
constructor(private typeaheadService: TypeaheadService) {
}
tagExists(tag) {
if (tag.length == 0) return true;
for (let t of this.tags) {
if (t.toLowerCase() == tag.toLowerCase()) return true;
}
return false;
}
handleDeleteTag(tag) {
let tags = [];
for (let t of this.tags) {
if (t != tag) tags.push(t);
}
this.tags = tags;
this.propagateChange(tags);
}
handleAddTag(event) {
if (!this.tagExists(this.tag)) {
this.tags.push(this.tag);
this.propagateChange(this.tags);
}
this.tag = "";
this.tagInputElement.nativeElement.focus();
}
handleCheckAddTag(event: KeyboardEvent) {
if (event.keyCode == 188) {
let tag = this.tag.substr(0, this.tag.length - 1); // strip ,
if (!this.tagExists(tag)) {
this.tags.push(tag);
this.propagateChange(this.tags);
}
this.tag = "";
}
}
handleSelect(event) {
if (!this.tagExists(event.item)) {
this.tags.push(event.item);
this.propagateChange(this.tags);
}
event.preventDefault();
this.tag = "";
}
propagateChange = (_: any) => { };
registerOnChange(fn) {
this.propagateChange = fn;
}
findTag = (text$: Observable<string>) =>
text$.pipe(
debounceTime(200),
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term => term.length < 1 ? of([]) :
this.typeaheadService.getTagTypeaheadItems(term).pipe(
tap(() => this.searchFailed = false),
catchError(() => {
this.searchFailed = true;
return of([]);
}))
),
tap(() => this.searching = false)
);
writeValue(value: any) {
this.tags = value;
this.tag = "";
}
registerOnTouched() { }
}
import { Component, Input, forwardRef,ElementRef,ViewChild } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR,NgModel } from '@angular/forms';
import { Observable,of } from 'rxjs';
import { tap,catchError,debounceTime,distinctUntilChanged,switchMap } from 'rxjs/operators'
import { TypeaheadService } from '../../services/typeahead.service';
@Component({
selector: 'fm-tag-input',
templateUrl: 'tag-input.component.html',
styleUrls: ['tag-input.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => TagInputComponent),
multi: true
}
]
})
export class TagInputComponent implements ControlValueAccessor {
@Input() tags: string[]
@ViewChild('taginput', { static: true }) tagInputElement: ElementRef;
public tag: string;
searching = false;
searchFailed = false;
constructor(private typeaheadService: TypeaheadService) {
}
tagExists(tag) {
if (tag.length == 0) return true;
for (let t of this.tags) {
if (t.toLowerCase() == tag.toLowerCase()) return true;
}
return false;
}
handleDeleteTag(tag) {
let tags = [];
for (let t of this.tags) {
if (t != tag) tags.push(t);
}
this.tags = tags;
this.propagateChange(tags);
}
handleAddTag(event) {
if (!this.tagExists(this.tag)) {
this.tags.push(this.tag);
this.propagateChange(this.tags);
}
this.tag = "";
this.tagInputElement.nativeElement.focus();
}
handleCheckAddTag(event: KeyboardEvent) {
if (event.keyCode == 188) {
let tag = this.tag.substr(0, this.tag.length - 1); // strip ,
if (!this.tagExists(tag)) {
this.tags.push(tag);
this.propagateChange(this.tags);
}
this.tag = "";
}
}
handleSelect(event) {
if (!this.tagExists(event.item)) {
this.tags.push(event.item);
this.propagateChange(this.tags);
}
event.preventDefault();
this.tag = "";
}
propagateChange = (_: any) => { };
registerOnChange(fn) {
this.propagateChange = fn;
}
findTag = (text$: Observable<string>) =>
text$.pipe(
debounceTime(200),
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term => term.length < 1 ? of([]) :
this.typeaheadService.getTagTypeaheadItems(term).pipe(
tap(() => this.searchFailed = false),
catchError(() => {
this.searchFailed = true;
return of([]);
}))
),
tap(() => this.searching = false)
);
writeValue(value: any) {
this.tags = value;
this.tag = "";
}
registerOnTouched() { }
}