refactor: folders and components
This commit is contained in:
src/components
common
data-spinner
footer
loading-indicator
notification
schedule
table-header
table
tabs
89
src/components/schedule/table/table.component.ts
Normal file
89
src/components/schedule/table/table.component.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import {Component, Input, OnChanges} from '@angular/core';
|
||||
import {MatTableDataSource, MatTableModule} from "@angular/material/table";
|
||||
import {MatIcon} from "@angular/material/icon";
|
||||
import {DatePipe} from "@angular/common";
|
||||
import {addDays} from "@progress/kendo-date-math";
|
||||
import {MatDivider} from "@angular/material/divider";
|
||||
import {Schedule} from "@page/schedule/schedule.component";
|
||||
import {DataSpinnerComponent} from "@component/common/data-spinner/data-spinner.component";
|
||||
|
||||
interface TableData {
|
||||
pairNumber: number;
|
||||
data: Dictionary;
|
||||
}
|
||||
|
||||
interface Dictionary {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-table',
|
||||
standalone: true,
|
||||
imports: [
|
||||
MatTableModule,
|
||||
MatIcon,
|
||||
DatePipe,
|
||||
MatDivider,
|
||||
DataSpinnerComponent
|
||||
],
|
||||
templateUrl: './table.component.html',
|
||||
styleUrl: './table.component.css',
|
||||
})
|
||||
|
||||
export class TableComponent implements OnChanges {
|
||||
protected tableDataSource: MatTableDataSource<TableData> = new MatTableDataSource<TableData>([]);
|
||||
protected daysOfWeek: string[] = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'];
|
||||
protected displayedColumns: string[] = ['pairNumber'];
|
||||
protected dataSource: Schedule[] = [];
|
||||
protected isOneGroup: boolean = false;
|
||||
|
||||
@Input() currentWeek!: number;
|
||||
@Input() startWeek!: Date;
|
||||
@Input() isLoad: boolean = false;
|
||||
|
||||
@Input() set data(schedule: Schedule[]) {
|
||||
this.dataSource = schedule;
|
||||
this.convertData();
|
||||
this.isOneGroup = schedule.every((item, _, array) => item.group === array[0].group);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: any) {
|
||||
if (changes.startWeek && !changes.startWeek.firstChange) {
|
||||
this.convertData();
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.displayedColumns = this.displayedColumns.concat(this.daysOfWeek);
|
||||
}
|
||||
|
||||
private convertData() {
|
||||
this.isLoad = true;
|
||||
let tableData: TableData[] = [];
|
||||
|
||||
for (let i: number = 1; i <= 7; i++) {
|
||||
let convertedData: TableData = {
|
||||
pairNumber: i,
|
||||
data: {}
|
||||
};
|
||||
|
||||
for (let k: number = 1; k < 7; k++) {
|
||||
convertedData.data[k.toString()] = this.dataSource.filter(x =>
|
||||
x.pairNumber === i
|
||||
&& x.dayOfWeek === k
|
||||
&& x.isEven === (this.currentWeek % 2 === 0));
|
||||
}
|
||||
|
||||
tableData.push(convertedData);
|
||||
}
|
||||
|
||||
this.tableDataSource = new MatTableDataSource<TableData>(tableData);
|
||||
this.isLoad = false;
|
||||
}
|
||||
|
||||
protected checkAvailableData(data: any[]): boolean {
|
||||
return data && data.length !== 0 && data.every(x => x !== null);
|
||||
}
|
||||
|
||||
protected readonly addDays = addDays;
|
||||
}
|
Reference in New Issue
Block a user