Skip to content

Commit

Permalink
Merge pull request #4431 from magfest/fix-magdev1218
Browse files Browse the repository at this point in the history
Add setup/teardown night warning to shifts
  • Loading branch information
kitsuta authored Nov 16, 2024
2 parents 8d60108 + 6fc0eea commit e2cac7a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
22 changes: 7 additions & 15 deletions uber/site_sections/staffing.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,8 @@ def hotel(self, session, message='', decline=None, **params):
}

@check_shutdown
def shifts(self, session, view='', start='', all=''):
joblist = session.jobs_for_signups(all=all)
con_days = -(-c.CON_LENGTH // 24) # Equivalent to ceil(c.CON_LENGTH / 24)

def shifts(self, session, start=''):
volunteer = session.logged_in_volunteer()
assigned_dept_ids = set(volunteer.assigned_depts_ids)
has_public_jobs = False
for job in joblist:
if job.is_public and job.department_id not in assigned_dept_ids:
has_public_jobs = True

has_setup = volunteer.can_work_setup or any(d.is_setup_approval_exempt for d in volunteer.assigned_depts)
has_teardown = volunteer.can_work_teardown or any(
Expand Down Expand Up @@ -260,26 +252,24 @@ def shifts(self, session, view='', start='', all=''):
other_filters = [
{'id': 'public', 'title': "Public Shifts",},
]

requested_hotel_nights = volunteer.hotel_requests.nights_ints if volunteer.hotel_requests else []

return {
'jobs': joblist,
'has_public_jobs': session.query(Job).filter(Job.is_public == True).count(),
'depts_with_roles': [membership.department.name for membership in volunteer.dept_memberships_with_role],
'assigned_depts_list': [(dept.id, dept.name) for dept in volunteer.assigned_depts],
'name': volunteer.full_name,
'hours': volunteer.weighted_hours,
'assigned_depts_labels': volunteer.assigned_depts_labels,
'default_filters': default_filters,
'all_filters': default_filters + other_filters,
'view': view,
'start': start.date(),
'end': end.date(),
'total_duration': total_duration,
'highlighted_dates': event_dates,
'setup_duration': 0 if not has_setup else (c.EPOCH - c.SETUP_JOB_START).days,
'teardown_duration': 0 if not has_teardown else (c.TEARDOWN_JOB_END - c.ESCHATON).days,
'start_day': c.SHIFTS_START_DAY if has_setup else c.EPOCH,
'show_all': all,
'requested_setup_nights': [c.NIGHTS[night] for night in requested_hotel_nights if night in c.SETUP_NIGHTS],
'requested_teardown_nights': [c.NIGHTS[night] for night in requested_hotel_nights if night in c.TEARDOWN_NIGHTS],
}

@ajax_gettable
Expand Down Expand Up @@ -344,6 +334,8 @@ def get_assigned_jobs(self, session, **params):
'weight': job.weight,
'slots': f"{job.slots_taken}/{job.slots}",
'is_public': job.is_public,
'is_setup': job.is_setup,
'is_teardown': job.is_teardown,
'assigned': True,
}
})
Expand Down
46 changes: 45 additions & 1 deletion uber/templates/staffing/shifts.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
</style>
{% endblock %}

{% block content %} <div class="d-none csrf_token"> {{ csrf_token() }} </div>
{% set requested_teardown_nights = ["Sunday"] %}
{% block content %}
<div class="d-none csrf_token"> {{ csrf_token() }} </div>
<div class="row justify-content-center">
<div class="col-12 col-md-10 text-center">
<h2>{{ c.CURRENT_VOLUNTEER.first_name }} {{ c.CURRENT_VOLUNTEER.last_name }}'s Available Shifts</h2>
Expand Down Expand Up @@ -74,6 +76,23 @@ <h2 class="accordion-header" id="shifts-info-details-header">
<p>
You are assigned to the following department{{ assigned_depts_labels|length|pluralize }}: {{ assigned_depts_labels|join(' / ') }}.
</p>

{% if requested_setup_nights or requested_teardown_nights %}
<div class="alert alert-warning pb-0" id="requested-night-warning">
<p>
You have requested hotel space on
{% if requested_setup_nights %}<strong>setup nights</strong> ({{ requested_setup_nights|readable_join }}) {% if requested_teardown_nights %}and {% endif %}{% endif %}
{% if requested_teardown_nights %}<strong>teardown nights</strong> ({{ requested_teardown_nights|readable_join }}){% endif %}
but you are not signed up for shifts on all requested nights.
</p>
<p>
Please make sure to sign up for
{% if requested_setup_nights and requested_teardown_nights %}BOTH {% endif %}{% if requested_setup_nights %}setup{% if requested_teardown_nights %} and {% endif %}{% endif %}
{% if requested_teardown_nights %}teardown{% endif %} shifts.
Failure to sign up for shifts in accordance with your hotel night requests may affect your ability to request staff crash space in the future.
</p>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down Expand Up @@ -373,12 +392,36 @@ <h2 class="accordion-header" id="restricted-jobs-info-header">
const eventLists = await Promise.all(responses.map((response) => response.json()));
let allNewEvents = [].concat(...eventLists);
fetchedEventList.push(...allNewEvents);

{% if requested_setup_nights or requested_teardown_nights %}
checkEdgeNights();
{% endif %}

return fetchedEventList;
} catch (e) {
showErrorMessage('Unable to connect to server, please try again.')
}
}

{% if requested_setup_nights or requested_teardown_nights %}
let checkEdgeNights = function() {
let allShifts = []
fetchedEventList.forEach(function(el) { allShifts.push(el.extendedProps) })
let setupShifts = allShifts.filter(function(el) { return el.is_setup == true; });
let teardownShifts = allShifts.filter(function(el) { return el.is_teardown == true; });

if ({% if requested_setup_nights %}setupShifts.length > 0
{% if requested_teardown_nights %}&&
{% endif %}{% endif %}
{% if requested_teardown_nights %}teardownShifts.length > 0
{% endif %}) {
$('#requested-night-warning').hide();
} else {
$('#requested-night-warning').show();
}
}
{% endif %}

let addEvents = function(id) {
fetchEventsURLS.push(possibleEventURLS[id]);
fetchedEventList.length = 0;
Expand Down Expand Up @@ -591,6 +634,7 @@ <h2 class="accordion-header" id="restricted-jobs-info-header">
eventClick: showEventDetails,
filterEventsWithResources: true,
resources: {{ default_filters|safe }},
eventClassNames: 'border border-white',
dayMaxEvents: true,
nowIndicator: true,
selectable: false,
Expand Down

0 comments on commit e2cac7a

Please sign in to comment.