Commit ·
9865854
1
Parent(s): adf63ae
シフト画面の出力制限・タイムライン並び順・PDFプレビューの表示崩れを修正
Browse files- 確定前はExcel/PDF出力を不可にし、PDFプレビューのみ「(案)」付きで利用可能にする
- タイムラインのスタッフ並び順をPDF/Excel出力と同じ規則に統一
- PDFプレビューが編集前の内容をキャッシュ表示する問題をno-store指定とURLのキャッシュバスターで解消
- routes/export_routes.py +16 -6
- routes/schedule.py +18 -1
- templates/schedule/index.html +38 -6
routes/export_routes.py
CHANGED
|
@@ -28,11 +28,14 @@ def _assignments_dict(period_id: int) -> dict:
|
|
| 28 |
|
| 29 |
@bp.get("/<int:period_id>/excel")
|
| 30 |
def excel(period_id):
|
| 31 |
-
"""Excel出力。
|
| 32 |
period = repo.get_period(period_id)
|
| 33 |
if not period:
|
| 34 |
flash("期間が見つかりません", "error")
|
| 35 |
return redirect(url_for("schedule.index", period_id=period_id))
|
|
|
|
|
|
|
|
|
|
| 36 |
employees = repo.get_all_employees(active_only=True)
|
| 37 |
assignments = _assignments_dict(period_id)
|
| 38 |
show_reserve = repo.get_app_setting("export_show_reservation_counts", "1") == "1"
|
|
@@ -40,18 +43,24 @@ def excel(period_id):
|
|
| 40 |
export_excel(buf, period, employees, assignments, show_reservation_counts=show_reserve)
|
| 41 |
buf.seek(0)
|
| 42 |
filename = _period_filename(period, "xlsx")
|
| 43 |
-
|
| 44 |
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
|
|
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
@bp.get("/<int:period_id>/pdf")
|
| 48 |
def pdf(period_id):
|
| 49 |
-
"""PDF出力。
|
| 50 |
-
?inline=1 で
|
| 51 |
period = repo.get_period(period_id)
|
| 52 |
if not period:
|
| 53 |
flash("期間が見つかりません", "error")
|
| 54 |
return redirect(url_for("schedule.index", period_id=period_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
employees = repo.get_all_employees(active_only=True)
|
| 56 |
assignments = _assignments_dict(period_id)
|
| 57 |
show_reserve = repo.get_app_setting("export_show_reservation_counts", "1") == "1"
|
|
@@ -59,6 +68,7 @@ def pdf(period_id):
|
|
| 59 |
export_pdf(buf, period, employees, assignments, show_reservation_counts=show_reserve)
|
| 60 |
buf.seek(0)
|
| 61 |
filename = _period_filename(period, "pdf")
|
| 62 |
-
|
| 63 |
-
return send_file(buf, as_attachment=not inline, download_name=filename,
|
| 64 |
mimetype="application/pdf")
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
@bp.get("/<int:period_id>/excel")
|
| 30 |
def excel(period_id):
|
| 31 |
+
"""Excel出力。確定済みの期間のみ出力できる"""
|
| 32 |
period = repo.get_period(period_id)
|
| 33 |
if not period:
|
| 34 |
flash("期間が見つかりません", "error")
|
| 35 |
return redirect(url_for("schedule.index", period_id=period_id))
|
| 36 |
+
if period.status != "confirmed":
|
| 37 |
+
flash("確定前のシフトはExcel出力できません。確定後に出力してください。", "error")
|
| 38 |
+
return redirect(url_for("schedule.index", period_id=period_id))
|
| 39 |
employees = repo.get_all_employees(active_only=True)
|
| 40 |
assignments = _assignments_dict(period_id)
|
| 41 |
show_reserve = repo.get_app_setting("export_show_reservation_counts", "1") == "1"
|
|
|
|
| 43 |
export_excel(buf, period, employees, assignments, show_reservation_counts=show_reserve)
|
| 44 |
buf.seek(0)
|
| 45 |
filename = _period_filename(period, "xlsx")
|
| 46 |
+
resp = send_file(buf, as_attachment=True, download_name=filename,
|
| 47 |
mimetype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
| 48 |
+
resp.headers["Cache-Control"] = "no-store"
|
| 49 |
+
return resp
|
| 50 |
|
| 51 |
|
| 52 |
@bp.get("/<int:period_id>/pdf")
|
| 53 |
def pdf(period_id):
|
| 54 |
+
"""PDF出力。確定済みの期間のみダウンロードできる。
|
| 55 |
+
?inline=1 の場合は未確定でも「(案)」付きでブラウザ内プレビューできる"""
|
| 56 |
period = repo.get_period(period_id)
|
| 57 |
if not period:
|
| 58 |
flash("期間が見つかりません", "error")
|
| 59 |
return redirect(url_for("schedule.index", period_id=period_id))
|
| 60 |
+
inline = request.args.get("inline") == "1"
|
| 61 |
+
if period.status != "confirmed" and not inline:
|
| 62 |
+
flash("確定前のシフトはPDF出力できません。PDFプレビューをご利用ください。", "error")
|
| 63 |
+
return redirect(url_for("schedule.index", period_id=period_id))
|
| 64 |
employees = repo.get_all_employees(active_only=True)
|
| 65 |
assignments = _assignments_dict(period_id)
|
| 66 |
show_reserve = repo.get_app_setting("export_show_reservation_counts", "1") == "1"
|
|
|
|
| 68 |
export_pdf(buf, period, employees, assignments, show_reservation_counts=show_reserve)
|
| 69 |
buf.seek(0)
|
| 70 |
filename = _period_filename(period, "pdf")
|
| 71 |
+
resp = send_file(buf, as_attachment=not inline, download_name=filename,
|
|
|
|
| 72 |
mimetype="application/pdf")
|
| 73 |
+
resp.headers["Cache-Control"] = "no-store"
|
| 74 |
+
return resp
|
routes/schedule.py
CHANGED
|
@@ -2,7 +2,7 @@ from collections import defaultdict
|
|
| 2 |
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
| 3 |
from db import repositories as repo
|
| 4 |
from models.schedule import ShiftAssignment
|
| 5 |
-
from utils.constants import TimeSlot, Position
|
| 6 |
|
| 7 |
from optimizer import forecast
|
| 8 |
from utils.holidays import holiday_set
|
|
@@ -259,6 +259,22 @@ def index(period_id):
|
|
| 259 |
|
| 260 |
# 人員充足チェック
|
| 261 |
all_employees = repo.get_all_employees(active_only=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
constraints = repo.get_shift_constraints()
|
| 263 |
reservation_counts = repo.get_reservation_counts(period_id)
|
| 264 |
reserv_thresh_b = safe_int(repo.get_app_setting("reserv_threshold_breakfast", "100"), 100)
|
|
@@ -397,6 +413,7 @@ def index(period_id):
|
|
| 397 |
reservation_counts=reservation_counts,
|
| 398 |
ft_off_dates=ft_off_dates,
|
| 399 |
cell_notes=cell_notes,
|
|
|
|
| 400 |
today=today,
|
| 401 |
ft_times=ft_times,
|
| 402 |
holidays=holidays,
|
|
|
|
| 2 |
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
| 3 |
from db import repositories as repo
|
| 4 |
from models.schedule import ShiftAssignment
|
| 5 |
+
from utils.constants import TimeSlot, Position, EmploymentType, PrimaryPosition
|
| 6 |
|
| 7 |
from optimizer import forecast
|
| 8 |
from utils.holidays import holiday_set
|
|
|
|
| 259 |
|
| 260 |
# 人員充足チェック
|
| 261 |
all_employees = repo.get_all_employees(active_only=True)
|
| 262 |
+
|
| 263 |
+
# PDF/Excel出力と同じ並び順(キッチン社員→キッチンA・P→ホール社員→ホールA・P、
|
| 264 |
+
# 各グループ内は display_order)のスタッフIDリスト。タイムラインの並び替えに使う
|
| 265 |
+
def _out_pos(e):
|
| 266 |
+
return e.output_position or e.primary_position
|
| 267 |
+
|
| 268 |
+
def _is_ft(e):
|
| 269 |
+
return e.employment_type == EmploymentType.FULL_TIME
|
| 270 |
+
|
| 271 |
+
_kitchen = [e for e in all_employees if _out_pos(e) == PrimaryPosition.KITCHEN]
|
| 272 |
+
_hall = [e for e in all_employees if _out_pos(e) != PrimaryPosition.KITCHEN]
|
| 273 |
+
export_emp_order = [e.id for e in (
|
| 274 |
+
[e for e in _kitchen if _is_ft(e)] + [e for e in _kitchen if not _is_ft(e)]
|
| 275 |
+
+ [e for e in _hall if _is_ft(e)] + [e for e in _hall if not _is_ft(e)]
|
| 276 |
+
)]
|
| 277 |
+
|
| 278 |
constraints = repo.get_shift_constraints()
|
| 279 |
reservation_counts = repo.get_reservation_counts(period_id)
|
| 280 |
reserv_thresh_b = safe_int(repo.get_app_setting("reserv_threshold_breakfast", "100"), 100)
|
|
|
|
| 413 |
reservation_counts=reservation_counts,
|
| 414 |
ft_off_dates=ft_off_dates,
|
| 415 |
cell_notes=cell_notes,
|
| 416 |
+
export_emp_order=export_emp_order,
|
| 417 |
today=today,
|
| 418 |
ft_times=ft_times,
|
| 419 |
holidays=holidays,
|
templates/schedule/index.html
CHANGED
|
@@ -257,14 +257,15 @@
|
|
| 257 |
</div>
|
| 258 |
<div class="ms-auto d-flex gap-1 align-items-center">
|
| 259 |
{% if period %}
|
| 260 |
-
{% set
|
|
|
|
| 261 |
{% if export_warnings %}
|
| 262 |
<button class="btn btn-outline-warning btn-sm" title="出力前の注意があります" aria-label="出力前の注意"
|
| 263 |
onclick="{% for w in export_warnings %}showToast({{ w | tojson }}, 'warning');{% endfor %}">
|
| 264 |
<i class="bi bi-exclamation-triangle"></i>
|
| 265 |
</button>
|
| 266 |
{% endif %}
|
| 267 |
-
|
| 268 |
<!-- 出力ドロップダウン -->
|
| 269 |
<div class="dropdown">
|
| 270 |
<button class="btn btn-outline-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" title="出力メニュー">
|
|
@@ -272,19 +273,31 @@
|
|
| 272 |
</button>
|
| 273 |
<ul class="dropdown-menu dropdown-menu-end" style="min-width: 180px;">
|
| 274 |
<li>
|
| 275 |
-
<a class="dropdown-item d-flex align-items-center gap-2" href="{{ url_for('export.pdf', period_id=period.id, inline=1) }}" target="_blank">
|
| 276 |
<i class="bi bi-eye text-primary"></i>PDFプレビュー{{ draft_hint }}
|
| 277 |
</a>
|
| 278 |
</li>
|
| 279 |
<li>
|
|
|
|
| 280 |
<a class="dropdown-item d-flex align-items-center gap-2" href="{{ url_for('export.excel', period_id=period.id) }}">
|
| 281 |
-
<i class="bi bi-file-earmark-spreadsheet text-success"></i>Excel出力
|
| 282 |
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
</li>
|
| 284 |
<li>
|
|
|
|
| 285 |
<a class="dropdown-item d-flex align-items-center gap-2" href="{{ url_for('export.pdf', period_id=period.id) }}">
|
| 286 |
-
<i class="bi bi-file-earmark-pdf text-danger"></i>PDF出力
|
| 287 |
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
</li>
|
| 289 |
</ul>
|
| 290 |
</div>
|
|
@@ -714,6 +727,8 @@ const IS_CONFIRMED = {{ 'true' if period.status == 'confirmed' else 'false'
|
|
| 714 |
const TOTAL_SHORTAGE = {{ total_shortage }};
|
| 715 |
const UNSUBMITTED_COUNT = {{ unsubmitted_count }};
|
| 716 |
const PERIOD_ID = {{ period.id }};
|
|
|
|
|
|
|
| 717 |
// スタッフ個別コメントキャッシュ {empId_date: note}
|
| 718 |
const CELL_NOTES = {
|
| 719 |
{% for (emp_id, date), note in cell_notes.items() %}
|
|
@@ -729,6 +744,7 @@ const TL_ASGN = {
|
|
| 729 |
"{{ sv }}": [
|
| 730 |
{% for a in alist %}
|
| 731 |
{ emp: {{ (emp_map[a.employee_id].name if a.employee_id in emp_map else '(不明)') | tojson }},
|
|
|
|
| 732 |
pos: "{{ a.position.value }}",
|
| 733 |
reinf: {{ 'true' if a.is_reinforcement else 'false' }},
|
| 734 |
rs: {{ (a.reinf_start or '') | tojson }},
|
|
@@ -782,6 +798,14 @@ function toggleShortage(header) {
|
|
| 782 |
chevron.classList.toggle('open', open);
|
| 783 |
}
|
| 784 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
function openTimeline(ds) {
|
| 786 |
const day = TL_ASGN[ds] || {};
|
| 787 |
const dow = ['月','火','水','木','金','土','日'];
|
|
@@ -799,7 +823,15 @@ function openTimeline(ds) {
|
|
| 799 |
...(day['breakfast'] || []).map(a=>({...a, slot:'breakfast'})),
|
| 800 |
...(day['dinner'] || []).map(a=>({...a, slot:'dinner'})),
|
| 801 |
];
|
| 802 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 803 |
|
| 804 |
const SLOT_RANGE = { breakfast:[6,11], dinner:[17,23] };
|
| 805 |
allItems.forEach(a => {
|
|
|
|
| 257 |
</div>
|
| 258 |
<div class="ms-auto d-flex gap-1 align-items-center">
|
| 259 |
{% if period %}
|
| 260 |
+
{% set is_confirmed = period.status == 'confirmed' %}
|
| 261 |
+
{% set draft_hint = '' if is_confirmed else ' (案)' %}
|
| 262 |
{% if export_warnings %}
|
| 263 |
<button class="btn btn-outline-warning btn-sm" title="出力前の注意があります" aria-label="出力前の注意"
|
| 264 |
onclick="{% for w in export_warnings %}showToast({{ w | tojson }}, 'warning');{% endfor %}">
|
| 265 |
<i class="bi bi-exclamation-triangle"></i>
|
| 266 |
</button>
|
| 267 |
{% endif %}
|
| 268 |
+
|
| 269 |
<!-- 出力ドロップダウン -->
|
| 270 |
<div class="dropdown">
|
| 271 |
<button class="btn btn-outline-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" title="出力メニュー">
|
|
|
|
| 273 |
</button>
|
| 274 |
<ul class="dropdown-menu dropdown-menu-end" style="min-width: 180px;">
|
| 275 |
<li>
|
| 276 |
+
<a class="dropdown-item d-flex align-items-center gap-2" href="{{ url_for('export.pdf', period_id=period.id, inline=1) }}" target="_blank" rel="noopener" onclick="return openPdfPreview(this)">
|
| 277 |
<i class="bi bi-eye text-primary"></i>PDFプレビュー{{ draft_hint }}
|
| 278 |
</a>
|
| 279 |
</li>
|
| 280 |
<li>
|
| 281 |
+
{% if is_confirmed %}
|
| 282 |
<a class="dropdown-item d-flex align-items-center gap-2" href="{{ url_for('export.excel', period_id=period.id) }}">
|
| 283 |
+
<i class="bi bi-file-earmark-spreadsheet text-success"></i>Excel出力
|
| 284 |
</a>
|
| 285 |
+
{% else %}
|
| 286 |
+
<span class="dropdown-item disabled d-flex align-items-center gap-2" aria-disabled="true" title="確定後に出力できます">
|
| 287 |
+
<i class="bi bi-file-earmark-spreadsheet text-success"></i>Excel出力(確定後)
|
| 288 |
+
</span>
|
| 289 |
+
{% endif %}
|
| 290 |
</li>
|
| 291 |
<li>
|
| 292 |
+
{% if is_confirmed %}
|
| 293 |
<a class="dropdown-item d-flex align-items-center gap-2" href="{{ url_for('export.pdf', period_id=period.id) }}">
|
| 294 |
+
<i class="bi bi-file-earmark-pdf text-danger"></i>PDF出力
|
| 295 |
</a>
|
| 296 |
+
{% else %}
|
| 297 |
+
<span class="dropdown-item disabled d-flex align-items-center gap-2" aria-disabled="true" title="確定後に出力できます">
|
| 298 |
+
<i class="bi bi-file-earmark-pdf text-danger"></i>PDF出力(確定後)
|
| 299 |
+
</span>
|
| 300 |
+
{% endif %}
|
| 301 |
</li>
|
| 302 |
</ul>
|
| 303 |
</div>
|
|
|
|
| 727 |
const TOTAL_SHORTAGE = {{ total_shortage }};
|
| 728 |
const UNSUBMITTED_COUNT = {{ unsubmitted_count }};
|
| 729 |
const PERIOD_ID = {{ period.id }};
|
| 730 |
+
// PDF/Excel出力と同じ並び順のスタッフIDリスト(タイムラインの並び替えに使用)
|
| 731 |
+
const EXPORT_EMP_ORDER = {{ export_emp_order | tojson }};
|
| 732 |
// スタッフ個別コメントキャッシュ {empId_date: note}
|
| 733 |
const CELL_NOTES = {
|
| 734 |
{% for (emp_id, date), note in cell_notes.items() %}
|
|
|
|
| 744 |
"{{ sv }}": [
|
| 745 |
{% for a in alist %}
|
| 746 |
{ emp: {{ (emp_map[a.employee_id].name if a.employee_id in emp_map else '(不明)') | tojson }},
|
| 747 |
+
empId: {{ a.employee_id }},
|
| 748 |
pos: "{{ a.position.value }}",
|
| 749 |
reinf: {{ 'true' if a.is_reinforcement else 'false' }},
|
| 750 |
rs: {{ (a.reinf_start or '') | tojson }},
|
|
|
|
| 798 |
chevron.classList.toggle('open', open);
|
| 799 |
}
|
| 800 |
|
| 801 |
+
// PDFプレビューは常に最新内容を表示させたいため、毎回キャッシュバスター付きURLで新規タブを開く
|
| 802 |
+
// (ブラウザのPDFビューアが同一URLのタブを再利用し、編集前の内容を表示し続けるのを防ぐ)
|
| 803 |
+
function openPdfPreview(el) {
|
| 804 |
+
const url = el.href + (el.href.includes('?') ? '&' : '?') + '_=' + Date.now();
|
| 805 |
+
window.open(url, '_blank', 'noopener');
|
| 806 |
+
return false;
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
function openTimeline(ds) {
|
| 810 |
const day = TL_ASGN[ds] || {};
|
| 811 |
const dow = ['月','火','水','木','金','土','日'];
|
|
|
|
| 823 |
...(day['breakfast'] || []).map(a=>({...a, slot:'breakfast'})),
|
| 824 |
...(day['dinner'] || []).map(a=>({...a, slot:'dinner'})),
|
| 825 |
];
|
| 826 |
+
// PDF/Excel出力と同じ並び順(キッチン社員→キッチンA・P→ホール社員→ホールA・P)でソート
|
| 827 |
+
allItems.sort((a,b) => {
|
| 828 |
+
let ia = EXPORT_EMP_ORDER.indexOf(a.empId);
|
| 829 |
+
let ib = EXPORT_EMP_ORDER.indexOf(b.empId);
|
| 830 |
+
if (ia === -1) ia = EXPORT_EMP_ORDER.length;
|
| 831 |
+
if (ib === -1) ib = EXPORT_EMP_ORDER.length;
|
| 832 |
+
if (ia !== ib) return ia - ib;
|
| 833 |
+
return a.emp.localeCompare(b.emp);
|
| 834 |
+
});
|
| 835 |
|
| 836 |
const SLOT_RANGE = { breakfast:[6,11], dinner:[17,23] };
|
| 837 |
allItems.forEach(a => {
|