-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lectures: Add dismiss modal for unsaved changes to title or period se…
…ction (#10023)
- Loading branch information
1 parent
3a6832e
commit 92b2aad
Showing
22 changed files
with
533 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...main/webapp/app/lecture/close-edit-lecture-dialog/close-edit-lecture-modal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div class="modal-header"> | ||
<h4 class="modal-title" jhiTranslate="artemisApp.lecture.dismissChangesModal.title"></h4> | ||
</div> | ||
<div class="modal-body"> | ||
<span jhiTranslate="artemisApp.lecture.dismissChangesModal.message" class="fw-bold"></span><br /> | ||
<!-- check if translation should be singular or plural, to be exchanged | ||
with computed signals once input signals are supported with ng-bootstrap modals --> | ||
@if (hasUnsavedChangesInTitleSection && hasUnsavedChangesInPeriodSection) { | ||
<span jhiTranslate="artemisApp.lecture.dismissChangesModal.sectionsThatContainUnsavedChangesPlural"></span> | ||
} @else { | ||
<span jhiTranslate="artemisApp.lecture.dismissChangesModal.sectionsThatContainUnsavedChangesSingular"></span> | ||
} | ||
<ul> | ||
@if (hasUnsavedChangesInTitleSection) { | ||
<li> | ||
<span jhiTranslate="artemisApp.lecture.wizardMode.steps.titleStepTitle"></span> | ||
</li> | ||
} | ||
@if (hasUnsavedChangesInPeriodSection) { | ||
<li> | ||
<span jhiTranslate="artemisApp.lecture.wizardMode.steps.periodStepTitle"></span> | ||
</li> | ||
} | ||
</ul> | ||
</div> | ||
<div class="modal-footer"> | ||
<button class="btn btn-default" (click)="closeWindow(true)"> | ||
<span jhiTranslate="entity.action.discardChanges"></span> | ||
</button> | ||
<button type="button" (click)="closeWindow(false)" class="btn btn-primary" type="submit"> | ||
<fa-icon [icon]="faTimes" /> | ||
<span class="ms-1" jhiTranslate="entity.action.cancel"></span> | ||
</button> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
src/main/webapp/app/lecture/close-edit-lecture-dialog/close-edit-lecture-modal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Component, Input, inject } from '@angular/core'; | ||
import { TranslateDirective } from 'app/shared/language/translate.directive'; | ||
import { faTimes } from '@fortawesome/free-solid-svg-icons'; | ||
import { ArtemisSharedCommonModule } from 'app/shared/shared-common.module'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'jhi-close-edit-lecture-modal', | ||
standalone: true, | ||
imports: [TranslateDirective, ArtemisSharedCommonModule], | ||
templateUrl: './close-edit-lecture-modal.component.html', | ||
}) | ||
export class CloseEditLectureModalComponent { | ||
protected readonly faTimes = faTimes; | ||
|
||
protected readonly activeModal = inject(NgbActiveModal); | ||
|
||
// no input signals yet as they can not be initialized with current ng-bootstrap version https://stackoverflow.com/a/79094268/16540383 | ||
@Input() hasUnsavedChangesInTitleSection: boolean; | ||
@Input() hasUnsavedChangesInPeriodSection: boolean; | ||
|
||
closeWindow(isCloseConfirmed: boolean): void { | ||
this.activeModal.close(isCloseConfirmed); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/webapp/app/lecture/hasLectureUnsavedChanges.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { inject } from '@angular/core'; | ||
import { CanDeactivateFn } from '@angular/router'; | ||
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; | ||
import { LectureUpdateComponent } from 'app/lecture/lecture-update.component'; | ||
import { Observable, from, of } from 'rxjs'; | ||
import { CloseEditLectureModalComponent } from 'app/lecture/close-edit-lecture-dialog/close-edit-lecture-modal.component'; | ||
|
||
export const hasLectureUnsavedChangesGuard: CanDeactivateFn<LectureUpdateComponent> = (component: LectureUpdateComponent): Observable<boolean> => { | ||
if (!component.shouldDisplayDismissWarning || component.isShowingWizardMode) { | ||
return of(true); | ||
} | ||
|
||
if (component.isChangeMadeToTitleOrPeriodSection) { | ||
const modalService = inject(NgbModal); | ||
|
||
const modalRef: NgbModalRef = modalService.open(CloseEditLectureModalComponent, { | ||
size: 'lg', | ||
backdrop: 'static', | ||
animation: true, | ||
}); | ||
modalRef.componentInstance.hasUnsavedChangesInTitleSection = component.isChangeMadeToTitleSection(); | ||
modalRef.componentInstance.hasUnsavedChangesInPeriodSection = component.isChangeMadeToPeriodSection(); | ||
|
||
return from(modalRef.result); | ||
} | ||
|
||
return of(true); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/webapp/app/lecture/lecture-period/lecture-period.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Component, Input, Signal, computed, input, viewChildren } from '@angular/core'; | ||
import { Lecture } from 'app/entities/lecture.model'; | ||
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component'; | ||
|
||
@Component({ | ||
selector: 'jhi-lecture-update-period', | ||
templateUrl: './lecture-period.component.html', | ||
}) | ||
export class LectureUpdatePeriodComponent { | ||
lecture = input.required<Lecture>(); | ||
@Input() validateDatesFunction: () => void; | ||
|
||
periodSectionDatepickers = viewChildren(FormDateTimePickerComponent); | ||
|
||
isPeriodSectionValid: Signal<boolean> = computed(() => { | ||
for (const periodSectionDatepicker of this.periodSectionDatepickers()) { | ||
if (!periodSectionDatepicker.isValid()) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.