2019-09-20 16:50:54 +09:00

217 lines
6.0 KiB
TypeScript

import { DataSource } from '@angular/cdk/table';
import { BehaviorSubject, Observable, merge, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { CollectionViewer } from '@angular/cdk/collections';
import { FixBonus } from 'src/modules/special/fix-bonus/model/fix-bonus.model';
import { FixBonusService } from 'src/modules/special/fix-bonus/service/fix-bonus.service';
import { FormControl, FormGroup, Validators, FormArray } from '@angular/forms';
const ELEMENT_DATA: FixBonus[] = [
{
gameType: 'gameType1',
gameDescription: '크로스',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType2',
gameDescription: '크로스',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType3',
gameDescription: '크로스',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType4',
gameDescription: '가상축구',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType5',
gameDescription: '가상축구',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType6',
gameDescription: '가상축구',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType7',
gameDescription: '스페셜',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType8',
gameDescription: '스페셜',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType9',
gameDescription: '스페셜',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType10',
gameDescription: '실시간',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType11',
gameDescription: '실시간',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType12',
gameDescription: '실시간',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
},
{
gameType: 'gameType13',
gameDescription: '개경주',
userDescription:
'[ 3폴더 ] 이상 조합가능 보너스 ㅡㅡㅡ 1.2배당 이상경기만 인정',
odds: '1.03',
folder: 3,
allow: false,
createdAt: null,
updatedAt: null
}
];
export class FixBonusDataSource extends DataSource<FixBonus> {
private _objectStore: FixBonus[] = [];
private _ObjectsSubject$ = new BehaviorSubject<FixBonus[]>([]);
private _loadingSubject$ = new BehaviorSubject<boolean>(false);
public loading$ = this._loadingSubject$.asObservable();
public formg: FormGroup;
constructor(private fixBonusService: FixBonusService) {
super();
}
connect(collectionViewer: CollectionViewer): Observable<FixBonus[]> {
// return this.fixBonusService.getAll().pipe(
// map(res => {
// res.forEach(m => this._objectStore.push(m as FixBonus));
// this._ObjectsSubject$.next(this._objectStore);
// let fa = <FormArray>this.formg.get('formarray');
// res.forEach(r => fa.push(this.createRowFormGroup(r)));
// return res;
// })
// );
return of(ELEMENT_DATA).pipe(
map(res => {
res.forEach(m => this._objectStore.push(m as FixBonus));
this._ObjectsSubject$.next(this._objectStore);
let fa = <FormArray>this.formg.get('formarray');
res.forEach(r => fa.push(this.createRowFormGroup(r)));
return res;
})
);
}
createRowFormGroup(r: FixBonus): FormGroup {
let f = new FormGroup({
gameType: this.createNewFormContorl(r, 'gameType'),
gameDescription: this.createNewFormContorl(r, 'gameDescription'),
userDescription: this.createNewFormContorl(r, 'userDescription'),
odds: this.createNewFormContorl(r, 'odds'),
folder: this.createNewFormContorl(r, 'folder'),
allow: this.createNewFormContorl(r, 'allow')
});
return f;
}
createNewFormContorl(r: FixBonus, 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._ObjectsSubject$.complete();
this._loadingSubject$.complete();
}
}