From d7318eb5ae6dbaf2cb5bab2e58ccb2a766f0f4be Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Fri, 10 Sep 2021 12:40:42 +0200 Subject: [PATCH] feat(settings): Added feature toggling. (TV-564) Squashed commit of the following: commit b67cced3bd44d1673173e5fa188d776d2d097fd4 Author: Erik Tiekstra Date: Fri Sep 10 11:59:37 2021 +0200 Added feature toggling for routes and navigation --- .../src/app/app-routing.module.ts | 95 +++++++++++-------- .../navigation/navigation.component.html | 4 +- .../navigation/navigation.component.ts | 10 ++ .../components/sidebar/sidebar.component.html | 6 +- .../components/sidebar/sidebar.component.ts | 24 +++-- .../src/app/shared/enums/feature.enum.ts | 9 ++ .../src/app/shared/models/ciam.model.ts | 5 + .../app/shared/models/environment.model.ts | 3 + .../src/environments/active-features.ts | 12 +++ apps/mina-sidor-fa/src/environments/ciam.ts | 19 ++++ .../src/environments/environment.acc.ts | 7 +- .../src/environments/environment.api.ts | 7 +- .../src/environments/environment.prod.ts | 7 +- .../src/environments/environment.ts | 8 +- 14 files changed, 154 insertions(+), 62 deletions(-) create mode 100644 apps/mina-sidor-fa/src/app/shared/enums/feature.enum.ts create mode 100644 apps/mina-sidor-fa/src/app/shared/models/ciam.model.ts create mode 100644 apps/mina-sidor-fa/src/environments/active-features.ts create mode 100644 apps/mina-sidor-fa/src/environments/ciam.ts diff --git a/apps/mina-sidor-fa/src/app/app-routing.module.ts b/apps/mina-sidor-fa/src/app/app-routing.module.ts index 5a54fc0..1b20e68 100644 --- a/apps/mina-sidor-fa/src/app/app-routing.module.ts +++ b/apps/mina-sidor-fa/src/app/app-routing.module.ts @@ -1,11 +1,14 @@ import { NgModule } from '@angular/core'; import { ExtraOptions, RouterModule, Routes } from '@angular/router'; +import { Feature } from '@msfa-enums/feature.enum'; import { RoleEnum } from '@msfa-enums/role.enum'; import { environment } from '@msfa-environment'; import { AuthGuard } from '@msfa-guards/auth.guard'; import { OrganizationGuard } from '@msfa-guards/organization.guard'; import { RoleGuard } from '@msfa-guards/role.guard'; +const activeFeatures: Feature[] = environment.activeFeatures; + const routes: Routes = [ { path: '', @@ -13,24 +16,6 @@ const routes: Routes = [ loadChildren: () => import('./pages/start/start.module').then(m => m.StartModule), canActivate: [AuthGuard, OrganizationGuard], }, - { - path: 'administration', - data: { title: 'Administration', expectedRole: RoleEnum.MSFA_AuthAdmin }, - loadChildren: () => import('./pages/administration/administration.module').then(m => m.AdministrationModule), - canActivate: [AuthGuard, OrganizationGuard, RoleGuard], - }, - { - path: 'deltagare', - data: { title: 'Deltagare', expectedRole: RoleEnum.MSFA_ReportAndPlanning }, - loadChildren: () => import('./pages/deltagare/deltagare.module').then(m => m.DeltagareModule), - canActivate: [AuthGuard, OrganizationGuard, RoleGuard], - }, - { - path: 'nya-deltagare', - data: { title: 'Nya deltagare', expectedRole: RoleEnum.MSFA_ReceiveDeltagare }, - loadChildren: () => import('./pages/avrop/avrop.module').then(m => m.AvropModule), - canActivate: [AuthGuard, OrganizationGuard, RoleGuard], - }, { path: 'logga-ut', data: { title: 'Logga ut' }, @@ -44,12 +29,6 @@ const routes: Routes = [ import('./pages/organization-picker/organization-picker.module').then(m => m.OrganizationPickerModule), canActivate: [AuthGuard], }, - { - path: 'mitt-konto', - data: { title: 'Mitt konto' }, - loadChildren: () => import('./pages/my-account/my-account.module').then(m => m.MyAccountModule), - canActivate: [AuthGuard, OrganizationGuard], - }, { path: 'obehorig', data: { title: 'Saknar behörighet' }, @@ -58,21 +37,59 @@ const routes: Routes = [ }, ]; -if (!environment.production) { - routes.push( - { - path: 'mock-login', - data: { title: 'Mock login' }, - loadChildren: () => import('./pages/mock-login/mock-login.module').then(m => m.MockLoginModule), - }, - { - path: 'releases', - data: { title: 'Releaser' }, - loadChildren: () => import('./pages/releases/releases.module').then(m => m.ReleasesModule), - canActivate: [AuthGuard], - } - ); -} +activeFeatures.forEach(feature => { + switch (feature) { + case Feature.ADMINISTRATION: + routes.push({ + path: 'administration', + data: { title: 'Administration', expectedRole: RoleEnum.MSFA_AuthAdmin }, + loadChildren: () => import('./pages/administration/administration.module').then(m => m.AdministrationModule), + canActivate: [AuthGuard, OrganizationGuard, RoleGuard], + }); + break; + case Feature.AVROP: + routes.push({ + path: 'nya-deltagare', + data: { title: 'Nya deltagare', expectedRole: RoleEnum.MSFA_ReceiveDeltagare }, + loadChildren: () => import('./pages/avrop/avrop.module').then(m => m.AvropModule), + canActivate: [AuthGuard, OrganizationGuard, RoleGuard], + }); + break; + case Feature.DELTAGARE: + routes.push({ + path: 'deltagare', + data: { title: 'Deltagare', expectedRole: RoleEnum.MSFA_ReportAndPlanning }, + loadChildren: () => import('./pages/deltagare/deltagare.module').then(m => m.DeltagareModule), + canActivate: [AuthGuard, OrganizationGuard, RoleGuard], + }); + break; + case Feature.MY_ACCOUNT: + routes.push({ + path: 'mitt-konto', + data: { title: 'Mitt konto' }, + loadChildren: () => import('./pages/my-account/my-account.module').then(m => m.MyAccountModule), + canActivate: [AuthGuard, OrganizationGuard], + }); + break; + case Feature.RELEASES: + routes.push({ + path: 'releases', + data: { title: 'Releaser' }, + loadChildren: () => import('./pages/releases/releases.module').then(m => m.ReleasesModule), + canActivate: [AuthGuard], + }); + break; + case Feature.MOCK_LOGIN: + routes.push({ + path: 'mock-login', + data: { title: 'Mock login' }, + loadChildren: () => import('./pages/mock-login/mock-login.module').then(m => m.MockLoginModule), + }); + break; + default: + break; + } +}); routes.push({ path: '**', diff --git a/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.html b/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.html index 30f85fb..3c5fef6 100644 --- a/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.html +++ b/apps/mina-sidor-fa/src/app/shared/components/layout/components/navigation/navigation.component.html @@ -5,13 +5,13 @@