| export class ListIncomeComponent implements OnInit { | export class ListIncomeComponent implements OnInit { | ||||
| public uploadMeta: UploadMetaModel = new UploadMetaModel({}); | public uploadMeta: UploadMetaModel = new UploadMetaModel({}); | ||||
| public Loan: LoanModel = new LoanModel({}); | public Loan: LoanModel = new LoanModel({}); | ||||
| public startLoad = false | |||||
| public startLoad = false; | |||||
| private UploadMetaFilterIsReady = false; | private UploadMetaFilterIsReady = false; | ||||
| private LoanFilterIsReady = false; | private LoanFilterIsReady = false; | ||||
| } | } | ||||
| private checkStartUpload(): void { | private checkStartUpload(): void { | ||||
| this.startLoad = this.UploadMetaFilterIsReady | |||||
| this.startLoad = this.UploadMetaFilterIsReady && this.LoanFilterIsReady; | |||||
| } | } | ||||
| } | } |
| <div class="card loan" (click)="onClick()"> | |||||
| <div class="card loan" (click)="onClick()" *ngIf="Loan!==undefined"> | |||||
| <span class="badge badge-success">{{Loan.Item}}</span> | <span class="badge badge-success">{{Loan.Item}}</span> | ||||
| <span> Amount: {{Loan.Amount | currency }}</span> | <span> Amount: {{Loan.Amount | currency }}</span> | ||||
| <span> Settlement: {{Loan.Settlement | date:'yyyy-mm-dd' }}</span> | <span> Settlement: {{Loan.Settlement | date:'yyyy-mm-dd' }}</span> |
| [Loan]="Loan" [ShowCloseButton]="false"></app-loan-card> | [Loan]="Loan" [ShowCloseButton]="false"></app-loan-card> | ||||
| </div> | </div> | ||||
| <kendo-popup [anchor]="anchor" [offset]="Offset" (anchorViewportLeave)="showPopup = false" *ngIf="showPopup"> | |||||
| <kendo-popup [offset]="Offset" (anchorViewportLeave)="showPopup = false" *ngIf="showPopup"> | |||||
| <div class='popup-content'> | <div class='popup-content'> | ||||
| <app-list-all-loans #list | <app-list-all-loans #list | ||||
| (LoanSelected)="onLoanSelected($event)" | (LoanSelected)="onLoanSelected($event)" |
| .popup-content { | .popup-content { | ||||
| box-shadow: 1px 1px 10px black; | box-shadow: 1px 1px 10px black; | ||||
| padding: 10px; | padding: 10px; | ||||
| width: 90vw; | |||||
| height: 50vw; | |||||
| width: calc(100vw - 20px); | |||||
| height:calc(100vh - 96px); | |||||
| color: #787878; | color: #787878; | ||||
| background-color: #fcf7f8; | background-color: #fcf7f8; | ||||
| border: 1px solid rgba(0,0,0,.05); | border: 1px solid rgba(0,0,0,.05); |
| import { Component, Input, OnInit, ViewChild} from '@angular/core'; | |||||
| import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core'; | |||||
| import {LoanModel} from '../models/loan.model'; | import {LoanModel} from '../models/loan.model'; | ||||
| import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; | import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms'; | ||||
| import {ListAllLoansComponent} from '../list-all-loans/list-all-loans.component'; | import {ListAllLoansComponent} from '../list-all-loans/list-all-loans.component'; | ||||
| @ViewChild('list', {static: false} ) list: ListAllLoansComponent; | @ViewChild('list', {static: false} ) list: ListAllLoansComponent; | ||||
| @Input() Max = 1; // we do not support multiple loan selection at the moment | @Input() Max = 1; // we do not support multiple loan selection at the moment | ||||
| @Input() readOnly = false; | @Input() readOnly = false; | ||||
| @Output() valueChange: EventEmitter<LoanModel> = new EventEmitter<LoanModel>(); | |||||
| public Loan: LoanModel; // for multiple selection ,it has to be array; we don't support it now. | public Loan: LoanModel; // for multiple selection ,it has to be array; we don't support it now. | ||||
| // popup | // popup | ||||
| public showPopup = false; | public showPopup = false; | ||||
| public Offset = { left: 0, top: 0 }; | |||||
| public Offset = { left: 10, top: 48 }; | |||||
| // formControl state | // formControl state | ||||
| private disabled = false; | private disabled = false; | ||||
| } | } | ||||
| onLoanSelected(loan: LoanModel): void { | onLoanSelected(loan: LoanModel): void { | ||||
| if (this.Loan.Id !== loan.Id){ | |||||
| this.valueChange.emit(loan); | |||||
| this.onChange(loan); | |||||
| this.Loan = loan; | |||||
| } | |||||
| this.Loan = loan; | this.Loan = loan; | ||||
| this.markAsTouched(); | this.markAsTouched(); | ||||
| this.onTouched(); | this.onTouched(); | ||||
| this.onChange(loan); | |||||
| this.showPopup = false; | this.showPopup = false; | ||||
| } | } | ||||
| [editable]="true " | [editable]="true " | ||||
| [sortable]="false"> | [sortable]="false"> | ||||
| <ng-template kendoGridCellTemplate let-dataItem> | <ng-template kendoGridCellTemplate let-dataItem> | ||||
| <app-loan-card *ngIf="dataItem.LoanId !== '' " [LoanId]="dataItem.LoanId"></app-loan-card> | |||||
| <app-loan-card *ngIf="dataItem.LoanId !== '' " [Loan]="dataItem.Loan"></app-loan-card> | |||||
| </ng-template> | </ng-template> | ||||
| <ng-template kendoGridEditTemplate let-dataItem> | <ng-template kendoGridEditTemplate let-dataItem> | ||||
| <app-loan-select [formControl]="incomeFormGroup.get('Loan')" | |||||
| <app-loan-select [formControl]="incomeFormGroup.get('Loan')" (valueChange)="onLoanChange($event)" | |||||
| [readOnly]="this.filterLoan !== undefined && this.filterLoan.Id !==''" | [readOnly]="this.filterLoan !== undefined && this.filterLoan.Id !==''" | ||||
| ></app-loan-select> | ></app-loan-select> | ||||
| </ng-template> | </ng-template> |
| constructor(private pis: PayInService, private lss: LoanSingleService, private router: Router) { } | constructor(private pis: PayInService, private lss: LoanSingleService, private router: Router) { } | ||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| this.debouncedLoadFilteredData = debounce(this.loadFilteredData, 100); | |||||
| this.debouncedLoadFilteredData = debounce(this.loadFilteredData, 500); | |||||
| if (this.privateLoadDataNow) { // not in delayed loading mode | |||||
| this.debouncedLoadFilteredData(); | |||||
| } | |||||
| } | } | ||||
| public loadFilteredData(): void{ | public loadFilteredData(): void{ | ||||
| } | } | ||||
| @Input() set LoadDataNow( value: boolean) { | @Input() set LoadDataNow( value: boolean) { | ||||
| this.privateLoadDataNow = value; | |||||
| if ( value === true ) { | |||||
| if ( value === true && this.privateLoadDataNow === false) { | |||||
| this.debouncedLoadFilteredData(); | this.debouncedLoadFilteredData(); | ||||
| } | } | ||||
| this.privateLoadDataNow = value; | |||||
| } | } | ||||
| get LoadDataNow(): boolean { | get LoadDataNow(): boolean { | ||||
| return this.privateLoadDataNow; | return this.privateLoadDataNow; | ||||
| const pi = this.buildPayInForSave(v, isNew); | const pi = this.buildPayInForSave(v, isNew); | ||||
| this.lss.savePayIn(pi, isNew).subscribe( | this.lss.savePayIn(pi, isNew).subscribe( | ||||
| (resp: PayInModel) => { | |||||
| this.Loan.cuPayIn(resp); | |||||
| this.updatePiInGrid(new PayInModel(resp)); | |||||
| (resp: PayInModelEx) => { | |||||
| this.Loan.cuPayIn( new PayInModel(resp)); | |||||
| this.updatePiInGrid(new PayInModelEx(resp)); | |||||
| }, | }, | ||||
| err => { | err => { | ||||
| // TODO: this.errorOccurred.emit('Error saving Income'); | // TODO: this.errorOccurred.emit('Error saving Income'); | ||||
| this.filter.Sort = sort; | this.filter.Sort = sort; | ||||
| this.loadFilteredData(); | this.loadFilteredData(); | ||||
| } | } | ||||
| public onLoanChange(loan: LoanModel): void { | |||||
| if ( loan.Id !== '' ) { | |||||
| this.incomeFormGroup.get('Lender').setValue(loan.Lender); | |||||
| this.incomeFormGroup.get('Lender').disable({onlySelf: true, emitEvent: false}); | |||||
| } | |||||
| } | |||||
| } | } |
| import {RewardModel} from '../models/reward.model'; | import {RewardModel} from '../models/reward.model'; | ||||
| import {ClonerService} from './clone.service'; | import {ClonerService} from './clone.service'; | ||||
| import {PayInModel} from '../models/pay-in.model'; | import {PayInModel} from '../models/pay-in.model'; | ||||
| import {PayInModelEx} from '../models/pay-in-ex.model'; | |||||
| @Injectable() | @Injectable() | ||||
| export class LoanSingleService { | export class LoanSingleService { | ||||
| ); | ); | ||||
| } | } | ||||
| public savePayIn(payIn: PayInModel, isNew: boolean): Observable<PayInModel> { | |||||
| return this.http.post<PayInModel>(this.auth.getUrl('payIn/'), payIn); | |||||
| public savePayIn(payIn: PayInModel, isNew: boolean): Observable<PayInModelEx> { | |||||
| return this.http.post<PayInModelEx>(this.auth.getUrl('payIn/'), payIn); | |||||
| } | } | ||||
| public removePayIn(id: number): void { | public removePayIn(id: number): void { |