Skip to content

Commit a439593

Browse files
Development: Replace bootstrap components with primeng in calendar (#11415)
1 parent 79eab54 commit a439593

File tree

36 files changed

+575
-866
lines changed

36 files changed

+575
-866
lines changed

package-lock.json

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/webapp/app/core/calendar/desktop/month-presentation/calendar-desktop-month-presentation.component.html

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@
2828
}
2929
</div>
3030

31-
<ng-template #eventPopover let-pop="popover">
32-
@let event = selectedEvent();
33-
@if (event) {
34-
<jhi-calendar-event-detail-popover [event]="event" (onClosePopover)="closePopover()" />
35-
}
36-
</ng-template>
37-
3831
<ng-template #eventCell let-event>
3932
<div
4033
class="event-cell"
@@ -44,15 +37,12 @@
4437
'tutorial-event-cell': event.isOfType(CalendarEventType.Tutorial),
4538
'exercise-event-cell': event.isOfExerciseType(),
4639
}"
47-
[ngbPopover]="eventPopover"
48-
triggers="manual"
49-
[autoClose]="false"
50-
[placement]="['bottom', 'right', 'left', 'top']"
51-
(click)="openPopover(event, popover)"
52-
#popover="ngbPopover"
40+
(click)="eventDetailPopover.open($event, event)"
5341
[attr.data-testid]="event.title"
5442
>
5543
<div class="event-label">{{ event.title }}</div>
5644
<fa-icon [icon]="utils.getIconForEvent(event)" />
5745
</div>
5846
</ng-template>
47+
48+
<jhi-calendar-event-detail-popover-component #eventDetailPopover />

src/main/webapp/app/core/calendar/desktop/month-presentation/calendar-desktop-month-presentation.component.spec.ts

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { CalendarService } from 'app/core/calendar/shared/service/calendar.servi
99
import { CalendarEvent, CalendarEventType } from 'app/core/calendar/shared/entities/calendar-event.model';
1010
import { CalendarDesktopMonthPresentationComponent } from './calendar-desktop-month-presentation.component';
1111
import { CalendarDayBadgeComponent } from 'app/core/calendar/shared/calendar-day-badge/calendar-day-badge.component';
12-
import { CalendarEventDetailPopoverComponent } from 'app/core/calendar/shared/calendar-event-detail-popover/calendar-event-detail-popover.component';
12+
import { CalendarEventDetailPopoverComponent } from 'app/core/calendar/shared/calendar-event-detail-popover-component/calendar-event-detail-popover.component';
13+
import { provideNoopAnimations } from '@angular/platform-browser/animations';
1314

1415
describe('CalendarDesktopMonthPresentationComponent', () => {
1516
let fixture: ComponentFixture<CalendarDesktopMonthPresentationComponent>;
@@ -61,6 +62,7 @@ describe('CalendarDesktopMonthPresentationComponent', () => {
6162
provide: CalendarService,
6263
useFactory: () => new MockCalendarService(mockMap),
6364
},
65+
provideNoopAnimations(),
6466
],
6567
}).compileComponents();
6668

@@ -105,66 +107,47 @@ describe('CalendarDesktopMonthPresentationComponent', () => {
105107
expect(lecture3EventCell).toBeFalsy();
106108
});
107109

108-
it('should open popover', () => {
109-
const eventCell = fixture.debugElement.query(By.css('[data-testid="Exam"]'));
110-
expect(eventCell).toBeTruthy();
110+
it('should open popover', async () => {
111+
const popoverDebugElement = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
112+
const popoverComponent = popoverDebugElement.componentInstance as CalendarEventDetailPopoverComponent;
111113

114+
const eventCell = fixture.debugElement.query(By.css('[data-testid="Exam"]'));
112115
eventCell.nativeElement.click();
113116
fixture.detectChanges();
117+
await fixture.whenStable();
114118

115-
expect(component.selectedEvent()?.id).toBe(events[0].id);
116-
117-
const popoverContent = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
118-
expect(popoverContent).toBeTruthy();
119+
expect(popoverComponent.isOpen()).toBeTrue();
119120
});
120121

121-
it('should close popover only when close button used', () => {
122+
it('should close popover only when close button used', async () => {
123+
const popoverDebugElement = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
124+
const popoverComponent = popoverDebugElement.componentInstance as CalendarEventDetailPopoverComponent;
125+
const closeSpy = jest.spyOn(popoverComponent, 'close');
126+
122127
const examEventCell = fixture.debugElement.query(By.css('[data-testid="Exam"]'));
123128
expect(examEventCell).toBeTruthy();
124-
125129
examEventCell.nativeElement.click();
126130
fixture.detectChanges();
127-
128-
let popoverComponent = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
129-
expect(component.selectedEvent()?.id).toBe(events[0].id);
130-
expect(popoverComponent).toBeTruthy();
131+
await fixture.whenStable();
132+
expect(popoverComponent.isOpen()).toBeTrue();
131133

132134
const emptyDayCell = fixture.debugElement.queryAll(By.css('.day-cell')).find((cell) => cell.queryAll(By.css('.event-cell')).length === 0);
133135
expect(emptyDayCell).toBeTruthy();
134-
135136
emptyDayCell!.nativeElement.click();
136137
fixture.detectChanges();
138+
await fixture.whenStable();
139+
expect(popoverComponent.isOpen()).toBeFalse();
137140

138-
expect(component.selectedEvent()?.id).toBe(events[0].id);
139-
popoverComponent = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
140-
expect(popoverComponent).toBeTruthy();
141-
142-
const closeButton = popoverComponent.query(By.css('.close-button'));
143-
expect(closeButton).toBeTruthy();
144-
145-
closeButton.nativeElement.click();
146-
fixture.detectChanges();
147-
148-
expect(component.selectedEvent()).toBeUndefined();
149-
popoverComponent = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
150-
expect(popoverComponent).toBeFalsy();
151-
});
152-
153-
it('should replace popover when other event selected', () => {
154-
const firstEventCell = fixture.debugElement.query(By.css('[data-testid="Exam"]'));
155-
firstEventCell.nativeElement.click();
141+
examEventCell.nativeElement.click();
156142
fixture.detectChanges();
143+
await fixture.whenStable();
144+
expect(popoverComponent.isOpen()).toBeTrue();
157145

158-
let popoverComponent = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
159-
expect(component.selectedEvent()?.id).toBe(events[0].id);
160-
expect(popoverComponent).toBeTruthy();
161-
162-
const secondEventCell = fixture.debugElement.query(By.css('[data-testid="Object Design"]'));
163-
secondEventCell.nativeElement.click();
146+
const closeButton = document.querySelector('.close-button') as HTMLElement;
147+
expect(closeButton).toBeTruthy();
148+
closeButton.click();
164149
fixture.detectChanges();
165-
166-
popoverComponent = fixture.debugElement.query(By.directive(CalendarEventDetailPopoverComponent));
167-
expect(popoverComponent).toBeTruthy();
168-
expect(component.selectedEvent()?.id).toBe(events[1].id);
150+
await fixture.whenStable();
151+
expect(closeSpy).toHaveBeenCalledOnce();
169152
});
170153
});

src/main/webapp/app/core/calendar/desktop/month-presentation/calendar-desktop-month-presentation.component.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,34 @@
1-
import { Component, computed, inject, input, signal } from '@angular/core';
1+
import { Component, computed, inject, input } from '@angular/core';
22
import { NgClass, NgTemplateOutlet } from '@angular/common';
3-
import { NgbPopover } from '@ng-bootstrap/ng-bootstrap';
43
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
54
import { Dayjs } from 'dayjs/esm';
65
import { TranslateDirective } from 'app/shared/language/translate.directive';
76
import * as utils from 'app/core/calendar/shared/util/calendar-util';
87
import { CalendarEvent, CalendarEventType } from 'app/core/calendar/shared/entities/calendar-event.model';
98
import { CalendarService } from 'app/core/calendar/shared/service/calendar.service';
109
import { CalendarDayBadgeComponent } from 'app/core/calendar/shared/calendar-day-badge/calendar-day-badge.component';
11-
import { CalendarEventDetailPopoverComponent } from 'app/core/calendar/shared/calendar-event-detail-popover/calendar-event-detail-popover.component';
10+
import { CalendarEventDetailPopoverComponent } from 'app/core/calendar/shared/calendar-event-detail-popover-component/calendar-event-detail-popover.component';
1211

1312
@Component({
1413
selector: 'jhi-calendar-desktop-month-presentation',
15-
imports: [NgClass, NgTemplateOutlet, NgbPopover, FaIconComponent, TranslateDirective, CalendarDayBadgeComponent, CalendarEventDetailPopoverComponent],
14+
imports: [NgClass, NgTemplateOutlet, FaIconComponent, TranslateDirective, CalendarDayBadgeComponent, CalendarEventDetailPopoverComponent],
1615
templateUrl: './calendar-desktop-month-presentation.component.html',
1716
styleUrls: ['./calendar-desktop-month-presentation.component.scss'],
1817
})
1918
export class CalendarDesktopMonthPresentationComponent {
20-
private popover?: NgbPopover;
2119
private eventMap = inject(CalendarService).eventMap;
2220

23-
firstDayOfCurrentMonth = input.required<Dayjs>();
24-
selectedEvent = signal<CalendarEvent | undefined>(undefined);
25-
2621
readonly utils = utils;
2722
readonly CalendarEventType = CalendarEventType;
28-
readonly weeks = computed(() => this.computeWeeksFrom(this.firstDayOfCurrentMonth()));
23+
24+
firstDayOfCurrentMonth = input.required<Dayjs>();
25+
weeks = computed(() => this.computeWeeksFrom(this.firstDayOfCurrentMonth()));
2926

3027
getEventsOf(day: Dayjs): CalendarEvent[] {
3128
const key = day.format('YYYY-MM-DD');
3229
return this.eventMap().get(key) ?? [];
3330
}
3431

35-
openPopover(event: CalendarEvent, popover: NgbPopover) {
36-
if (this.selectedEvent() === event) {
37-
this.closePopover();
38-
return;
39-
}
40-
this.selectedEvent.set(event);
41-
this.popover?.close();
42-
this.popover = popover;
43-
popover.open();
44-
}
45-
46-
closePopover() {
47-
this.popover?.close();
48-
this.popover = undefined;
49-
this.selectedEvent.set(undefined);
50-
}
51-
5232
/**
5333
* Computes all weeks overlapping with the month of the parameter.
5434
*

0 commit comments

Comments
 (0)