-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding new interfaces & services closes #18 * Fixes #19 Update intOnly to use modern approach * Updates for App Configuration 15.1.6
- Loading branch information
1 parent
2247e7e
commit b919aa1
Showing
9 changed files
with
117 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export interface IOltAppSettings { | ||
hosts: IOltAppSettingHost[]; | ||
} | ||
|
||
export interface IOltAppSettingHost { | ||
host: string; | ||
apiEndpoint: string; | ||
environment: string; | ||
production: boolean; | ||
} | ||
|
||
export interface IOltAppSettingResult<T> { | ||
served: boolean; | ||
withError: boolean | null | ||
settings: T | null; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { HttpClient } from "@angular/common/http"; | ||
import { BehaviorSubject, Observable, catchError, map, of } from "rxjs"; | ||
import { IOltAppSettingResult } from "../interfaces/app-settings"; | ||
import { OltHelperService } from "./helper.service"; | ||
|
||
|
||
export abstract class OltAppSettingsServiceBase<T> { | ||
private config = new BehaviorSubject<IOltAppSettingResult<T> | null>(null); //this.FALL_BACK_SETTINGS | ||
protected static _appSettings: IOltAppSettingResult<any>; | ||
|
||
constructor( | ||
protected helperService: OltHelperService, | ||
protected http: HttpClient | ||
) { } | ||
|
||
get settings(): T { | ||
return OltAppSettingsServiceBase._appSettings?.settings; | ||
} | ||
abstract get FALL_BACK_SETTINGS(): IOltAppSettingResult<T>; | ||
abstract get settingsURL(): string; | ||
|
||
appSetting$: Observable<IOltAppSettingResult<T> | null> = this.config.asObservable(); | ||
|
||
private _createConfig(appSettings: IOltAppSettingResult<T>, 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<boolean> { | ||
const url = this.helperService.resolveUrl(this.settingsURL); | ||
return this.http.get<IOltAppSettingResult<T>>(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); | ||
}) | ||
); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters