From 36f718c03412c345031429e24343043d6ebcd85e Mon Sep 17 00:00:00 2001 From: Chris Straw Date: Mon, 25 Sep 2023 17:31:23 -0400 Subject: [PATCH 1/3] Adding new interfaces & services closes #18 --- projects/olt-core/package.json | 2 +- .../src/lib/interfaces/app-settings.ts | 18 +++++++ projects/olt-core/src/lib/interfaces/index.ts | 1 + .../src/lib/services/app-setting.service.ts | 50 +++++++++++++++++++ projects/olt-ngx-bootstrap/package.json | 2 +- 5 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 projects/olt-core/src/lib/interfaces/app-settings.ts create mode 100644 projects/olt-core/src/lib/services/app-setting.service.ts diff --git a/projects/olt-core/package.json b/projects/olt-core/package.json index 212db10..d4eaaaf 100644 --- a/projects/olt-core/package.json +++ b/projects/olt-core/package.json @@ -1,6 +1,6 @@ { "name": "@outerlimitstech/ngx-app-core", - "version": "15.1.2", + "version": "15.1.3", "description": "Common Angular components, models, etc. for OuterLimits Technologies applications", "bugs": "https://github.com/OuterlimitsTech/olt-angular-libraries/issues", "homepage": "https://github.com/OuterlimitsTech/olt-angular-libraries#readme", diff --git a/projects/olt-core/src/lib/interfaces/app-settings.ts b/projects/olt-core/src/lib/interfaces/app-settings.ts new file mode 100644 index 0000000..109727b --- /dev/null +++ b/projects/olt-core/src/lib/interfaces/app-settings.ts @@ -0,0 +1,18 @@ +export interface IOltAppSettings { + hosts: IOltAppSettingHost[]; +} + +export interface IOltAppSettingHost { + host: string; + apiEndpoint: string; + environment: string; + production: boolean; +} + +export interface IOltAppSettingResult { + served: boolean; + withError: boolean | null + settings: T | null; + } + + \ No newline at end of file diff --git a/projects/olt-core/src/lib/interfaces/index.ts b/projects/olt-core/src/lib/interfaces/index.ts index 1621d5e..a512896 100644 --- a/projects/olt-core/src/lib/interfaces/index.ts +++ b/projects/olt-core/src/lib/interfaces/index.ts @@ -1,5 +1,6 @@ export * from './address.interface'; export * from './api-param.interface'; +export * from './app-settings'; export * from './auth-service.interface'; export * from './broadcast-message.interface'; export * from './cache-content.interface'; diff --git a/projects/olt-core/src/lib/services/app-setting.service.ts b/projects/olt-core/src/lib/services/app-setting.service.ts new file mode 100644 index 0000000..b669873 --- /dev/null +++ b/projects/olt-core/src/lib/services/app-setting.service.ts @@ -0,0 +1,50 @@ +import { HttpClient } from "@angular/common/http"; +import { OltHelperService } from "@outerlimitstech/ngx-app-core"; +import { BehaviorSubject, Observable, catchError, map, of } from "rxjs"; +import { IOltAppSettingResult } from "../interfaces/app-settings"; + + +export abstract class OltAppSettingsServiceBase { + private config = new BehaviorSubject | null>(null); //this.FALL_BACK_SETTINGS + protected static _appSettings: IOltAppSettingResult; + + constructor( + protected helperService: OltHelperService, + protected http: HttpClient + ) { } + + get settings(): T { + return OltAppSettingsServiceBase._appSettings?.settings; + } + abstract get FALL_BACK_SETTINGS(): IOltAppSettingResult; + abstract get settingsURL(): string; + + appSetting$: Observable | null> = this.config.asObservable(); + + private _createConfig(appSettings: IOltAppSettingResult, withError: boolean): void { + const _config = { ...this.FALL_BACK_SETTINGS, ...appSettings }; + _config.served = appSettings.served; + _config.withError = withError; + OltAppSettingsServiceBase._appSettings = _config; + console.log('_createConfig', _config); + this.config.next(appSettings); + } + + loadAppConfig(): Observable { + const url = this.helperService.resolveUrl(this.settingsURL); + return this.http.get>(url).pipe( + map((response) => { + this._createConfig(response, false); + return true; + }), + catchError((error) => { + // if in error, return set fall back from environment + this._createConfig(this.FALL_BACK_SETTINGS, true); + console.error(error); + return of(false); + }) + ); + } + + +} diff --git a/projects/olt-ngx-bootstrap/package.json b/projects/olt-ngx-bootstrap/package.json index 73355e3..493cfb2 100644 --- a/projects/olt-ngx-bootstrap/package.json +++ b/projects/olt-ngx-bootstrap/package.json @@ -1,6 +1,6 @@ { "name": "@outerlimitstech/ngx-bootstrap", - "version": "15.1.2", + "version": "15.1.3", "description": "Components that utilize ngx-bootstrap for OuterLimits Technologies applications", "bugs": "https://github.com/OuterlimitsTech/olt-angular-libraries/issues", "homepage": "https://github.com/OuterlimitsTech/olt-angular-libraries#readme", From 42646689bae6338beb270f3823a31d14915aa002 Mon Sep 17 00:00:00 2001 From: Chris Straw Date: Sun, 26 Nov 2023 14:01:21 -0500 Subject: [PATCH 2/3] Fixes #19 Update intOnly to use modern approach --- .../src/lib/directives/int-entry.directive.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/projects/olt-core/src/lib/directives/int-entry.directive.ts b/projects/olt-core/src/lib/directives/int-entry.directive.ts index 9423fd9..6dfb3da 100644 --- a/projects/olt-core/src/lib/directives/int-entry.directive.ts +++ b/projects/olt-core/src/lib/directives/int-entry.directive.ts @@ -1,7 +1,30 @@ -import { ElementRef, forwardRef, Directive, HostListener } from '@angular/core'; -import { NG_VALUE_ACCESSOR } from '@angular/forms'; -import { OltUtility } from '../utilities/utility'; +import { ElementRef, Directive, HostListener, EventEmitter, Output } from '@angular/core'; +// https://dev.to/dilika/restrict-angular-input-to-number-only-4o4k + +@Directive({ + selector: 'input[oltIntEntry]' +}) +export class IntEntryDirective { + + @Output() valueChange = new EventEmitter() + + constructor(private elementRef: ElementRef) { + } + + @HostListener('input', ['$event']) onInputChange(event: any) { + const initalValue = this.elementRef.nativeElement.value; + const newValue = initalValue.replace(/[^0-9]*/g, ''); + this.elementRef.nativeElement.value = newValue; + this.valueChange.emit(newValue); + if (initalValue !== this.elementRef.nativeElement.value) { + event.stopPropagation(); + } + } + +} + +/* Old Directive const noop = () => { }; const clean = (value: string | null) => { @@ -78,3 +101,4 @@ export class IntEntryDirective { this.disabled = isDisabled; } } +*/ \ No newline at end of file From 1b3eb055374307d4218118c0a855a60b486a6673 Mon Sep 17 00:00:00 2001 From: Chris Straw Date: Fri, 26 Apr 2024 16:07:04 -0400 Subject: [PATCH 3/3] Updates for App Configuration 15.1.6 --- projects/olt-core/package.json | 2 +- .../src/lib/models/authenticated-user-token.model.ts | 12 +++++++++++- .../olt-core/src/lib/services/app-setting.service.ts | 2 +- projects/olt-core/src/lib/services/index.ts | 2 +- .../src/date-time-picker.component.ts | 9 +++++++-- projects/olt-ngx-bootstrap/package.json | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/projects/olt-core/package.json b/projects/olt-core/package.json index d4eaaaf..e2be399 100644 --- a/projects/olt-core/package.json +++ b/projects/olt-core/package.json @@ -1,6 +1,6 @@ { "name": "@outerlimitstech/ngx-app-core", - "version": "15.1.3", + "version": "15.1.6", "description": "Common Angular components, models, etc. for OuterLimits Technologies applications", "bugs": "https://github.com/OuterlimitsTech/olt-angular-libraries/issues", "homepage": "https://github.com/OuterlimitsTech/olt-angular-libraries#readme", diff --git a/projects/olt-core/src/lib/models/authenticated-user-token.model.ts b/projects/olt-core/src/lib/models/authenticated-user-token.model.ts index 4fbd06f..06f2959 100644 --- a/projects/olt-core/src/lib/models/authenticated-user-token.model.ts +++ b/projects/olt-core/src/lib/models/authenticated-user-token.model.ts @@ -3,13 +3,22 @@ import { PersonName } from './person-name.model'; export class AuthenticatedUser { userPrincipalName!: string; name!: PersonName; + + tokenType!: string; + /** + * @deprecated Move to tokenType + */ authenticationType!: string; + token!: string; issued!: string; expires!: string; expiresIn!: string; roles!: string[]; permissions!: string[]; + /** + * @deprecated No longer used + */ otherClaims?: any; username!: string; email!: string; @@ -46,7 +55,8 @@ export class AuthenticatedUser { constructor(data?: any) { this.userPrincipalName = data?.userPrincipalName; - this.authenticationType = data?.authenticationType || data?.token_type || 'Bearer'; + this.authenticationType = data?.authenticationType || data?.tokenType || data?.token_type || 'Bearer'; + this.tokenType = data?.tokenType || data?.token_type || data?.authenticationType || 'Bearer'; this.token = data?.token || data?.access_token; this.issued = data?.issued; this.expires = data?.expires; diff --git a/projects/olt-core/src/lib/services/app-setting.service.ts b/projects/olt-core/src/lib/services/app-setting.service.ts index b669873..6f69f62 100644 --- a/projects/olt-core/src/lib/services/app-setting.service.ts +++ b/projects/olt-core/src/lib/services/app-setting.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from "@angular/common/http"; -import { OltHelperService } from "@outerlimitstech/ngx-app-core"; import { BehaviorSubject, Observable, catchError, map, of } from "rxjs"; import { IOltAppSettingResult } from "../interfaces/app-settings"; +import { OltHelperService } from "./helper.service"; export abstract class OltAppSettingsServiceBase { diff --git a/projects/olt-core/src/lib/services/index.ts b/projects/olt-core/src/lib/services/index.ts index 41c8789..2f9c50a 100644 --- a/projects/olt-core/src/lib/services/index.ts +++ b/projects/olt-core/src/lib/services/index.ts @@ -1,7 +1,7 @@ export * from './api.service'; +export * from './app-setting.service'; export * from './auth.service'; export * from './cache.service'; export * from './config.service'; export * from './error.service'; export * from './helper.service'; -// export * from './modal.service'; diff --git a/projects/olt-ngx-bootstrap/date-time-picker/src/date-time-picker.component.ts b/projects/olt-ngx-bootstrap/date-time-picker/src/date-time-picker.component.ts index 3250746..770f94a 100644 --- a/projects/olt-ngx-bootstrap/date-time-picker/src/date-time-picker.component.ts +++ b/projects/olt-ngx-bootstrap/date-time-picker/src/date-time-picker.component.ts @@ -1,5 +1,5 @@ import { Component, Input, forwardRef } from '@angular/core'; -import { AbstractControl, ControlValueAccessor, NG_VALUE_ACCESSOR, ValidationErrors, Validator } from '@angular/forms'; +import { AbstractControl, ControlValueAccessor, NG_VALIDATORS, NG_VALUE_ACCESSOR, ValidationErrors, Validator } from '@angular/forms'; import { OltUtility } from '@outerlimitstech/ngx-app-core'; @Component({ @@ -11,7 +11,12 @@ import { OltUtility } from '@outerlimitstech/ngx-app-core'; provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => DateTimePickerComponent), multi: true - } + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => DateTimePickerComponent), + multi: true, + } ] }) export class DateTimePickerComponent implements ControlValueAccessor, Validator { diff --git a/projects/olt-ngx-bootstrap/package.json b/projects/olt-ngx-bootstrap/package.json index 493cfb2..648c66b 100644 --- a/projects/olt-ngx-bootstrap/package.json +++ b/projects/olt-ngx-bootstrap/package.json @@ -1,6 +1,6 @@ { "name": "@outerlimitstech/ngx-bootstrap", - "version": "15.1.3", + "version": "15.1.6", "description": "Components that utilize ngx-bootstrap for OuterLimits Technologies applications", "bugs": "https://github.com/OuterlimitsTech/olt-angular-libraries/issues", "homepage": "https://github.com/OuterlimitsTech/olt-angular-libraries#readme",