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 30 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 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
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
46 changes: 46 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,43 @@
from app.logic.spreadsheet import createSpreadsheet


@admin_bp.route('/event/<eventId>/inviteCohorts', methods=['POST'])
stevensonmichel 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_or_create(id=eventId)[0]
cohort_years = request.json.get('cohorts', [])

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

except IntegrityError:
continue

event.save()
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('/admin/reports')
def reports():
academicYears = Term.select(Term.academicYear).distinct().order_by(Term.academicYear.desc())
Expand Down Expand Up @@ -314,6 +352,13 @@ 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,
))
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 +370,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.")
14 changes: 14 additions & 0 deletions app/models/eventCohort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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_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?
70 changes: 70 additions & 0 deletions app/static/js/createEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ $(document).ready(function() {
$("#checkBonners").prop('checked', true);
}
}
const eventId = $("#eventId").val();
if (eventId) {
getCohortStatus(eventId);
}

// Initialize datepicker with proper options
$.datepicker.setDefaults({
dateFormat: 'yy/mm/dd', // Ensures compatibility across browsers
Expand Down Expand Up @@ -484,3 +489,68 @@ $(".startDatePicker, .endDatePicker").change(function () {

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

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

inviteCohorts(eventId, selectedCohorts)
.then(() => {
$("input[name='cohorts[]']:checked").prop('checked', false);
})
.catch(error => {
msgFlash("Error inviting cohorts: " + error.message, "danger");
});

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

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

function displayCohortStatus(invitedCohorts) {
bledsoef marked this conversation as resolved.
Show resolved Hide resolved
$(".cohortStatus").add();

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

if (cohortElement.length) {
const statusHtml = `
<div class="cohortStatus 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');
}
});
}
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
1 change: 1 addition & 0 deletions database/migrate_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pem add app.models.eventRsvpLog.EventRsvpLog
pem add app.models.celtsLabor.CeltsLabor
pem add app.models.communityEngagementRequest.CommunityEngagementRequest
pem add app.models.individualRequirement.IndividualRequirement
pem add app.models.eventCohort.EventCohort


pem watch
Expand Down
Loading