Skip to content

Commit

Permalink
Add holidays to calendar view and update shift types in roster table
Browse files Browse the repository at this point in the history
  • Loading branch information
Tubo committed Jan 4, 2024
1 parent 2afe099 commit d0bb885
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
23 changes: 20 additions & 3 deletions radscheduler/core/views/calendar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from datetime import date

import holidays
from django.http import JsonResponse
from django.shortcuts import HttpResponse, render

Expand All @@ -24,10 +25,26 @@ def get_calendar(request):
leaves = Leave.objects.filter(date__gte=start, date__lte=end).select_related(
"registrar", "registrar__user"
)
events = shifts_to_events(shifts) + leaves_to_events(leaves)
events = shifts_to_events(shifts) + leaves_to_events(leaves) + holidays_to_events(start.year)
return JsonResponse(events, safe=False)


def holidays_to_events(year):
cant_holidays = holidays.country_holidays("NZ", subdiv="CAN", years=year)
result = []
for date, name in cant_holidays.items():
result.append(
{
"title": name,
"start": format_date(date),
"allDay": True,
"order": 0,
"display": "background",
}
)
return result


def shifts_to_events(shifts):
result = []

Expand All @@ -39,7 +56,7 @@ def shifts_to_events(shifts):
"start": format_date(shift.date),
"title": f"{shift_name}: {shift.registrar.user.username}" + (" (extra)" if shift.extra_duty else ""),
"allDay": True,
"order": 0,
"order": 1,
**map_shift_type_to_colour(shift.type),
}
)
Expand All @@ -60,7 +77,7 @@ def leaves_to_events(leaves):
"start": format_date(leave.date),
"title": f"{leave_name.capitalize()} {portion}: {leave.registrar.user.username}" + tbc,
"allDay": True,
"order": 1,
"order": 2,
"textColor": "black" if approved else "white",
"backgroundColor": "DarkSeaGreen" if approved else "grey",
}
Expand Down
27 changes: 13 additions & 14 deletions radscheduler/static/js/roster_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,10 @@ function rosterTable(id) {
content += " 💵"
}

if (shift.type === "Sleep day") {
el.style.backgroundColor = 'inherit'
content = "💤"
if (shift.type === "Sleep") {
el.style.backgroundColor = 'rgba(144, 238, 144, 0.53)'
} else if (shift.type === "RDO") {
el.style.backgroundColor = 'inherit'
content = "🏡"
el.style.backgroundColor = 'rgba(144, 238, 144, 0.53)'
}
}
} else {
Expand All @@ -147,11 +145,7 @@ function rosterTable(id) {

if (relevantStatus.length > 0) {
relevantStatus.map((status) => status.type).forEach((statusType) => {
if (statusType === "Reliever") {
if (content === "") {
content += " <small>🛟</small>"
}
} else if (statusType === "Buddy required") {
if (statusType === "Buddy required") {
if (content === "Long day") {
content += " <small>🤝</small>"
}
Expand Down Expand Up @@ -196,8 +190,12 @@ function rosterTable(id) {
}
}

const tip = document.createElement("div");
tip.appendChild(document.createTextNode(content))
const tip = document.createElement("ul");

if (content !== "") {
var li = tip.appendChild(document.createElement("li"))
li.innerHTML = content
}

const relevantStatus = statuses.filter((status) => {
const start = DateTime.fromISO(status.start)
Expand All @@ -213,8 +211,9 @@ function rosterTable(id) {

if (relevantStatus.length > 0) {
relevantStatus.forEach((status) => {
var status = document.createTextNode(status.type);
tip.appendChild(status)
var li = document.createElement("li");
li.innerHTML = status.type
tip.appendChild(li)
})
}

Expand Down

0 comments on commit d0bb885

Please sign in to comment.