-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(demo): improved app initialization to have all config during demo…
… generation (#1890) * moved app initialisation steps to APP_INITIALIZER * fix: demo config is generated before other demo entities
- Loading branch information
1 parent
cb7aea3
commit 7e58e13
Showing
13 changed files
with
126 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
APP_INITIALIZER, | ||
Injector, | ||
ɵcreateInjector as createInjector, | ||
} from "@angular/core"; | ||
import { ConfigService } from "./core/config/config.service"; | ||
import { RouterService } from "./core/view/dynamic-routing/router.service"; | ||
import { EntityConfigService } from "./core/entity/entity-config.service"; | ||
import { Router } from "@angular/router"; | ||
import { SessionService } from "./core/session/session-service/session.service"; | ||
import { AnalyticsService } from "./core/analytics/analytics.service"; | ||
import { LoginState } from "./core/session/session-states/login-state.enum"; | ||
import { LoggingService } from "./core/logging/logging.service"; | ||
import { environment } from "../environments/environment"; | ||
|
||
export const appInitializers = { | ||
provide: APP_INITIALIZER, | ||
useFactory: | ||
( | ||
injector: Injector, | ||
configService: ConfigService, | ||
routerService: RouterService, | ||
entityConfigService: EntityConfigService, | ||
router: Router, | ||
sessionService: SessionService, | ||
analyticsService: AnalyticsService | ||
) => | ||
async () => { | ||
// Re-trigger services that depend on the config when something changes | ||
configService.configUpdates.subscribe(() => { | ||
routerService.initRouting(); | ||
entityConfigService.setupEntitiesFromConfig(); | ||
const url = location.href.replace(location.origin, ""); | ||
router.navigateByUrl(url, { skipLocationChange: true }); | ||
}); | ||
|
||
// update the user context for remote error logging and tracking and load config initially | ||
sessionService.loginState.subscribe((newState) => { | ||
if (newState === LoginState.LOGGED_IN) { | ||
const username = sessionService.getCurrentUser().name; | ||
LoggingService.setLoggingContextUser(username); | ||
analyticsService.setUser(username); | ||
} else { | ||
LoggingService.setLoggingContextUser(undefined); | ||
analyticsService.setUser(undefined); | ||
} | ||
}); | ||
|
||
if (environment.production) { | ||
analyticsService.init(); | ||
} | ||
if (environment.demo_mode) { | ||
const m = await import("./core/demo-data/demo-data.module"); | ||
await createInjector(m.DemoDataModule, injector) | ||
.get(m.DemoDataModule) | ||
.publishDemoData(); | ||
} | ||
}, | ||
deps: [ | ||
Injector, | ||
ConfigService, | ||
RouterService, | ||
EntityConfigService, | ||
Router, | ||
SessionService, | ||
AnalyticsService, | ||
], | ||
multi: true, | ||
}; |
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
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
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.