Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit b71938c7 authored by Sebastian-Ion TINCU's avatar Sebastian-Ion TINCU
Browse files

EDELIVERY-11824 Password change success message should appear in a green alert

Add alert message when changing password.
Fix alert message stickyness.
Fix style error.
parent c4061c5e
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,6 @@ import {HttpClient} from "@angular/common/http"; ...@@ -10,7 +10,6 @@ import {HttpClient} from "@angular/common/http";
import {SidenavComponent} from "./window/sidenav/sidenav.component"; import {SidenavComponent} from "./window/sidenav/sidenav.component";
import {ToolbarComponent} from "./window/toolbar/toolbar.component"; import {ToolbarComponent} from "./window/toolbar/toolbar.component";
import {ThemeService} from "./common/theme-service/theme.service"; import {ThemeService} from "./common/theme-service/theme.service";
import {AlertMessageComponent} from "./common/alert-message/alert-message.component";
import 'codemirror/mode/javascript/javascript'; import 'codemirror/mode/javascript/javascript';
import 'codemirror/mode/markdown/markdown'; import 'codemirror/mode/markdown/markdown';
import 'codemirror/mode/xml/xml'; import 'codemirror/mode/xml/xml';
...@@ -24,8 +23,6 @@ import 'codemirror/mode/properties/properties'; ...@@ -24,8 +23,6 @@ import 'codemirror/mode/properties/properties';
}) })
export class AppComponent { export class AppComponent {
@ViewChild('alertMessage') alertMessage: AlertMessageComponent;
@ViewChild('sidenav') sidenav: SidenavComponent; @ViewChild('sidenav') sidenav: SidenavComponent;
@ViewChild('windowToolbar') windowToolbar: ToolbarComponent; @ViewChild('windowToolbar') windowToolbar: ToolbarComponent;
...@@ -44,10 +41,9 @@ export class AppComponent { ...@@ -44,10 +41,9 @@ export class AppComponent {
private themeService: ThemeService, private themeService: ThemeService,
) { ) {
this.userController = new UserController(this.http, this.lookups, this.dialog); this.userController = new UserController(this.http, this.lookups, this.dialog);
themeService.updateThemeFromLocalStorage(); this.themeService.updateThemeFromLocalStorage();
} }
isCurrentUserSystemAdmin(): boolean { isCurrentUserSystemAdmin(): boolean {
return this.securityService.isCurrentUserInRole([Authority.SYSTEM_ADMIN]); return this.securityService.isCurrentUserInRole([Authority.SYSTEM_ADMIN]);
} }
...@@ -60,7 +56,6 @@ export class AppComponent { ...@@ -60,7 +56,6 @@ export class AppComponent {
return this.securityService.isCurrentUserInRole([Authority.SERVICE_GROUP_ADMIN]); return this.securityService.isCurrentUserInRole([Authority.SERVICE_GROUP_ADMIN]);
} }
get currentUser(): string { get currentUser(): string {
let user = this.securityService.getCurrentUser(); let user = this.securityService.getCurrentUser();
return user ? user.username : ""; return user ? user.username : "";
...@@ -108,7 +103,7 @@ export class AppComponent { ...@@ -108,7 +103,7 @@ export class AppComponent {
onDrawerContentScroll(scrollEvent: any){ onDrawerContentScroll(scrollEvent: any){
let scrollTop = scrollEvent.srcElement.scrollTop; let scrollTop = scrollEvent.srcElement.scrollTop;
this.alertMessage.setSticky(scrollTop > 0) this.alertService.setSticky(scrollTop > 0)
} }
} }
...@@ -12,14 +12,6 @@ ...@@ -12,14 +12,6 @@
z-index: 2000; z-index: 2000;
} }
.stickyError {
position: fixed;
z-index: 1000;
top: 0;
right: 0;
left: 180px;
}
.closebtn { .closebtn {
margin-left: 15px; margin-left: 15px;
color: white; color: white;
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
*ngIf="message" [ngClass]="{ 'alert-message': message, *ngIf="message" [ngClass]="{ 'alert-message': message,
'alert-success': message.type === 'success', 'alert-success': message.type === 'success',
'alert-error': message.type === 'error'}" 'alert-error': message.type === 'error'}"
id="alertmessage_id" id="alertmessage_id">
<span class="closebtn" (click)="clearAlert(true)">&times;</span>
> {{ message.text }}
<span class="closebtn" (click)="clearAlert()">&times;</span>
{{messageText}}
</div> </div>
import {Component, OnInit, ViewChild} from '@angular/core'; import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {AlertMessageService} from './alert-message.service'; import {AlertMessageService} from './alert-message.service';
import {AlertComponent} from "../../alert/alert.component";
import {Subscription} from "rxjs";
@Component({ @Component({
selector: 'alert', selector: 'alert',
...@@ -7,41 +9,35 @@ import {AlertMessageService} from './alert-message.service'; ...@@ -7,41 +9,35 @@ import {AlertMessageService} from './alert-message.service';
styleUrls: ['./alert-message.component.css'] styleUrls: ['./alert-message.component.css']
}) })
export class AlertMessageComponent implements OnInit { export class AlertMessageComponent implements OnInit, OnDestroy {
@ViewChild('alertMessage') alertMessage;
showSticky:boolean = false;
message: any=null;
readonly successTimeout: number = 3000; readonly successTimeout: number = 3000;
message: any;
constructor(private alertService: AlertMessageService) { } private subscription: Subscription;
ngOnInit() { constructor(private alertService: AlertMessageService) {
this.alertService.getMessage().subscribe(message => { this.showMessage(message); });
} }
clearAlert():void { ngOnInit() {
this.alertService.clearAlert(); this.subscription = this.alertService.getMessage().subscribe(message => { this.showMessage(message); });
} }
setSticky(sticky: boolean):void { ngOnDestroy(): void {
this.showSticky = sticky; this.subscription.unsubscribe();
} }
get messageText(){ clearAlert(force = false):void {
if (!!this.message){ this.alertService.clearAlert(force);
return this.message.text;
}
} }
showMessage(message: any) { showMessage(message: any) {
this.message = message; this.message = message;
if (message?.type==='success') { if (message && message.type && message.type === 'success') {
setTimeout(() => { setTimeout(() => {
this.clearAlert(); this.clearAlert();
}, this.successTimeout); }, this.successTimeout);
} }
} }
} }
...@@ -5,52 +5,75 @@ import {Observable, Subject} from 'rxjs'; ...@@ -5,52 +5,75 @@ import {Observable, Subject} from 'rxjs';
@Injectable() @Injectable()
export class AlertMessageService { export class AlertMessageService {
private subject = new Subject<any>(); private subject = new Subject<any>();
private previousRoute: string;
private previousRoute = '';
private sticky = false;
private message: { type: string, text: string };
//TODO move the logic in the ngInit block //TODO move the logic in the ngInit block
constructor (private router: Router) { constructor (private router: Router) {
this.previousRoute = '';
// clear alert message on route change // clear alert message on route change
router.events.subscribe(event => { router.events.subscribe(event => {
if (event instanceof NavigationStart) { if (event instanceof NavigationStart) {
if (this.isRouteChanged(event.url)) { if (this.isRouteChanged(event.url)) {
this.clearAlert(); this.clearAlert();
} else { } else {
console.log('Alert kept when navigating from [' + this.previousRoute + '] to [' + event.url + ']'); console.log('Alert after when navigating from [' + this.previousRoute + '] to [' + event.url + ']');
} }
} else if (event instanceof NavigationEnd) { } else if (event instanceof NavigationEnd) {
this.previousRoute = event.url; this.previousRoute = event.url;
if (this.sticky) {
this.displayCurrentMessage();
this.reset();
}
} }
}); });
} }
private reset () {
this.sticky = false;
this.message = null;
}
getPath (url: string): string { getPath (url: string): string {
var parser = document.createElement('a'); const parser = document.createElement('a');
parser.href = url; parser.href = url;
return parser.pathname; return parser.pathname;
} }
isRouteChanged (currentRoute: string): boolean { isRouteChanged (currentRoute: string): boolean {
let result = false;
let previousRoutePath = this.getPath(this.previousRoute); let previousRoutePath = this.getPath(this.previousRoute);
let currentRoutePath = this.getPath(currentRoute); let currentRoutePath = this.getPath(currentRoute);
if (previousRoutePath !== currentRoutePath) { return previousRoutePath !== currentRoutePath;
result = true;
}
return result;
} }
clearAlert (): void { clearAlert (force = false): void {
if (!force && this.sticky) {
return;
}
this.subject.next(null); this.subject.next(null);
} }
setSticky (sticky: boolean) {
this.sticky = sticky;
}
displayCurrentMessage () {
this.subject.next(this.message);
}
success (message: string, keepAfterNavigationChange = false) { success (message: string, keepAfterNavigationChange = false) {
this.subject.next({type: 'success', text: message}); this.setSticky(keepAfterNavigationChange);
this.message = {type: 'success', text: message};
this.displayCurrentMessage();
} }
error (message: string, keepAfterNavigationChange = false) { error (message: string, keepAfterNavigationChange = false) {
this.subject.next({type: 'error', text: message}); this.setSticky(keepAfterNavigationChange);
this.message = {type: 'error', text: message};
this.displayCurrentMessage();
} }
exception (message: string, error: any, keepAfterNavigationChange = false): void { exception (message: string, error: any, keepAfterNavigationChange = false): void {
......
...@@ -128,19 +128,15 @@ export class PasswordChangeDialogComponent { ...@@ -128,19 +128,15 @@ export class PasswordChangeDialogComponent {
} }
} }
showPassChangeDialog() { async showPassChangeDialog() {
this.dialog.open(InformationDialogComponent, { this.alertService.success("Password has been successfully set/changed." +
data: { (!this.adminUser ? " Login again to the application with the new password!" : ""), true);
title: "Password set/changed",
description: "Password has been successfully set/changed." +
(!this.adminUser ? " Login again to the application with the new password!" : "") if (!this.adminUser) {
} // logout if changed for itself
}).afterClosed().subscribe(result => { this.securityService.finalizeLogout({});
if (!this.adminUser) { }
// logout if changed for itself
this.securityService.finalizeLogout(result);
}
})
} }
showSuccessMessage(value: string) { showSuccessMessage(value: string) {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<mat-card-title class="title-panel" >SSO Login: {{lookups.cachedApplicationInfo.ssoAuthenticationLabel}}</mat-card-title> <mat-card-title class="title-panel" >SSO Login: {{lookups.cachedApplicationInfo.ssoAuthenticationLabel}}</mat-card-title>
<mat-card-content style="align-items: center;justify-content: center;display: flex;height: 200px;"> <mat-card-content style="align-items: center;justify-content: center;display: flex;height: 200px;">
<a mat-raised-button color="primary" href="{{lookups.cachedApplicationInfo.ssoAuthenticationURI}}" <a mat-raised-button color="primary" href="{{lookups.cachedApplicationInfo.ssoAuthenticationURI}}"
[style]="'width=150px'"> [style]="'width:150px'">
<mat-icon>input</mat-icon> <mat-icon>input</mat-icon>
<span> SSO Login</span> <span> SSO Login</span>
</a> </a>
......
...@@ -2,27 +2,26 @@ ...@@ -2,27 +2,26 @@
import {Observable, ReplaySubject} from 'rxjs'; import {Observable, ReplaySubject} from 'rxjs';
import {User} from './user.model'; import {User} from './user.model';
import {SecurityEventService} from './security-event.service'; import {SecurityEventService} from './security-event.service';
import {HttpClient, HttpErrorResponse, HttpHeaders} from '@angular/common/http'; import {HttpClient, HttpHeaders} from '@angular/common/http';
import {SmpConstants} from "../smp.constants"; import {SmpConstants} from "../smp.constants";
import {Authority} from "./authority.model"; import {Authority} from "./authority.model";
import {AlertMessageService} from "../common/alert-message/alert-message.service"; import {AlertMessageService} from "../common/alert-message/alert-message.service";
import {PasswordChangeDialogComponent} from "../common/dialogs/password-change-dialog/password-change-dialog.component"; import {PasswordChangeDialogComponent} from "../common/dialogs/password-change-dialog/password-change-dialog.component";
import {MatDialog} from "@angular/material/dialog"; import {MatDialog} from "@angular/material/dialog";
import {Router} from "@angular/router";
@Injectable() @Injectable()
export class SecurityService { export class SecurityService {
readonly LOCAL_STORAGE_KEY_CURRENT_USER = 'currentUser'; readonly LOCAL_STORAGE_KEY_CURRENT_USER = 'currentUser';
constructor( constructor(
private http: HttpClient, private http: HttpClient,
private alertService: AlertMessageService, private alertService: AlertMessageService,
private securityEventService: SecurityEventService, private securityEventService: SecurityEventService,
private dialog: MatDialog, private dialog: MatDialog,
) { private router: Router) {
this.securityEventService.onLogoutSuccessEvent().subscribe(() => window.location.reload()); this.securityEventService.onLogoutSuccessEvent().subscribe(() => { this.dialog.closeAll(); this.router.navigateByUrl('/'); });
this.securityEventService.onLogoutErrorEvent().subscribe((error) => this.alertService.error(error)); this.securityEventService.onLogoutErrorEvent().subscribe((error) => this.alertService.error(error));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment