issue-32 #34

Merged
sebastian merged 6 commits from issue-32 into master 2023-10-29 12:35:11 +01:00
11 changed files with 220 additions and 9 deletions
Showing only changes of commit 9de0e1a119 - Show all commits

View File

@ -4,9 +4,8 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="List missed Schedules"> <list default="true" id="3a869f59-290a-4ab2-b036-a878ce801bc4" name="Changes" comment="Forget single schedule">
<change beforePath="$PROJECT_DIR$/../frontend/src/app/missed-schedules/missed-schedules.component.html" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/missed-schedules/missed-schedules.component.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/core/api/controller/ScheduleController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../frontend/src/app/missed-schedules/missed-schedules.component.ts" beforeDir="false" afterPath="$PROJECT_DIR$/../frontend/src/app/missed-schedules/missed-schedules.component.ts" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -251,7 +250,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1698570969924</updated> <updated>1698570969924</updated>
</task> </task>
<option name="localTasksCounter" value="19" /> <task id="LOCAL-00019" summary="Forget single schedule">
<option name="closed" value="true" />
<created>1698573369764</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1698573369764</updated>
</task>
<option name="localTasksCounter" value="20" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -277,7 +284,8 @@
<MESSAGE value="Load worked minutes when reloading dashboard" /> <MESSAGE value="Load worked minutes when reloading dashboard" />
<MESSAGE value="Check if there is another active schedule when starting task now" /> <MESSAGE value="Check if there is another active schedule when starting task now" />
<MESSAGE value="List missed Schedules" /> <MESSAGE value="List missed Schedules" />
<option name="LAST_COMMIT_MESSAGE" value="List missed Schedules" /> <MESSAGE value="Forget single schedule" />
<option name="LAST_COMMIT_MESSAGE" value="Forget single schedule" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View File

@ -231,4 +231,25 @@ public class ScheduleController {
List<BasicTaskSchedule> schedules = taskScheduleService.loadMissedSchedules(user.get()); List<BasicTaskSchedule> schedules = taskScheduleService.loadMissedSchedules(user.get());
return ResponseEntity.ok(schedules.stream().map(ScheduleInfo::new).toList()); return ResponseEntity.ok(schedules.stream().map(ScheduleInfo::new).toList());
} }
@DeleteMapping("/schedules/{scheduleIDs}/all")
public ResponseEntity<?> deleteSchedules(@PathVariable long[] scheduleIDs) {
List<BasicTaskSchedule> schedulesToDelete = new LinkedList<>();
for(long scheduleID: scheduleIDs) {
PermissionResult<BasicTaskSchedule> permissionResult = taskScheduleService.getSchedulePermissions(scheduleID, SecurityContextHolder.getContext().getAuthentication().getName());
if(!permissionResult.isHasPermissions()) {
return ResponseEntity.status(403).body(new SimpleStatusResponse("failed"));
}
if(permissionResult.getExitCode() == ServiceExitCode.MISSING_ENTITY) {
return ResponseEntity.status(404).body(new SimpleStatusResponse("failed"));
}
schedulesToDelete.add(permissionResult.getResult());
}
for(BasicTaskSchedule schedule : schedulesToDelete) {
this.taskScheduleService.deleteBasicSchedule(schedule);
}
return ResponseEntity.ok(new SimpleStatusResponse("success"));
}
} }

View File

@ -512,6 +512,65 @@ export class ScheduleService {
); );
} }
/**
* deletes multiple schedules
* deletes multiple schedules at once
* @param scheduleIDs internal ids of schedules to delete
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public schedulesScheduleIDsAllDelete(scheduleIDs: Array<number>, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<Array<SimpleStatusResponse>>;
public schedulesScheduleIDsAllDelete(scheduleIDs: Array<number>, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpResponse<Array<SimpleStatusResponse>>>;
public schedulesScheduleIDsAllDelete(scheduleIDs: Array<number>, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<HttpEvent<Array<SimpleStatusResponse>>>;
public schedulesScheduleIDsAllDelete(scheduleIDs: Array<number>, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext}): Observable<any> {
if (scheduleIDs === null || scheduleIDs === undefined) {
throw new Error('Required parameter scheduleIDs was null or undefined when calling schedulesScheduleIDsAllDelete.');
}
let localVarHeaders = this.defaultHeaders;
let localVarCredential: string | undefined;
// authentication (API_TOKEN) required
localVarCredential = this.configuration.lookupCredential('API_TOKEN');
if (localVarCredential) {
localVarHeaders = localVarHeaders.set('Authorization', 'Bearer ' + localVarCredential);
}
let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept;
if (localVarHttpHeaderAcceptSelected === undefined) {
// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json'
];
localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (localVarHttpHeaderAcceptSelected !== undefined) {
localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected);
}
let localVarHttpContext: HttpContext | undefined = options && options.context;
if (localVarHttpContext === undefined) {
localVarHttpContext = new HttpContext();
}
let responseType_: 'text' | 'json' = 'json';
if(localVarHttpHeaderAcceptSelected && localVarHttpHeaderAcceptSelected.startsWith('text')) {
responseType_ = 'text';
}
return this.httpClient.delete<Array<SimpleStatusResponse>>(`${this.configuration.basePath}/schedules/${encodeURIComponent(String(scheduleIDs))}/all`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
withCredentials: this.configuration.withCredentials,
headers: localVarHeaders,
observe: observe,
reportProgress: reportProgress
}
);
}
/** /**
* get number of active minutes * get number of active minutes
* get number of worked minutes today * get number of worked minutes today

View File

@ -70,6 +70,7 @@ import { TaskOverviewComponent } from './dashboard/task-overview/task-overview.c
import { ForgottenTaskStartDialogComponent } from './dashboard/forgotten-task-start-dialog/forgotten-task-start-dialog.component'; import { ForgottenTaskStartDialogComponent } from './dashboard/forgotten-task-start-dialog/forgotten-task-start-dialog.component';
import {MatAutocompleteModule} from "@angular/material/autocomplete"; import {MatAutocompleteModule} from "@angular/material/autocomplete";
import { MissedSchedulesComponent } from './missed-schedules/missed-schedules.component'; import { MissedSchedulesComponent } from './missed-schedules/missed-schedules.component';
import { MissedScheduleForgetConfirmationDialogComponent } from './missed-schedules/missed-schedule-forget-confirmation-dialog/missed-schedule-forget-confirmation-dialog.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
@ -102,7 +103,8 @@ import { MissedSchedulesComponent } from './missed-schedules/missed-schedules.co
TaskgroupOverviewComponent, TaskgroupOverviewComponent,
TaskOverviewComponent, TaskOverviewComponent,
ForgottenTaskStartDialogComponent, ForgottenTaskStartDialogComponent,
MissedSchedulesComponent MissedSchedulesComponent,
MissedScheduleForgetConfirmationDialogComponent
], ],
imports: [ imports: [
BrowserModule, BrowserModule,

View File

@ -0,0 +1,9 @@
<h1 mat-dialog-title>Forget All Missed Schedules </h1>
<div mat-dialog-content>
<p>Are you sure you want to forget all missed schedules? This would delete <b>{{this.missedSchedules.length}}</b> schedules.</p>
<p>This <b>cannot</b> be undone!</p>
</div>
<div mat-dialog-actions align="end">
<button mat-raised-button (click)="cancel()">Cancel</button>
<button mat-raised-button color="warn" (click)="confirm()">Confirm</button>
</div>

View File

@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MissedScheduleForgetConfirmationDialogComponent } from './missed-schedule-forget-confirmation-dialog.component';
describe('MissedScheduleForgetConfirmationDialogComponent', () => {
let component: MissedScheduleForgetConfirmationDialogComponent;
let fixture: ComponentFixture<MissedScheduleForgetConfirmationDialogComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [MissedScheduleForgetConfirmationDialogComponent]
});
fixture = TestBed.createComponent(MissedScheduleForgetConfirmationDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,40 @@
import {Component, Inject} from '@angular/core';
import {MAT_DIALOG_DATA, MatDialogRef} from "@angular/material/dialog";
import {ScheduleInfo, ScheduleService} from "../../../api";
import {MatSnackBar} from "@angular/material/snack-bar";
@Component({
selector: 'app-missed-schedule-forget-confirmation-dialog',
templateUrl: './missed-schedule-forget-confirmation-dialog.component.html',
styleUrls: ['./missed-schedule-forget-confirmation-dialog.component.css']
})
export class MissedScheduleForgetConfirmationDialogComponent {
constructor(@Inject(MAT_DIALOG_DATA) public missedSchedules: ScheduleInfo[],
private dialogRef: MatDialogRef<MissedScheduleForgetConfirmationDialogComponent>,
private scheduleService: ScheduleService,
private snackbar: MatSnackBar) {
}
cancel() {
this.dialogRef.close();
}
confirm() {
this.scheduleService.schedulesScheduleIDsAllDelete(this.missedSchedules.map(schedule => schedule.scheduleID)).subscribe({
next: resp => {
this.dialogRef.close(resp);
},
error: err => {
if(err.status == 403) {
this.snackbar.open("No permission", "", {duration: 2000});
} else if(err.status == 404) {
this.snackbar.open("Not found", "", {duration: 2000});
} else {
this.snackbar.open("Unexpected error", "", {duration: 2000});
}
}
})
}
}

View File

@ -15,5 +15,5 @@
</div> </div>
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
<button mat-raised-button color="warn" class="forget-all-btn"><mat-icon>delete</mat-icon>Forget All</button> <button mat-raised-button color="warn" class="forget-all-btn" *ngIf="missedSchedules.length > 0" (click)="forgetAllSchedules()"><mat-icon>delete</mat-icon>Forget All</button>
</div> </div>

View File

@ -2,6 +2,10 @@ import {Component, OnInit} from '@angular/core';
import {ScheduleInfo, ScheduleService} from "../../api"; import {ScheduleInfo, ScheduleService} from "../../api";
import {NavigationLink} from "../navigation-link-list/navigation-link-list.component"; import {NavigationLink} from "../navigation-link-list/navigation-link-list.component";
import {MatSnackBar} from "@angular/material/snack-bar"; import {MatSnackBar} from "@angular/material/snack-bar";
import {MatDialog} from "@angular/material/dialog";
import {
MissedScheduleForgetConfirmationDialogComponent
} from "./missed-schedule-forget-confirmation-dialog/missed-schedule-forget-confirmation-dialog.component";
@Component({ @Component({
selector: 'app-missed-schedules', selector: 'app-missed-schedules',
@ -22,7 +26,8 @@ export class MissedSchedulesComponent implements OnInit{
} }
] ]
constructor(private scheduleService: ScheduleService, constructor(private scheduleService: ScheduleService,
private snackbar: MatSnackBar) { private snackbar: MatSnackBar,
private dialog: MatDialog) {
} }
ngOnInit() { ngOnInit() {
@ -49,4 +54,13 @@ export class MissedSchedulesComponent implements OnInit{
} }
}) })
} }
forgetAllSchedules() {
const dialogRef = this.dialog.open(MissedScheduleForgetConfirmationDialogComponent, {data: this.missedSchedules, width: "400px"});
dialogRef.afterClosed().subscribe(res => {
if(res != undefined) {
this.missedSchedules = [];
}
})
}
} }

View File

@ -1717,7 +1717,44 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SimpleStatusResponse' $ref: '#/components/schemas/SimpleStatusResponse'
/schedules/{scheduleIDs}/all:
delete:
security:
- API_TOKEN: []
tags:
- schedule
description: deletes multiple schedules at once
summary: deletes multiple schedules
parameters:
- name: scheduleIDs
in: path
description: internal ids of schedules to delete
required: true
schema:
type: array
items:
type: number
responses:
200:
description: Operation successfull
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/SimpleStatusResponse'
403:
description: No permission
content:
application/json:
schema:
$ref: '#/components/schemas/SimpleStatusResponse'
404:
description: Schedule not found
content:
application/json:
schema:
$ref: '#/components/schemas/SimpleStatusResponse'
components: components:
securitySchemes: securitySchemes:
API_TOKEN: API_TOKEN: