From f861e466bff174acba1110828af312dfb3128fe9 Mon Sep 17 00:00:00 2001 From: Muskan Khedia <36980003+muskankhedia@users.noreply.github.com> Date: Tue, 14 Jul 2020 10:42:53 +0530 Subject: [PATCH] feat: add centers action (activate) (#1085) Fixes: #1084 --- src/app/centers/centers-routing.module.ts | 73 ++++++++++------- .../activate-center.component.html | 30 +++++++ .../activate-center.component.scss | 3 + .../activate-center.component.spec.ts | 25 ++++++ .../activate-center.component.ts | 82 +++++++++++++++++++ .../center-actions.component.html | 1 + .../center-actions.component.scss | 0 .../center-actions.component.spec.ts | 25 ++++++ .../center-actions.component.ts | 32 ++++++++ .../centers-view/centers-view.component.html | 2 +- .../centers-view/centers-view.component.ts | 19 ++++- src/app/centers/centers.component.html | 2 +- src/app/centers/centers.module.ts | 6 +- src/app/centers/centers.service.ts | 11 +++ src/app/groups/groups.component.html | 2 +- 15 files changed, 276 insertions(+), 37 deletions(-) create mode 100644 src/app/centers/centers-view/center-actions/activate-center/activate-center.component.html create mode 100644 src/app/centers/centers-view/center-actions/activate-center/activate-center.component.scss create mode 100644 src/app/centers/centers-view/center-actions/activate-center/activate-center.component.spec.ts create mode 100644 src/app/centers/centers-view/center-actions/activate-center/activate-center.component.ts create mode 100644 src/app/centers/centers-view/center-actions/center-actions.component.html create mode 100644 src/app/centers/centers-view/center-actions/center-actions.component.scss create mode 100644 src/app/centers/centers-view/center-actions/center-actions.component.spec.ts create mode 100644 src/app/centers/centers-view/center-actions/center-actions.component.ts diff --git a/src/app/centers/centers-routing.module.ts b/src/app/centers/centers-routing.module.ts index 5f271e39b..62b1fd5cf 100644 --- a/src/app/centers/centers-routing.module.ts +++ b/src/app/centers/centers-routing.module.ts @@ -24,6 +24,7 @@ import { CenterSummaryResolver } from './common-resolvers/center-summary.resolve import { CenterNotesResolver } from './common-resolvers/center-notes.resolver'; import { CenterDatatableResolver } from './common-resolvers/center-datatable.resolver'; import { CenterDatatablesResolver } from './common-resolvers/center-datatables.resolver'; +import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component'; const routes: Routes = [ Route.withShell([ @@ -46,42 +47,52 @@ const routes: Routes = [ }, { path: ':centerId', - component: CentersViewComponent, data: { title: extract('Centers View'), routeParamBreadcrumb: 'centerId' }, - resolve: { - centerViewData: CenterViewResolver, - centerDatatables: CenterDatatablesResolver - }, children: [ { - path: 'general', - component: GeneralTabComponent, - data: { title: extract('General'), breadcrumb: 'General', routeParamBreadcrumb: false }, + path: '', + component: CentersViewComponent, resolve: { - centerSummaryData: CenterSummaryResolver, - centerViewData: CenterResourceResolver, - savingsAccountData: SavingsAccountResolver - } - }, - { - path: 'notes', - component: NotesTabComponent, - data: { title: extract('Notes'), breadcrumb: 'Notes', routeParamBreadcrumb: false }, - resolve: { - centerNotes: CenterNotesResolver - } - }, - { - path: 'datatables', - children: [{ - path: ':datatableName', - component: DatatableTabComponent, - data: { title: extract('Data Table View'), routeParamBreadcrumb: 'datatableName' }, - resolve: { - centerDatatable: CenterDatatableResolver + centerViewData: CenterViewResolver, + centerDatatables: CenterDatatablesResolver + }, + children: [ + { + path: 'general', + component: GeneralTabComponent, + data: { title: extract('General'), breadcrumb: 'General', routeParamBreadcrumb: false }, + resolve: { + centerSummaryData: CenterSummaryResolver, + centerViewData: CenterResourceResolver, + savingsAccountData: SavingsAccountResolver + } + }, + { + path: 'notes', + component: NotesTabComponent, + data: { title: extract('Notes'), breadcrumb: 'Notes', routeParamBreadcrumb: false }, + resolve: { + centerNotes: CenterNotesResolver + } + }, + { + path: 'datatables', + children: [{ + path: ':datatableName', + component: DatatableTabComponent, + data: { title: extract('Data Table View'), routeParamBreadcrumb: 'datatableName' }, + resolve: { + centerDatatable: CenterDatatableResolver + } + }] } - }] - } + ] + }, + { + path: 'actions/:name', + data: { title: extract('Center Actions'), routeParamBreadcrumb: 'name' }, + component: CenterActionsComponent + }, ] } ] diff --git a/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.html b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.html new file mode 100644 index 000000000..e503246df --- /dev/null +++ b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.html @@ -0,0 +1,30 @@ +
+ + + +
+ + + + + Activated On Date + + + + + Activated On Date is required + + + + + + + + + + +
+ +
+ +
diff --git a/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.scss b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.scss new file mode 100644 index 000000000..f6edc1a09 --- /dev/null +++ b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.spec.ts b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.spec.ts new file mode 100644 index 000000000..411946f07 --- /dev/null +++ b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ActivateCenterComponent } from './activate-center.component'; + +describe('ActivateCenterComponent', () => { + let component: ActivateCenterComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ActivateCenterComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ActivateCenterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.ts b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.ts new file mode 100644 index 000000000..16857c69c --- /dev/null +++ b/src/app/centers/centers-view/center-actions/activate-center/activate-center.component.ts @@ -0,0 +1,82 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { FormGroup, FormBuilder, Validators } from '@angular/forms'; +import { DatePipe } from '@angular/common'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** Custom Services */ +import { CentersService } from 'app/centers/centers.service'; + +/** + * Activate Center Component + */ +@Component({ + selector: 'mifosx-activate-center', + templateUrl: './activate-center.component.html', + styleUrls: ['./activate-center.component.scss'] +}) +export class ActivateCenterComponent implements OnInit { + + /** Minimum date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum date allowed. */ + maxDate = new Date(); + /** Activate center form. */ + activateCenterForm: FormGroup; + /** Group Account Id */ + centerId: any; + + /** + * @param {FormBuilder} formBuilder Form Builder + * @param {centersService} CentersService Shares Service + * @param {DatePipe} datePipe Date Pipe + * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + */ + constructor(private formBuilder: FormBuilder, + private centersService: CentersService, + private datePipe: DatePipe, + private route: ActivatedRoute, + private router: Router) { + this.centerId = this.route.parent.snapshot.params['centerId']; + } + + /** + * Creates the activate center form. + */ + ngOnInit() { + this.createActivateCenterForm(); + } + + /** + * Creates the activate center form. + */ + createActivateCenterForm() { + this.activateCenterForm = this.formBuilder.group({ + 'activationDate': [new Date(), Validators.required] + }); + } + + /** + * Submits the form and activates the center, + * if successful redirects to the center. + */ + submit() { + // TODO: Update once language and date settings are setup + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const prevactivationDate: Date = this.activateCenterForm.value.activationDate; + this.activateCenterForm.patchValue({ + activationDate: this.datePipe.transform(prevactivationDate, dateFormat), + }); + const data = { + ...this.activateCenterForm.value, + dateFormat, + locale + }; + this.centersService.executeCenterActionCommand(this.centerId, 'activate', data).subscribe(() => { + this.router.navigate(['../../'], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/centers/centers-view/center-actions/center-actions.component.html b/src/app/centers/centers-view/center-actions/center-actions.component.html new file mode 100644 index 000000000..59caaa7ec --- /dev/null +++ b/src/app/centers/centers-view/center-actions/center-actions.component.html @@ -0,0 +1 @@ + diff --git a/src/app/centers/centers-view/center-actions/center-actions.component.scss b/src/app/centers/centers-view/center-actions/center-actions.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/centers/centers-view/center-actions/center-actions.component.spec.ts b/src/app/centers/centers-view/center-actions/center-actions.component.spec.ts new file mode 100644 index 000000000..7ca3e739c --- /dev/null +++ b/src/app/centers/centers-view/center-actions/center-actions.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CenterActionsComponent } from './center-actions.component'; + +describe('CenterActionsComponent', () => { + let component: CenterActionsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CenterActionsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CenterActionsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/centers/centers-view/center-actions/center-actions.component.ts b/src/app/centers/centers-view/center-actions/center-actions.component.ts new file mode 100644 index 000000000..dc031d75e --- /dev/null +++ b/src/app/centers/centers-view/center-actions/center-actions.component.ts @@ -0,0 +1,32 @@ +/** Angular Imports */ +import { Component } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; + +/** + * Center actions component. + */ +@Component({ + selector: 'mifosx-center-actions', + templateUrl: './center-actions.component.html', + styleUrls: ['./center-actions.component.scss'] +}) +export class CenterActionsComponent { + + /** Flag object to store possible actions and render appropriate UI to the user */ + actions: { + 'Activate': boolean + } = { + 'Activate': false, + }; + + /** + * @param {ActivatedRoute} route Activated Route + */ + constructor(private route: ActivatedRoute, + private router: Router) { + this.router.routeReuseStrategy.shouldReuseRoute = () => false; + const name = this.route.snapshot.params['name']; + this.actions[name] = true; + } + +} diff --git a/src/app/centers/centers-view/centers-view.component.html b/src/app/centers/centers-view/centers-view.component.html index d9b2f7830..910321907 100644 --- a/src/app/centers/centers-view/centers-view.component.html +++ b/src/app/centers/centers-view/centers-view.component.html @@ -51,7 +51,7 @@ - + diff --git a/src/app/centers/centers-view/centers-view.component.ts b/src/app/centers/centers-view/centers-view.component.ts index 308b6a2c2..5287a79c4 100644 --- a/src/app/centers/centers-view/centers-view.component.ts +++ b/src/app/centers/centers-view/centers-view.component.ts @@ -1,6 +1,7 @@ /** Angular Imports */ import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, Router } from '@angular/router'; +import { MatDialog } from '@angular/material'; /** * Create Center View @@ -23,7 +24,9 @@ export class CentersViewComponent implements OnInit { * Retrieves the data for center * @param route route Activated Route. */ - constructor(private route: ActivatedRoute) { + constructor(private route: ActivatedRoute, + private router: Router, + public dialog: MatDialog) { this.route.data.subscribe((data: { centerViewData: any, centerDatatables: any @@ -39,4 +42,16 @@ export class CentersViewComponent implements OnInit { } else { this.meetingData = false; } } + /** + * Performs action button/option action. + * @param {string} name action name. + */ + doAction(name: string) { + switch (name) { + case 'Activate': + this.router.navigate([`actions/${name}`], { relativeTo: this.route }); + break; + } + } + } diff --git a/src/app/centers/centers.component.html b/src/app/centers/centers.component.html index 3a66a3f36..036b24b98 100644 --- a/src/app/centers/centers.component.html +++ b/src/app/centers/centers.component.html @@ -40,7 +40,7 @@ Status -
+
diff --git a/src/app/centers/centers.module.ts b/src/app/centers/centers.module.ts index 260fc48ad..251cdab39 100644 --- a/src/app/centers/centers.module.ts +++ b/src/app/centers/centers.module.ts @@ -16,6 +16,8 @@ import { NotesTabComponent } from './centers-view/notes-tab/notes-tab.component' import { DatatableTabComponent } from './centers-view/datatable-tab/datatable-tab.component'; import { MultiRowComponent } from './centers-view/datatable-tab/multi-row/multi-row.component'; import { SingleRowComponent } from './centers-view/datatable-tab/single-row/single-row.component'; +import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component'; +import { ActivateCenterComponent } from './centers-view/center-actions/activate-center/activate-center.component'; /** * Centers Module @@ -37,7 +39,9 @@ import { SingleRowComponent } from './centers-view/datatable-tab/single-row/sing NotesTabComponent, DatatableTabComponent, MultiRowComponent, - SingleRowComponent + SingleRowComponent, + CenterActionsComponent, + ActivateCenterComponent ] }) export class CentersModule { } diff --git a/src/app/centers/centers.service.ts b/src/app/centers/centers.service.ts index d8a0b92e9..b5b4d9f45 100644 --- a/src/app/centers/centers.service.ts +++ b/src/app/centers/centers.service.ts @@ -176,4 +176,15 @@ export class CentersService { return this.http.delete(`/datatables/${datatableName}/${centerId}`, { params: httpParams }); } + /** + * @param {string} centerId Center Id + * @param {string} command Command + * @param {any} data Data + * @returns {Observable} + */ + executeCenterActionCommand(centerId: string, command: string, data: any): Observable { + const httpParams = new HttpParams().set('command', command); + return this.http.post(`/centers/${centerId}`, data, { params: httpParams }); + } + } diff --git a/src/app/groups/groups.component.html b/src/app/groups/groups.component.html index 4caa2094d..492cdec4a 100644 --- a/src/app/groups/groups.component.html +++ b/src/app/groups/groups.component.html @@ -33,7 +33,7 @@ Status -
+