-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into chore/pr-labeller-2
- Loading branch information
Showing
11 changed files
with
176 additions
and
101 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
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,17 @@ | ||
import { NgModule } from "@angular/core"; | ||
|
||
import { AnalyticsModule } from "./shared/services/analytics"; | ||
|
||
/** | ||
* Module imports required for specific deployment features | ||
* | ||
* NOTE - as angular needs all modules to be statically defined during compilation | ||
* it is not possible to conditionally load modules at runtime. | ||
* | ||
* Therefore all modules are defined and loaded as part of the core build process, | ||
* but it is still possible to override this file to create specific feature-optimised builds | ||
* | ||
* This is a feature marked for future implementation | ||
*/ | ||
@NgModule({ imports: [AnalyticsModule] }) | ||
export class DeploymentFeaturesModule {} |
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,45 @@ | ||
import { NgModule } from "@angular/core"; | ||
|
||
import { | ||
MATOMO_CONFIGURATION, | ||
MatomoConfiguration, | ||
provideMatomo, | ||
withRouter, | ||
} from "ngx-matomo-client"; | ||
|
||
import { IDeploymentRuntimeConfig } from "packages/data-models"; | ||
import { DEPLOYMENT_CONFIG } from "../deployment/deployment.service"; | ||
import { environment } from "src/environments/environment"; | ||
|
||
/** When running locally can configure to target local running containing (if required) */ | ||
const devConfig: MatomoConfiguration = { | ||
disabled: true, | ||
trackerUrl: "http://localhost/analytics", | ||
siteId: 1, | ||
}; | ||
|
||
/** | ||
* When configuring the analytics module | ||
* This should be imported into the main app.module.ts | ||
*/ | ||
@NgModule({ | ||
imports: [], | ||
providers: [ | ||
provideMatomo(null, withRouter()), | ||
// Dynamically provide the configuration used by the matomo provider so that it can | ||
// access deployment config (injected from token) | ||
{ | ||
provide: MATOMO_CONFIGURATION, | ||
useFactory: (deploymentConfig: IDeploymentRuntimeConfig): MatomoConfiguration => { | ||
if (environment.production) { | ||
const { enabled, endpoint, siteId } = deploymentConfig.analytics; | ||
return { disabled: !enabled, siteId, trackerUrl: endpoint }; | ||
} else { | ||
return devConfig; | ||
} | ||
}, | ||
deps: [DEPLOYMENT_CONFIG], | ||
}, | ||
], | ||
}) | ||
export class AnalyticsModule {} |
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,2 @@ | ||
export * from "./analytics.module"; | ||
export * from "./analytics.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,33 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { AsyncServiceBase } from "../asyncService.base"; | ||
import { HttpClient } from "@angular/common/http"; | ||
import { catchError, map, of, firstValueFrom } from "rxjs"; | ||
import { DEPLOYMENT_RUNTIME_CONFIG_DEFAULTS, IDeploymentRuntimeConfig } from "packages/data-models"; | ||
import { Inject, Injectable, InjectionToken } from "@angular/core"; | ||
import { IDeploymentRuntimeConfig } from "packages/data-models"; | ||
import { SyncServiceBase } from "../syncService.base"; | ||
|
||
@Injectable({ providedIn: "root" }) | ||
/** | ||
* Deployment runtime config settings | ||
* Token to inject deployment config value into any service. | ||
* This is populated from json file before platform load, as part of src\main.ts | ||
* | ||
* NOTE - this is intialized using an `APP_INITIALIZER` token within | ||
* the main app.module.ts and will block all other services from loading until | ||
* it is fully initialised | ||
* Can be used directly by any service or module initialised at any time | ||
* (including app.module.ts). | ||
* | ||
* Services that access the deployment config therefore do not need to await | ||
* DeploymentService init/ready methods. | ||
* @example Inject into service | ||
* ```ts | ||
* constructor(@Inject(DEPLOYMENT_CONFIG)) | ||
* ``` | ||
* @example Inject into module | ||
* ``` | ||
* {provide: MyModule, useFactory:(config)=>{...}, deps: [DEPLOYMENT_CONFIG]`} | ||
* ``` | ||
*/ | ||
export class DeploymentService extends AsyncServiceBase { | ||
constructor(private http: HttpClient) { | ||
super("Deployment Service"); | ||
this.registerInitFunction(this.initialise); | ||
} | ||
|
||
/** Private writeable config to allow population from JSON */ | ||
private _config = DEPLOYMENT_RUNTIME_CONFIG_DEFAULTS; | ||
|
||
/** Read-only access to deployment runtime config */ | ||
public get config() { | ||
return this._config; | ||
} | ||
export const DEPLOYMENT_CONFIG: InjectionToken<IDeploymentRuntimeConfig> = | ||
new InjectionToken<IDeploymentRuntimeConfig>("Application Configuration"); | ||
|
||
/** Load active deployment configuration from JSON file */ | ||
private async initialise() { | ||
const deployment = await firstValueFrom(this.loadDeployment()); | ||
if (deployment) { | ||
this._config = deployment; | ||
} | ||
} | ||
|
||
private loadDeployment() { | ||
return this.http.get("assets/app_data/deployment.json").pipe( | ||
catchError(() => { | ||
console.warn("No deployment config available"); | ||
return of(null); | ||
}), | ||
map((v) => v as IDeploymentRuntimeConfig) | ||
); | ||
/** | ||
* The deployment service provides access to values loaded from the deployment json file | ||
* It is an alternative to injecting directly via `@Inject(DEPLOYMENT_CONFIG)` | ||
*/ | ||
@Injectable({ providedIn: "root" }) | ||
export class DeploymentService extends SyncServiceBase { | ||
constructor(@Inject(DEPLOYMENT_CONFIG) public readonly config: IDeploymentRuntimeConfig) { | ||
super("Deployment 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
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
Oops, something went wrong.