feat: add centers action (assign and unassign staff) (#1091)
Fixes: #1090
This commit is contained in:
@@ -3,6 +3,12 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
/** Dialog Imports */
|
||||
import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/confirmation-dialog.component';
|
||||
|
||||
/** Custom Services */
|
||||
import { CentersService } from '../centers.service';
|
||||
|
||||
/**
|
||||
* Create Center View
|
||||
*/
|
||||
@@ -26,7 +32,8 @@ export class CentersViewComponent implements OnInit {
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
public dialog: MatDialog) {
|
||||
public dialog: MatDialog,
|
||||
public centersService: CentersService) {
|
||||
this.route.data.subscribe((data: {
|
||||
centerViewData: any,
|
||||
centerDatatables: any
|
||||
@@ -49,9 +56,40 @@ export class CentersViewComponent implements OnInit {
|
||||
doAction(name: string) {
|
||||
switch (name) {
|
||||
case 'Activate':
|
||||
case 'Assign Staff':
|
||||
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
|
||||
break;
|
||||
case 'Unassign Staff':
|
||||
this.centersUnassignStaff();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unassign's the centers's staff.
|
||||
*/
|
||||
private centersUnassignStaff() {
|
||||
const unAssignStaffDialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
||||
data: { heading: 'Unassign Staff', dialogContext: 'Are you sure you want Unassign Staff ?' }
|
||||
});
|
||||
unAssignStaffDialogRef.afterClosed().subscribe((response: { confirm: any }) => {
|
||||
if (response.confirm) {
|
||||
this.centersService.executeGroupActionCommand(this.centerViewData.id, 'unassignStaff', { staffId: this.centerViewData.staffId })
|
||||
.subscribe(() => {
|
||||
this.reload();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Refetches data for the component
|
||||
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
|
||||
*/
|
||||
reload() {
|
||||
const url: string = this.router.url;
|
||||
this.router.navigateByUrl(`/centers`, {skipLocationChange: true})
|
||||
.then(() => this.router.navigate([url]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user