Commit 6346a078 authored by Rasko Leinonen's avatar Rasko Leinonen
Browse files

Added redirect URL to the update request page: ena/submit/webin?page=update-request.

parent 6f0ad18c
......@@ -74,7 +74,7 @@ const appRoutes: Routes = [
// Router
RouterModule.forRoot(
appRoutes,
{ enableTracing: true } // <-- debugging purposes only
{ enableTracing: false } // <-- debugging purposes only
),
],
declarations: [
......
......@@ -35,6 +35,10 @@
<app-report #unsubmittedFiles [reportType]="ReportType.unsubmittedFiles" (reportChange)="consumeReportChange($event)"></app-report>
</mat-tab>
<mat-tab label="Update request">
<app-update-request></app-update-request>
</mat-tab>
</ng-container>
<ng-container *ngIf="isEga()">
......
......@@ -13,8 +13,12 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UiModule } from '../ui/ui.module';
import { WebinAuthenticationService } from '../webin-authentication.service';
import { MockWebinAuthenticationService } from '../mock/mock-webin-authentication.service';
import { UpdateRequestComponent } from '../update-request/update-request.component';
import { MockReportComponent } from '../mock/mock-report.component';
import { MockSubmitComponent } from '../mock/mock-submit.component';
import { WebinRestService } from '../webin-rest.service';
import { MockWebinRestService } from '../mock/mock-webin-rest.service';
import { RouterTestingModule } from '@angular/router/testing';
import { DashboardComponent } from './dashboard.component';
......@@ -26,17 +30,20 @@ describe('DashboardComponent', () => {
TestBed.configureTestingModule({
declarations: [
DashboardComponent,
UpdateRequestComponent,
MockReportComponent,
MockSubmitComponent,
],
imports: [
UiModule,
],
imports: [ UiModule, RouterTestingModule ],
providers: [
{
provide: WebinAuthenticationService,
useClass: MockWebinAuthenticationService
},
{
provide: WebinRestService,
useClass: MockWebinRestService
},
]
})
.compileComponents();
......
......@@ -11,6 +11,7 @@
import { Component, ViewEncapsulation, ViewChild } from '@angular/core';
import { MatTabGroup } from '@angular/material/tabs';
import { Router, ActivatedRoute} from '@angular/router';
import { ReportComponent } from '../report/report.component';
import { WebinAuthenticationService } from '../webin-authentication.service';
import { ReportType } from '../report-type.enum';
......@@ -44,8 +45,27 @@ export class DashboardComponent {
@ViewChild('datasets') datasets: ReportComponent;
constructor(
private _router: Router,
private _route: ActivatedRoute,
private _webinAuthenticationService: WebinAuthenticationService) { }
private _sub;
ngOnInit() {
this._sub = this._route
.queryParams
.subscribe(params => {
if(params.page === 'update-request' && !this.isEga()) {
this.tabGroup.selectedIndex = 10;
this._router.navigateByUrl(''); // Remove query parameters.
}
});
}
ngOnDestroy() {
this._sub.unsubscribe();
}
isEga(): boolean {
return this._webinAuthenticationService.ega;
}
......
......@@ -5,7 +5,7 @@
<div class="masthead-inner row expanded">
<!-- local-title -->
<div class="float-left inline-block padding-left-large" id="local-title">
<h4 style="color:white">{{getTitle()}}</h4> <!-- ** Application specific content ** -->
<a routerLink=""><h4 style="color:white">{{getTitle()}}</h4></a> <!-- ** Application specific content ** -->
</div>
<!-- /local-title -->
<!-- local-nav -->
......
......@@ -33,7 +33,7 @@ export class LoginComponent implements OnInit {
private _webinAuthenticationService: WebinAuthenticationService) { }
ngOnInit() {
console.log('** LoginComponent.ngOnInit **');
// console.log('LoginComponent.ngOnInit');
if (this._webinAuthenticationService.authenticated) {
this._router.navigateByUrl('');
}
......@@ -45,7 +45,7 @@ export class LoginComponent implements OnInit {
this._webinAuthenticationService.login(this.username, this.password).
pipe(
mergeMap(data => {
console.log('WebinAuthenticationService.login succeeded');
// console.log('WebinAuthenticationService.login succeeded');
this._webinAuthenticationService.ega = data.roles.EGA;
this._webinAuthenticationService.account = data.principle;
return this._webinAuthenticationService.loginToken(this.username, this.password);
......@@ -53,9 +53,16 @@ export class LoginComponent implements OnInit {
).
subscribe(
data => {
console.log('WebinAuthenticationService.loginToken succeeded');
// console.log('WebinAuthenticationService.loginToken succeeded');
this._webinAuthenticationService.token = data;
this._router.navigateByUrl('');
const redirectUrl = this._webinAuthenticationService.redirectUrl;
if (redirectUrl) {
this._router.navigateByUrl(redirectUrl);
this._webinAuthenticationService.redirectUrl = null;
}
else {
this._router.navigateByUrl('');
}
},
// Errors.
(err: HttpErrorResponse) => {
......
......@@ -16,7 +16,7 @@
<span class = "app-primary-color">
<i class="material-icons">info</i>
</span>
This page is used for making new submissions. To access reports please select one of the other pages above.
This page is used for making new submissions. To access other functionality please select one of the other pages above.
</p>
</div>
......@@ -71,19 +71,6 @@
<button mat-raised-button color="accent" [disabled]="!canSubmit()" (click)="submit()">Submit</button>
</mat-expansion-panel>
<mat-expansion-panel *ngIf="!isEga()">
<mat-expansion-panel-header>
<mat-panel-title>
<b>Request an update</b>
</mat-panel-title>
</mat-expansion-panel-header>
<app-update-request></app-update-request>
</mat-expansion-panel>
<mat-expansion-panel *ngIf="!isEga()">
<mat-expansion-panel-header>
<mat-panel-title>
......
......@@ -15,6 +15,9 @@
<div fxLayout="row">
<div fxFlex="100%">
<p>
<span class = "app-primary-color">
<i class="material-icons">info</i>
</span>
Use this page to request changes to records that can't be updated by any other means.
</p>
<p>
......
......@@ -19,21 +19,27 @@ export class WebinAuthenticationGuardService implements CanActivate {
constructor(private webinAuthenticationService: WebinAuthenticationService, private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
console.log('** WebinAuthenticationGuardService.canActivate **');
// console.log('WebinAuthenticationGuardService.canActivate');
if (this.webinAuthenticationService.authenticated) {
if (new Date() >=
this.webinAuthenticationService.logoutDate) {
console.log('** WebinAuthenticationGuardService: authentication timeout **');
// console.log('WebinAuthenticationGuardService: authentication timeout');
this.webinAuthenticationService.logout();
this.router.navigate(['login']);
return false;
} else {
console.log('** WebinAuthenticationGuardService: authenticated **');
// console.log('WebinAuthenticationGuardService: authenticated');
return true;
}
}
console.log('** WebinAuthenticationGuardService: not authenticated **');
// console.log('WebinAuthenticationGuardService: not authenticated');
const url = state.url;
if (url.startsWith("/?page=")) {
// console.log('WebinAuthenticationGuardService: set redirectUrl', url);
this.webinAuthenticationService.redirectUrl = url;
}
this.router.navigate(['login']);
return false;
}
......
......@@ -24,7 +24,7 @@ export class WebinAuthenticationInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!req.url.startsWith(environment.webinAuthenticationServiceUrl)) {
console.log('** Webin authentication interceptor **');
// console.log('Webin authentication interceptor');
const webinAuthenticationService = this.injector.get(WebinAuthenticationService);
/* if (req.url.startsWith(environment.webinReportServiceUrl)) {
......
......@@ -21,6 +21,8 @@ import { WebinAuthenticationResultInterface } from './webin-authentication-resul
@Injectable()
export class WebinAuthenticationService implements WebinAuthenticationServiceInterface {
redirectUrl: string;
get username(): string {
return sessionStorage.getItem('username');
}
......@@ -88,7 +90,7 @@ export class WebinAuthenticationService implements WebinAuthenticationServiceInt
}
logout() {
console.log('** logout **');
// console.log('logout');
sessionStorage.removeItem('username');
sessionStorage.removeItem('token');
......@@ -101,7 +103,7 @@ export class WebinAuthenticationService implements WebinAuthenticationServiceInt
login(username: string, password: string): Observable<WebinAuthenticationResultInterface> {
const baseUrl: string = environment.webinAuthenticationServiceUrl;
console.log('** Webin authentication login **', baseUrl);
// console.log('Webin authentication login', baseUrl);
this.username = username;
const today = new Date();
......@@ -118,7 +120,7 @@ export class WebinAuthenticationService implements WebinAuthenticationServiceInt
loginToken(username: string, password: string): Observable<string> {
const baseUrl: string = environment.webinAuthenticationTokenUrl;
console.log('** Webin authentication token **', baseUrl);
// console.log('Webin authentication token', baseUrl);
this.username = username;
const today = new Date();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment