Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate for Duplicate Event Entries within Multiple Offering Modal #1327

Merged
merged 25 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
49682e9
Added some javascript to check for duplicate events before we let the…
hoerstl Aug 28, 2024
6bc07d7
Modified invalid feedback message
stevensonmichel Aug 30, 2024
83fbd81
Fixed spacing of the add new offerings + button
hoerstl Sep 4, 2024
04963ee
Removed end time as part of duplicate check for event with multiple t…
stevensonmichel Sep 4, 2024
d84dd6f
Merge branch 'development' into 1306-Multiple-Offering-Duplicate-Entries
stevensonmichel Sep 4, 2024
d919e49
Merge branch 'development' into 1306-Multiple-Offering-Duplicate-Entries
bledsoef Sep 6, 2024
b471411
Started refactoring the way we save multiple offerings so we can chec…
hoerstl Sep 6, 2024
886525a
Merge branch '1306-Multiple-Offering-Duplicate-Entries' of github.com…
hoerstl Sep 6, 2024
c891d06
Added docstrings and completed the todos for changing how we handle t…
hoerstl Sep 6, 2024
318feb0
Renamed some variables and changed a data structure for clarity
hoerstl Sep 9, 2024
e03b521
Modified preexisting functions
stevensonmichel Sep 9, 2024
4f981fd
Added preprocessing for multipleOfferingData
hoerstl Sep 9, 2024
66f4d51
Merge branch 'development' into 1306-Multiple-Offering-Duplicate-Entries
bledsoef Sep 10, 2024
fb01536
Renamed a class to be more specific
hoerstl Sep 11, 2024
08853cb
Changed the multiple offerings modal so it loads from the data table …
hoerstl Sep 11, 2024
8ee0224
Fixed syntax for indexing elements in list
stevensonmichel Sep 13, 2024
19c9924
Fixed camel case issue
stevensonmichel Sep 13, 2024
ce05764
Changed comment wording
stevensonmichel Sep 13, 2024
76bbeba
Merge branch 'development' into 1306-Multiple-Offering-Duplicate-Entries
stevensonmichel Sep 13, 2024
716b550
Created function for code reusability in notification for invalidation
stevensonmichel Sep 13, 2024
bca5c8c
Fixed a bug in development where it was possible to save a single off…
hoerstl Sep 16, 2024
93c52d1
Fixed a bug where dismissing an alert would dismiss all alerts
hoerstl Sep 16, 2024
6181c4b
Created tests for attemptSaveMultipleOfferings function
stevensonmichel Sep 16, 2024
fe8972c
Added tests for changes made to preprocessEventData for multipleOffer…
hoerstl Sep 16, 2024
6e299b5
Merge branch 'development' into 1306-Multiple-Offering-Duplicate-Entries
bledsoef Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions app/static/js/createEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function calculateRecurringEventFrequency(){
var recurringEvents = JSON.parse(jsonData)
var recurringTable = $("#recurringEventsTable")
$("#recurringEventsTable tbody tr").remove();
for (var event of recurringEvents){
for(var event of recurringEvents){
var eventdate = new Date(event.date).toLocaleDateString()
recurringTable.append("<tr><td>"+event.name+"</td><td><input name='week"+event.week+"' type='hidden' value='"+eventdate+"'>"+eventdate+"</td></tr>");
}
Expand All @@ -59,25 +59,29 @@ function calculateRecurringEventFrequency(){
}
});
}
$('#submitParticipant').on('click', function() {
$('#multipleOfferingSave').on('click', function() {
//Requires that modal info updated before it can be saved, gives notifier if there are empty fields
let eventNameInputs = document.querySelectorAll('.multipleOfferingNameField');
let datePickerInputs = document.querySelectorAll('.multipleOfferingDatePicker');
let startTimeInputs = document.querySelectorAll('.multipleOfferingStartTime');
let endTimeInputs = document.querySelectorAll('.multipleOfferingEndTime');
let eventOfferings = $('.eventOffering');
let eventNameInputs = $('.multipleOfferingNameField');
let datePickerInputs = $('.multipleOfferingDatePicker');
let startTimeInputs = $('.multipleOfferingStartTime');
let endTimeInputs = $('.multipleOfferingEndTime');
let isEmpty = false;
let timeCheck = false;
eventNameInputs.forEach(eventNameInput => {
// Check if the input field is empty
let hasValidTimes = true;
let hasDuplicateListings = false;

// Check if the input field is empty
eventNameInputs.each((index, eventNameInput) => {
if (eventNameInput.value.trim() === '') {
isEmpty = true;
$(eventNameInput).addClass('border-red');
isEmpty = true;
$(eventNameInput).addClass('border-red');
} else{
$(eventNameInput).removeClass('border-red');
}
});
datePickerInputs.forEach(datePickerInput => {
// Check if the input field is empty
});

// Check if the date input field is empty
datePickerInputs.each((index, datePickerInput) => {
if (datePickerInput.value.trim() === '') {
isEmpty = true;
$(datePickerInput).addClass('border-red');
Expand All @@ -86,19 +90,36 @@ function calculateRecurringEventFrequency(){
}
});

// Check if the start time is after the end time
for(let i = 0; i < startTimeInputs.length; i++){
if(startTimeInputs[i].value >= endTimeInputs[i].value){
console.log(startTimeInputs[i]);
console.log(endTimeInputs[i]);
$(startTimeInputs[i]).addClass('border-red');
$(endTimeInputs[i]).addClass('border-red');
timeCheck = true;
}else{
if(startTimeInputs[i].value < endTimeInputs[i].value){
$(startTimeInputs[i]).removeClass('border-red');
$(endTimeInputs[i]).removeClass('border-red');
} else {
$(startTimeInputs[i]).addClass('border-red');
$(endTimeInputs[i]).addClass('border-red');
hasValidTimes = false;
}
console.log(timeCheck);
}

// Check if there are duplicate event offerings
let eventListings = {};
for(let i = 0; i < eventOfferings.length; i++){
let eventName = eventNameInputs[i].value
let date = datePickerInputs[i].value.trim()
let startTime = startTimeInputs[i].value
let eventListing = JSON.stringify([eventName, date, startTime])

if (eventListing in eventListings){ // If we've seen this event before mark this event and the previous as duplicates
hasDuplicateListings = true
$(eventOfferings[i]).addClass('border-red');
$(eventOfferings[eventListings[eventListing]]).addClass('border-red')
} else { // If we haven't seen this event before
$(eventOfferings[i]).removeClass('border-red');
eventListings[eventListing] = i
}
}

if (isEmpty){
$('#textNotifierPadding').addClass('pt-5');
$('.invalidFeedback').text("Event name or date field is empty");
Expand All @@ -107,18 +128,24 @@ function calculateRecurringEventFrequency(){
$('.invalidFeedback').css('display', 'none');
$('#textNotifierPadding').removeClass('pt-5')
});
isEmpty = false;
}
else if(timeCheck){
else if(!hasValidTimes){
$('#textNotifierPadding').addClass('pt-5');
$('.invalidFeedback').text("Event end time must be after start time");
$('.invalidFeedback').css('display', 'block');
$('.invalidFeedback').on('animationend', function() {
$('.invalidFeedback').css('display', 'none');
$('#textNotifierPadding').removeClass('pt-5')
});
timeCheck= false;

}
else if (hasDuplicateListings){
$('#textNotifierPadding').addClass('pt-5');
$('.invalidFeedback').text("Event listings cannot have the same event name, date, and start time");
$('.invalidFeedback').css('display', 'block');
$('.invalidFeedback').on('animationend', function() {
$('.invalidFeedback').css('display', 'none');
$('#textNotifierPadding').removeClass('pt-5')
});
}
else {
storeMultipleOfferingEventAttributes();
Expand Down
9 changes: 4 additions & 5 deletions app/templates/admin/createEvent.html
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ <h5 class="modal-title">This is an event with multiple time offerings.</h5>
<br>
</div>
<div class="extraSlots"><!--addition slot for data start time and end time-->
<div class="row mb-2 divStripes pt-3 pb-4" id="multipleOfferingEvent">
<div class="eventOffering row mb-2 divStripes pt-3 pb-4" id="multipleOfferingEvent">
<br>
<div class="form-group mb-3">
<label class="form-label required" for="eventName"><strong>Event Name</strong></label>
Expand Down Expand Up @@ -526,17 +526,16 @@ <h5 class="modal-title">This is an event with multiple time offerings.</h5>
</div>
</div>

<div class="addMultipleOfferingEvent"> <!--add button for the slots-->
<div class="addMultipleOfferingEvent mb-3 mt-2"> <!--add button for the slots-->
<i
class="bi bi-plus-square col-md-1 py-2 d-flex flex-row justify-content-center btn-success btn-lg addMultipleBtn"></i>
</div>
<br>
<div class="modal-footer">
<button type="button" class="btn btn-secondary me-auto" data-bs-dismiss="modal" name="cancelModalPreview"
id="cancelModalPreview">Cancel</button>
{% set disableSave = "disabled" if cpPreviewErrors|count else "" %}
<button type="submit" name="submitParticipant" class="btn btn-primary multipleOfferingSave" {{disableSave}}
id="submitParticipant">Save</button> <!--check if text box empty upon save-->
<button type="submit" name="multipleOfferingSave" class="btn btn-primary multipleOfferingSave" {{disableSave}}
id="multipleOfferingSave">Save</button> <!--check if text box empty upon save-->
</div>
</div>
</div>
Expand Down
Loading