Skip to content

Commit

Permalink
Merge pull request #2097 from navikt/TOLK-2483-frilanstolk-fravær
Browse files Browse the repository at this point in the history
Tolk 2483 frilanstolk fravær
  • Loading branch information
AndreMarthinsen authored Oct 16, 2024
2 parents 32acf8e + 83873a1 commit 850cbf0
Show file tree
Hide file tree
Showing 22 changed files with 1,415 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<apexClass>HOT_DuplicateHandler</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>HOT_FreelanceAbsenceController</apexClass>
<enabled>true</enabled>
</classAccesses>
<classAccesses>
<apexClass>HOT_FreelanceQualificationsController</apexClass>
<enabled>true</enabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public with sharing class HOT_FullCalendarController {
event.description = 'Ferie';
}
when else {
event.description = 'Annet fravær';
event.description = 'Annet';
}
}
events.add(event);
Expand Down
50 changes: 38 additions & 12 deletions force-app/main/freelanceCalendar/lwc/hot_calendar/hot_calendar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { LightningElement, track, wire } from 'lwc';
import { LightningElement, track, wire, api } from 'lwc';
import FULL_CALENDAR from '@salesforce/resourceUrl/FullCalendar';
import { loadScript, loadStyle } from 'lightning/platformResourceLoader';
import getCalendarEvents from '@salesforce/apex/HOT_FullCalendarController.getCalendarEvents';
import IKONER from '@salesforce/resourceUrl/ikoner';
import { NavigationMixin } from 'lightning/navigation';
import { CalendarEvent } from './calendar_event';
import Hot_Calendar_Absence_Modal from 'c/hot_calendar_absence_modal';

export default class LibsFullCalendar extends NavigationMixin(LightningElement) {
static MILLISECONDS_PER_DAY = 86400000;
Expand Down Expand Up @@ -114,6 +115,12 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)
click: () => {
this.refreshCalendar(); // Call the refresh method
}
},
absence: {
text: 'Nytt fravær',
click: () => {
this.openAbsenceModal();
}
}
},
buttonText: {
Expand All @@ -127,7 +134,8 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)
end: 'dayGridMonth today prev,next'
},
footerToolbar: {
left: 'refresh'
left: 'refresh',
right: 'absence'
},
slotLabelFormat: {
hour: '2-digit',
Expand Down Expand Up @@ -239,7 +247,7 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)

handleEventClick(context) {
if (context.view.type === 'timeGridDay' || !this.isMobileSize) {
this.navigateToDetailView(context.event.extendedProps);
this.navigateToDetailView(context.event);
} else {
this.calendar.changeView('timeGridDay', new Date(context.event.start));
}
Expand Down Expand Up @@ -272,6 +280,14 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)
this.isLoading = false;
}

async openAbsenceModal(event) {
const result = await Hot_Calendar_Absence_Modal.open({ event: event });
if (result) {
await this.refreshCalendar(false);
this.updatePseudoEventsDisplay(this.calendar.view);
}
}

async updateEventsFromDateRange(earliestDateInView, latestDateInView) {
const earliestTimeInView = earliestDateInView.getTime();
const latestTimeInView = latestDateInView.getTime();
Expand Down Expand Up @@ -303,10 +319,20 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)
}

async fetchUniqueEventsForTimeRegion(earliestTime, latestTime) {
const data = await getCalendarEvents({
earliestEventEndTimeInMilliseconds: earliestTime,
latestEventStartInMilliseconds: latestTime
});
let data;
try {
data = await getCalendarEvents({
earliestEventEndTimeInMilliseconds: earliestTime,
latestEventStartInMilliseconds: latestTime
});
} catch {
const event = new ShowToastEvent({
title: 'Det oppsto en feil',
message: 'Feil ved henting av avtaler i dette tidsrommet, prøv igjen senere.',
variant: 'error'
});
this.dispatchEvent(event);
}
if (data) {
return data
.map((event) => new CalendarEvent(event))
Expand Down Expand Up @@ -360,11 +386,8 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)
return pseudoEvents;
}

navigateToDetailView(eventExtendedProps) {
if (eventExtendedProps.type === 'RESOURCE_ABSENCE') {
return;
}

async navigateToDetailView(event) {
const eventExtendedProps = event.extendedProps;
switch (eventExtendedProps.type) {
case 'COMPLETED_SERVICE_APPOINTMENT':
this.showDetails = true;
Expand All @@ -384,6 +407,9 @@ export default class LibsFullCalendar extends NavigationMixin(LightningElement)
.querySelector('c-hot_information-modal')
.goToRecordDetailsWCFromId(eventExtendedProps.recordId);
break;
case 'RESOURCE_ABSENCE':
await this.openAbsenceModal(event);
break;
}
}
handleRefreshRecords() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createElement } from 'lwc';
import Hot_calendar_absence_modal from 'c/hot_calendar_absence_modal';

describe('c-hot-calendar-absence-modal', () => {
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});

it('TODO: test case generated by CLI command, please fill in test logic', () => {
// Arrange
const element = createElement('c-hot-calendar-absence-modal', {
is: Hot_calendar_absence_modal
});

// Act
document.body.appendChild(element);

// Assert
// const div = element.shadowRoot.querySelector('div');
expect(1).toBe(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.button-container {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
}
.cancel-button {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
padding-left: 3rem;
padding-right: 3rem;
}
.custom-button {
margin-bottom: 0.25rem;
margin-left: 0.25rem;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
padding-left: 2rem;
padding-right: 2rem;
}
.modal-container {
position: relative;
}

.spinner-wrapper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
z-index: 1000;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<template>
<div class="modal-container">
<template if:true={isLoading}>
<div class="spinner-wrapper">
<lightning-spinner alternative-text="Loading" size="large"></lightning-spinner>
</div>
</template>
<template lwc:if={isEdit}>
<lightning-modal-header label="Endre/Slett fravær"></lightning-modal-header>
<lightning-modal-body>
<lightning-radio-group
name="radioGroup"
lwc:ref="absenceTypeRadioGroup"
label="Type fravær"
options={options}
value={absenceType}
type="radio"
>
</lightning-radio-group>
<lightning-input
type="datetime"
name="input1"
lwc:ref="absenceStartDateTimeInput"
label="Legg inn ny start dato/tid"
value={absenceStart}
></lightning-input>
<lightning-input
type="datetime"
name="input2"
lwc:ref="absenceEndDateTimeInput"
label="Legg inn ny slutt dato/tid"
value={absenceEnd}
></lightning-input>
</lightning-modal-body>
<lightning-modal-footer>
<div class="button-container">
<button
class="slds-button slds-button_destructive cancel-button custom-button"
onclick={handleDeleteAbsence}
>
Slett
</button>
<button class="slds-button slds-button_brand custom-button" onclick={handleOkay}>Endre</button>
</div>
</lightning-modal-footer>
</template>
<template lwc:else>
<lightning-modal-header label="Registrer nytt fravær"></lightning-modal-header>
<lightning-modal-body>
<lightning-radio-group
name="radioGroup"
lwc:ref="absenceTypeRadioGroup"
label="Type fravær"
options={options}
value={value}
type="radio"
>
</lightning-radio-group>
<lightning-input
type="datetime"
name="input1"
lwc:ref="absenceStartDateTimeInput"
label="Legg inn start dato/tid"
value={absenceStart}
></lightning-input>
<lightning-input
type="datetime"
name="input2"
lwc:ref="absenceEndDateTimeInput"
label="Legg inn slutt dato/tid"
value={absenceEnd}
></lightning-input>
</lightning-modal-body>
<lightning-modal-footer>
<lightning-button variant="brand" label="Registrer" onclick={handleOkay}></lightning-button>
</lightning-modal-footer>
</template>
</div>
</template>
Loading

0 comments on commit 850cbf0

Please sign in to comment.