welcome screen

This commit is contained in:
2020-04-26 16:38:06 +02:00
committed by smuddy
parent 3b6bebcbac
commit 5d47c0c611
29 changed files with 538 additions and 16 deletions

View File

@@ -1,12 +1,12 @@
<nav [class.hidden]="(windowScroll$|async)>60" class="head">
<div class="links">
<app-brand></app-brand>
<app-brand routerLink="/brand"></app-brand>
<app-link *appRole="['user','presenter', 'leader']" [icon]="faSongs" link="/songs" text="Lieder"></app-link>
<app-link *appRole="['leader']" [icon]="faShows" link="/shows" text="Veranstaltungen"></app-link>
<app-link *appRole="['presenter']" [icon]="faPresentation" link="/presentation" text="Präsentation"></app-link>
<app-link [icon]="faUser" link="/user" text="Benutzer"></app-link>
</div>
<div class="actions">
<div *appRole="['user','presenter', 'leader']" class="actions">
<app-filter></app-filter>
</div>
</nav>

View File

@@ -37,4 +37,5 @@ nav {
.links {
display: flex;
height: 50px;
}

View File

@@ -1,6 +1,6 @@
<button mat-button>
<span *ngIf="icon"><fa-icon [icon]="icon"></fa-icon><span class="content">&nbsp;</span></span>
<span class="content">
<span class="button-content">
<ng-content></ng-content>
</span>
</button>

View File

@@ -5,7 +5,7 @@ button {
}
}
.content {
.button-content {
@media screen and (max-width: 860px) {
display: none ;
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -0,0 +1,5 @@
svg {
width: 512px;
height: 512px;
margin: 40px;
}

View File

@@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {LogoComponent} from './logo.component';
describe('LogoComponent', () => {
let component: LogoComponent;
let fixture: ComponentFixture<LogoComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [LogoComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LogoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,16 @@
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-logo',
templateUrl: './logo.component.html',
styleUrls: ['./logo.component.less']
})
export class LogoComponent implements OnInit {
constructor() {
}
ngOnInit(): void {
}
}

View File

@@ -0,0 +1,16 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {LogoComponent} from './logo.component';
@NgModule({
declarations: [LogoComponent],
exports: [
LogoComponent
],
imports: [
CommonModule
]
})
export class LogoModule {
}

View File

@@ -0,0 +1,16 @@
import {TestBed} from '@angular/core/testing';
import {RoleGuard} from './role.guard';
describe('RoleGuard', () => {
let guard: RoleGuard;
beforeEach(() => {
TestBed.configureTestingModule({});
guard = TestBed.inject(RoleGuard);
});
it('should be created', () => {
expect(guard).toBeTruthy();
});
});

View File

@@ -0,0 +1,45 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from '@angular/router';
import {Observable} from 'rxjs';
import {UserService} from '../../services/user/user.service';
import {map} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class RoleGuard implements CanActivate {
constructor(private userService: UserService, private router: Router) {
}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> {
const requiredRoles = next.data.requiredRoles;
if (!requiredRoles) throw new Error('requiredRoles is not defined!');
return this.userService.user$.pipe(
map(user => {
const roles = user.role?.split(';') ?? [];
if (roles.indexOf('admin') !== -1) return true;
const allowed = roles.some(s => requiredRoles.indexOf(s) !== -1);
return allowed || this.router.createUrlTree(this.defaultRoute(roles));
})
)
}
private defaultRoute(roles: string[]): string[] {
if (!roles || roles.length === 0) return ['brand', 'new-user'];
switch (roles[0]) {
case 'user':
return ['songs'];
case 'presenter':
return ['presentation'];
case 'leader':
return ['shows'];
}
return ['brand', 'new-user'];
}
}