barker/bookie/src/app/sales/tables-dialog/tables-dialog.component.ts

42 lines
1.1 KiB
TypeScript

import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { Observable } from 'rxjs';
import { Table } from "../../core/table";
@Component({
selector: 'app-tables-dialog',
templateUrl: './tables-dialog.component.html',
styleUrls: ['./tables-dialog.component.css']
})
export class TablesDialogComponent {
list: Table[];
canChooseRunning: boolean;
selected: Table;
constructor(
public dialogRef: MatDialogRef<TablesDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: { list: Observable<Table[]>, canChooseRunning: boolean }) {
this.data.list.subscribe((list: Table[]) => {
this.list = list;
});
this.canChooseRunning = data.canChooseRunning;
this.selected = null;
}
select(t: Table) {
if (!this.canChooseRunning && t.status) {
return;
}
if (this.selected === t) {
this.selected = null;
} else {
this.selected = t;
}
}
accept(): void {
if (this.selected !== null) {
this.dialogRef.close(this.selected);
}
}
}