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

Changes to the invite cohort #1297

Open
wants to merge 31 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
85aaf3c
Changes to the invite cohort
Mbeweg Jul 25, 2024
9914f5e
Merge branch 'development' into BCI1
bledsoef Sep 6, 2024
d3dcc50
bonner cohort remain checked
doucoureb Sep 17, 2024
08aab57
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
doucoureb Sep 17, 2024
100f0cc
improved code
doucoureb Sep 20, 2024
5e10bdd
Merge branch 'development' into BCI1
doucoureb Oct 2, 2024
651a9c5
Merge branch 'development' of github.com:BCStudentSoftwareDevTeam/cel…
bledsoef Oct 3, 2024
3b62689
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Oct 3, 2024
616aa8c
Bonner Cohort checkbox fixed + merge conflict
doucoureb Oct 4, 2024
0842823
pr modifications
doucoureb Oct 9, 2024
d4078be
Ready for PR
Oct 18, 2024
d0a825b
invitation cohort attempt
doucoureb Oct 29, 2024
6ef35d2
pr test
doucoureb Oct 31, 2024
06c6d26
Merge branch 'development' of github.com:BCStudentSoftwareDevTeam/cel…
bledsoef Oct 31, 2024
f42411e
pr test
doucoureb Nov 4, 2024
1cd75cd
pr test 1
doucoureb Nov 8, 2024
231a773
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Nov 8, 2024
8c6e1d1
Merge branch 'development' into BCI1
bledsoef Nov 11, 2024
b42ce9a
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Nov 12, 2024
2646217
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Nov 12, 2024
a88b114
test pr 2
doucoureb Nov 12, 2024
d64297f
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
doucoureb Nov 12, 2024
cc12edb
PR test 3: I haven't moved the function inviteCohortsToEvent to the e…
doucoureb Nov 22, 2024
350f1aa
Merge branch 'BCI1' of github.com:BCStudentSoftwareDevTeam/celts into…
bledsoef Dec 3, 2024
401682c
Merge branch 'development' of github.com:BCStudentSoftwareDevTeam/cel…
bledsoef Dec 3, 2024
e179c8f
Change variables from snake_case to camelCasee
stevensonmichel Dec 26, 2024
a6a4f7d
Fixed checkbox for event cohort
stevensonmichel Dec 26, 2024
c022d6a
Merge branch 'development' into BCI1
stevensonmichel Dec 26, 2024
c28fd89
removed unnecessary codes and moved functions to logic
stevensonmichel Dec 27, 2024
a6e42dc
Finished test for inviteCohorts and updateCohorts to events functions
stevensonmichel Dec 30, 2024
0f55362
resolved many of the comments from print statements and removing cohorts
WackyWeaver Jan 14, 2025
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
61 changes: 61 additions & 0 deletions app/controllers/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from app.models.program import Program
from app.models.event import Event
from app.models.eventRsvp import EventRsvp
from app.models.eventCohort import EventCohort
from app.models.eventParticipant import EventParticipant
from app.models.user import User
from app.models.course import Course
Expand Down Expand Up @@ -41,6 +42,57 @@
from app.logic.spreadsheet import createSpreadsheet


@admin_bp.route('/event/<eventId>/invite-cohorts', methods=['POST'])
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
def inviteCohorts(eventId):
if not (g.current_user.isCeltsAdmin or g.current_user.isProgramManagerForEvent(Event.get_by_id(eventId))):
abort(403)

try:
event = Event.get_by_id(eventId)
cohort_years = request.json.get('cohorts', [])

for year in cohort_years:
try:
EventCohort.create(
event=event,
year=int(year),
invited=True,
invited_at=datetime.now()
)
addBonnerCohortToRsvpLog(int(year), event.id)
rsvpForBonnerCohort(int(year), event.id)

except IntegrityError:
continue

createActivityLog(f"Invited Bonner cohorts {', '.join(map(str, cohort_years))} to event {event.name}")
return jsonify({
"success": True,
"message": "Cohorts successfully invited",
"invited_cohorts": cohort_years
})

except Exception as e:
print(f"Error inviting cohorts: {e}")
return jsonify({
"success": False,
"message": "Error inviting cohorts"
}), 500

@admin_bp.route('/event/<eventId>/cohort-status', methods=['GET'])
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
def getCohortStatus(eventId):
try:
invited_cohorts = EventCohort.select().where(
EventCohort.event_id == eventId,
EventCohort.invited == True
)
return jsonify({
"invited_cohorts": [{"year": inv.year, "invited_at": inv.invited_at} for inv in invited_cohorts]
})
except Exception as e:
print(f"Error getting cohort status: {e}")
return jsonify({"error": "Error fetching cohort status"}), 500

@admin_bp.route('/admin/reports')
def reports():
academicYears = Term.select(Term.academicYear).distinct().order_by(Term.academicYear.desc())
Expand Down Expand Up @@ -314,6 +366,14 @@ def eventDisplay(eventId):
if eventData['program'] and eventData['program'].isBonnerScholars:
requirements = getCertRequirements(Certification.BONNER)
bonnerCohorts = getBonnerCohorts(limit=5)

invited_cohorts = list(EventCohort.select().where(
stevensonmichel marked this conversation as resolved.
Show resolved Hide resolved
EventCohort.event_id == eventId,
EventCohort.invited == True
))
invited_years = [inv.year for inv in invited_cohorts]
stevensonmichel marked this conversation as resolved.
Show resolved Hide resolved
else:
requirements, bonnerCohorts, invited_years = [], [], []

rule = request.url_rule

Expand All @@ -325,6 +385,7 @@ def eventDisplay(eventId):
event = event,
requirements = requirements,
bonnerCohorts = bonnerCohorts,
invited_years = invited_years,
userHasRSVPed = userHasRSVPed,
isProgramManager = isProgramManager,
filepaths = filepaths)
Expand Down
2 changes: 1 addition & 1 deletion app/logic/bonner.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ def addBonnerCohortToRsvpLog(year, event):
.where(BonnerCohort.year == year))
for bonner in bonnerCohort:
fullName = bonner.fullName
createRsvpLog(eventId=event, content=f"Added {fullName} to RSVP list.")
createRsvpLog(eventId=event, content=f"Added {fullName} to RSVP list.")
15 changes: 15 additions & 0 deletions app/models/eventCohort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import datetime
from app.models import*
from app.models.event import Event
from app.models.bonnerCohort import BonnerCohort

class EventCohort(baseModel):
event = ForeignKeyField(Event)
year = IntegerField()
invited = BooleanField(default=False)
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
invited_at = DateTimeField(default=datetime.now)

class Meta:
indexes = ( (('event', 'year'), True), )

#wouldn't it be more logic to add columns in the bonnerCohort table instead?
85 changes: 85 additions & 0 deletions app/static/js/createEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,88 @@ $(".startDatePicker, .endDatePicker").change(function () {

setCharacterLimit($("#inputCharacters"), "#remainingCharacters");
});

function inviteCohorts(eventId, selectedCohorts) {
stevensonmichel marked this conversation as resolved.
Show resolved Hide resolved
return $.ajax({
type: "POST",
url: `/event/${eventId}/invite-cohorts`,
contentType: "application/json",
data: JSON.stringify({
cohorts: selectedCohorts
}),
success: function(response) {
if (response.success) {
msgFlash("Cohorts successfully invited!", "success");
updateCohortStatus(eventId);
} else {
msgFlash("Error inviting cohorts", "danger");
}
}
});
}

function getCohortStatus(eventId) {
return $.ajax({
type: "GET",
url: `/event/${eventId}/cohort-status`,
success: function(response) {
displayCohortStatus(response.invited_cohorts);
}
});
}

function displayCohortStatus(invitedCohorts) {
bledsoef marked this conversation as resolved.
Show resolved Hide resolved
$(".cohort-status").remove();

invitedCohorts.forEach(cohort => {
const invitedDate = new Date(cohort.invited_at).toLocaleDateString();
const cohortElement = $(`#cohort-${cohort.year}`);

if (cohortElement.length) {
const statusHtml = `
<div class="cohort-status mt-1 ml-4">
<small class="text-success">
<i class="fas fa-check-circle"></i>
Invited on ${invitedDate}
</small>
</div>
`;
cohortElement.closest('.form-check').append(statusHtml);
cohortElement.prop('disabled', true);
cohortElement.closest('.form-check-label').addClass('text-muted');
}
});
}

function updateCohortStatus(eventId) {
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
getCohortStatus(eventId);
}

$(document).ready(function() {
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
const eventId = $("#eventId").val();

if (eventId) {
updateCohortStatus(eventId);
}

$("#inviteCohortForm").on("submit", function(e) {
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();

const selectedCohorts = [];
$("input[name='cohorts[]']:checked").each(function() {
selectedCohorts.push($(this).val());
});

if (selectedCohorts.length === 0) {
msgFlash("Please select at least one cohort to invite", "warning");
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
return;
}

inviteCohorts(eventId, selectedCohorts).then(() => {
$("input[name='cohorts[]']:checked").each(function() {
$(this).prop('checked', false);
});
saveSelectedCohorts();
doucoureb marked this conversation as resolved.
Show resolved Hide resolved
});
});
});
2 changes: 1 addition & 1 deletion app/templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{% if g.current_user.isAdmin %}
<li>
<a href="/eventTemplates" class="nav-link text-white {{'active' if 'eventTemplates' in request.path}}" {{"aria-current='page'" if 'eventTemplates' in request.path}}>
Create Event
Create Event
</a>
</li>
<li>
Expand Down
Loading