Skip to content

Commit

Permalink
Use generic delete dialog for resetting, cleanup (ls1intum#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxr96 authored and Stephan Krusche committed Dec 4, 2019
1 parent 461a723 commit 9b44b15
Show file tree
Hide file tree
Showing 70 changed files with 512 additions and 793 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public ResponseEntity<Resource> cleanup(@PathVariable Long id, @RequestParam(def
return forbidden();
exerciseService.cleanup(id, deleteRepositories);
log.info("Cleanup build plans was successful for Exercise : {}", id);
return ResponseEntity.ok().headers(HeaderUtil.createAlert(applicationName, "Cleanup was successful. Repositories have been deleted: " + deleteRepositories, "")).build();
return ResponseEntity.ok().build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ <h2>
[entityTitle]="notification.id"
deleteQuestion="artemisApp.notificationManagement.delete.question"
(delete)="deleteNotification(notification.id)"
[dialogError]="dialogError$"
>
<fa-icon [icon]="'times'"></fa-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { UserService } from 'app/core/user/user.service';
import { AccountService } from 'app/core/auth/account.service';
import { SystemNotification, SystemNotificationService } from 'app/entities/system-notification';
import * as moment from 'moment';
import { onError } from 'app/utils/global.utils';
import { Subject } from 'rxjs';

@Component({
selector: 'jhi-notification-mgmt',
Expand All @@ -30,6 +32,9 @@ export class NotificationMgmtComponent implements OnInit, OnDestroy {
previousPage: number;
reverse: boolean;

private dialogErrorSource = new Subject<string>();
dialogError$ = this.dialogErrorSource.asObservable();

constructor(
private userService: UserService,
private systemNotificationService: SystemNotificationService,
Expand Down Expand Up @@ -65,6 +70,7 @@ export class NotificationMgmtComponent implements OnInit, OnDestroy {
*/
ngOnDestroy() {
this.routeData.unsubscribe();
this.dialogErrorSource.unsubscribe();
}

/**
Expand All @@ -79,12 +85,16 @@ export class NotificationMgmtComponent implements OnInit, OnDestroy {
* @param notificationId the id of the notification that we want to delete
*/
deleteNotification(notificationId: number) {
this.systemNotificationService.delete(notificationId).subscribe(() => {
this.eventManager.broadcast({
name: 'notificationListModification',
content: 'Deleted a system notification',
});
});
this.systemNotificationService.delete(notificationId).subscribe(
() => {
this.eventManager.broadcast({
name: 'notificationListModification',
content: 'Deleted a system notification',
});
this.dialogErrorSource.next('');
},
(error: HttpErrorResponse) => this.dialogErrorSource.next(error.message),
);
}

/**
Expand All @@ -99,7 +109,7 @@ export class NotificationMgmtComponent implements OnInit, OnDestroy {
})
.subscribe(
(res: HttpResponse<SystemNotification[]>) => this.onSuccess(res.body!, res.headers),
(res: HttpErrorResponse) => this.onError(res),
(res: HttpErrorResponse) => onError(this.alertService, res),
);
}

Expand Down Expand Up @@ -160,8 +170,4 @@ export class NotificationMgmtComponent implements OnInit, OnDestroy {
this.totalItems = headers.get('X-Total-Count')!;
this.notifications = data;
}

private onError(error: HttpErrorResponse) {
this.alertService.error(error.error, error.message, undefined);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ <h2>
[entityTitle]="user.login"
deleteQuestion="userManagement.delete.question"
(delete)="deleteUser(user.login)"
[dialogError]="dialogError$"
[disabled]="currentAccount.login === user.login"
>
<fa-icon [icon]="'times'"></fa-icon>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { HttpErrorResponse, HttpHeaders, HttpResponse } from '@angular/common/http';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

import { ActivatedRoute, Router } from '@angular/router';
import { JhiAlertService, JhiEventManager, JhiParseLinks } from 'ng-jhipster';
import { Subscription } from 'rxjs/Subscription';

import { ITEMS_PER_PAGE } from 'app/shared';
import { onError } from 'app/utils/global.utils';
import { User } from 'app/core';
import { UserService } from 'app/core/user/user.service';
import { AccountService } from 'app/core/auth/account.service';
import { Subject } from 'rxjs';

@Component({
selector: 'jhi-user-management',
Expand All @@ -29,6 +29,9 @@ export class UserManagementComponent implements OnInit, OnDestroy {
previousPage: number;
reverse: boolean;

private dialogErrorSource = new Subject<string>();
dialogError$ = this.dialogErrorSource.asObservable();

constructor(
private userService: UserService,
private alertService: JhiAlertService,
Expand All @@ -37,7 +40,6 @@ export class UserManagementComponent implements OnInit, OnDestroy {
private activatedRoute: ActivatedRoute,
private router: Router,
private eventManager: JhiEventManager,
private modalService: NgbModal,
) {
this.itemsPerPage = ITEMS_PER_PAGE;
this.routeData = this.activatedRoute.data.subscribe(data => {
Expand All @@ -64,6 +66,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
*/
ngOnDestroy() {
this.routeData.unsubscribe();
this.dialogErrorSource.unsubscribe();
}

/**
Expand Down Expand Up @@ -105,7 +108,7 @@ export class UserManagementComponent implements OnInit, OnDestroy {
})
.subscribe(
(res: HttpResponse<User[]>) => this.onSuccess(res.body!, res.headers),
(res: HttpErrorResponse) => this.onError(res),
(res: HttpErrorResponse) => onError(this.alertService, res),
);
}

Expand Down Expand Up @@ -158,21 +161,21 @@ export class UserManagementComponent implements OnInit, OnDestroy {
* @param login of the user that should be deleted
*/
deleteUser(login: string) {
this.userService.delete(login).subscribe(() => {
this.eventManager.broadcast({
name: 'userListModification',
content: 'Deleted a user',
});
});
this.userService.delete(login).subscribe(
() => {
this.eventManager.broadcast({
name: 'userListModification',
content: 'Deleted a user',
});
this.dialogErrorSource.next('');
},
(error: HttpErrorResponse) => this.dialogErrorSource.next(error.message),
);
}

private onSuccess(data: User[], headers: HttpHeaders) {
this.links = this.parseLinks.parse(headers.get('link')!);
this.totalItems = headers.get('X-Total-Count')!;
this.users = data;
}

private onError(error: HttpErrorResponse) {
this.alertService.error(error.error, error.message, undefined);
}
}
1 change: 1 addition & 0 deletions src/main/webapp/app/entities/course/course.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ <h4 id="course-page-heading" jhiTranslate="artemisApp.course.home.title">Courses
deleteQuestion="artemisApp.course.delete.question"
deleteConfirmationText="artemisApp.course.delete.typeNameToConfirm"
(delete)="deleteCourse(course.id)"
[dialogError]="dialogError$"
>
<fa-icon [icon]="'times'"></fa-icon>
</button>
Expand Down
15 changes: 9 additions & 6 deletions src/main/webapp/app/entities/course/course.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { JhiAlertService, JhiEventManager } from 'ng-jhipster';
import { Course } from './course.model';
import { CourseService } from './course.service';
import { ARTEMIS_DEFAULT_COLOR } from 'app/app.constants';
import { onError } from 'app/utils/global.utils';
import { Subject } from 'rxjs';

@Component({
selector: 'jhi-course',
Expand All @@ -19,6 +21,9 @@ export class CourseComponent implements OnInit, OnDestroy {
courses: Course[];
eventSubscriber: Subscription;

private dialogErrorSource = new Subject<string>();
dialogError$ = this.dialogErrorSource.asObservable();

readonly ARTEMIS_DEFAULT_COLOR = ARTEMIS_DEFAULT_COLOR;

constructor(private courseService: CourseService, private jhiAlertService: JhiAlertService, private eventManager: JhiEventManager) {
Expand All @@ -32,7 +37,7 @@ export class CourseComponent implements OnInit, OnDestroy {
(res: HttpResponse<Course[]>) => {
this.courses = res.body!;
},
(res: HttpErrorResponse) => this.onError(res),
(res: HttpErrorResponse) => onError(this.jhiAlertService, res),
);
}

Expand All @@ -43,6 +48,7 @@ export class CourseComponent implements OnInit, OnDestroy {

ngOnDestroy() {
this.eventManager.destroy(this.eventSubscriber);
this.dialogErrorSource.unsubscribe();
}

trackId(index: number, item: Course) {
Expand All @@ -64,15 +70,12 @@ export class CourseComponent implements OnInit, OnDestroy {
name: 'courseListModification',
content: 'Deleted an course',
});
this.dialogErrorSource.next('');
},
error => this.onError(error),
(error: HttpErrorResponse) => this.dialogErrorSource.next(error.message),
);
}

private onError(error: HttpErrorResponse) {
this.jhiAlertService.error(error.message);
}

callback() {}

get today(): Date {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2 id="page-heading">
[entityTitle]="exerciseHint.title"
deleteQuestion="artemisApp.exerciseHint.delete.question"
(delete)="deleteExerciseHint(exerciseHint.id)"
[dialogError]="dialogError$"
>
<fa-icon [icon]="'times'"></fa-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
import { Subscription } from 'rxjs';
import { Subscription, Subject } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { JhiAlertService, JhiEventManager } from 'ng-jhipster';

import { ExerciseHint } from 'app/entities/exercise-hint/exercise-hint.model';
import { ExerciseHintService } from './exercise-hint.service';
import { onError } from 'app/utils/global.utils';

@Component({
selector: 'jhi-exercise-hint',
Expand All @@ -17,12 +18,15 @@ export class ExerciseHintComponent implements OnInit, OnDestroy {
exerciseHints: ExerciseHint[];
eventSubscriber: Subscription;

private dialogErrorSource = new Subject<string>();
dialogError$ = this.dialogErrorSource.asObservable();

paramSub: Subscription;

constructor(
private route: ActivatedRoute,
protected exerciseHintService: ExerciseHintService,
protected jhiAlertService: JhiAlertService,
private jhiAlertService: JhiAlertService,
protected eventManager: JhiEventManager,
) {}

Expand All @@ -42,6 +46,7 @@ export class ExerciseHintComponent implements OnInit, OnDestroy {
this.paramSub.unsubscribe();
}
this.eventManager.destroy(this.eventSubscriber);
this.dialogErrorSource.unsubscribe();
}

/**
Expand All @@ -58,7 +63,7 @@ export class ExerciseHintComponent implements OnInit, OnDestroy {
(res: ExerciseHint[]) => {
this.exerciseHints = res;
},
(res: HttpErrorResponse) => this.onError(res.message),
(res: HttpErrorResponse) => onError(this.jhiAlertService, res),
);
}

Expand All @@ -84,12 +89,9 @@ export class ExerciseHintComponent implements OnInit, OnDestroy {
name: 'exerciseHintListModification',
content: 'Deleted an exerciseHint',
});
this.dialogErrorSource.next('');
},
error => this.onError(error),
(error: HttpErrorResponse) => this.dialogErrorSource.next(error.message),
);
}

protected onError(errorMessage: string) {
this.jhiAlertService.error(errorMessage, null, undefined);
}
}

This file was deleted.

Loading

0 comments on commit 9b44b15

Please sign in to comment.