From d6a4dcae77cc4b486d326625052ce2a1c7750306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Fri, 19 Mar 2021 22:05:40 +0200 Subject: [PATCH] Extract routing to module --- apps/red-ui/src/app/app-routing.module.ts | 212 ++++++++++++++++++++++ apps/red-ui/src/app/app.module.ts | 190 +------------------ 2 files changed, 215 insertions(+), 187 deletions(-) create mode 100644 apps/red-ui/src/app/app-routing.module.ts diff --git a/apps/red-ui/src/app/app-routing.module.ts b/apps/red-ui/src/app/app-routing.module.ts new file mode 100644 index 000000000..bf29d8918 --- /dev/null +++ b/apps/red-ui/src/app/app-routing.module.ts @@ -0,0 +1,212 @@ +import { AuthErrorComponent } from './screens/auth-error/auth-error.component'; +import { AuthGuard } from './auth/auth.guard'; +import { PdfViewerScreenComponent } from './screens/pdf-viewer-screen/pdf-viewer-screen.component'; +import { CompositeRouteGuard } from './utils/composite-route.guard'; +import { RedRoleGuard } from './auth/red-role.guard'; +import { HtmlDebugScreenComponent } from './screens/html-debug-screen/html-debug-screen.component'; +import { BaseScreenComponent } from './screens/base-screen/base-screen.component'; +import { ProjectListingScreenComponent } from './screens/project-listing-screen/project-listing-screen.component'; +import { AppStateGuard } from './state/app-state.guard'; +import { ProjectOverviewScreenComponent } from './screens/project-overview-screen/project-overview-screen.component'; +import { FilePreviewScreenComponent } from './screens/file/file-preview-screen/file-preview-screen.component'; +import { DownloadsListScreenComponent } from './screens/downloads-list-screen/downloads-list-screen.component'; +import { RuleSetsListingScreenComponent } from './screens/admin/rule-sets-listing-screen/rule-sets-listing-screen.component'; +import { DictionaryListingScreenComponent } from './screens/admin/dictionary-listing-screen/dictionary-listing-screen.component'; +import { DictionaryOverviewScreenComponent } from './screens/admin/dictionary-overview-screen/dictionary-overview-screen.component'; +import { PendingChangesGuard } from './utils/can-deactivate.guard'; +import { RulesScreenComponent } from './screens/admin/rules-screen/rules-screen.component'; +import { FileAttributesListingScreenComponent } from './screens/admin/file-attributes-listing-screen/file-attributes-listing-screen.component'; +import { WatermarkScreenComponent } from './screens/admin/watermark-screen/watermark-screen.component'; +import { DefaultColorsScreenComponent } from './screens/admin/default-colors-screen/default-colors-screen.component'; +import { UserListingScreenComponent } from './screens/admin/user-listing-screen/user-listing-screen.component'; +import { LicenseInformationScreenComponent } from './screens/admin/license-information-screen/license-information-screen.component'; +import { DigitalSignatureScreenComponent } from './screens/admin/digital-signature-screen/digital-signature-screen.component'; +import { AuditScreenComponent } from './screens/admin/audit-screen/audit-screen.component'; +import { RouterModule } from '@angular/router'; +import { NgModule } from '@angular/core'; + +const routes = [ + { + path: '', + redirectTo: 'ui/projects', + pathMatch: 'full' + }, + { + path: 'auth-error', + component: AuthErrorComponent, + canActivate: [AuthGuard] + }, + { + path: 'pdf-preview/:projectId/:fileId', + component: PdfViewerScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard] + } + }, + { + path: 'html-debug/:projectId/:fileId', + component: HtmlDebugScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard] + } + }, + + { + path: 'ui', + component: BaseScreenComponent, + children: [ + { + path: 'projects', + component: ProjectListingScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'projects/:projectId', + component: ProjectOverviewScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'projects/:projectId/file/:fileId', + component: FilePreviewScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'downloads', + component: DownloadsListScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'admin', + children: [ + { path: '', redirectTo: 'project-templates', pathMatch: 'full' }, + { + path: 'project-templates', + children: [ + { + path: '', + component: RuleSetsListingScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: ':ruleSetId', + children: [ + { + path: 'dictionaries', + children: [ + { + path: '', + component: DictionaryListingScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: ':type', + component: DictionaryOverviewScreenComponent, + canActivate: [CompositeRouteGuard], + canDeactivate: [PendingChangesGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + } + ] + }, + { + path: 'rules', + component: RulesScreenComponent, + canActivate: [CompositeRouteGuard], + canDeactivate: [PendingChangesGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'file-attributes', + component: FileAttributesListingScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'watermark', + component: WatermarkScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'default-colors', + component: DefaultColorsScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { path: '', redirectTo: 'dictionaries', pathMatch: 'full' } + ] + } + ] + }, + { + path: 'users', + component: UserListingScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'license-info', + component: LicenseInformationScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'digital-signature', + component: DigitalSignatureScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + }, + { + path: 'audit', + component: AuditScreenComponent, + canActivate: [CompositeRouteGuard], + data: { + routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] + } + } + ] + } + ] + } +]; + +@NgModule({ + imports: [RouterModule.forRoot(routes)], + exports: [RouterModule] +}) +export class AppRoutingModule {} diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index d73af6f1f..944c3e907 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -1,7 +1,7 @@ import { BrowserModule } from '@angular/platform-browser'; import { APP_INITIALIZER, NgModule } from '@angular/core'; import { AppComponent } from './app.component'; -import { ActivatedRoute, Router, RouterModule } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from '@angular/common/http'; @@ -43,15 +43,11 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { InitialsAvatarComponent } from './common/initials-avatar/initials-avatar.component'; import { StatusBarComponent } from './components/status-bar/status-bar.component'; import { LogoComponent } from './logo/logo.component'; -import { CompositeRouteGuard } from './utils/composite-route.guard'; -import { AppStateGuard } from './state/app-state.guard'; import { SimpleDoughnutChartComponent } from './components/simple-doughnut-chart/simple-doughnut-chart.component'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatSlideToggleModule } from '@angular/material/slide-toggle'; import { AnnotationIconComponent } from './components/annotation-icon/annotation-icon.component'; -import { AuthGuard } from './auth/auth.guard'; import { AuthErrorComponent } from './screens/auth-error/auth-error.component'; -import { RedRoleGuard } from './auth/red-role.guard'; import { MatListModule } from '@angular/material/list'; import { AssignOwnerDialogComponent } from './dialogs/assign-owner-dialog/assign-owner-dialog.component'; import { MatDatepickerModule } from '@angular/material/datepicker'; @@ -101,7 +97,6 @@ import { AddEditRuleSetDialogComponent } from './screens/admin/rule-sets-listing import { RuleSetActionsComponent } from './components/rule-set-actions/rule-set-actions.component'; import { TabsComponent } from './components/rule-set-view-switch/tabs.component'; import { MatSliderModule } from '@angular/material/slider'; -import { PendingChangesGuard } from './utils/can-deactivate.guard'; import { OverwriteFilesDialogComponent } from './dialogs/overwrite-files-dialog/overwrite-files-dialog.component'; import { KeycloakService } from 'keycloak-angular'; import { FileDownloadBtnComponent } from './components/buttons/file-download-btn/file-download-btn.component'; @@ -120,191 +115,12 @@ import { AuditScreenComponent } from './screens/admin/audit-screen/audit-screen. import { PaginationComponent } from './components/pagination/pagination.component'; import { FileAttributesListingScreenComponent } from './screens/admin/file-attributes-listing-screen/file-attributes-listing-screen.component'; import { SearchInputComponent } from './components/search-input/search-input.component'; +import { AppRoutingModule } from './app-routing.module'; export function HttpLoaderFactory(httpClient: HttpClient) { return new TranslateHttpLoader(httpClient, '/assets/i18n/', '.json'); } -const routes = [ - { - path: '', - redirectTo: 'ui/projects', - pathMatch: 'full' - }, - { - path: 'auth-error', - component: AuthErrorComponent, - canActivate: [AuthGuard] - }, - { - path: 'pdf-preview/:projectId/:fileId', - component: PdfViewerScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard] - } - }, - { - path: 'html-debug/:projectId/:fileId', - component: HtmlDebugScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard] - } - }, - - { - path: 'ui', - component: BaseScreenComponent, - children: [ - { - path: 'projects', - component: ProjectListingScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'projects/:projectId', - component: ProjectOverviewScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'projects/:projectId/file/:fileId', - component: FilePreviewScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'downloads', - component: DownloadsListScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'admin', - children: [ - { path: '', redirectTo: 'project-templates', pathMatch: 'full' }, - { - path: 'project-templates', - children: [ - { - path: '', - component: RuleSetsListingScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: ':ruleSetId', - children: [ - { - path: 'dictionaries', - children: [ - { - path: '', - component: DictionaryListingScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: ':type', - component: DictionaryOverviewScreenComponent, - canActivate: [CompositeRouteGuard], - canDeactivate: [PendingChangesGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - } - ] - }, - { - path: 'rules', - component: RulesScreenComponent, - canActivate: [CompositeRouteGuard], - canDeactivate: [PendingChangesGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'file-attributes', - component: FileAttributesListingScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'watermark', - component: WatermarkScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'default-colors', - component: DefaultColorsScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { path: '', redirectTo: 'dictionaries', pathMatch: 'full' } - ] - } - ] - }, - { - path: 'users', - component: UserListingScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'license-info', - component: LicenseInformationScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'digital-signature', - component: DigitalSignatureScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - }, - { - path: 'audit', - component: AuditScreenComponent, - canActivate: [CompositeRouteGuard], - data: { - routeGuards: [AuthGuard, RedRoleGuard, AppStateGuard] - } - } - ] - } - ] - } -]; - const matImports = [ MatDialogModule, MatNativeDateModule, @@ -421,7 +237,7 @@ const matImports = [ deps: [HttpClient] } }), - RouterModule.forRoot(routes), + AppRoutingModule, NgpSortModule, ...matImports, ToastrModule.forRoot({