diff --git a/app/controllers/main/routes.py b/app/controllers/main/routes.py index f9d17d1c4..16979f3b3 100644 --- a/app/controllers/main/routes.py +++ b/app/controllers/main/routes.py @@ -26,7 +26,7 @@ from app.models.courseInstructor import CourseInstructor from app.models.backgroundCheckType import BackgroundCheckType -from app.logic.events import getUpcomingEventsForUser, getParticipatedEventsForUser, getTrainingEvents, getEventRsvpCountsForTerm, getUpcomingVolunteerOpportunitiesCount, getVolunteerOpportunities, getBonnerEvents, getCeltsLabor, getEngagementEvents +from app.logic.events import getUpcomingEventsForUser, getParticipatedEventsForUser, getTrainingEvents, getEventRsvpCountsForTerm, getUpcomingVolunteerOpportunitiesCount, getVolunteerOpportunities, getBonnerEvents, getCeltsLabor, getEngagementEvents, getpastVolunteerOpportunitiesCount from app.logic.transcript import * from app.logic.loginManager import logout from app.logic.searchUsers import searchUsers @@ -92,6 +92,7 @@ def events(selectedTerm, activeTab, programID): currentEventRsvpAmount = getEventRsvpCountsForTerm(term) volunteerOpportunities = getVolunteerOpportunities(term) countUpcomingVolunteerOpportunities = getUpcomingVolunteerOpportunitiesCount(term, currentTime) + countPastVolunteerOpportunities = getpastVolunteerOpportunitiesCount(term, currentTime) trainingEvents = getTrainingEvents(term, g.current_user) engagementEvents = getEngagementEvents(term) bonnerEvents = getBonnerEvents(term) @@ -109,6 +110,8 @@ def events(selectedTerm, activeTab, programID): # Get the count of all term events for each category to display in the event list page. volunteerOpportunitiesCount: int = len(studentEvents) + countUpcomingVolunteerOpportunitiesCount: int = len(countUpcomingVolunteerOpportunities) + countPastVolunteerOpportunitiesCount: int = len(countPastVolunteerOpportunities) trainingEventsCount: int = len(trainingEvents) engagementEventsCount: int = len(engagementEvents) bonnerEventsCount: int = len(bonnerEvents) @@ -133,6 +136,8 @@ def events(selectedTerm, activeTab, programID): if request.headers.get('X-Requested-With') == 'XMLHttpRequest': return jsonify({ "volunteerOpportunitiesCount": volunteerOpportunitiesCount, + "countPastVolunteerOpportunitiesCount": countPastVolunteerOpportunitiesCount, + "countUpcomingVolunteerOpportunitiesCount": countUpcomingVolunteerOpportunitiesCount, "trainingEventsCount": trainingEventsCount, "engagementEventsCount": engagementEventsCount, "bonnerEventsCount": bonnerEventsCount, @@ -155,6 +160,7 @@ def events(selectedTerm, activeTab, programID): programID = int(programID), managersProgramDict = managersProgramDict, countUpcomingVolunteerOpportunities = countUpcomingVolunteerOpportunities, + countPastVolunteerOpportunities = countPastVolunteerOpportunities, toggleState = toggleState, ) diff --git a/app/logic/events.py b/app/logic/events.py index db921d149..99d3668e4 100644 --- a/app/logic/events.py +++ b/app/logic/events.py @@ -251,7 +251,7 @@ def getEngagementEvents(term): .execute()) return engagementEvents -def getUpcomingVolunteerOpportunitiesCount(term, currentTime): +def getUpcomingVolunteerOpportunitiesCount(term, currentDate): """ Return a count of all upcoming events for each volunteer opportunitiesprogram. """ @@ -265,8 +265,8 @@ def getUpcomingVolunteerOpportunitiesCount(term, currentTime): (Event.deletionDate.is_null(True)) & (Event.isService == True) & ((Event.isLaborOnly == False) | Event.isLaborOnly.is_null(True)) & - ((Event.startDate > currentTime) | - ((Event.startDate == currentTime) & (Event.timeEnd >= currentTime))) & + ((Event.startDate > currentDate) | + ((Event.startDate == currentDate) & (Event.timeEnd >= currentDate))) & (Event.isCanceled == False) ) .group_by(Program.id) @@ -277,6 +277,32 @@ def getUpcomingVolunteerOpportunitiesCount(term, currentTime): programCountDict[programCount.id] = programCount.eventCount return programCountDict +def getpastVolunteerOpportunitiesCount(term, currentDate): + """ + Return a count of all past events for each volunteer opportunities program. + """ + + pastCount = ( + Program + .select(Program.id, fn.COUNT(Event.id).alias("eventCount")) + .join(Event, on=(Program.id == Event.program_id)) + .where( + (Event.term == term) & + (Event.deletionDate.is_null(True)) & + (Event.isService == True) & + ((Event.isLaborOnly == False) | Event.isLaborOnly.is_null(True)) & + ((Event.startDate < currentDate) | + ((Event.startDate == currentDate) & (Event.timeStart <= currentDate))) & + (Event.isCanceled == False) + ) + .group_by(Program.id) + ) + + programCountDict = {} + for programCount in pastCount: + programCountDict[programCount.id] = programCount.eventCount + return programCountDict + def getTrainingEvents(term, user): """ The allTrainingsEvent query is designed to select and count eventId's after grouping them diff --git a/app/static/js/eventList.js b/app/static/js/eventList.js index e776503f5..6e675349d 100644 --- a/app/static/js/eventList.js +++ b/app/static/js/eventList.js @@ -87,6 +87,7 @@ function updateIndicatorCounts(isChecked){ }, success: function(eventsCount) { const volunteerOpportunitiesCount = Number(eventsCount.volunteerOpportunitiesCount); + const upcomingVolunteerCount = Number(eventsCount.countUpcomingVolunteerOpportunitiesCount); const trainingEventsCount = Number(eventsCount.trainingEventsCount); const engagementEventsCount = Number(eventsCount.engagementEventsCount); const bonnerEventsCount = Number(eventsCount.bonnerEventsCount); @@ -94,9 +95,31 @@ function updateIndicatorCounts(isChecked){ const toggleStatus = eventsCount.toggleStatus; $("#viewPastEventsToggle").prop(toggleStatus, true); + + // Update tab labels with event counts: + // - When toggle is ON, show total volunteer opportunities (upcoming + past) + // - When toggle is OFF, show upcoming volunteer opportunities only + // - For all tabs, show counts only if greater than zero; otherwise show the label without a count - // use ternary operators to populate the tab with a number if there are events, and clear the count if there are none - volunteerOpportunitiesCount > 0 ? $("#volunteerOpportunities").html(`Volunteer Opportunities (${volunteerOpportunitiesCount})`) : $("#volunteerOpportunities").html(`Volunteer Opportunities`) + if (toggleStatus === "checked") { + // Toggle ON: show total (upcoming + past) + if (volunteerOpportunitiesCount > 0) { + $("#volunteerOpportunities").html( + `Volunteer Opportunities (${volunteerOpportunitiesCount})` + ); + } else { + $("#volunteerOpportunities").html(`Volunteer Opportunities`); + } + } else { + // Toggle OFF: show upcoming only + if (upcomingVolunteerCount > 0) { + $("#volunteerOpportunities").html( + `Volunteer Opportunities (${upcomingVolunteerCount})` + ); + } else { + $("#volunteerOpportunities").html(`Volunteer Opportunities`); + } + } trainingEventsCount > 0 ? $("#trainingEvents").html(`Trainings (${trainingEventsCount})`) : $("#trainingEvents").html(`Trainings`) engagementEventsCount > 0 ? $("#engagementEvents").html(`Education and Engagement (${engagementEventsCount})`) : $("#engagementEvents").html('Education and Engagement') bonnerEventsCount > 0 ? $("#bonnerScholarsEvents").html(`Bonner Scholars (${bonnerEventsCount})`) : $("#bonnerScholarsEvents").html(`Bonner Scholars`) diff --git a/app/templates/events/eventList.html b/app/templates/events/eventList.html index ff0dbf522..d5cc0d00a 100644 --- a/app/templates/events/eventList.html +++ b/app/templates/events/eventList.html @@ -51,13 +51,13 @@