diff --git a/src/app/pages/moneys/money/component/deposit.component.ts b/src/app/pages/moneys/money/component/deposit.component.ts index 00466d8..e53bf92 100644 --- a/src/app/pages/moneys/money/component/deposit.component.ts +++ b/src/app/pages/moneys/money/component/deposit.component.ts @@ -1,12 +1,62 @@ -import { Component, OnInit } from '@angular/core'; +import { + Component, + ElementRef, + OnDestroy, + OnInit, + ViewChild, + ViewEncapsulation, + AfterViewInit +} from '@angular/core'; +import { MatPaginator } from '@angular/material/paginator'; +import { MatSort } from '@angular/material/sort'; + +import { fromEvent, Subject } from 'rxjs'; +import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; + +import { fuseAnimations } from 'src/@fuse/animations'; @Component({ - selector: 'app-deposit', + selector: 'app-pages-deposit-list', templateUrl: './deposit.component.html', - styleUrls: ['./deposit.component.scss'] + styleUrls: ['./deposit.component.scss'], + animations: fuseAnimations, + encapsulation: ViewEncapsulation.None }) -export class DepositComponent implements OnInit { - constructor() {} +export class DepositComponent implements OnInit, OnDestroy, AfterViewInit { + @ViewChild(MatPaginator, { static: true }) + paginator: MatPaginator; + @ViewChild('filter', { static: true }) + filter: ElementRef; + + @ViewChild(MatSort, { static: true }) + sort: MatSort; + + // Private + private _unsubscribeAll: Subject; + + constructor() { + // Set the private defaults + this._unsubscribeAll = new Subject(); + } + + // ----------------------------------------------------------------------------------------------------- + // @ Lifecycle hooks + // ----------------------------------------------------------------------------------------------------- + + /** + * On init + */ ngOnInit() {} + + /** + * On destroy + */ + ngOnDestroy(): void { + // Unsubscribe from all subscriptions + this._unsubscribeAll.next(); + this._unsubscribeAll.complete(); + } + + ngAfterViewInit(): void {} } diff --git a/src/app/pages/sites/bank-info/component/list.component.html b/src/app/pages/sites/bank-info/component/list.component.html index 574597d..7844f0a 100644 --- a/src/app/pages/sites/bank-info/component/list.component.html +++ b/src/app/pages/sites/bank-info/component/list.component.html @@ -36,7 +36,7 @@ >
@@ -46,48 +46,88 @@ [dataSource]="dataSource" [@animateStagger]="{ value: '50' }" matSort - formArrayName="items" + formArrayName="formarray" > 계좌순번 - {{ bankInfo.id }} + {{ + bankInfo.id + }} 은행명 - {{ - bankInfo.name - }} + + + + + + + 계좌번호 - {{ - bankInfo.number - }} + + + + + 예금주 - {{ - bankInfo.holder - }} + + + + + 설명 - {{ - bankInfo.description - }} + + + + + ; displayedColumns = ['id', 'name', 'number', 'holder', 'description']; - bankInfoForm: FormGroup; - bankInfoFormArray: FormArray; + public bankInfoFormGroup: FormGroup; + public bankInfoFormArray: FormArray; @ViewChild('filter', { static: true }) filter: ElementRef; @@ -54,29 +62,13 @@ export class ListComponent implements OnInit, OnDestroy, AfterViewInit { } ngOnInit() { - this.dataSource = new BankInfoDataSource(this.bankInfoService); - - this.bankInfoForm = this.fb.group({ - items: this.createFormArray() + this.bankInfoFormArray = this.fb.array([]); + this.bankInfoFormGroup = this.fb.group({ + formarray: this.bankInfoFormArray }); + this.dataSource.formg = this.bankInfoFormGroup; } - createFormArray(): FormArray { - return new FormArray( - this.dataSource[0]( - item => - new FormGroup({ - id: new FormControl(item.id), - name: new FormControl(item.name, [Validators.required]), - number: new FormControl(item.number, [Validators.required]), - holder: new FormControl(item.holder, [Validators.required]), - description: new FormControl(item.description, [ - Validators.required - ]) - }) - ) - ); - } /** * On destroy */ diff --git a/src/app/pages/sites/bank-info/component/list.data-source.ts b/src/app/pages/sites/bank-info/component/list.data-source.ts index be23818..3cc9aee 100644 --- a/src/app/pages/sites/bank-info/component/list.data-source.ts +++ b/src/app/pages/sites/bank-info/component/list.data-source.ts @@ -1,7 +1,7 @@ import { DataSource } from '@angular/cdk/table'; import { BehaviorSubject, Observable, merge } from 'rxjs'; -import { switchMap, map } from 'rxjs/operators'; +import { switchMap, map, tap } from 'rxjs/operators'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; @@ -10,32 +10,63 @@ import { CollectionViewer } from '@angular/cdk/collections'; import { BankInfo } from 'src/modules/sites/bank-info/model/bank-info.model'; import { BankInfoService } from 'src/modules/sites/bank-info/service/bank-info.service'; import { Page } from 'src/modules/common/data/model/page'; +import { + FormControl, + FormsModule, + ReactiveFormsModule, + FormGroup, + FormBuilder, + Validators, + NgControl, + NgForm, + FormArray +} from '@angular/forms'; export class BankInfoDataSource extends DataSource { - private filterSubject = new BehaviorSubject(''); - // private pageSubject = new BehaviorSubject>({}); + private _objectStore: BankInfo[] = []; + private _ObjectsSubject$ = new BehaviorSubject([]); + private _loadingSubject$ = new BehaviorSubject(false); + + public loading$ = this._loadingSubject$.asObservable(); + public formg: FormGroup; constructor(private bankInfoService: BankInfoService) { super(); } - connect( - collectionViewer: CollectionViewer - ): Observable { - const displayDataChanges = [this.filterSubject]; - - return merge(...displayDataChanges).pipe( - switchMap(() => { - return this.bankInfoService.getBankInfos().pipe( - map(page => { - return page.content; - }) - ); + connect(collectionViewer: CollectionViewer): Observable { + return this.bankInfoService.getAllAsFormArray().pipe( + map(res => { + res.forEach(m => this._objectStore.push(m as BankInfo)); + this._ObjectsSubject$.next(this._objectStore); + let fa = this.formg.get('formarray'); + res.forEach(r => fa.push(this.createRowFormGroup(r))); + return res; }) ); } + createRowFormGroup(r: BankInfo): FormGroup { + let f = new FormGroup({ + id: this.createNewFormContorl(r, 'id'), + name: this.createNewFormContorl(r, 'name'), + number: this.createNewFormContorl(r, 'number'), + holder: this.createNewFormContorl(r, 'holder'), + description: this.createNewFormContorl(r, 'description') + }); + return f; + } + + createNewFormContorl(r: BankInfo, propName: string): FormControl { + let m = new FormControl(r[propName], Validators.required); + m.valueChanges.subscribe(val => { + r[propName] = val; + }); + return m; + } + disconnect(collectionViewer: CollectionViewer): void { - this.filterSubject.complete(); + this._ObjectsSubject$.complete(); + this._loadingSubject$.complete(); } } diff --git a/src/modules/sites/bank-info/service/bank-info.service.ts b/src/modules/sites/bank-info/service/bank-info.service.ts index 69d8339..c08f928 100644 --- a/src/modules/sites/bank-info/service/bank-info.service.ts +++ b/src/modules/sites/bank-info/service/bank-info.service.ts @@ -2,9 +2,11 @@ import { Injectable, Inject } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; +import { map, takeUntil } from 'rxjs/operators'; import { BankInfo } from '../model/bank-info.model'; import { API_BASE_URL } from 'src/modules/common/type/injection-token.type'; import { Page } from 'src/modules/common/data/model/page'; +import { FormArray } from '@angular/forms'; @Injectable({ providedIn: 'root' @@ -22,6 +24,12 @@ export class BankInfoService { ); } + public getAllAsFormArray(): Observable { + return this.httpClient.get( + `${this.apiBaseUrl}/bank_info/test`, + {} + ); + } // public getUser(id: number): Observable { // return this.httpClient.get(`${this.apiBaseUrl}/users/${id}`, {}); // }