Blacked and isorted the python files
Prettied and eslinted the typescript/html files
This commit is contained in:
@ -1,16 +1,14 @@
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
export class DiscountDataSource extends DataSource<{name: string, discount: number}> {
|
||||
|
||||
constructor(private data: {name: string, discount: number}[]) {
|
||||
export class DiscountDataSource extends DataSource<{ name: string; discount: number }> {
|
||||
constructor(private data: { name: string; discount: number }[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<{name: string, discount: number}[]> {
|
||||
connect(): Observable<{ name: string; discount: number }[]> {
|
||||
return observableOf(this.data);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
disconnect() {}
|
||||
}
|
||||
|
||||
@ -2,11 +2,10 @@
|
||||
<mat-dialog-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<mat-table #table [dataSource]="dataSource" formArrayName="discounts">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.name }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Discount Column -->
|
||||
@ -14,13 +13,13 @@
|
||||
<mat-header-cell *matHeaderCellDef class="center" fxFlex>Discount</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row; let i = index" class="center" [formGroupName]="i" fxFlex>
|
||||
<mat-form-field>
|
||||
<input matInput type="number" formControlName="discount" autocomplete="off">
|
||||
<input matInput type="number" formControlName="discount" autocomplete="off" />
|
||||
</mat-form-field>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
|
||||
@ -8,9 +8,8 @@ describe('DiscountComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ DiscountComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [DiscountComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@ -1,13 +1,14 @@
|
||||
import { Component, Inject } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Observable } from 'rxjs';
|
||||
import { FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||
|
||||
import { DiscountDataSource } from './discount-datasource';
|
||||
|
||||
@Component({
|
||||
selector: 'app-modifiers',
|
||||
templateUrl: './discount.component.html',
|
||||
styleUrls: ['./discount.component.css']
|
||||
styleUrls: ['./discount.component.css'],
|
||||
})
|
||||
export class DiscountComponent {
|
||||
list: any[];
|
||||
@ -19,26 +20,29 @@ export class DiscountComponent {
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<DiscountComponent>,
|
||||
private fb: FormBuilder,
|
||||
@Inject(MAT_DIALOG_DATA) public data: Observable<any[]>
|
||||
@Inject(MAT_DIALOG_DATA) public data: Observable<any[]>,
|
||||
) {
|
||||
this.createForm();
|
||||
this.data.subscribe((list: any[]) => {
|
||||
this.list = list;
|
||||
this.form.setControl('discounts', this.fb.array(
|
||||
this.list.map(
|
||||
x => this.fb.group({
|
||||
this.form.setControl(
|
||||
'discounts',
|
||||
this.fb.array(
|
||||
this.list.map((x) =>
|
||||
this.fb.group({
|
||||
name: [x.name],
|
||||
discount: ['', [Validators.min(0), Validators.max(100)]]
|
||||
})
|
||||
)
|
||||
));
|
||||
discount: ['', [Validators.min(0), Validators.max(100)]],
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new DiscountDataSource(list);
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
discounts: ''
|
||||
discounts: '',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user