issue-77 #105

Merged
sebastian merged 17 commits from issue-77 into master 2024-03-16 10:12:35 +01:00
6 changed files with 219 additions and 0 deletions
Showing only changes of commit 49119b2549 - Show all commits

View File

@ -0,0 +1,24 @@
/**
* API Title
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
export interface TaskRepeatWeekDayInfo {
/**
* number repeating days
*/
offset: number;
/**
* internal identifier of task
*/
taskID: number;
}

View File

@ -0,0 +1,31 @@
/**
* API Title
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { TaskRepeatWeekDayInfo } from './taskRepeatWeekDayInfo';
export interface TaskRepeatWeekInfo {
deadlineStrategy: TaskRepeatWeekInfo.DeadlineStrategyEnum;
/**
* Date until the tasks repeat
*/
endDate: string;
weekDayInfos: Array<TaskRepeatWeekDayInfo>;
}
export namespace TaskRepeatWeekInfo {
export type DeadlineStrategyEnum = 'DEADLINE_EQUAL_START' | 'DEADLINE_FIT_START';
export const DeadlineStrategyEnum = {
EqualStart: 'DEADLINE_EQUAL_START' as DeadlineStrategyEnum,
FitStart: 'DEADLINE_FIT_START' as DeadlineStrategyEnum
};
}

View File

@ -0,0 +1,10 @@
#deadline-strategy-form {
margin-top: 10px;
padding-left: 10px;
padding-right: 10px;
}
#endDate-form {
padding-left: 10px;
padding-right: 10px;
}

View File

@ -0,0 +1,50 @@
<h1 mat-dialog-title>Configure Weekly Repeating Tasks</h1>
<form [formGroup]="repeatingOffsetForm" *ngIf="repeatingOffsetForm != undefined">
<div formArrayName="offsets">
<mat-accordion>
<div *ngFor="let task of offsets.controls; let i = index" [formGroupName]="i">
<mat-expansion-panel hideToggle>
<mat-expansion-panel-header>
<mat-panel-title>{{getDayOfWeek(tasks[i].startDate)}}</mat-panel-title>
<mat-panel-description>{{formatDate(tasks[i].startDate)}}</mat-panel-description>
</mat-expansion-panel-header>
<p>Taskname: {{tasks[i].taskName}}</p>
<p>Eta: {{tasks[i].eta}} Minutes</p>
<p>Startdate: {{formatDate(tasks[i].startDate)}}</p>
<p>Deadline: {{formatDate(tasks[i].deadline)}}</p>
<mat-form-field appearance="outline" class="long-form">
<mat-label>Repeating-Offset</mat-label>
<input matInput formControlName="offsetCtrl">
<mat-hint>Number of weeks until the task is to be repeated</mat-hint>
</mat-form-field>
<mat-action-row>
<button mat-icon-button color="warn" (click)="removeTaskFromRepeatingList(tasks[i], i)"><mat-icon>delete</mat-icon></button>
</mat-action-row>
</mat-expansion-panel>
</div>
</mat-accordion>
</div>
<mat-form-field appearance="outline" class="long-form" id="deadline-strategy-form">
<mat-label>Deadline-Strategy</mat-label>
<mat-select formControlName="deadlineStrategyCtrl">
<mat-option *ngFor="let deadlineStrategy of availableDeadlineStrategys" [value]="deadlineStrategy">
{{deadlineStrategy}}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" class="long-form" id="endDate-form">
<mat-label>Ending Date</mat-label>
<input matInput [matDatepicker]="picker" formControlName="endingDateCtrl">
<mat-hint>MM/DD/YYYY</mat-hint>
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
<div mat-dialog-actions align="end">
<button mat-raised-button (click)="cancel()">Cancel</button>
<button mat-raised-button color="primary" [disabled]="repeatingOffsetForm.invalid" (click)="saveRepeatingTask()">Save</button>
</div>
</form>

View File

@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TaskWeeklySeriesCreatorComponent } from './task-weekly-series-creator.component';
describe('TaskWeeklySeriesCreatorComponent', () => {
let component: TaskWeeklySeriesCreatorComponent;
let fixture: ComponentFixture<TaskWeeklySeriesCreatorComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TaskWeeklySeriesCreatorComponent]
});
fixture = TestBed.createComponent(TaskWeeklySeriesCreatorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,83 @@
import {Component, Inject, OnInit} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {TaskEntityInfo, TaskRepeatDayInfo, TaskRepeatWeekDayInfo, TaskseriesService} from "../../../api";
import * as moment from "moment";
import {FormArray, FormBuilder, FormGroup, Validators} from "@angular/forms";
import DeadlineStrategyEnum = TaskRepeatDayInfo.DeadlineStrategyEnum;
@Component({
selector: 'app-task-weekly-series-creator',
templateUrl: './task-weekly-series-creator.component.html',
styleUrls: ['./task-weekly-series-creator.component.css']
})
export class TaskWeeklySeriesCreatorComponent implements OnInit{
repeatingOffsetForm: FormGroup | undefined
availableDeadlineStrategys: DeadlineStrategyEnum[] = ["DEADLINE_EQUAL_START", "DEADLINE_FIT_START"]
constructor(private dialogRef: MatDialogRef<TaskWeeklySeriesCreatorComponent>,
private taskRepeatingService: TaskseriesService,
@Inject(MAT_DIALOG_DATA) public tasks: TaskEntityInfo[],
private formbuilder: FormBuilder) {
}
ngOnInit(): void {
this.repeatingOffsetForm = this.formbuilder.group({
offsets: this.formbuilder.array(this.tasks.map(task => this.formbuilder.group({
offsetCtrl: ['', [Validators.required, Validators.min(1)]]
}))),
deadlineStrategyCtrl: ['', Validators.required],
endingDateCtrl: ['', Validators.required]
})
}
getDayOfWeek(date: string) {
return moment(date).format("dddd")
}
formatDate(date: string): string {
return moment(date).format("dd, DD. MMMM YYYY")
}
removeTaskFromRepeatingList(task: TaskEntityInfo, formIndex: number) {
this.tasks = this.tasks.filter(t => t.taskID !== task.taskID);
this.deleteOffset(formIndex)
}
get offsets() {
return this.repeatingOffsetForm!.controls["offsets"] as FormArray
}
deleteOffset(taskIndex: number) {
this.offsets.removeAt(taskIndex);
}
saveRepeatingTask() {
const weekDayInfos: TaskRepeatWeekDayInfo[] = []
const formArrayValues: {offsetCtrl: string}[] = this.offsets.value
for(let i=0; i<formArrayValues.length; i++) {
weekDayInfos.push({
taskID: this.tasks[i].taskID,
offset: Number(formArrayValues[i].offsetCtrl) * 7
})
}
this.taskRepeatingService.tasksTaskseriesWeeklyPost({
deadlineStrategy: this.repeatingOffsetForm!.controls['deadlineStrategyCtrl']!.value!,
endDate: moment(this.repeatingOffsetForm!.controls['endingDateCtrl']!.value!).format('YYYY-MM-DDTHH:mm:ss.SSSZ'),
weekDayInfos: weekDayInfos
}).subscribe({
next: resp => {
this.dialogRef.close(true)
}
})
}
cancel() {
this.dialogRef.close(false);
}
}