Skip to content

Commit

Permalink
SHIBUI-1062 Updated path for new user request, added notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jan 22, 2019
1 parent 2b6065c commit 26abb41
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 20 deletions.
17 changes: 3 additions & 14 deletions ui/src/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import { Component, OnInit } from '@angular/core';
import { LoadRoleRequest } from '../core/action/configuration.action';

import * as fromRoot from '../app.reducer';
import { Store } from '@ngrx/store';
import { LoadAdminRequest } from './action/collection.action';
import { Component } from '@angular/core';

@Component({
selector: 'admin-page',
templateUrl: './admin.component.html',
styleUrls: []
})
export class AdminComponent implements OnInit {
constructor(
private store: Store<fromRoot.State>
) { }

ngOnInit(): void {
this.store.dispatch(new LoadAdminRequest());
}
export class AdminComponent {
constructor() { }
}
4 changes: 3 additions & 1 deletion ui/src/app/admin/container/action-required.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export class ActionRequiredPageComponent {

constructor(
private store: Store<fromRoot.State>
) {}
) {
this.store.dispatch(new LoadNewUsersRequest());
}
}
4 changes: 3 additions & 1 deletion ui/src/app/admin/container/admin-management.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ export class AdminManagementPageComponent {

constructor(
private store: Store<fromRoot.State>
) {}
) {
this.store.dispatch(new LoadAdminRequest());
}
}
30 changes: 29 additions & 1 deletion ui/src/app/admin/effect/collection.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
LoadNewUsersRequest
} from '../action/collection.action';
import { AdminService } from '../service/admin.service';
import { AddNotification } from '../../notification/action/notification.action';
import { Notification, NotificationType } from '../../notification/model/notification';


/* istanbul ignore next */
Expand All @@ -32,7 +34,7 @@ export class AdminCollectionEffects {
@Effect()
loadNewUsersRequest$ = this.actions$.pipe(
ofType<LoadNewUsersRequest>(AdminCollectionActionTypes.LOAD_NEW_USERS_REQUEST),
switchMap(() => this.adminService.query().pipe(
switchMap(() => this.adminService.queryByRole('ROLE_NONE').pipe(
map(users => new LoadAdminSuccess(users))
))
);
Expand All @@ -49,6 +51,19 @@ export class AdminCollectionEffects {
))
);

@Effect()
updateAdminRoleSuccess$ = this.actions$.pipe(
ofType<UpdateAdminSuccess>(AdminCollectionActionTypes.UPDATE_ADMIN_SUCCESS),
map(action => action.payload),
map(user => new AddNotification(
new Notification(
NotificationType.Success,
`User update successful for ${ user.changes.username }`,
5000
)
))
);

@Effect()
removeAdminRequest$ = this.actions$.pipe(
ofType<RemoveAdminRequest>(AdminCollectionActionTypes.REMOVE_ADMIN_REQUEST),
Expand All @@ -64,6 +79,19 @@ export class AdminCollectionEffects {
map(action => new LoadAdminRequest())
);

@Effect()
deleteAdminRoleSuccess$ = this.actions$.pipe(
ofType<RemoveAdminSuccess>(AdminCollectionActionTypes.REMOVE_ADMIN_SUCCESS),
map(action => action.payload),
map(user => new AddNotification(
new Notification(
NotificationType.Success,
`User deleted.`,
5000
)
))
);

constructor(
private actions$: Actions,
private adminService: AdminService,
Expand Down
8 changes: 8 additions & 0 deletions ui/src/app/admin/service/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export class AdminService {
);
}

queryByRole(role: string): Observable<Admin[]> {
return this.http.get<Admin[]>(
`${this.base}${this.endpoint}/role/${role}`, {}
).pipe(
map(users => users.map(u => new AdminEntity(u)))
);
}

update(user: Admin): Observable<Admin> {
return this.http.patch<Admin>(
`${this.base}${this.endpoint}/${user.username}`, {...user}
Expand Down
2 changes: 0 additions & 2 deletions ui/src/app/dashboard/container/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export class DashboardPageComponent {
) {
this.actionsRequired$ = this.store.select(fromAdmin.getTotalActionsRequired);
this.hasActions$ = this.actionsRequired$.pipe(map(a => a > 0));

this.store.dispatch(new LoadAdminRequest());
this.store.dispatch(new LoadRoleRequest());
}
}
2 changes: 1 addition & 1 deletion ui/src/app/notification/model/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class Notification {
}

export enum NotificationType {
Success = 'alert-succes',
Success = 'alert-success',
Info = 'alert-info',
Warning = 'alert-warning',
Danger = 'alert-danger'
Expand Down

0 comments on commit 26abb41

Please sign in to comment.