diff --git a/web/src/app/app-routing.module.ts b/web/src/app/app-routing.module.ts index 7bca924..fdc73e1 100644 --- a/web/src/app/app-routing.module.ts +++ b/web/src/app/app-routing.module.ts @@ -3,9 +3,11 @@ import { Routes, RouterModule } from '@angular/router'; import {RootTeamPageComponent} from './static-pages/root-team-page/root-team-page.component'; import {GithubOrganisationStats} from './_models/github-organisation-stats'; import {GithubOrganisationPageComponent} from './github/github-organisation-page/github-organisation-page.component'; +import {ApplyTokenComponent} from './apply-token/apply-token.component'; const routes: Routes = [ + {path: 'applyToken', component: ApplyTokenComponent}, {path: '', redirectTo: '/union/github.com/org/web-tree', pathMatch: 'full'}, {path: 'root-team', component: RootTeamPageComponent}, {path: 'union/github.com/org/:organisation', component: GithubOrganisationPageComponent}, diff --git a/web/src/app/app.module.ts b/web/src/app/app.module.ts index 3dc3174..ca75d30 100644 --- a/web/src/app/app.module.ts +++ b/web/src/app/app.module.ts @@ -19,11 +19,13 @@ import {ImprintService} from './_services/imprint.service'; import {MatListModule} from '@angular/material/list'; import {MatBadgeModule} from '@angular/material/badge'; import { GithubOrganisationPageComponent } from './github/github-organisation-page/github-organisation-page.component'; +import {ApplyTokenComponent} from './apply-token/apply-token.component'; import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; @NgModule({ declarations: [ AppComponent, + ApplyTokenComponent, ProfileLogoComponent, RootTeamPageComponent, UserListComponent, diff --git a/web/src/app/apply-token/apply-token.component.html b/web/src/app/apply-token/apply-token.component.html new file mode 100644 index 0000000..e69de29 diff --git a/web/src/app/apply-token/apply-token.component.scss b/web/src/app/apply-token/apply-token.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/web/src/app/apply-token/apply-token.component.spec.ts b/web/src/app/apply-token/apply-token.component.spec.ts new file mode 100644 index 0000000..50c4b79 --- /dev/null +++ b/web/src/app/apply-token/apply-token.component.spec.ts @@ -0,0 +1,37 @@ +import {async, ComponentFixture, TestBed} from '@angular/core/testing'; + +import {ApplyTokenComponent} from './apply-token.component'; +import {ActivatedRoute, Router} from '@angular/router'; +import {TokenService} from '../_services/token.service'; + +describe('ApplyTokenComponent', () => { + let component: ApplyTokenComponent; + let fixture: ComponentFixture; + let activatedRoute: ActivatedRoute; + let router: Router; + + beforeEach(async(() => { + activatedRoute = jasmine.createSpyObj('ActivatedRoute', ['']); + router = jasmine.createSpyObj('Router', ['']); + activatedRoute.fragment = jasmine.createSpyObj('Subscribe', ['subscribe']); + TestBed.configureTestingModule({ + declarations: [ApplyTokenComponent], + providers: [ + TokenService, + {provide: ActivatedRoute, useValue: activatedRoute}, + {provide: Router, useValue: router}, + ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ApplyTokenComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/web/src/app/apply-token/apply-token.component.ts b/web/src/app/apply-token/apply-token.component.ts new file mode 100644 index 0000000..794d376 --- /dev/null +++ b/web/src/app/apply-token/apply-token.component.ts @@ -0,0 +1,28 @@ +import {Component, OnInit} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {HttpParams} from '@angular/common/http'; +import {TokenService} from '../_services/token.service'; + +@Component({ + selector: 'imprint-app-apply-token', + templateUrl: './apply-token.component.html', + styleUrls: ['./apply-token.component.scss'] +}) +export class ApplyTokenComponent implements OnInit { + + constructor( + private route: ActivatedRoute, + private router: Router, + private tokenService: TokenService + ) { + } + + ngOnInit() { + this.route.fragment.subscribe((fragment: string) => { + const params = new HttpParams({fromString: fragment}); + this.tokenService.saveToken(params.get('token')); + this.router.navigate(['/']).then(() => window.location.reload()); + }); + } + +}