fix: Split admin comm service into multiple services
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<h1 mat-dialog-title>Tworzenie wpisów do jadłospisu</h1>
|
||||
<mat-dialog-content>
|
||||
<mat-radio-group [(ngModel)]="type">
|
||||
<mat-radio-button value="day">Dzień</mat-radio-button>
|
||||
<mat-radio-button value="week">Tydzień</mat-radio-button>
|
||||
<mat-radio-button value="file">Plik</mat-radio-button>
|
||||
</mat-radio-group>
|
||||
<div>
|
||||
@switch (type) {
|
||||
@case ("day") {
|
||||
<app-date-selector [filter]="filter" [(date)]="day"></app-date-selector>
|
||||
}
|
||||
@case ("week") {
|
||||
<mat-form-field>
|
||||
<mat-label>Wybierz tydzień</mat-label>
|
||||
<mat-date-range-input [rangePicker]="picker" [formGroup]="range">
|
||||
<input matStartDate formControlName="start">
|
||||
<input matEndDate formControlName="end">
|
||||
</mat-date-range-input>
|
||||
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
|
||||
<mat-date-range-picker #picker></mat-date-range-picker>
|
||||
</mat-form-field>
|
||||
}
|
||||
@case ("file") {
|
||||
<button mat-flat-button color="accent" (click)="activateUpload()">Otwórz okno</button>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions>
|
||||
<button mat-raised-button color="accent" (click)="submit()">Utwórz pozycje</button>
|
||||
<button mat-button mat-dialog-close>Anuluj</button>
|
||||
</mat-dialog-actions>
|
||||
@@ -0,0 +1,39 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
|
||||
import { MenuAddComponent } from './menu-add.component'
|
||||
import {
|
||||
MAT_DIALOG_DATA,
|
||||
MatDialogModule,
|
||||
MatDialogRef,
|
||||
} from '@angular/material/dialog'
|
||||
import { MatRadioModule } from '@angular/material/radio'
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||
|
||||
describe('MenuAddComponent', () => {
|
||||
let component: MenuAddComponent
|
||||
let fixture: ComponentFixture<MenuAddComponent>
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [MenuAddComponent],
|
||||
providers: [
|
||||
{ provide: MAT_DIALOG_DATA, useValue: {} },
|
||||
{ provide: MatDialogRef, useValue: {} },
|
||||
],
|
||||
imports: [
|
||||
MatDialogModule,
|
||||
MatRadioModule,
|
||||
ReactiveFormsModule,
|
||||
FormsModule,
|
||||
],
|
||||
}).compileComponents()
|
||||
|
||||
fixture = TestBed.createComponent(MenuAddComponent)
|
||||
component = fixture.componentInstance
|
||||
fixture.detectChanges()
|
||||
})
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy()
|
||||
})
|
||||
})
|
||||
60
src/app/admin-view/menu-edit/menu-add/menu-add.component.ts
Normal file
60
src/app/admin-view/menu-edit/menu-add/menu-add.component.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Component } from '@angular/core'
|
||||
import { MenuUploadComponent } from '../menu-upload/menu-upload.component'
|
||||
import { MatDialog, MatDialogRef } from '@angular/material/dialog'
|
||||
import { FDSelection, weekendFilter } from 'src/app/fd.da'
|
||||
import { FormControl, FormGroup } from '@angular/forms'
|
||||
import { MAT_DATE_RANGE_SELECTION_STRATEGY } from '@angular/material/datepicker'
|
||||
import { DateTime } from 'luxon'
|
||||
|
||||
@Component({
|
||||
selector: 'app-menu-add',
|
||||
templateUrl: './menu-add.component.html',
|
||||
styleUrl: './menu-add.component.scss',
|
||||
providers: [
|
||||
{ provide: MAT_DATE_RANGE_SELECTION_STRATEGY, useClass: FDSelection },
|
||||
],
|
||||
standalone: false,
|
||||
})
|
||||
export class MenuAddComponent {
|
||||
type: string | undefined
|
||||
filter = weekendFilter
|
||||
|
||||
day: string = DateTime.now().toISODate()
|
||||
|
||||
range = new FormGroup({
|
||||
start: new FormControl<DateTime | null>(null),
|
||||
end: new FormControl<DateTime | null>(null),
|
||||
})
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<MenuAddComponent>,
|
||||
private dialog: MatDialog
|
||||
) {}
|
||||
|
||||
submit() {
|
||||
switch (this.type) {
|
||||
case 'day':
|
||||
this.dialogRef.close({ type: 'day', value: this.day })
|
||||
break
|
||||
case 'week':
|
||||
this.dialogRef.close({
|
||||
type: 'week',
|
||||
value: { start: this.range.value.start?.toISODate(), count: 5 },
|
||||
})
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
activateUpload() {
|
||||
this.dialog
|
||||
.open(MenuUploadComponent)
|
||||
.afterClosed()
|
||||
.subscribe(data => {
|
||||
if (data) {
|
||||
this.dialogRef.close({ type: 'file', ...data })
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user