Commit ·
faeb100
1
Parent(s): 221bb3c
シフト表で朝食/ディナーのタブを廃止し、ホール/キッチンごとに朝食表・ディナー表を縦に並べて表示
Browse files- routes/schedule.py +18 -15
- templates/schedule/index.html +31 -30
routes/schedule.py
CHANGED
|
@@ -122,7 +122,6 @@ def index(period_id):
|
|
| 122 |
asgn_map.setdefault(a.date, {}).setdefault(a.time_slot.value, []).append(a)
|
| 123 |
|
| 124 |
from datetime import date as _date
|
| 125 |
-
slot = request.args.get("slot", "breakfast")
|
| 126 |
pos = request.args.get("pos", "hall")
|
| 127 |
today = _date.today().isoformat()
|
| 128 |
notes = repo.get_schedule_notes(period_id)
|
|
@@ -192,19 +191,24 @@ def index(period_id):
|
|
| 192 |
]
|
| 193 |
total_shortage = sum(g['short_count'] for g in shortage_groups)
|
| 194 |
|
| 195 |
-
#
|
| 196 |
-
assigned_in_slot = {a.employee_id for a in assignments if a.time_slot.value == slot}
|
| 197 |
-
# このスロットで希望シフトを提出している従業員ID(専任外でも「希望はあるのに未アサイン」が見えるよう表示対象に含める)
|
| 198 |
-
submitted_in_slot = {eid for (eid, _ds, sv) in time_map.keys() if sv == slot}
|
| 199 |
-
|
| 200 |
-
# ポジション × スロットでメンバーを絞り込み
|
| 201 |
# 並び順は employees の取得順(社員 → 専任 → 兼任、各カテゴリ内は display_order)をそのまま維持
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
needs_regen = repo.get_period_gen_status(period_id).get("needs_regen", False)
|
| 210 |
|
|
@@ -242,11 +246,10 @@ def index(period_id):
|
|
| 242 |
"schedule/index.html",
|
| 243 |
period=period,
|
| 244 |
periods=periods,
|
| 245 |
-
|
| 246 |
emp_map=emp_map,
|
| 247 |
dates=dates,
|
| 248 |
asgn_map=asgn_map,
|
| 249 |
-
slot=slot,
|
| 250 |
pos=pos,
|
| 251 |
notes=notes,
|
| 252 |
time_map=time_map,
|
|
|
|
| 122 |
asgn_map.setdefault(a.date, {}).setdefault(a.time_slot.value, []).append(a)
|
| 123 |
|
| 124 |
from datetime import date as _date
|
|
|
|
| 125 |
pos = request.args.get("pos", "hall")
|
| 126 |
today = _date.today().isoformat()
|
| 127 |
notes = repo.get_schedule_notes(period_id)
|
|
|
|
| 191 |
]
|
| 192 |
total_shortage = sum(g['short_count'] for g in shortage_groups)
|
| 193 |
|
| 194 |
+
# ポジションでメンバーを絞り込み(朝食/ディナーは1画面に両方表示するため、スロットごとのリストを用意する)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
# 並び順は employees の取得順(社員 → 専任 → 兼任、各カテゴリ内は display_order)をそのまま維持
|
| 196 |
+
def _filter_employees_for_slot(slot_val):
|
| 197 |
+
# このスロットで実際に担当が入っている従業員ID(手動割当済みは専任外でも表示)
|
| 198 |
+
assigned_in_slot = {a.employee_id for a in assignments if a.time_slot.value == slot_val}
|
| 199 |
+
# このスロットで希望シフトを提出している従業員ID(専任外でも「希望はあるのに未アサイン」が見えるよう表示対象に含める)
|
| 200 |
+
submitted_in_slot = {eid for (eid, _ds, sv) in time_map.keys() if sv == slot_val}
|
| 201 |
+
return [
|
| 202 |
+
e for e in employees
|
| 203 |
+
if (e.primary_position is None or e.can_work_both_positions or e.primary_position.value == pos)
|
| 204 |
+
and (e.primary_timeslot is None or e.primary_timeslot.value == slot_val
|
| 205 |
+
or e.id in assigned_in_slot or e.id in submitted_in_slot)
|
| 206 |
+
]
|
| 207 |
+
|
| 208 |
+
employees_by_slot = {
|
| 209 |
+
"breakfast": _filter_employees_for_slot("breakfast"),
|
| 210 |
+
"dinner": _filter_employees_for_slot("dinner"),
|
| 211 |
+
}
|
| 212 |
|
| 213 |
needs_regen = repo.get_period_gen_status(period_id).get("needs_regen", False)
|
| 214 |
|
|
|
|
| 246 |
"schedule/index.html",
|
| 247 |
period=period,
|
| 248 |
periods=periods,
|
| 249 |
+
employees_by_slot=employees_by_slot,
|
| 250 |
emp_map=emp_map,
|
| 251 |
dates=dates,
|
| 252 |
asgn_map=asgn_map,
|
|
|
|
| 253 |
pos=pos,
|
| 254 |
notes=notes,
|
| 255 |
time_map=time_map,
|
templates/schedule/index.html
CHANGED
|
@@ -262,24 +262,20 @@
|
|
| 262 |
</form>
|
| 263 |
{% endif %}
|
| 264 |
</div>
|
| 265 |
-
<!-- 2行目:
|
| 266 |
<div class="d-flex gap-2 align-items-center flex-wrap">
|
| 267 |
<div class="btn-group btn-group-sm">
|
| 268 |
-
<a href="?
|
| 269 |
-
<a href="?slot=dinner&pos={{ pos }}" class="btn {{ 'btn-primary' if slot == 'dinner' else 'btn-outline-secondary' }}">ディナー</a>
|
| 270 |
-
</div>
|
| 271 |
-
<div class="btn-group btn-group-sm">
|
| 272 |
-
<a href="?slot={{ slot }}&pos=hall" class="btn {{ 'btn-success' if pos == 'hall' else 'btn-outline-secondary' }}">
|
| 273 |
<i class="bi bi-people me-1"></i>ホール
|
| 274 |
</a>
|
| 275 |
-
<a href="?
|
| 276 |
<i class="bi bi-egg-fried me-1"></i>キッチン
|
| 277 |
</a>
|
| 278 |
</div>
|
| 279 |
</div>
|
| 280 |
</div>
|
| 281 |
|
| 282 |
-
{% if not
|
| 283 |
<div class="alert alert-info mx-0 mb-3">
|
| 284 |
<i class="bi bi-info-circle me-2"></i>
|
| 285 |
表示するスタッフがいません。
|
|
@@ -343,8 +339,12 @@
|
|
| 343 |
{% endfor %}
|
| 344 |
</div>
|
| 345 |
|
| 346 |
-
|
| 347 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
<table class="table table-bordered table-sm mb-0">
|
| 349 |
<thead>
|
| 350 |
<tr>
|
|
@@ -353,7 +353,7 @@
|
|
| 353 |
{% set dow = d.weekday() %}
|
| 354 |
{% set ds_h = d.isoformat() %}
|
| 355 |
{% set is_holiday = ds_h in holidays %}
|
| 356 |
-
{% set st = staffing.get((ds_h,
|
| 357 |
{% set hdr_cls = 'short-staff' if st.get('short_staff') else 'short-leader' if st.get('short_leader') else '' %}
|
| 358 |
{% set is_today = ds_h == today %}
|
| 359 |
{% set day_cls = 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' %}
|
|
@@ -378,7 +378,7 @@
|
|
| 378 |
{% set dow = d.weekday() %}
|
| 379 |
{% set is_holiday = ds in holidays %}
|
| 380 |
{% set day_cls = 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' %}
|
| 381 |
-
{% set res_count = reservation_counts.get(ds, {}).get(
|
| 382 |
<td class="text-center {{ day_cls }} {{ 'today-col' if ds == today else '' }}" style="font-size:.75rem">
|
| 383 |
{% if res_count %}
|
| 384 |
<span style="color:#94a3b8">{{ res_count }}名</span>
|
|
@@ -404,7 +404,7 @@
|
|
| 404 |
</td>
|
| 405 |
{% endfor %}
|
| 406 |
</tr>
|
| 407 |
-
{% for emp in
|
| 408 |
<tr>
|
| 409 |
<td class="emp-col">
|
| 410 |
<a href="{{ url_for('employees.edit', emp_id=emp.id) }}"
|
|
@@ -414,13 +414,13 @@
|
|
| 414 |
{% set ds = d|string %}
|
| 415 |
{% set dow = d.weekday() %}
|
| 416 |
{% set is_holiday = ds in holidays %}
|
| 417 |
-
{% set day_assignments = asgn_map.get(ds, {}).get(
|
| 418 |
{% set emp_asgn = day_assignments | selectattr('employee_id', 'equalto', emp.id) | selectattr('position.value', 'equalto', pos) | list | first %}
|
| 419 |
{# 社員はポジション別デフォルトスロット時間を使用(設定画面で変更可) #}
|
| 420 |
{% set is_ft = emp.employment_type.value == 'full_time' %}
|
| 421 |
-
{% set default_slot_time = ft_times.get(pos, ft_times['hall'])[
|
| 422 |
-
{% set req_time = time_map.get((emp.id, ds,
|
| 423 |
-
{% set has_request = (emp.id, ds,
|
| 424 |
{% set display_time = req_time if req_time else (default_slot_time if is_ft else '') %}
|
| 425 |
{% set is_ft_off = (emp.id, ds) in ft_off_dates %}
|
| 426 |
{% set cell_note = cell_notes.get((emp.id, ds), '') %}
|
|
@@ -430,7 +430,7 @@
|
|
| 430 |
data-emp-id="{{ emp.id }}"
|
| 431 |
data-emp-name="{{ emp.name }}"
|
| 432 |
data-date="{{ ds }}"
|
| 433 |
-
data-slot="{{
|
| 434 |
data-pos="{{ emp_asgn.position.value if emp_asgn else '' }}"
|
| 435 |
data-assigned="{{ 'true' if emp_asgn else 'false' }}"
|
| 436 |
data-reinf="{{ 'true' if emp_asgn and emp_asgn.is_reinforcement else 'false' }}"
|
|
@@ -474,6 +474,7 @@
|
|
| 474 |
</tbody>
|
| 475 |
</table>
|
| 476 |
</div>
|
|
|
|
| 477 |
|
| 478 |
<!-- 凡例 -->
|
| 479 |
<div class="d-flex gap-3 mt-2 small text-muted flex-wrap">
|
|
@@ -481,7 +482,7 @@
|
|
| 481 |
<span><span class="chip-kitchen">K</span> キッチン出勤</span>
|
| 482 |
<span><span class="chip-unassigned">希</span> 希望提出済み・未アサイン</span>
|
| 483 |
<span class="text-secondary">— 該当なし</span>
|
| 484 |
-
<span class="ms-auto">表示中:{{ '
|
| 485 |
</div>
|
| 486 |
{% endif %}
|
| 487 |
</div>
|
|
@@ -628,16 +629,15 @@ const TL_ASGN = {
|
|
| 628 |
{% endfor %}
|
| 629 |
};
|
| 630 |
|
| 631 |
-
// スクロール復元 or 今日の列へ自動スクロール
|
| 632 |
-
(
|
| 633 |
-
const
|
| 634 |
-
|
| 635 |
-
const saved = sessionStorage.getItem('schedScroll');
|
| 636 |
if (saved) {
|
| 637 |
const { top, left } = JSON.parse(saved);
|
| 638 |
grid.scrollTop = top;
|
| 639 |
grid.scrollLeft = left;
|
| 640 |
-
sessionStorage.removeItem(
|
| 641 |
} else {
|
| 642 |
const todayTh = grid.querySelector('thead th.today-col');
|
| 643 |
if (todayTh) {
|
|
@@ -646,7 +646,7 @@ const TL_ASGN = {
|
|
| 646 |
grid.scrollLeft = Math.max(0, todayTh.offsetLeft - empColW - 8);
|
| 647 |
}
|
| 648 |
}
|
| 649 |
-
})
|
| 650 |
|
| 651 |
function toggleSg(id) {
|
| 652 |
const body = document.getElementById(id);
|
|
@@ -904,10 +904,11 @@ function _saveCellNote() {
|
|
| 904 |
|
| 905 |
function callAssign(payload) {
|
| 906 |
const periodId = PERIOD_ID;
|
| 907 |
-
// スクロール位置を保存してリロード後に復元
|
| 908 |
-
|
| 909 |
-
|
| 910 |
-
|
|
|
|
| 911 |
fetch(`/schedule/${periodId}/assign`, {
|
| 912 |
method: 'POST', headers: {'Content-Type': 'application/json'},
|
| 913 |
body: JSON.stringify(payload)
|
|
|
|
| 262 |
</form>
|
| 263 |
{% endif %}
|
| 264 |
</div>
|
| 265 |
+
<!-- 2行目:ホール/キッチン -->
|
| 266 |
<div class="d-flex gap-2 align-items-center flex-wrap">
|
| 267 |
<div class="btn-group btn-group-sm">
|
| 268 |
+
<a href="?pos=hall" class="btn {{ 'btn-success' if pos == 'hall' else 'btn-outline-secondary' }}">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
<i class="bi bi-people me-1"></i>ホール
|
| 270 |
</a>
|
| 271 |
+
<a href="?pos=kitchen" class="btn {{ 'btn-success' if pos == 'kitchen' else 'btn-outline-secondary' }}">
|
| 272 |
<i class="bi bi-egg-fried me-1"></i>キッチン
|
| 273 |
</a>
|
| 274 |
</div>
|
| 275 |
</div>
|
| 276 |
</div>
|
| 277 |
|
| 278 |
+
{% if not employees_by_slot.breakfast and not employees_by_slot.dinner %}
|
| 279 |
<div class="alert alert-info mx-0 mb-3">
|
| 280 |
<i class="bi bi-info-circle me-2"></i>
|
| 281 |
表示するスタッフがいません。
|
|
|
|
| 339 |
{% endfor %}
|
| 340 |
</div>
|
| 341 |
|
| 342 |
+
{% for sk, slabel in [('breakfast', '朝食'), ('dinner', 'ディナー')] %}
|
| 343 |
+
<!-- シフトグリッド({{ slabel }}) -->
|
| 344 |
+
<div class="fw-semibold mb-1 {{ '' if loop.first else 'mt-4' }}" style="font-size:.85rem;color:#94a3b8">
|
| 345 |
+
<i class="bi {{ 'bi-sunrise' if sk == 'breakfast' else 'bi-moon-stars' }} me-1"></i>{{ slabel }}
|
| 346 |
+
</div>
|
| 347 |
+
<div class="sched-grid" data-slot="{{ sk }}">
|
| 348 |
<table class="table table-bordered table-sm mb-0">
|
| 349 |
<thead>
|
| 350 |
<tr>
|
|
|
|
| 353 |
{% set dow = d.weekday() %}
|
| 354 |
{% set ds_h = d.isoformat() %}
|
| 355 |
{% set is_holiday = ds_h in holidays %}
|
| 356 |
+
{% set st = staffing.get((ds_h, sk, pos), {}) %}
|
| 357 |
{% set hdr_cls = 'short-staff' if st.get('short_staff') else 'short-leader' if st.get('short_leader') else '' %}
|
| 358 |
{% set is_today = ds_h == today %}
|
| 359 |
{% set day_cls = 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' %}
|
|
|
|
| 378 |
{% set dow = d.weekday() %}
|
| 379 |
{% set is_holiday = ds in holidays %}
|
| 380 |
{% set day_cls = 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' %}
|
| 381 |
+
{% set res_count = reservation_counts.get(ds, {}).get(sk, 0) %}
|
| 382 |
<td class="text-center {{ day_cls }} {{ 'today-col' if ds == today else '' }}" style="font-size:.75rem">
|
| 383 |
{% if res_count %}
|
| 384 |
<span style="color:#94a3b8">{{ res_count }}名</span>
|
|
|
|
| 404 |
</td>
|
| 405 |
{% endfor %}
|
| 406 |
</tr>
|
| 407 |
+
{% for emp in employees_by_slot[sk] %}
|
| 408 |
<tr>
|
| 409 |
<td class="emp-col">
|
| 410 |
<a href="{{ url_for('employees.edit', emp_id=emp.id) }}"
|
|
|
|
| 414 |
{% set ds = d|string %}
|
| 415 |
{% set dow = d.weekday() %}
|
| 416 |
{% set is_holiday = ds in holidays %}
|
| 417 |
+
{% set day_assignments = asgn_map.get(ds, {}).get(sk, []) %}
|
| 418 |
{% set emp_asgn = day_assignments | selectattr('employee_id', 'equalto', emp.id) | selectattr('position.value', 'equalto', pos) | list | first %}
|
| 419 |
{# 社員はポジション別デフォルトスロット時間を使用(設定画面で変更可) #}
|
| 420 |
{% set is_ft = emp.employment_type.value == 'full_time' %}
|
| 421 |
+
{% set default_slot_time = ft_times.get(pos, ft_times['hall'])[sk] %}
|
| 422 |
+
{% set req_time = time_map.get((emp.id, ds, sk), '') %}
|
| 423 |
+
{% set has_request = (emp.id, ds, sk) in time_map %}
|
| 424 |
{% set display_time = req_time if req_time else (default_slot_time if is_ft else '') %}
|
| 425 |
{% set is_ft_off = (emp.id, ds) in ft_off_dates %}
|
| 426 |
{% set cell_note = cell_notes.get((emp.id, ds), '') %}
|
|
|
|
| 430 |
data-emp-id="{{ emp.id }}"
|
| 431 |
data-emp-name="{{ emp.name }}"
|
| 432 |
data-date="{{ ds }}"
|
| 433 |
+
data-slot="{{ sk }}"
|
| 434 |
data-pos="{{ emp_asgn.position.value if emp_asgn else '' }}"
|
| 435 |
data-assigned="{{ 'true' if emp_asgn else 'false' }}"
|
| 436 |
data-reinf="{{ 'true' if emp_asgn and emp_asgn.is_reinforcement else 'false' }}"
|
|
|
|
| 474 |
</tbody>
|
| 475 |
</table>
|
| 476 |
</div>
|
| 477 |
+
{% endfor %}
|
| 478 |
|
| 479 |
<!-- 凡例 -->
|
| 480 |
<div class="d-flex gap-3 mt-2 small text-muted flex-wrap">
|
|
|
|
| 482 |
<span><span class="chip-kitchen">K</span> キッチン出勤</span>
|
| 483 |
<span><span class="chip-unassigned">希</span> 希望提出済み・未アサイン</span>
|
| 484 |
<span class="text-secondary">— 該当なし</span>
|
| 485 |
+
<span class="ms-auto">表示中:{{ 'ホール' if pos == 'hall' else 'キッチン' }}</span>
|
| 486 |
</div>
|
| 487 |
{% endif %}
|
| 488 |
</div>
|
|
|
|
| 629 |
{% endfor %}
|
| 630 |
};
|
| 631 |
|
| 632 |
+
// スクロール復元 or 今日の列へ自動スクロール(朝食・ディナー両グリッド)
|
| 633 |
+
document.querySelectorAll('.sched-grid').forEach(grid => {
|
| 634 |
+
const key = 'schedScroll_' + grid.dataset.slot;
|
| 635 |
+
const saved = sessionStorage.getItem(key);
|
|
|
|
| 636 |
if (saved) {
|
| 637 |
const { top, left } = JSON.parse(saved);
|
| 638 |
grid.scrollTop = top;
|
| 639 |
grid.scrollLeft = left;
|
| 640 |
+
sessionStorage.removeItem(key);
|
| 641 |
} else {
|
| 642 |
const todayTh = grid.querySelector('thead th.today-col');
|
| 643 |
if (todayTh) {
|
|
|
|
| 646 |
grid.scrollLeft = Math.max(0, todayTh.offsetLeft - empColW - 8);
|
| 647 |
}
|
| 648 |
}
|
| 649 |
+
});
|
| 650 |
|
| 651 |
function toggleSg(id) {
|
| 652 |
const body = document.getElementById(id);
|
|
|
|
| 904 |
|
| 905 |
function callAssign(payload) {
|
| 906 |
const periodId = PERIOD_ID;
|
| 907 |
+
// スクロール位置を保存してリロード後に復元(朝食・ディナー両グリッド)
|
| 908 |
+
document.querySelectorAll('.sched-grid').forEach(grid => {
|
| 909 |
+
sessionStorage.setItem('schedScroll_' + grid.dataset.slot,
|
| 910 |
+
JSON.stringify({ top: grid.scrollTop, left: grid.scrollLeft }));
|
| 911 |
+
});
|
| 912 |
fetch(`/schedule/${periodId}/assign`, {
|
| 913 |
method: 'POST', headers: {'Content-Type': 'application/json'},
|
| 914 |
body: JSON.stringify(payload)
|