diff --git a/support-portal-frontend/src/app/app.module.ts b/support-portal-frontend/src/app/app.module.ts index 26dee7d..e05a2b8 100644 --- a/support-portal-frontend/src/app/app.module.ts +++ b/support-portal-frontend/src/app/app.module.ts @@ -18,7 +18,6 @@ import {UsersComponent} from './component/management/users/users.component'; import {SettingsComponent} from './component/management/settings/settings.component'; import {ProfileComponent} from './component/management/profile/profile.component'; import {UsersTableComponent} from './component/management/users/users-table/users-table.component'; -import {UserRowComponent} from './component/management/users/users-table/user-row/user-row.component'; import {UserViewComponent} from './component/management/users/user-view/user-view.component'; import {UserEditComponent} from './component/management/users/user-edit/user-edit.component'; @@ -33,7 +32,6 @@ import {UserEditComponent} from './component/management/users/user-edit/user-edi SettingsComponent, ProfileComponent, UsersTableComponent, - UserRowComponent, UserViewComponent, UserEditComponent ], diff --git a/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.css b/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.css deleted file mode 100644 index e69de29..0000000 diff --git a/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.html b/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.html deleted file mode 100644 index 7d1c053..0000000 --- a/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.html +++ /dev/null @@ -1 +0,0 @@ -

user-row works!

diff --git a/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.ts b/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.ts deleted file mode 100644 index 6c6e769..0000000 --- a/support-portal-frontend/src/app/component/management/users/users-table/user-row/user-row.component.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {Component, OnInit} from '@angular/core'; - -@Component({ - selector: 'app-user-row', - templateUrl: './user-row.component.html', - styleUrls: ['./user-row.component.css'] -}) -export class UserRowComponent implements OnInit { - - constructor() { } - - ngOnInit(): void { - } - -} diff --git a/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.html b/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.html index 90cfd81..6ccd4aa 100644 --- a/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.html +++ b/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.html @@ -1,2 +1,41 @@ -

users-table works!

- + + + + + + + + + + + + + + + + + + + + + + + + + + +
PhotoUser IDFirst NameLast NameUsernameEmailStatusActions
+ + {{user.userId}}{{user.firstName}}{{user.lastName}}{{user.username}}{{user.email}} + + {{user?.active ? 'Active' : 'Inactive'}} + + +
+ + +
+
diff --git a/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.ts b/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.ts index c999316..b00ffc3 100644 --- a/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.ts +++ b/support-portal-frontend/src/app/component/management/users/users-table/users-table.component.ts @@ -1,15 +1,75 @@ -import {Component, OnInit} from '@angular/core'; +import {Component, OnDestroy, OnInit} from '@angular/core'; +import {User} from "../../../../model/user"; +import {NotificationType} from "../../../../notification/notification-type"; +import {HttpErrorResponse} from "@angular/common/http"; +import {SubSink} from "subsink"; +import {UserService} from "../../../../service/user.service"; +import {NotificationService} from "../../../../service/notification.service"; +import {AuthenticationService} from "../../../../service/authentication.service"; +import {Router} from "@angular/router"; @Component({ selector: 'app-users-table', templateUrl: './users-table.component.html', styleUrls: ['./users-table.component.css'] }) -export class UsersTableComponent implements OnInit { +export class UsersTableComponent implements OnInit, OnDestroy { - constructor() { } + public users: User[] = []; + + public refreshing: boolean; + private subs = new SubSink(); + + constructor(private userService: UserService, + private notificationService: NotificationService, + private authenticationService: AuthenticationService, + private router: Router) { + } ngOnInit(): void { + this.getUsers(true); + } + + ngOnDestroy(): void { + this.subs.unsubscribe(); + } + + public getUsers(showNotification: boolean) { + this.refreshing = true; + + this.subs.sink = this.userService.getAllUsers() + .subscribe( + usersPage => { + this.users = usersPage.content; + this.userService.addUsersToLocalStorage(this.users); + if (showNotification) + this.notificationService.notify(NotificationType.SUCCESS, `${this.users.length} users loaded successfully`) + }, + (errorResponse: HttpErrorResponse) => { + this.notificationService.notify(NotificationType.ERROR, errorResponse.error.message); + this.refreshing = false; + }, + () => { + this.refreshing = false; + } + ); + + } + + public get isAdmin(): boolean { + return this.authenticationService.isLoggedUserHasRoleAdmin(); + } + + onSelectUser(user: User) { + console.log(`User ${user.username} is selected`); + } + + onEditUser(user: User) { + console.log(`User ${user.username} is clicked to be edited`); + } + + onDeleteUser(user: User) { + console.log(`User ${user.username} is clicked to be deleted`); } } diff --git a/support-portal-frontend/src/app/component/management/users/users.component.html b/support-portal-frontend/src/app/component/management/users/users.component.html index 42b8d30..72b72a1 100644 --- a/support-portal-frontend/src/app/component/management/users/users.component.html +++ b/support-portal-frontend/src/app/component/management/users/users.component.html @@ -1,3 +1,4 @@ -

users works!

- - +
+ + +