diff --git a/web/angular/.angular-cli.json b/web/angular/.angular-cli.json index 605f9ab..50b6e38 100644 --- a/web/angular/.angular-cli.json +++ b/web/angular/.angular-cli.json @@ -21,7 +21,8 @@ "styles": [ "../node_modules/font-awesome/css/font-awesome.css", "../node_modules/simple-line-icons/css/simple-line-icons.css", - "../src/scss/style.scss" + "../src/scss/style.scss", + "../node_modules/ngx-toastr/toastr.css" ], "scripts": [ "../node_modules/chart.js/dist/Chart.bundle.min.js", diff --git a/web/angular/package.json b/web/angular/package.json index ffc87cc..c8cecbd 100644 --- a/web/angular/package.json +++ b/web/angular/package.json @@ -14,6 +14,7 @@ }, "private": true, "dependencies": { + "@angular/animations": "^5.1.2", "@angular/common": "5.0.1", "@angular/compiler": "5.0.1", "@angular/core": "5.0.1", @@ -32,6 +33,7 @@ "moment": "2.19.1", "ng2-charts": "1.6.0", "ngx-bootstrap": "1.9.3", + "ngx-toastr": "^8.0.0", "rxjs": "5.5.2", "simple-line-icons": "^2.4.1", "ts-helpers": "1.1.2", diff --git a/web/angular/src/app/app.module.ts b/web/angular/src/app/app.module.ts index 84338da..e626a6d 100755 --- a/web/angular/src/app/app.module.ts +++ b/web/angular/src/app/app.module.ts @@ -2,6 +2,7 @@ import { BrowserModule } from '@angular/platform-browser'; import {FormsModule} from "@angular/forms"; import { NgModule } from '@angular/core'; import {LocationStrategy, HashLocationStrategy, PathLocationStrategy} from '@angular/common'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; @@ -116,19 +117,23 @@ import { TabsModule } from 'ngx-bootstrap/tabs'; import { PaginationModule } from 'ngx-bootstrap/pagination'; import { ModalModule } from 'ngx-bootstrap/modal'; import { ChartsModule } from 'ng2-charts/ng2-charts'; - +import { ToastrModule } from 'ngx-toastr'; @NgModule({ imports: [ BrowserModule, FormsModule, HttpClientModule, + BrowserAnimationsModule, AppRoutingModule, BsDropdownModule.forRoot(), TabsModule.forRoot(), PaginationModule.forRoot(), ModalModule.forRoot(), - ChartsModule + ChartsModule, + ToastrModule.forRoot({ + newestOnTop: true + }) ], declarations: [ AppComponent, diff --git a/web/angular/src/app/views/components/user-management/user-management.component.html b/web/angular/src/app/views/components/user-management/user-management.component.html index 6122d16..e769782 100644 --- a/web/angular/src/app/views/components/user-management/user-management.component.html +++ b/web/angular/src/app/views/components/user-management/user-management.component.html @@ -22,8 +22,8 @@ {{user.email}} - {{role}} - {{role}} + {{role}} + {{role}} @@ -31,14 +31,11 @@ Inactive - - - @@ -76,48 +73,7 @@ - - - - - - - - - - diff --git a/web/angular/src/app/views/components/user-management/user-management.component.ts b/web/angular/src/app/views/components/user-management/user-management.component.ts index e4d4c78..6022b65 100644 --- a/web/angular/src/app/views/components/user-management/user-management.component.ts +++ b/web/angular/src/app/views/components/user-management/user-management.component.ts @@ -3,6 +3,7 @@ import {ConsoleService} from "../../../console.service"; import {ApiClientService} from "../../../../api/index"; import {UserPage} from "../../../../api/models/userpage.model"; import {User} from "../../../../api/models/user.model"; +import { ToastrService } from 'ngx-toastr'; @Component({ selector: 'app-user-management', @@ -24,12 +25,10 @@ export class UserManagementComponent implements OnInit{ errorMessage:string = ''; @ViewChild('deleteModal') deleteModal; - @ViewChild('successModal') successModal; - @ViewChild('dangerModal') dangerModal; @ViewChild('reactiveModal') reactiveModal; - - constructor(private consoleService: ConsoleService, private apiClientService:ApiClientService) {} + constructor(private consoleService: ConsoleService, private apiClientService:ApiClientService, + private toastr: ToastrService) {} ngOnInit(){ this.loadUser(this.getPageOffset(this.bigCurrentPage)); @@ -41,6 +40,21 @@ export class UserManagementComponent implements OnInit{ this.loadUser(this.getPageOffset(event.page)); } + // success toast + showSuccess(title:string, message:string) { + this.toastr.success(message, title,{ + progressBar: true, + closeButton: true + }); + } + // error toast + showError(title:string, message:string){ + this.toastr.error(message, title, { + progressBar: true, + closeButton: true + }); + } + // load 10 User from server loadUser(pageOffset:number){ this.consoleService.log("Load User requested."); @@ -98,59 +112,30 @@ export class UserManagementComponent implements OnInit{ return tempTableUserList; } - - - deleteUser(index:number){ + showDeleteUserModal(index:number){ this.selectedUserId = index; this.deleteModal.show() } - confirmDelete(): void { - console.log("delete user"); - const deleteUser:User = this.currentUsers[this.selectedUserId]; - deleteUser.deleted = true; - this.consoleService.log("Delete User requested."); - this.apiClientService.setUser(deleteUser.id, deleteUser).subscribe(result => { - this.consoleService.log("Delete user received."); - console.log(result.body); - this.loadUser(this.getPageOffset(this.bigCurrentPage)); - this.deleteModal.hide(); - this.successModal.show(); - }, error => { - if (error.status == 400) { - this.errorMessage = "Invalid user."; - this.consoleService.log(this.errorMessage); - } else if (error.status == 403) { - this.errorMessage = "Insufficient privileges to retrieve the user."; - this.consoleService.log(this.errorMessage); - } else if (error.status == 409){ - this.errorMessage = "User modified in parallel."; - this.consoleService.log(this.errorMessage); - } else { - this.errorMessage = "Unknown error."; - this.consoleService.log(this.errorMessage); - } - this.dangerModal.show(); - this.deleteModal.hide(); - }); - } - - showReactiveUser(index:number){ + showReactiveUserModal(index:number){ this.selectedUserId = index; this.reactiveModal.show() } - reactiveUser(){ - console.log("reactive user"); - const reactiveUser:User = this.currentUsers[this.selectedUserId]; - reactiveUser.deleted = false; - this.consoleService.log("Reactive User requested."); - this.apiClientService.setUser(reactiveUser.id, reactiveUser).subscribe(result => { - this.consoleService.log("Reactive user received."); + reactiveOrDeleteUser(){ + console.log("reactive or delete user"); + const tempUser:User = this.currentUsers[this.selectedUserId]; + tempUser.deleted = !tempUser.deleted; + this.changeUser(tempUser); + } + + changeUser(user:User){ + this.consoleService.log("Put User requested."); + this.apiClientService.setUser(user.id, user).subscribe(result => { + this.consoleService.log("Put user received."); console.log(result.body); this.loadUser(this.getPageOffset(this.bigCurrentPage)); - this.reactiveModal.hide(); - this.successModal.show(); + this.showSuccess("Success", "User "+result.body.name +" cahnged successful!"); }, error => { if (error.status == 400) { this.errorMessage = "Invalid user."; @@ -165,9 +150,10 @@ export class UserManagementComponent implements OnInit{ this.errorMessage = "Unknown error."; this.consoleService.log(this.errorMessage); } - this.dangerModal.show(); - this.reactiveModal.hide(); + this.showError("Error occured", this.errorMessage); }); + this.reactiveModal.hide(); + this.deleteModal.hide(); } } diff --git a/web/angular/src/scss/style.scss b/web/angular/src/scss/style.scss index 571b6ea..41491d0 100755 --- a/web/angular/src/scss/style.scss +++ b/web/angular/src/scss/style.scss @@ -10,7 +10,7 @@ @import "bootstrap-variables"; // Import Bootstrap source files -@import "node_modules/bootstrap/scss/bootstrap"; +@import "../../node_modules/bootstrap/scss/bootstrap"; // Override core variables @import "core-variables";