Created a period table for date ranges and made the recipes dependent on it instead of having arbitrary date ranges. This will enable easy copying into new months.

This commit is contained in:
2022-07-28 22:16:28 +05:30
parent 492b80e116
commit 3eb715e2de
68 changed files with 996 additions and 353 deletions
@@ -0,0 +1,16 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
import { Period } from '../period';
export class PeriodListDataSource extends DataSource<Period> {
constructor(public data: Period[]) {
super();
}
connect(): Observable<Period[]> {
return observableOf(this.data);
}
disconnect() {}
}
@@ -0,0 +1,31 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Periods</mat-card-title>
<a mat-button [routerLink]="['/periods', 'new']">
<mat-icon>add_box</mat-icon>
Add
</a>
</mat-card-title-group>
<mat-card-content>
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
<!-- Valid From Column -->
<ng-container matColumnDef="validFrom">
<mat-header-cell *matHeaderCellDef>Valid From</mat-header-cell>
<mat-cell *matCellDef="let row">
<a [routerLink]="['/periods', row.id]">
{{ row.validFrom }}
</a>
</mat-cell>
</ng-container>
<!-- Valid Till Column -->
<ng-container matColumnDef="validTill">
<mat-header-cell *matHeaderCellDef>Valid Till</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.validTill }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>
</mat-card-content>
</mat-card>
@@ -0,0 +1,25 @@
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { PeriodListComponent } from './period-list.component';
describe('PeriodListComponent', () => {
let component: PeriodListComponent;
let fixture: ComponentFixture<PeriodListComponent>;
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, RouterTestingModule],
declarations: [PeriodListComponent],
}).compileComponents();
fixture = TestBed.createComponent(PeriodListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should compile', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,33 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Period } from '../period';
import { PeriodListDataSource } from './period-list-datasource';
@Component({
selector: 'app-period-list',
templateUrl: './period-list.component.html',
styleUrls: ['./period-list.component.css'],
})
export class PeriodListComponent implements OnInit {
dataSource: PeriodListDataSource;
list: Period[] = [];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['validFrom', 'validTill'];
constructor(private route: ActivatedRoute) {
this.dataSource = new PeriodListDataSource(this.list);
}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { list: Period[] };
this.list = data.list;
});
this.dataSource = new PeriodListDataSource(this.list);
}
}