Skip to content

Commit

Permalink
BC-7936 initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
UzaeirKhan committed Oct 17, 2024
1 parent b98ed09 commit 0549ef9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
54 changes: 47 additions & 7 deletions static/scripts/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ const getCalendarLanguage = (langAttribute) => {
}
};

// Add data-testid attributes to navigation buttons in calendar page
const addDatatestidsToCalendarNavigation = () => {
const buttonData = [
{ selector: '.fc-right .fc-prev-button', testId: 'right-prev-button' },
{ selector: '.fc-right .fc-next-button', testId: 'right-next-button' },
{ selector: '.fc-right .fc-today-button', testId: 'right-today-button' },
{ selector: '.fc-right .fc-timeGridDay-button', testId: 'right-day-view-button' },
{ selector: '.fc-right .fc-timeGridWeek-button', testId: 'right-week-view-button' },
{ selector: '.fc-right .fc-dayGridMonth-button', testId: 'right-month-view-button' },
];

buttonData.forEach(({ selector, testId }) => {
const button = document.querySelector(selector);
if (button) {
button.setAttribute('data-testid', testId);
}
});
};

$(document).ready(() => {
const $createEventModal = $('.create-event-modal');
const $editEventModal = $('.edit-event-modal');
Expand Down Expand Up @@ -119,7 +138,12 @@ $(document).ready(() => {
const getLangAttribute = () => document.querySelector('html').getAttribute('lang');

const calendar = new Calendar(getCalendarElement(), {
plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin, momentTimezonePlugin],
plugins: [
dayGridPlugin,
timeGridPlugin,
interactionPlugin,
momentTimezonePlugin,
],
defaultView: getView() || 'dayGridMonth',
editable: false,
timeZone: getCalendarTimezone(),
Expand All @@ -143,8 +167,12 @@ $(document).ready(() => {
return false;
}
// personal event
const startDate = toMoment(event.start, calendar).format($t('format.dateTimeToPicker'));
const endDate = toMoment(event.end || event.start, calendar).format($t('format.dateTimeToPicker'));
const startDate = toMoment(event.start, calendar).format(
$t('format.dateTimeToPicker'),
);
const endDate = toMoment(event.end || event.start, calendar).format(
$t('format.dateTimeToPicker'),
);

const eventData = event.extendedProps || {};

Expand All @@ -163,7 +191,8 @@ $(document).ready(() => {
action: URI.getSingleEvent(eventData._id),
});

if (!eventData['x-sc-teamId']) { // course or non-course event
if (!eventData['x-sc-teamId']) {
// course or non-course event
transformCourseOrTeamEvent($editEventModal, eventData);
$editEventModal.find('.btn-delete').click(() => {
$.ajax({
Expand All @@ -178,7 +207,8 @@ $(document).ready(() => {
$editEventModal.appendTo('body').modal('show');
}

if (eventData['x-sc-teamId']) { // team event
if (eventData['x-sc-teamId']) {
// team event
const teamId = eventData['x-sc-teamId'];
window.location.assign(`/teams/${teamId}?activeTab=events`);
}
Expand All @@ -189,8 +219,12 @@ $(document).ready(() => {
const { date } = info;

// open create event modal
const startDate = toMoment(date, calendar).format($t('format.dateTimeToPicker'));
const endDate = toMoment(date, calendar).add(1, 'hour').format($t('format.dateTimeToPicker'));
const startDate = toMoment(date, calendar).format(
$t('format.dateTimeToPicker'),
);
const endDate = toMoment(date, calendar)
.add(1, 'hour')
.format($t('format.dateTimeToPicker'));

populateModalForm($createEventModal, {
title: $t('global.headline.addDate'),
Expand All @@ -207,6 +241,12 @@ $(document).ready(() => {
viewRender(info) {
window.location.hash = info.view.name;
},

// viewSkeletonRender to trigger the addition of data-testid to navigation buttons
viewSkeletonRender() {
// Add custom data-testids for navigation buttons
addDatatestidsToCalendarNavigation();
},
});

calendar.render();
Expand Down
4 changes: 2 additions & 2 deletions views/calendar/calendar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
currentTimezoneOffset=../currentTimezoneOffset
}}
{{#content "fields"}}
{{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="2" collapseIdTeam="3"}}
{{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="2" collapseIdTeam="3" testIdPrefix="create"}}
{{/content}}
{{/embed}}
{{/userHasPermission}}
Expand All @@ -42,7 +42,7 @@
currentTimezoneOffset=../currentTimezoneOffset
}}
{{#content "fields"}}
{{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="4" collapseIdTeam="5"}}
{{> "calendar/forms/form-create-event" addCourse="true" addTeam="true" collapseIdCourse="4" collapseIdTeam="5" testIdPrefix="edit"}}
{{/content}}
{{#content "additional-actions"}}
<button type="button" class="btn btn-primary btn-danger btn-delete" data-testid='calendar-event-btn-delete'>
Expand Down
11 changes: 6 additions & 5 deletions views/calendar/forms/form-create-event.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<input name="scopeId" type="hidden" data-force-value="true" value="{{userId}}" />
<div class="form-group">
<label class="control-label" for="title">{{$t "global.label.title" }}</label>
<input data-testid="team_event_name" class="form-control" name="summary" required placeholder="{{$t "calendar.input.egHandballTraining"}}">
<input data-testid="{{testIdPrefix}}-event-name" class="form-control" name="summary" required placeholder="{{$t "calendar.input.egHandballTraining"}}">
</div>
<div class="form-group">
{{> "lib/forms/form-datetime-input" label=($t "global.label.from") id="startDate" class="input-group" }}
{{> "lib/forms/form-datetime-input" label=($t "global.label.to") id="endDate" class="input-group" }}
{{> "lib/forms/form-datetime-input" label=($t "global.label.from") id="startDate" class="input-group" data-testid="{{testIdPrefix}}-startDate" }}
{{> "lib/forms/form-datetime-input" label=($t "global.label.to") id="endDate" class="input-group" data-testid="{{testIdPrefix}}-endDate" }}
</div>
<div class="form-group">
<label class="control-label" for="description">{{$t "global.label.description" }}</label>
<textarea class="form-control" name="description" aria-label="{{$t "global.label.description"}}" placeholder="" data-testid="team_event_description" ></textarea>
<textarea class="form-control" name="description" aria-label="{{$t "global.label.description"}}" placeholder="" data-testid="{{testIdPrefix}}-event-description"></textarea>
</div>
<div class="form-group">
<label class="control-label" for="location">{{$t "calendar.label.location" }}</label>
<input id="location" data-testid="team_event_location" class="form-control" name="location" placeholder="{{$t "calendar.input.egGym"}}">
<input id="location" data-testid="{{testIdPrefix}}-event-location" class="form-control" name="location" placeholder="{{$t "calendar.input.egGym"}}">
</div>

{{#ifConfig "FEATURE_VIDEOCONFERENCE_ENABLED" true}}
{{#if ../showVideoconferenceOption}}
<div class="form-group create-videoconference hidden">
Expand Down

0 comments on commit 0549ef9

Please sign in to comment.