Skip to content

Commit 21693be

Browse files
fix[frontend](federation_service): added instance selector and actions
1 parent d00923d commit 21693be

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

frontend/src/app/core/auth/user-route-access-service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import {Injectable, isDevMode} from '@angular/core';
22
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
33
import {ModalService} from '../modal/modal.service';
44

5+
import {FederationInstanceStateService} from '../../federation/services/federation-instance-state.service';
6+
import {FederationModeService} from '../../federation/services/federation-mode.service';
57
import {AccountService} from './account.service';
68
import {StateStorageService} from './state-storage.service';
79

10+
const FEDERATION_WELCOME_URL = '/federation/welcome';
11+
812
@Injectable({providedIn: 'root'})
913
export class UserRouteAccessService implements CanActivate {
1014
constructor(
1115
private router: Router,
1216
private accountService: AccountService,
13-
private stateStorageService: StateStorageService
17+
private stateStorageService: StateStorageService,
18+
private federationModeService: FederationModeService,
19+
private federationInstanceState: FederationInstanceStateService
1420
) {
1521
}
1622

@@ -28,6 +34,14 @@ export class UserRouteAccessService implements CanActivate {
2834
return false;
2935
}
3036
if (account) {
37+
if (
38+
this.federationModeService.isActive &&
39+
this.federationInstanceState.instances.length === 0 &&
40+
!url.startsWith(FEDERATION_WELCOME_URL)
41+
) {
42+
this.router.navigate([FEDERATION_WELCOME_URL]);
43+
return false;
44+
}
3145
const hasAnyAuthority = this.accountService.hasAnyAuthority(authorities);
3246
if (hasAnyAuthority) {
3347
return true;

frontend/src/app/federation/components/instance-switcher/instance-switcher.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ <h6 class="dropdown-header text-uppercase">Instances</h6>
2727
class="federation-instance-row dropdown-item d-flex align-items-center justify-content-between"
2828
[class.active]="active && instance.id === active.id">
2929
<button type="button"
30+
[class.textActive]="active && instance.id === active.id"
3031
class="btn btn-link p-0 flex-grow-1 text-left text-truncate federation-instance-name-btn"
3132
(click)="select(instance, $event)">
3233
<i *ngIf="active && instance.id === active.id" class="icon-check mr-1"></i>

frontend/src/app/federation/components/instance-switcher/instance-switcher.component.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
&.active {
2424
background-color: rgba(35, 47, 62, 0.08);
25-
color: inherit;
25+
color: white !important;
2626
}
2727
}
2828

@@ -55,3 +55,6 @@
5555
cursor: pointer;
5656
}
5757
}
58+
.textActive{
59+
color: white !important;
60+
}

frontend/src/app/federation/federation-routing.module.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import {NgModule} from '@angular/core';
22
import {RouterModule, Routes} from '@angular/router';
3+
import {UserRouteAccessService} from '../core/auth/user-route-access-service';
34
import {WelcomeComponent} from './pages/welcome/welcome.component';
45

56
const routes: Routes = [
67
{
78
path: 'federation',
89
children: [
910
{path: '', redirectTo: 'welcome', pathMatch: 'full'},
10-
{path: 'welcome', component: WelcomeComponent},
11-
{path: 'instances', component: WelcomeComponent}
11+
{
12+
path: 'welcome',
13+
component: WelcomeComponent,
14+
data: {authorities: ['ROLE_USER']},
15+
canActivate: [UserRouteAccessService]
16+
},
17+
{
18+
path: 'instances',
19+
component: WelcomeComponent,
20+
data: {authorities: ['ROLE_USER']},
21+
canActivate: [UserRouteAccessService]
22+
}
1223
]
1324
}
1425
];

0 commit comments

Comments
 (0)