@@ -1,5 +1,5 @@
|
|||||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||||
<button mat-raised-button color="primary">
|
<button mat-raised-button color="primary" [routerLink]="'manage'">
|
||||||
<fa-icon icon="plus"></fa-icon>
|
<fa-icon icon="plus"></fa-icon>
|
||||||
Add/Edit
|
Add/Edit
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<mat-card>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<form #formRef="ngForm" [formGroup]="currencyForm" fxLayout="row" fxLayoutAlign="start baseline" fxLayoutGap="20px"
|
||||||
|
fxFlex="48%" (ngSubmit)="addCurrency()">
|
||||||
|
|
||||||
|
<mat-form-field fxFlex="calc(90%-20px)">
|
||||||
|
<mat-label>Currency</mat-label>
|
||||||
|
<mat-select required formControlName="currency">
|
||||||
|
<mat-option *ngFor="let currency of currencyData" [value]="currency">
|
||||||
|
{{ currency.name }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="currencyForm.controls.currency.hasError('required')">
|
||||||
|
Currency is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<button mat-raised-button fxFlex color="primary"
|
||||||
|
[disabled]="!currencyForm.valid">
|
||||||
|
<fa-icon icon="plus"></fa-icon>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<mat-grid-list cols="2" rowHeight="50px">
|
||||||
|
|
||||||
|
<mat-grid-tile *ngFor="let currency of selectedCurrencies; index as i">
|
||||||
|
|
||||||
|
<input matInput [value]="currency.name">
|
||||||
|
|
||||||
|
<div fxLayout="row" fxLayoutAlign="flex-start">
|
||||||
|
<button mat-button color="warn" (click)="deleteCurrency(currency.code, i)">
|
||||||
|
<fa-icon icon="trash"></fa-icon>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</mat-grid-tile>
|
||||||
|
|
||||||
|
</mat-grid-list>
|
||||||
|
|
||||||
|
</mat-card>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.container{
|
||||||
|
width: 74rem;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ManageCurrenciesComponent } from './manage-currencies.component';
|
||||||
|
|
||||||
|
describe('ManageCurrenciesComponent', () => {
|
||||||
|
let component: ManageCurrenciesComponent;
|
||||||
|
let fixture: ComponentFixture<ManageCurrenciesComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ ManageCurrenciesComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ManageCurrenciesComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
import { FormBuilder, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
/** Custom Dialogs */
|
||||||
|
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
|
||||||
|
|
||||||
|
/** Custom Services */
|
||||||
|
import { OrganizationService } from '../../organization.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manage Currencies component.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-manage-currencies',
|
||||||
|
templateUrl: './manage-currencies.component.html',
|
||||||
|
styleUrls: ['./manage-currencies.component.scss']
|
||||||
|
})
|
||||||
|
export class ManageCurrenciesComponent implements OnInit {
|
||||||
|
|
||||||
|
/** Selected Currencies data. */
|
||||||
|
selectedCurrencies: any[];
|
||||||
|
/** Currency options data */
|
||||||
|
currencyData: any;
|
||||||
|
/** Currency form */
|
||||||
|
currencyForm: any;
|
||||||
|
|
||||||
|
/** Currency form reference */
|
||||||
|
@ViewChild('formRef') formRef: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the currency data from `resolve`.
|
||||||
|
* @param {ActivatedRoute} route Activated Route
|
||||||
|
* @param {FormBuilder} formBuilder Form Builder
|
||||||
|
* @param {OrganizationService} organizationservice Organization Service
|
||||||
|
* @param {MatDialog} dialog Mat Dialog
|
||||||
|
*/
|
||||||
|
constructor(private route: ActivatedRoute,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private organizationservice: OrganizationService,
|
||||||
|
public dialog: MatDialog) {
|
||||||
|
this.route.parent.data.subscribe(( data: { currencies: any }) => {
|
||||||
|
this.selectedCurrencies = data.currencies.selectedCurrencyOptions;
|
||||||
|
this.currencyData = data.currencies.currencyOptions;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.createCurrencyForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the currency form.
|
||||||
|
*/
|
||||||
|
createCurrencyForm() {
|
||||||
|
this.currencyForm = this.formBuilder.group({
|
||||||
|
'currency': ['', Validators.required]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new currency to the list.
|
||||||
|
*/
|
||||||
|
addCurrency() {
|
||||||
|
const newCurrency = this.currencyForm.value.currency;
|
||||||
|
const selectedCurrencyCodes: any[] = this.selectedCurrencies.map(currency => currency.code);
|
||||||
|
if (!selectedCurrencyCodes.includes(newCurrency.code)) {
|
||||||
|
selectedCurrencyCodes.push(newCurrency.code);
|
||||||
|
this.organizationservice.updateCurrencies(selectedCurrencyCodes)
|
||||||
|
.subscribe((response: any) => {
|
||||||
|
this.selectedCurrencies.push(newCurrency);
|
||||||
|
this.formRef.resetForm();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes Currency
|
||||||
|
* @param {string} currencyCode Currency Code
|
||||||
|
* @param {number} index Index
|
||||||
|
*/
|
||||||
|
deleteCurrency(currencyCode: string, index: number) {
|
||||||
|
const selectedCurrencyCodes: any[] = this.selectedCurrencies.map(currency => currency.code);
|
||||||
|
selectedCurrencyCodes.splice(index, 1);
|
||||||
|
const deleteCurrencyDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||||
|
data: { deleteContext: `currency: ${currencyCode}` }
|
||||||
|
});
|
||||||
|
deleteCurrencyDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response.delete) {
|
||||||
|
this.organizationservice.updateCurrencies(selectedCurrencyCodes)
|
||||||
|
.subscribe(() => {
|
||||||
|
this.selectedCurrencies.splice(index, 1);
|
||||||
|
this.formRef.resetForm();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -40,6 +40,7 @@ import { GeneralTabComponent } from './offices/view-office/general-tab/general-t
|
|||||||
import { DatatableTabsComponent } from './offices/view-office/datatable-tabs/datatable-tabs.component';
|
import { DatatableTabsComponent } from './offices/view-office/datatable-tabs/datatable-tabs.component';
|
||||||
import { ViewCampaignComponent } from './sms-campaigns/view-campaign/view-campaign.component';
|
import { ViewCampaignComponent } from './sms-campaigns/view-campaign/view-campaign.component';
|
||||||
import { ManageFundsComponent } from './manage-funds/manage-funds.component';
|
import { ManageFundsComponent } from './manage-funds/manage-funds.component';
|
||||||
|
import { ManageCurrenciesComponent } from './currencies/manage-currencies/manage-currencies.component';
|
||||||
|
|
||||||
/** Custom Resolvers */
|
/** Custom Resolvers */
|
||||||
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
||||||
@@ -218,11 +219,21 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'currencies',
|
path: 'currencies',
|
||||||
component: CurrenciesComponent,
|
|
||||||
data: { title: extract('Currency Configuration'), breadcrumb: 'Currency Configuration' },
|
data: { title: extract('Currency Configuration'), breadcrumb: 'Currency Configuration' },
|
||||||
resolve: {
|
resolve: {
|
||||||
currencies: CurrenciesResolver
|
currencies: CurrenciesResolver
|
||||||
}
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: CurrenciesComponent,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'manage',
|
||||||
|
data: { title: extract('Manage Currencies'), breadcrumb: 'Manage Currencies' },
|
||||||
|
component: ManageCurrenciesComponent
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'sms-campaigns',
|
path: 'sms-campaigns',
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import { SingleRowComponent } from './offices/view-office/datatable-tabs/single-
|
|||||||
import { MultiRowComponent } from './offices/view-office/datatable-tabs/multi-row/multi-row.component';
|
import { MultiRowComponent } from './offices/view-office/datatable-tabs/multi-row/multi-row.component';
|
||||||
import { ViewCampaignComponent } from './sms-campaigns/view-campaign/view-campaign.component';
|
import { ViewCampaignComponent } from './sms-campaigns/view-campaign/view-campaign.component';
|
||||||
import { ManageFundsComponent } from './manage-funds/manage-funds.component';
|
import { ManageFundsComponent } from './manage-funds/manage-funds.component';
|
||||||
|
import { ManageCurrenciesComponent } from './currencies/manage-currencies/manage-currencies.component';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Organization Module
|
* Organization Module
|
||||||
@@ -91,7 +92,8 @@ import { ManageFundsComponent } from './manage-funds/manage-funds.component';
|
|||||||
SingleRowComponent,
|
SingleRowComponent,
|
||||||
MultiRowComponent,
|
MultiRowComponent,
|
||||||
ViewCampaignComponent,
|
ViewCampaignComponent,
|
||||||
ManageFundsComponent
|
ManageFundsComponent,
|
||||||
|
ManageCurrenciesComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class OrganizationModule { }
|
export class OrganizationModule { }
|
||||||
|
|||||||
@@ -166,6 +166,14 @@ export class OrganizationService {
|
|||||||
return this.http.get('/currencies');
|
return this.http.get('/currencies');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any[]} currencies
|
||||||
|
* @returns {Observable<any>} Currencies data
|
||||||
|
*/
|
||||||
|
updateCurrencies(currencies: any[]): Observable<any> {
|
||||||
|
return this.http.put('/currencies', {currencies});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Observable<any>} SMS Campaigns data
|
* @returns {Observable<any>} SMS Campaigns data
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user