feat: add password preferences component

Fixes: #510
This commit is contained in:
punwai
2019-12-29 16:34:49 +05:30
committed by Jivjyot Singh
parent dc61cba5d6
commit 2ce737e53d
9 changed files with 194 additions and 3 deletions
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { OrganizationService } from '../organization.service';
/**
* Password Preferences Template data resolver.
*/
@Injectable()
export class PasswordPreferencesTemplateResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the password preferences template data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.organizationService.getPasswordPreferencesTemplate();
}
}
@@ -0,0 +1,26 @@
<div class="container">
<mat-card>
<form [formGroup]="passwordPreferencesForm" (ngSubmit)="submit()">
<mat-card-content>
<mat-radio-group fxLayout="column" formControlName="validationPolicyId" fxLayoutGap="10px">
<mat-radio-button *ngFor="let passwordPreference of passwordPreferencesData" [value]="passwordPreference.id">
<span class="description-wrap">{{ passwordPreference.description }}</span>
</mat-radio-button>
</mat-radio-group>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary" [disabled]="passwordPreferencesForm.pristine">Submit</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.description-wrap {
white-space: normal;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { PasswordPreferencesComponent } from './password-preferences.component';
describe('PasswordPreferencesComponent', () => {
let component: PasswordPreferencesComponent;
let fixture: ComponentFixture<PasswordPreferencesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PasswordPreferencesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PasswordPreferencesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,79 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
/** Custom Services */
import { OrganizationService } from '../organization.service';
/**
* Password preferences component.
*/
@Component({
selector: 'mifosx-password-preferences',
templateUrl: './password-preferences.component.html',
styleUrls: ['./password-preferences.component.scss']
})
export class PasswordPreferencesComponent implements OnInit {
/** Password preferences form. */
passwordPreferencesForm: FormGroup;
/** Password preferences data. */
passwordPreferencesData: any;
/**
* Retrieves the password preferences data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {OrganizationService} organizationService Organization Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { passwordPreferencesTemplate: any}) => {
this.passwordPreferencesData = data.passwordPreferencesTemplate;
});
}
/**
* Creates and sets the password preferences form.
*/
ngOnInit() {
this.createPasswordPreferencesForm();
this.setPasswordPreferencesForm();
}
/**
* Creates the password preferences form.
*/
createPasswordPreferencesForm() {
this.passwordPreferencesForm = this.formBuilder.group({
'validationPolicyId': ['']
});
}
/**
* Sets the password preferences form.
*/
setPasswordPreferencesForm() {
for (const passwordPreference of this.passwordPreferencesData) {
if (passwordPreference.active === true) {
this.passwordPreferencesForm.get('validationPolicyId').setValue(passwordPreference.id);
}
}
}
/**
* Submits the password preferences form and updates password preferences,
* if successful redirects to organization view.
*/
submit() {
const passwordPreferences = this.passwordPreferencesForm.value;
this.organizationService.updatePasswordPreferences(passwordPreferences).subscribe((response: any) => {
this.router.navigate(['../'], { relativeTo: this.route });
});
}
}