mirror of
https://github.com/Sea-Haven-Industries/afterhours-shift-manager.git
synced 2026-09-30 06:43:12 +00:00
Merge pull request #5 from Sea-Haven-Industries/feature/extend-schedule-two-weeks
feat: Extend schedule to 2 full weeks at a time
This commit is contained in:
commit
23e4f7edf6
3 changed files with 23 additions and 14 deletions
|
|
@ -150,8 +150,10 @@ def create_app(bot_token: str, signing_secret: str) -> App:
|
|||
|
||||
def _show_next_week(respond, schedule):
|
||||
now = datetime.now(EASTERN)
|
||||
next_monday = now + timedelta(days=(7 - now.weekday()))
|
||||
blocks = build_week_schedule(schedule, start_date=next_monday)
|
||||
# Jump 2 weeks ahead from this week's Monday
|
||||
this_monday = now - timedelta(days=now.weekday())
|
||||
next_start = this_monday + timedelta(days=14)
|
||||
blocks = build_week_schedule(schedule, start_date=next_start)
|
||||
respond(blocks=blocks)
|
||||
|
||||
def _handle_register(respond, schedule, user_id, text):
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ def _format_shift_line(date: datetime, ext: str, name: str, source: str, is_toda
|
|||
|
||||
|
||||
def build_week_schedule(schedule, start_date: datetime | None = None) -> list[dict]:
|
||||
"""Build Block Kit blocks showing the week's schedule.
|
||||
"""Build Block Kit blocks showing the two-week schedule.
|
||||
|
||||
Args:
|
||||
schedule: ShiftSchedule instance
|
||||
start_date: Monday of the week to show. Defaults to current week's Monday.
|
||||
start_date: Monday of the first week to show. Defaults to current week's Monday.
|
||||
"""
|
||||
now = datetime.now(EASTERN)
|
||||
if start_date is None:
|
||||
|
|
@ -33,14 +33,18 @@ def build_week_schedule(schedule, start_date: datetime | None = None) -> list[di
|
|||
start_date = start_date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
today_str = now.strftime("%Y-%m-%d")
|
||||
week_label = start_date.strftime("%b %-d")
|
||||
end_label = (start_date + timedelta(days=6)).strftime("%b %-d")
|
||||
start_label = start_date.strftime("%b %-d")
|
||||
end_label = (start_date + timedelta(days=13)).strftime("%b %-d")
|
||||
|
||||
# Build lines for both weeks, separated by a blank line
|
||||
lines = []
|
||||
open_dates = []
|
||||
for i, day_name in enumerate(DAY_ORDER):
|
||||
for i in range(14):
|
||||
if i == 7:
|
||||
lines.append("") # visual separator between weeks
|
||||
date = start_date + timedelta(days=i)
|
||||
date_str = date.strftime("%Y-%m-%d")
|
||||
day_name = DAY_ORDER[i % 7]
|
||||
ext, name, source = schedule.resolve_shift(date_str, day_name)
|
||||
is_today = date_str == today_str
|
||||
lines.append(_format_shift_line(date, ext, name, source, is_today))
|
||||
|
|
@ -50,7 +54,7 @@ def build_week_schedule(schedule, start_date: datetime | None = None) -> list[di
|
|||
blocks = [
|
||||
{
|
||||
"type": "header",
|
||||
"text": {"type": "plain_text", "text": f"After-Hours Schedule — {week_label} to {end_label}"},
|
||||
"text": {"type": "plain_text", "text": f"After-Hours Schedule — {start_label} to {end_label}"},
|
||||
},
|
||||
{
|
||||
"type": "section",
|
||||
|
|
@ -58,7 +62,7 @@ def build_week_schedule(schedule, start_date: datetime | None = None) -> list[di
|
|||
},
|
||||
]
|
||||
|
||||
# Add pickup buttons for open shifts
|
||||
# Add pickup buttons for open shifts (Slack max 5 per actions block)
|
||||
if open_dates:
|
||||
blocks.append({"type": "divider"})
|
||||
elements = []
|
||||
|
|
@ -72,7 +76,9 @@ def build_week_schedule(schedule, start_date: datetime | None = None) -> list[di
|
|||
"style": "primary",
|
||||
}
|
||||
)
|
||||
blocks.append({"type": "actions", "elements": elements[:5]}) # Slack max 5 buttons
|
||||
# Slack allows max 5 buttons per actions block — use multiple blocks
|
||||
for chunk_start in range(0, len(elements), 5):
|
||||
blocks.append({"type": "actions", "elements": elements[chunk_start:chunk_start + 5]})
|
||||
|
||||
return blocks
|
||||
|
||||
|
|
@ -100,8 +106,8 @@ def build_help_blocks() -> list[dict]:
|
|||
"""Build help message blocks."""
|
||||
text = (
|
||||
"*After-Hours Shift Manager*\n\n"
|
||||
"`/oncall` — Show this week's schedule\n"
|
||||
"`/oncall next` — Show next week's schedule\n"
|
||||
"`/oncall` — Show the two-week schedule\n"
|
||||
"`/oncall next` — Show the following two weeks\n"
|
||||
"`/oncall pick <date>` — Pick up a shift\n"
|
||||
"`/oncall drop <date>` — Drop your shift (marks it open)\n"
|
||||
"`/oncall swap <date> @person` — Swap your shift with someone\n"
|
||||
|
|
|
|||
|
|
@ -36,13 +36,14 @@ def handler(event, context):
|
|||
schedule = ShiftSchedule()
|
||||
slack = WebClient(token=bot_token)
|
||||
|
||||
# Show this week (Monday = today)
|
||||
# Show two weeks starting from today (Monday)
|
||||
blocks = build_week_schedule(schedule, start_date=now)
|
||||
|
||||
end_date = now + timedelta(days=13)
|
||||
slack.chat_postMessage(
|
||||
channel=channel_id,
|
||||
blocks=blocks,
|
||||
text=f"After-Hours Schedule — Week of {now.strftime('%b %-d')}",
|
||||
text=f"After-Hours Schedule — {now.strftime('%b %-d')} to {end_date.strftime('%b %-d')}",
|
||||
)
|
||||
|
||||
logger.info("Posted weekly schedule to channel %s", channel_id)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue