Commit ·
46f3a06
1
Parent(s): 32106e7
feat: 複数機能追加・改善
Browse files- Windows版DBパス変更: %APPDATA%\SDU-Shift\shift_tool.db
- 応援要員: 希望外の従業員をシフト表に追加可能(橙色セルで区別)
- 集計行スティッキー: ホール/キッチン人数行を常に下部に固定表示
- ヘルプページ: 使い方/クレジット/バグ報告タブのダイアログを追加
- アップデートチェック: 起動時にGitHub Releasesを確認しサイドバーに通知
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- .github/workflows/build-windows.yml +9 -0
- README.md +1 -1
- db/database.py +9 -6
- db/repositories.py +23 -11
- models/schedule.py +1 -0
- ui/help_view.py +139 -0
- ui/main_window.py +87 -15
- ui/schedule_view.py +262 -242
- utils/theme.py +4 -0
- utils/version.py +42 -0
.github/workflows/build-windows.yml
CHANGED
|
@@ -23,6 +23,11 @@ jobs:
|
|
| 23 |
- name: 依存パッケージをインストール
|
| 24 |
run: pip install -r requirements.txt
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
- name: EXE をビルド
|
| 27 |
run: pyinstaller shift_tool.spec --clean --noconfirm
|
| 28 |
|
|
@@ -80,6 +85,10 @@ jobs:
|
|
| 80 |
print(f'icon.icns 生成完了: {os.path.getsize(\"assets/icon.icns\"):,} bytes')
|
| 81 |
"
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
- name: .app をビルド
|
| 84 |
run: pyinstaller shift_tool.spec --clean --noconfirm
|
| 85 |
|
|
|
|
| 23 |
- name: 依存パッケージをインストール
|
| 24 |
run: pip install -r requirements.txt
|
| 25 |
|
| 26 |
+
- name: バージョン情報を埋め込む
|
| 27 |
+
run: |
|
| 28 |
+
echo "APP_VERSION = 'build-${{ github.run_number }}'" > utils/_version.py
|
| 29 |
+
shell: pwsh
|
| 30 |
+
|
| 31 |
- name: EXE をビルド
|
| 32 |
run: pyinstaller shift_tool.spec --clean --noconfirm
|
| 33 |
|
|
|
|
| 85 |
print(f'icon.icns 生成完了: {os.path.getsize(\"assets/icon.icns\"):,} bytes')
|
| 86 |
"
|
| 87 |
|
| 88 |
+
- name: バージョン情報を埋め込む
|
| 89 |
+
run: |
|
| 90 |
+
echo "APP_VERSION = 'build-${{ github.run_number }}'" > utils/_version.py
|
| 91 |
+
|
| 92 |
- name: .app をビルド
|
| 93 |
run: pyinstaller shift_tool.spec --clean --noconfirm
|
| 94 |
|
README.md
CHANGED
|
@@ -123,7 +123,7 @@
|
|
| 123 |
| 実行方法 | 保存先 |
|
| 124 |
|---|---|
|
| 125 |
| macOS .app | `~/Library/Application Support/SDU-Shift/shift_tool.db` |
|
| 126 |
-
| Windows EXE |
|
| 127 |
| 開発環境(python main.py) | `~/.shift_tool/shift_tool.db` |
|
| 128 |
|
| 129 |
設定画面のバックアップ機能を使うと、任意の場所にDBを保存・復元できます。
|
|
|
|
| 123 |
| 実行方法 | 保存先 |
|
| 124 |
|---|---|
|
| 125 |
| macOS .app | `~/Library/Application Support/SDU-Shift/shift_tool.db` |
|
| 126 |
+
| Windows EXE | `%APPDATA%\SDU-Shift\shift_tool.db`(初回起動時に自動作成) |
|
| 127 |
| 開発環境(python main.py) | `~/.shift_tool/shift_tool.db` |
|
| 128 |
|
| 129 |
設定画面のバックアップ機能を使うと、任意の場所にDBを保存・復元できます。
|
db/database.py
CHANGED
|
@@ -12,7 +12,9 @@ if getattr(sys, "frozen", False):
|
|
| 12 |
DB_PATH = (Path.home() / "Library" / "Application Support"
|
| 13 |
/ "SDU-Shift" / "shift_tool.db")
|
| 14 |
else:
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
else:
|
| 17 |
DB_PATH = Path.home() / ".shift_tool" / "shift_tool.db"
|
| 18 |
|
|
@@ -91,11 +93,12 @@ def initialize_db():
|
|
| 91 |
|
| 92 |
# マイグレーション: 新カラムを既存テーブルへ追加
|
| 93 |
migrations = [
|
| 94 |
-
("shift_requests",
|
| 95 |
-
("shift_requests",
|
| 96 |
-
("shift_requests",
|
| 97 |
-
("employees",
|
| 98 |
-
("employees",
|
|
|
|
| 99 |
]
|
| 100 |
for table, col, definition in migrations:
|
| 101 |
try:
|
|
|
|
| 12 |
DB_PATH = (Path.home() / "Library" / "Application Support"
|
| 13 |
/ "SDU-Shift" / "shift_tool.db")
|
| 14 |
else:
|
| 15 |
+
# Windows: %APPDATA%\SDU-Shift\shift_tool.db
|
| 16 |
+
import os
|
| 17 |
+
DB_PATH = Path(os.environ.get("APPDATA", Path.home())) / "SDU-Shift" / "shift_tool.db"
|
| 18 |
else:
|
| 19 |
DB_PATH = Path.home() / ".shift_tool" / "shift_tool.db"
|
| 20 |
|
|
|
|
| 93 |
|
| 94 |
# マイグレーション: 新カラムを既存テーブルへ追加
|
| 95 |
migrations = [
|
| 96 |
+
("shift_requests", "pattern_id", "TEXT"),
|
| 97 |
+
("shift_requests", "custom_start", "TEXT"),
|
| 98 |
+
("shift_requests", "custom_end", "TEXT"),
|
| 99 |
+
("employees", "primary_position", "TEXT DEFAULT NULL"),
|
| 100 |
+
("employees", "primary_timeslot", "TEXT DEFAULT NULL"),
|
| 101 |
+
("shift_assignments","is_reinforcement", "INTEGER NOT NULL DEFAULT 0"),
|
| 102 |
]
|
| 103 |
for table, col, definition in migrations:
|
| 104 |
try:
|
db/repositories.py
CHANGED
|
@@ -218,11 +218,16 @@ def get_assignments(period_id: int) -> list[ShiftAssignment]:
|
|
| 218 |
(period_id,)
|
| 219 |
).fetchall()
|
| 220 |
conn.close()
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
|
| 227 |
|
| 228 |
def save_assignments(period_id: int, assignments: list[ShiftAssignment]):
|
|
@@ -230,8 +235,11 @@ def save_assignments(period_id: int, assignments: list[ShiftAssignment]):
|
|
| 230 |
conn.execute("DELETE FROM shift_assignments WHERE period_id=?", (period_id,))
|
| 231 |
for a in assignments:
|
| 232 |
conn.execute(
|
| 233 |
-
"INSERT INTO shift_assignments
|
| 234 |
-
(period_id,
|
|
|
|
|
|
|
|
|
|
| 235 |
)
|
| 236 |
conn.commit()
|
| 237 |
conn.close()
|
|
@@ -240,11 +248,15 @@ def save_assignments(period_id: int, assignments: list[ShiftAssignment]):
|
|
| 240 |
def add_assignment(period_id: int, assignment: ShiftAssignment):
|
| 241 |
conn = get_connection()
|
| 242 |
conn.execute(
|
| 243 |
-
"""INSERT INTO shift_assignments
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
| 246 |
(period_id, assignment.employee_id, assignment.date,
|
| 247 |
-
assignment.time_slot.value, assignment.position.value
|
|
|
|
| 248 |
)
|
| 249 |
conn.commit()
|
| 250 |
conn.close()
|
|
|
|
| 218 |
(period_id,)
|
| 219 |
).fetchall()
|
| 220 |
conn.close()
|
| 221 |
+
result = []
|
| 222 |
+
for r in rows:
|
| 223 |
+
keys = r.keys()
|
| 224 |
+
is_r = bool(r["is_reinforcement"]) if "is_reinforcement" in keys else False
|
| 225 |
+
result.append(ShiftAssignment(
|
| 226 |
+
employee_id=r["employee_id"], date=r["date"],
|
| 227 |
+
time_slot=TimeSlot(r["time_slot"]), position=Position(r["position"]),
|
| 228 |
+
is_reinforcement=is_r,
|
| 229 |
+
))
|
| 230 |
+
return result
|
| 231 |
|
| 232 |
|
| 233 |
def save_assignments(period_id: int, assignments: list[ShiftAssignment]):
|
|
|
|
| 235 |
conn.execute("DELETE FROM shift_assignments WHERE period_id=?", (period_id,))
|
| 236 |
for a in assignments:
|
| 237 |
conn.execute(
|
| 238 |
+
"INSERT INTO shift_assignments "
|
| 239 |
+
"(period_id, employee_id, date, time_slot, position, is_reinforcement) "
|
| 240 |
+
"VALUES (?,?,?,?,?,?)",
|
| 241 |
+
(period_id, a.employee_id, a.date, a.time_slot.value,
|
| 242 |
+
a.position.value, int(a.is_reinforcement))
|
| 243 |
)
|
| 244 |
conn.commit()
|
| 245 |
conn.close()
|
|
|
|
| 248 |
def add_assignment(period_id: int, assignment: ShiftAssignment):
|
| 249 |
conn = get_connection()
|
| 250 |
conn.execute(
|
| 251 |
+
"""INSERT INTO shift_assignments
|
| 252 |
+
(period_id, employee_id, date, time_slot, position, is_reinforcement)
|
| 253 |
+
VALUES (?,?,?,?,?,?)
|
| 254 |
+
ON CONFLICT(period_id, employee_id, date, time_slot) DO UPDATE SET
|
| 255 |
+
position=excluded.position,
|
| 256 |
+
is_reinforcement=excluded.is_reinforcement""",
|
| 257 |
(period_id, assignment.employee_id, assignment.date,
|
| 258 |
+
assignment.time_slot.value, assignment.position.value,
|
| 259 |
+
int(assignment.is_reinforcement))
|
| 260 |
)
|
| 261 |
conn.commit()
|
| 262 |
conn.close()
|
models/schedule.py
CHANGED
|
@@ -58,6 +58,7 @@ class ShiftAssignment:
|
|
| 58 |
date: str # YYYY-MM-DD
|
| 59 |
time_slot: TimeSlot
|
| 60 |
position: Position
|
|
|
|
| 61 |
|
| 62 |
|
| 63 |
@dataclass
|
|
|
|
| 58 |
date: str # YYYY-MM-DD
|
| 59 |
time_slot: TimeSlot
|
| 60 |
position: Position
|
| 61 |
+
is_reinforcement: bool = False # 応援要員として追加された場合 True
|
| 62 |
|
| 63 |
|
| 64 |
@dataclass
|
ui/help_view.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ヘルプ・クレジット・バグ報告ダイアログ"""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
from PyQt6.QtWidgets import (
|
| 4 |
+
QDialog, QVBoxLayout, QHBoxLayout, QTabWidget,
|
| 5 |
+
QLabel, QPushButton, QScrollArea, QWidget, QTextBrowser
|
| 6 |
+
)
|
| 7 |
+
from PyQt6.QtCore import Qt, QUrl
|
| 8 |
+
from PyQt6.QtGui import QFont, QDesktopServices
|
| 9 |
+
from utils.theme import theme
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
_HELP_HTML = """
|
| 13 |
+
<h2>SDU-Shift 使い方ガイド</h2>
|
| 14 |
+
|
| 15 |
+
<h3>📋 基本的な流れ</h3>
|
| 16 |
+
<ol>
|
| 17 |
+
<li><b>従業員管理</b> — 従業員を登録します。<br>
|
| 18 |
+
所属ポジション(ホール/キッチン専任)、勤務時間帯(朝食/ディナー専任)、
|
| 19 |
+
習熟度(リーダー/ベテラン/一般/新人)を設定してください。</li>
|
| 20 |
+
<li><b>希望シフト入力</b> — 期間を設定し、従業員ごとに出勤希望を入力します。<br>
|
| 21 |
+
シフトパターンを選択するか、カスタムで時刻を入力してください。</li>
|
| 22 |
+
<li><b>シフト自動生成</b> — 希望を元に最適なシフトを自動生成します。<br>
|
| 23 |
+
制約を満たせない場合はベストエフォートで生成し、不足箇所をメッセージで知らせます。</li>
|
| 24 |
+
<li><b>シフト表示・編集</b> — 生成結果を確認・手動で調整します。<br>
|
| 25 |
+
不足している枠には「応援要員」として任意のメンバーを追加できます。</li>
|
| 26 |
+
<li><b>出力</b> — シフト表示・編集画面の「出力 →」ボタンから PDF または Excel でエクスポートできます。</li>
|
| 27 |
+
</ol>
|
| 28 |
+
|
| 29 |
+
<h3>⌨️ キーボードショートカット(希望シフト入力)</h3>
|
| 30 |
+
<table border="1" cellpadding="4" cellspacing="0">
|
| 31 |
+
<tr><th>キー</th><th>動作</th></tr>
|
| 32 |
+
<tr><td>← / →</td><td>前/次の従業員に切り替え</td></tr>
|
| 33 |
+
<tr><td>0〜9</td><td>現在選択行のシフトパターンを番号で選択(0=休み)</td></tr>
|
| 34 |
+
</table>
|
| 35 |
+
|
| 36 |
+
<h3>🖱️ シフト表の操作</h3>
|
| 37 |
+
<ul>
|
| 38 |
+
<li><b>日付ヘッダーをクリック</b> — その日の希望シフトをタイムライン表示します</li>
|
| 39 |
+
<li><b>△(希望あり)セルをクリック</b> — ポジションを選択してアサインします</li>
|
| 40 |
+
<li><b>空白(希望なし)セルをクリック</b> — 応援要員として追加できます(橙色で表示)</li>
|
| 41 |
+
<li><b>アサイン済みセルをクリック</b> — アサインを削除します</li>
|
| 42 |
+
</ul>
|
| 43 |
+
|
| 44 |
+
<h3>💾 データの保存場所</h3>
|
| 45 |
+
<table border="1" cellpadding="4" cellspacing="0">
|
| 46 |
+
<tr><th>環境</th><th>保存先</th></tr>
|
| 47 |
+
<tr><td>macOS .app</td><td>~/Library/Application Support/SDU-Shift/shift_tool.db</td></tr>
|
| 48 |
+
<tr><td>Windows EXE</td><td>%APPDATA%\\SDU-Shift\\shift_tool.db</td></tr>
|
| 49 |
+
<tr><td>開発環境</td><td>~/.shift_tool/shift_tool.db</td></tr>
|
| 50 |
+
</table>
|
| 51 |
+
|
| 52 |
+
<h3>🔒 バックアップ</h3>
|
| 53 |
+
<p>「設定」画面のバックアップ機能で任意の場所に DB を保存できます。
|
| 54 |
+
アップデート前は必ずバックアップを取ることを推奨します。</p>
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
_CREDITS_HTML = """
|
| 58 |
+
<h2>クレジット</h2>
|
| 59 |
+
|
| 60 |
+
<h3>開発</h3>
|
| 61 |
+
<p>Richiesss</p>
|
| 62 |
+
|
| 63 |
+
<h3>使用ライブラリ</h3>
|
| 64 |
+
<table border="1" cellpadding="4" cellspacing="0">
|
| 65 |
+
<tr><th>ライブラリ</th><th>用途</th><th>ライセンス</th></tr>
|
| 66 |
+
<tr><td>PyQt6</td><td>GUI フレームワーク</td><td>GPL v3 / Commercial</td></tr>
|
| 67 |
+
<tr><td>Google OR-Tools</td><td>CP-SAT ソルバー(最適化)</td><td>Apache 2.0</td></tr>
|
| 68 |
+
<tr><td>SQLite</td><td>データベース</td><td>Public Domain</td></tr>
|
| 69 |
+
<tr><td>openpyxl</td><td>Excel 出力</td><td>MIT</td></tr>
|
| 70 |
+
<tr><td>reportlab</td><td>PDF 出力</td><td>BSD</td></tr>
|
| 71 |
+
<tr><td>PyInstaller</td><td>実行ファイルのビルド</td><td>GPL v2</td></tr>
|
| 72 |
+
</table>
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
_BUG_HTML = """
|
| 76 |
+
<h2>バグ報告・フィードバック</h2>
|
| 77 |
+
|
| 78 |
+
<p>バグの報告・機能リクエストは GitHub Issues からお願いします。</p>
|
| 79 |
+
|
| 80 |
+
<h3>報告時に含めてほしい情報</h3>
|
| 81 |
+
<ul>
|
| 82 |
+
<li>OS(Windows 10/11、macOS バージョン)</li>
|
| 83 |
+
<li>アプリのバージョン(サイドバー下部に表示)</li>
|
| 84 |
+
<li>再現手順(何をしたらどうなったか)</li>
|
| 85 |
+
<li>エラーメッセージがあればそのテキスト</li>
|
| 86 |
+
</ul>
|
| 87 |
+
|
| 88 |
+
<p><a href="https://github.com/Richiesss/shift-tool/issues">
|
| 89 |
+
→ GitHub Issues を開く</a></p>
|
| 90 |
+
|
| 91 |
+
<h3>よくある問題</h3>
|
| 92 |
+
<ul>
|
| 93 |
+
<li><b>Windows で起動しない</b> — SmartScreen の警告が出た場合は「詳細情報」→「実行」を選択してください</li>
|
| 94 |
+
<li><b>macOS で開けない</b> — Finder で右クリック → 「開く」→「開く」で起動できます</li>
|
| 95 |
+
<li><b>データが消えた</b> — 設定画面のバックアップから復元できます</li>
|
| 96 |
+
<li><b>シフトが生成できない</b> — 希望シフト入力が完了しているか確認してください。
|
| 97 |
+
制約に合わない場合はベストエフォートで生成されます</li>
|
| 98 |
+
</ul>
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class HelpDialog(QDialog):
|
| 103 |
+
def __init__(self, parent=None):
|
| 104 |
+
super().__init__(parent)
|
| 105 |
+
self.setWindowTitle("ヘルプ")
|
| 106 |
+
self.setMinimumSize(620, 520)
|
| 107 |
+
self._build_ui()
|
| 108 |
+
|
| 109 |
+
def _build_ui(self):
|
| 110 |
+
layout = QVBoxLayout(self)
|
| 111 |
+
layout.setSpacing(8)
|
| 112 |
+
|
| 113 |
+
tabs = QTabWidget()
|
| 114 |
+
|
| 115 |
+
for title, html in [
|
| 116 |
+
("📖 使い方", _HELP_HTML),
|
| 117 |
+
("👥 クレジット", _CREDITS_HTML),
|
| 118 |
+
("🐛 バグ報告", _BUG_HTML),
|
| 119 |
+
]:
|
| 120 |
+
browser = QTextBrowser()
|
| 121 |
+
browser.setHtml(html)
|
| 122 |
+
browser.setOpenLinks(False)
|
| 123 |
+
browser.anchorClicked.connect(self._on_link_clicked)
|
| 124 |
+
c = theme.c
|
| 125 |
+
browser.setStyleSheet(
|
| 126 |
+
f"background:{c['bg']}; color:{c['text']}; border:none; padding:8px;"
|
| 127 |
+
)
|
| 128 |
+
tabs.addTab(browser, title)
|
| 129 |
+
|
| 130 |
+
layout.addWidget(tabs)
|
| 131 |
+
|
| 132 |
+
btn = QPushButton("閉じる")
|
| 133 |
+
btn.clicked.connect(self.accept)
|
| 134 |
+
btn.setFixedHeight(32)
|
| 135 |
+
layout.addWidget(btn)
|
| 136 |
+
|
| 137 |
+
@staticmethod
|
| 138 |
+
def _on_link_clicked(url: QUrl):
|
| 139 |
+
QDesktopServices.openUrl(url)
|
ui/main_window.py
CHANGED
|
@@ -4,27 +4,43 @@ from PyQt6.QtWidgets import (
|
|
| 4 |
QMainWindow, QWidget, QHBoxLayout, QVBoxLayout,
|
| 5 |
QPushButton, QLabel, QStackedWidget, QFrame, QSizePolicy
|
| 6 |
)
|
| 7 |
-
from PyQt6.QtCore import Qt, QSize
|
| 8 |
-
from PyQt6.QtGui import QFont
|
|
|
|
| 9 |
|
| 10 |
from ui.employee_view import EmployeeView
|
| 11 |
from ui.shift_input_view import ShiftInputView
|
| 12 |
from ui.generate_view import GenerateView
|
| 13 |
from ui.schedule_view import ScheduleView
|
| 14 |
from ui.settings_view import SettingsView
|
|
|
|
| 15 |
from utils.theme import theme
|
|
|
|
| 16 |
|
| 17 |
NAV_ITEMS = [
|
| 18 |
-
("👥", "従業員管理",
|
| 19 |
("📝", "希望シフト入力", 1),
|
| 20 |
("⚡", "シフト自動生成", 2),
|
| 21 |
("📅", "シフト表示・編集", 3),
|
| 22 |
-
("⚙️", "設定",
|
| 23 |
]
|
| 24 |
|
| 25 |
SIDEBAR_W = 160
|
| 26 |
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
class SidebarButton(QPushButton):
|
| 29 |
def __init__(self, icon: str, text: str, parent=None):
|
| 30 |
super().__init__(parent)
|
|
@@ -38,7 +54,7 @@ class SidebarButton(QPushButton):
|
|
| 38 |
|
| 39 |
def _update_style(self):
|
| 40 |
c = theme.c
|
| 41 |
-
bg
|
| 42 |
hover = c["sidebar_active"] if self._active else c["sidebar_hover"]
|
| 43 |
self.setStyleSheet(f"""
|
| 44 |
QPushButton {{
|
|
@@ -61,6 +77,8 @@ class SidebarButton(QPushButton):
|
|
| 61 |
self._update_style()
|
| 62 |
|
| 63 |
|
|
|
|
|
|
|
| 64 |
class MainWindow(QMainWindow):
|
| 65 |
def __init__(self):
|
| 66 |
super().__init__()
|
|
@@ -69,6 +87,7 @@ class MainWindow(QMainWindow):
|
|
| 69 |
self._build_ui()
|
| 70 |
self._nav_to(0)
|
| 71 |
theme.changed.connect(self._on_theme_changed)
|
|
|
|
| 72 |
|
| 73 |
def _build_ui(self):
|
| 74 |
central = QWidget()
|
|
@@ -77,7 +96,7 @@ class MainWindow(QMainWindow):
|
|
| 77 |
root.setContentsMargins(0, 0, 0, 0)
|
| 78 |
root.setSpacing(0)
|
| 79 |
|
| 80 |
-
# サイドバー
|
| 81 |
self._sidebar = QWidget()
|
| 82 |
self._sidebar.setFixedWidth(SIDEBAR_W)
|
| 83 |
sb_layout = QVBoxLayout(self._sidebar)
|
|
@@ -99,7 +118,24 @@ class MainWindow(QMainWindow):
|
|
| 99 |
|
| 100 |
sb_layout.addStretch()
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
self._ver_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 104 |
sb_layout.addWidget(self._ver_label)
|
| 105 |
|
|
@@ -110,14 +146,14 @@ class MainWindow(QMainWindow):
|
|
| 110 |
self._sep.setFrameShape(QFrame.Shape.VLine)
|
| 111 |
root.addWidget(self._sep)
|
| 112 |
|
| 113 |
-
# コンテンツエリア
|
| 114 |
self.stack = QStackedWidget()
|
| 115 |
|
| 116 |
-
self._employee_view
|
| 117 |
self._shift_input_view = ShiftInputView()
|
| 118 |
-
self._generate_view
|
| 119 |
-
self._schedule_view
|
| 120 |
-
self._settings_view
|
| 121 |
|
| 122 |
self.stack.addWidget(self._employee_view)
|
| 123 |
self.stack.addWidget(self._shift_input_view)
|
|
@@ -142,6 +178,17 @@ class MainWindow(QMainWindow):
|
|
| 142 |
f"color: {c['text2']}; font-size: 10px; padding: 8px; "
|
| 143 |
f"background: {c['sidebar_bg']};"
|
| 144 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
self._sep.setStyleSheet(f"color: {c['border']};")
|
| 146 |
self.stack.setStyleSheet(f"background: {c['bg']};")
|
| 147 |
|
|
@@ -149,7 +196,6 @@ class MainWindow(QMainWindow):
|
|
| 149 |
self._apply_sidebar_style()
|
| 150 |
for btn in self._nav_buttons:
|
| 151 |
btn.apply_theme()
|
| 152 |
-
# 各ビューのテーマ更新
|
| 153 |
for view in (self._employee_view, self._shift_input_view,
|
| 154 |
self._generate_view, self._schedule_view, self._settings_view):
|
| 155 |
if hasattr(view, "apply_theme"):
|
|
@@ -159,7 +205,6 @@ class MainWindow(QMainWindow):
|
|
| 159 |
self.stack.setCurrentIndex(idx)
|
| 160 |
for i, btn in enumerate(self._nav_buttons):
|
| 161 |
btn.setActive(i == idx)
|
| 162 |
-
|
| 163 |
if idx == 2:
|
| 164 |
self._generate_view.refresh()
|
| 165 |
elif idx == 3:
|
|
@@ -170,8 +215,35 @@ class MainWindow(QMainWindow):
|
|
| 170 |
self._nav_to(3)
|
| 171 |
|
| 172 |
def _on_db_imported(self):
|
| 173 |
-
"""DB入れ替え後、全ビューのデータを再読み込み"""
|
| 174 |
self._employee_view.refresh()
|
| 175 |
self._shift_input_view._load_periods()
|
| 176 |
self._generate_view.refresh()
|
| 177 |
self._schedule_view.refresh()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
QMainWindow, QWidget, QHBoxLayout, QVBoxLayout,
|
| 5 |
QPushButton, QLabel, QStackedWidget, QFrame, QSizePolicy
|
| 6 |
)
|
| 7 |
+
from PyQt6.QtCore import Qt, QSize, QThread, pyqtSignal
|
| 8 |
+
from PyQt6.QtGui import QFont, QDesktopServices
|
| 9 |
+
from PyQt6.QtCore import QUrl
|
| 10 |
|
| 11 |
from ui.employee_view import EmployeeView
|
| 12 |
from ui.shift_input_view import ShiftInputView
|
| 13 |
from ui.generate_view import GenerateView
|
| 14 |
from ui.schedule_view import ScheduleView
|
| 15 |
from ui.settings_view import SettingsView
|
| 16 |
+
from ui.help_view import HelpDialog
|
| 17 |
from utils.theme import theme
|
| 18 |
+
from utils.version import APP_VERSION
|
| 19 |
|
| 20 |
NAV_ITEMS = [
|
| 21 |
+
("👥", "従業員管理", 0),
|
| 22 |
("📝", "希望シフト入力", 1),
|
| 23 |
("⚡", "シフト自動生成", 2),
|
| 24 |
("📅", "シフト表示・編集", 3),
|
| 25 |
+
("⚙️", "設定", 4),
|
| 26 |
]
|
| 27 |
|
| 28 |
SIDEBAR_W = 160
|
| 29 |
|
| 30 |
|
| 31 |
+
# ── アップデートチェッカー(バックグラウンドスレッド)──────────────────────
|
| 32 |
+
|
| 33 |
+
class _UpdateChecker(QThread):
|
| 34 |
+
result = pyqtSignal(bool, str, str) # (is_newer, tag, url)
|
| 35 |
+
|
| 36 |
+
def run(self):
|
| 37 |
+
from utils.version import check_for_update
|
| 38 |
+
is_newer, tag, url = check_for_update()
|
| 39 |
+
self.result.emit(is_newer, tag, url)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# ── サイドバーボタン ──────────────────────────────────────────────────────
|
| 43 |
+
|
| 44 |
class SidebarButton(QPushButton):
|
| 45 |
def __init__(self, icon: str, text: str, parent=None):
|
| 46 |
super().__init__(parent)
|
|
|
|
| 54 |
|
| 55 |
def _update_style(self):
|
| 56 |
c = theme.c
|
| 57 |
+
bg = c["sidebar_active"] if self._active else "transparent"
|
| 58 |
hover = c["sidebar_active"] if self._active else c["sidebar_hover"]
|
| 59 |
self.setStyleSheet(f"""
|
| 60 |
QPushButton {{
|
|
|
|
| 77 |
self._update_style()
|
| 78 |
|
| 79 |
|
| 80 |
+
# ── メインウィンドウ ──────────────────────────────────────────────────────
|
| 81 |
+
|
| 82 |
class MainWindow(QMainWindow):
|
| 83 |
def __init__(self):
|
| 84 |
super().__init__()
|
|
|
|
| 87 |
self._build_ui()
|
| 88 |
self._nav_to(0)
|
| 89 |
theme.changed.connect(self._on_theme_changed)
|
| 90 |
+
self._start_update_check()
|
| 91 |
|
| 92 |
def _build_ui(self):
|
| 93 |
central = QWidget()
|
|
|
|
| 96 |
root.setContentsMargins(0, 0, 0, 0)
|
| 97 |
root.setSpacing(0)
|
| 98 |
|
| 99 |
+
# ── サイドバー ───────────────────────────────────────────────────
|
| 100 |
self._sidebar = QWidget()
|
| 101 |
self._sidebar.setFixedWidth(SIDEBAR_W)
|
| 102 |
sb_layout = QVBoxLayout(self._sidebar)
|
|
|
|
| 118 |
|
| 119 |
sb_layout.addStretch()
|
| 120 |
|
| 121 |
+
# ヘルプボタン
|
| 122 |
+
self._btn_help = QPushButton(" ❓\n ヘルプ")
|
| 123 |
+
self._btn_help.setFixedHeight(56)
|
| 124 |
+
self._btn_help.setFixedWidth(SIDEBAR_W)
|
| 125 |
+
self._btn_help.setFont(QFont("", 10))
|
| 126 |
+
self._btn_help.clicked.connect(self._on_help)
|
| 127 |
+
sb_layout.addWidget(self._btn_help)
|
| 128 |
+
|
| 129 |
+
# アップデート通知ラベル(初期非表示)
|
| 130 |
+
self._update_label = QLabel("")
|
| 131 |
+
self._update_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 132 |
+
self._update_label.setWordWrap(True)
|
| 133 |
+
self._update_label.setVisible(False)
|
| 134 |
+
self._update_label.setCursor(Qt.CursorShape.PointingHandCursor)
|
| 135 |
+
self._update_label.mousePressEvent = self._on_update_label_clicked
|
| 136 |
+
sb_layout.addWidget(self._update_label)
|
| 137 |
+
|
| 138 |
+
self._ver_label = QLabel(APP_VERSION)
|
| 139 |
self._ver_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 140 |
sb_layout.addWidget(self._ver_label)
|
| 141 |
|
|
|
|
| 146 |
self._sep.setFrameShape(QFrame.Shape.VLine)
|
| 147 |
root.addWidget(self._sep)
|
| 148 |
|
| 149 |
+
# ── コンテンツエリア ─────────────────────────────────────────────
|
| 150 |
self.stack = QStackedWidget()
|
| 151 |
|
| 152 |
+
self._employee_view = EmployeeView()
|
| 153 |
self._shift_input_view = ShiftInputView()
|
| 154 |
+
self._generate_view = GenerateView()
|
| 155 |
+
self._schedule_view = ScheduleView()
|
| 156 |
+
self._settings_view = SettingsView()
|
| 157 |
|
| 158 |
self.stack.addWidget(self._employee_view)
|
| 159 |
self.stack.addWidget(self._shift_input_view)
|
|
|
|
| 178 |
f"color: {c['text2']}; font-size: 10px; padding: 8px; "
|
| 179 |
f"background: {c['sidebar_bg']};"
|
| 180 |
)
|
| 181 |
+
self._btn_help.setStyleSheet(f"""
|
| 182 |
+
QPushButton {{
|
| 183 |
+
background: transparent;
|
| 184 |
+
color: {c["sidebar_text"]};
|
| 185 |
+
border: none;
|
| 186 |
+
text-align: left;
|
| 187 |
+
padding-left: 16px;
|
| 188 |
+
border-radius: 0;
|
| 189 |
+
}}
|
| 190 |
+
QPushButton:hover {{ background: {c["sidebar_hover"]}; }}
|
| 191 |
+
""")
|
| 192 |
self._sep.setStyleSheet(f"color: {c['border']};")
|
| 193 |
self.stack.setStyleSheet(f"background: {c['bg']};")
|
| 194 |
|
|
|
|
| 196 |
self._apply_sidebar_style()
|
| 197 |
for btn in self._nav_buttons:
|
| 198 |
btn.apply_theme()
|
|
|
|
| 199 |
for view in (self._employee_view, self._shift_input_view,
|
| 200 |
self._generate_view, self._schedule_view, self._settings_view):
|
| 201 |
if hasattr(view, "apply_theme"):
|
|
|
|
| 205 |
self.stack.setCurrentIndex(idx)
|
| 206 |
for i, btn in enumerate(self._nav_buttons):
|
| 207 |
btn.setActive(i == idx)
|
|
|
|
| 208 |
if idx == 2:
|
| 209 |
self._generate_view.refresh()
|
| 210 |
elif idx == 3:
|
|
|
|
| 215 |
self._nav_to(3)
|
| 216 |
|
| 217 |
def _on_db_imported(self):
|
|
|
|
| 218 |
self._employee_view.refresh()
|
| 219 |
self._shift_input_view._load_periods()
|
| 220 |
self._generate_view.refresh()
|
| 221 |
self._schedule_view.refresh()
|
| 222 |
+
|
| 223 |
+
def _on_help(self):
|
| 224 |
+
dlg = HelpDialog(parent=self)
|
| 225 |
+
dlg.exec()
|
| 226 |
+
|
| 227 |
+
# ── アップデートチェック ─────────────────────────────────────────────
|
| 228 |
+
|
| 229 |
+
def _start_update_check(self):
|
| 230 |
+
self._updater = _UpdateChecker()
|
| 231 |
+
self._updater.result.connect(self._on_update_result)
|
| 232 |
+
self._updater.start()
|
| 233 |
+
|
| 234 |
+
def _on_update_result(self, is_newer: bool, tag: str, url: str):
|
| 235 |
+
self._update_url = url
|
| 236 |
+
if is_newer:
|
| 237 |
+
self._update_label.setText(
|
| 238 |
+
f"🆕 {tag} が\n利用可能です\nクリックして\nダウンロード"
|
| 239 |
+
)
|
| 240 |
+
self._update_label.setVisible(True)
|
| 241 |
+
self._update_label.setStyleSheet(
|
| 242 |
+
"background:#1d4ed8; color:white; font-size:10px; "
|
| 243 |
+
"padding:6px 4px; border-radius:4px; margin:4px;"
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
def _on_update_label_clicked(self, event):
|
| 247 |
+
url = getattr(self, "_update_url", "")
|
| 248 |
+
if url:
|
| 249 |
+
QDesktopServices.openUrl(QUrl(url))
|
ui/schedule_view.py
CHANGED
|
@@ -5,22 +5,20 @@ from collections import defaultdict
|
|
| 5 |
from PyQt6.QtWidgets import (
|
| 6 |
QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
| 7 |
QComboBox, QTableWidget, QTableWidgetItem, QHeaderView,
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
QMessageBox, QAbstractItemView, QTabWidget, QScrollBar
|
| 11 |
)
|
| 12 |
from PyQt6.QtCore import Qt, pyqtSignal
|
| 13 |
-
from PyQt6.QtGui import QFont, QColor, QBrush, QPainter, QPen
|
| 14 |
from db import repositories as repo
|
| 15 |
from models.employee import Employee
|
| 16 |
from models.schedule import ShiftAssignment, ShiftRequest
|
| 17 |
from utils.constants import (
|
| 18 |
-
TimeSlot, Position, PrimaryPosition, SkillLevel,
|
| 19 |
-
SHIFT_CONSTRAINTS
|
| 20 |
)
|
| 21 |
from utils.theme import theme
|
| 22 |
|
| 23 |
-
# 習熟度バッジ
|
| 24 |
SKILL_BADGE = {
|
| 25 |
SkillLevel.LEADER: "★★",
|
| 26 |
SkillLevel.VETERAN: "★",
|
|
@@ -28,10 +26,8 @@ SKILL_BADGE = {
|
|
| 28 |
SkillLevel.BEGINNER: "▼",
|
| 29 |
}
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
COLOR_WARN = QColor("#fef3c7")
|
| 34 |
-
COLOR_ERROR = QColor("#fee2e2")
|
| 35 |
|
| 36 |
|
| 37 |
class ScheduleView(QWidget):
|
|
@@ -39,18 +35,20 @@ class ScheduleView(QWidget):
|
|
| 39 |
super().__init__(parent)
|
| 40 |
self._period = None
|
| 41 |
self._employees: list[Employee] = []
|
| 42 |
-
|
|
|
|
| 43 |
self._requests: dict[tuple[int, str], tuple[bool, bool]] = {}
|
| 44 |
self._raw_requests: dict[tuple[int, str], ShiftRequest] = {}
|
| 45 |
self._build_ui()
|
| 46 |
self._load_periods()
|
| 47 |
|
|
|
|
|
|
|
| 48 |
def _build_ui(self):
|
| 49 |
layout = QVBoxLayout(self)
|
| 50 |
layout.setContentsMargins(16, 16, 16, 16)
|
| 51 |
layout.setSpacing(10)
|
| 52 |
|
| 53 |
-
# ヘッダー
|
| 54 |
header = QHBoxLayout()
|
| 55 |
title = QLabel("シフト表 確認・編集")
|
| 56 |
title.setFont(QFont("", 16, QFont.Weight.Bold))
|
|
@@ -81,21 +79,26 @@ class ScheduleView(QWidget):
|
|
| 81 |
self._status_legend_labels.append((lbl, color_key))
|
| 82 |
legend.addWidget(lbl)
|
| 83 |
legend.addStretch()
|
| 84 |
-
legend.addWidget(QLabel("習熟度: ★★リーダー ★ベテラン ▼新人"))
|
|
|
|
|
|
|
|
|
|
| 85 |
layout.addLayout(legend)
|
| 86 |
|
| 87 |
-
# タブ
|
| 88 |
self._show_other: dict[TimeSlot, bool] = {
|
| 89 |
TimeSlot.BREAKFAST: False,
|
| 90 |
-
TimeSlot.DINNER:
|
| 91 |
}
|
| 92 |
self.tab_widget = QTabWidget()
|
| 93 |
-
|
|
|
|
| 94 |
self._btn_other_b, self._warn_label_b) = self._make_tab_widget(TimeSlot.BREAKFAST)
|
| 95 |
-
(
|
| 96 |
self._btn_other_d, self._warn_label_d) = self._make_tab_widget(TimeSlot.DINNER)
|
| 97 |
-
|
| 98 |
-
self.tab_widget.addTab(
|
|
|
|
| 99 |
layout.addWidget(self.tab_widget)
|
| 100 |
|
| 101 |
self.status_label = QLabel("")
|
|
@@ -104,11 +107,11 @@ class ScheduleView(QWidget):
|
|
| 104 |
self._apply_styles()
|
| 105 |
|
| 106 |
def _make_tab_widget(self, slot: TimeSlot):
|
| 107 |
-
"""タブの中身
|
| 108 |
container = QWidget()
|
| 109 |
vbox = QVBoxLayout(container)
|
| 110 |
vbox.setContentsMargins(0, 6, 0, 0)
|
| 111 |
-
vbox.setSpacing(
|
| 112 |
|
| 113 |
# 他スロット専任メンバー表示トグル
|
| 114 |
other_label = "ディナー専任" if slot == TimeSlot.BREAKFAST else "朝食専任"
|
|
@@ -131,26 +134,60 @@ class ScheduleView(QWidget):
|
|
| 131 |
)
|
| 132 |
vbox.addWidget(warn_label)
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
def _on_toggle_other(self, slot: TimeSlot, checked: bool):
|
| 150 |
self._show_other[slot] = checked
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
self.
|
|
|
|
| 154 |
|
| 155 |
def _apply_styles(self):
|
| 156 |
c = theme.c
|
|
@@ -174,6 +211,8 @@ class ScheduleView(QWidget):
|
|
| 174 |
self._apply_styles()
|
| 175 |
self._render_table()
|
| 176 |
|
|
|
|
|
|
|
| 177 |
def _load_periods(self):
|
| 178 |
periods = repo.get_all_periods()
|
| 179 |
self.period_combo.blockSignals(True)
|
|
@@ -196,7 +235,8 @@ class ScheduleView(QWidget):
|
|
| 196 |
def _on_period_changed(self, idx):
|
| 197 |
self._period = self.period_combo.currentData()
|
| 198 |
if not self._period:
|
| 199 |
-
for t in (self.
|
|
|
|
| 200 |
t.setRowCount(0)
|
| 201 |
t.setColumnCount(0)
|
| 202 |
return
|
|
@@ -208,7 +248,7 @@ class ScheduleView(QWidget):
|
|
| 208 |
assignments = repo.get_assignments(self._period.id)
|
| 209 |
requests = repo.get_shift_requests(self._period.id)
|
| 210 |
self._assignments = {
|
| 211 |
-
(a.employee_id, a.date, a.time_slot.value): a.position.value
|
| 212 |
for a in assignments
|
| 213 |
}
|
| 214 |
self._requests = {
|
|
@@ -220,13 +260,18 @@ class ScheduleView(QWidget):
|
|
| 220 |
for r in requests
|
| 221 |
}
|
| 222 |
|
|
|
|
|
|
|
| 223 |
def _render_table(self):
|
| 224 |
if not self._period or not self._employees:
|
| 225 |
return
|
| 226 |
-
self._render_slot_table(
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
|
| 229 |
-
def _render_slot_table(self,
|
|
|
|
| 230 |
dates = self._period.date_range()
|
| 231 |
|
| 232 |
col_headers = ["氏名"]
|
|
@@ -241,20 +286,20 @@ class ScheduleView(QWidget):
|
|
| 241 |
# 従業員フィルタリング
|
| 242 |
primary_emps = [e for e in self._employees
|
| 243 |
if e.primary_timeslot is None or e.primary_timeslot == slot]
|
| 244 |
-
other_emps
|
| 245 |
-
|
| 246 |
other_ids = {e.id for e in other_emps}
|
| 247 |
show_other = self._show_other.get(slot, False)
|
| 248 |
display_emps = primary_emps + (other_emps if show_other else [])
|
| 249 |
|
| 250 |
-
# ポジション別グループ
|
| 251 |
hall_emps = [e for e in display_emps
|
| 252 |
if e.primary_position is not None and e.primary_position.value == "hall"]
|
| 253 |
any_emps = [e for e in display_emps if e.primary_position is None]
|
| 254 |
kit_emps = [e for e in display_emps
|
| 255 |
if e.primary_position is not None and e.primary_position.value == "kitchen"]
|
| 256 |
|
| 257 |
-
|
| 258 |
for group_label, group_emps in [
|
| 259 |
("ホール専任", hall_emps),
|
| 260 |
("どちらでも", any_emps),
|
|
@@ -262,25 +307,14 @@ class ScheduleView(QWidget):
|
|
| 262 |
]:
|
| 263 |
if not group_emps:
|
| 264 |
continue
|
| 265 |
-
|
| 266 |
for emp in group_emps:
|
| 267 |
-
|
| 268 |
-
for pos in Position:
|
| 269 |
-
rows_data.append(("summary", pos))
|
| 270 |
-
|
| 271 |
-
table.setRowCount(len(rows_data))
|
| 272 |
-
table.setColumnCount(len(col_headers))
|
| 273 |
-
table.setHorizontalHeaderLabels(col_headers)
|
| 274 |
-
table.setColumnWidth(0, 95)
|
| 275 |
-
for c_idx in range(1, len(col_headers) - 1):
|
| 276 |
-
table.setColumnWidth(c_idx, 50)
|
| 277 |
-
table.setColumnWidth(len(col_headers) - 1, 36)
|
| 278 |
-
table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Fixed)
|
| 279 |
|
| 280 |
# 集計
|
| 281 |
-
count_map:
|
| 282 |
leader_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 283 |
-
for (emp_id, ds, slot_v), pos_v in self._assignments.items():
|
| 284 |
if slot_v != slot.value:
|
| 285 |
continue
|
| 286 |
count_map[(ds, pos_v)] += 1
|
|
@@ -288,24 +322,43 @@ class ScheduleView(QWidget):
|
|
| 288 |
if emp and emp.is_leader(pos_v):
|
| 289 |
leader_map[(ds, pos_v)] += 1
|
| 290 |
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
if row_type == "employee":
|
| 293 |
-
self.
|
| 294 |
-
|
| 295 |
-
table.setRowHeight(row_idx, 28)
|
| 296 |
-
elif row_type == "divider":
|
| 297 |
-
self._fill_divider_row(table, row_idx, row_data, len(col_headers))
|
| 298 |
-
table.setRowHeight(row_idx, 18)
|
| 299 |
else:
|
| 300 |
-
self.
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
self._update_constraint_warnings(warn_label, slot, dates, count_map, leader_map)
|
| 306 |
|
| 307 |
def _fill_divider_row(self, table: QTableWidget, row: int, label: str, col_count: int):
|
| 308 |
-
"""ポジショングループの区切り行"""
|
| 309 |
c = theme.c
|
| 310 |
bg = QBrush(QColor(c["surface2"]))
|
| 311 |
for col in range(col_count):
|
|
@@ -313,22 +366,21 @@ class ScheduleView(QWidget):
|
|
| 313 |
item.setBackground(bg)
|
| 314 |
item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 315 |
item.setForeground(QBrush(QColor(c["text3"])))
|
| 316 |
-
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 317 |
table.setItem(row, col, item)
|
| 318 |
|
| 319 |
-
def
|
| 320 |
-
|
| 321 |
skill_b = SKILL_BADGE.get(emp.hall_skill, "")
|
| 322 |
skill_k = SKILL_BADGE.get(emp.kitchen_skill, "")
|
| 323 |
pp = f"[{emp.primary_position.label()[:1]}]" if emp.primary_position else ""
|
| 324 |
-
is_other =
|
| 325 |
other_slot = TimeSlot.DINNER if slot == TimeSlot.BREAKFAST else TimeSlot.BREAKFAST
|
| 326 |
suffix = f" ↔{other_slot.short_label()}" if is_other else ""
|
| 327 |
name_item = QTableWidgetItem(f"{emp.name}{pp}{suffix}\nH:{skill_b} K:{skill_k}")
|
| 328 |
name_item.setFont(QFont("", 9))
|
| 329 |
name_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 330 |
|
| 331 |
-
# ポジション専任で背景色を区別
|
| 332 |
c = theme.c
|
| 333 |
if is_other:
|
| 334 |
name_item.setBackground(QBrush(QColor(c["cell_other_slot"])))
|
|
@@ -343,7 +395,9 @@ class ScheduleView(QWidget):
|
|
| 343 |
for col_idx, ds in enumerate(col_date_strs):
|
| 344 |
if ds is None:
|
| 345 |
continue
|
| 346 |
-
|
|
|
|
|
|
|
| 347 |
req = self._requests.get((emp.id, ds))
|
| 348 |
can_work = (req[0] if slot == TimeSlot.BREAKFAST else req[1]) if req else False
|
| 349 |
|
|
@@ -351,8 +405,10 @@ class ScheduleView(QWidget):
|
|
| 351 |
skill = emp.hall_skill if pos_v == "hall" else emp.kitchen_skill
|
| 352 |
badge = SKILL_BADGE.get(skill, "")
|
| 353 |
pos_label = "H" if pos_v == "hall" else "K"
|
| 354 |
-
|
| 355 |
-
item
|
|
|
|
|
|
|
| 356 |
item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 357 |
item.setData(Qt.ItemDataRole.UserRole, ("assigned", emp.id, ds, slot_v))
|
| 358 |
total += 1
|
|
@@ -374,9 +430,9 @@ class ScheduleView(QWidget):
|
|
| 374 |
total_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 375 |
table.setItem(row, len(col_date_strs) - 1, total_item)
|
| 376 |
|
| 377 |
-
def
|
| 378 |
-
|
| 379 |
-
|
| 380 |
label_item = QTableWidgetItem(pos.label())
|
| 381 |
label_item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 382 |
label_item.setBackground(QBrush(QColor(theme.c["surface2"])))
|
|
@@ -384,16 +440,15 @@ class ScheduleView(QWidget):
|
|
| 384 |
table.setItem(row, 0, label_item)
|
| 385 |
|
| 386 |
constraint = SHIFT_CONSTRAINTS.get((slot, pos), {})
|
| 387 |
-
min_req
|
| 388 |
min_leader = constraint.get("min_leader", 0)
|
| 389 |
|
| 390 |
for col_idx, ds in enumerate(col_date_strs):
|
| 391 |
if ds is None:
|
| 392 |
continue
|
| 393 |
cnt = count_map[(ds, pos.value)]
|
| 394 |
-
ld
|
| 395 |
-
|
| 396 |
-
item = QTableWidgetItem(text)
|
| 397 |
item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 398 |
item.setFont(QFont("", 8))
|
| 399 |
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
|
@@ -410,48 +465,38 @@ class ScheduleView(QWidget):
|
|
| 410 |
|
| 411 |
def _update_constraint_warnings(self, warn_label: QLabel, slot: TimeSlot,
|
| 412 |
dates: list, count_map: dict, leader_map: dict):
|
| 413 |
-
"""制約違反を集計してタブの警告ラベルに表示"""
|
| 414 |
violations = []
|
| 415 |
for d in dates:
|
| 416 |
ds = d.isoformat()
|
| 417 |
d_label = f"{d.month}/{d.day}({DAY_OF_WEEK_LABELS[d.weekday()]})"
|
| 418 |
for pos in Position:
|
| 419 |
cnt = count_map[(ds, pos.value)]
|
| 420 |
-
ld
|
| 421 |
constraint = SHIFT_CONSTRAINTS.get((slot, pos), {})
|
| 422 |
-
min_req
|
| 423 |
min_leader = constraint.get("min_leader", 0)
|
| 424 |
if cnt < min_req:
|
| 425 |
-
violations.append(
|
| 426 |
-
f"❌ {d_label} {pos.label()}: {cnt}/{min_req}名不足"
|
| 427 |
-
)
|
| 428 |
elif ld < min_leader:
|
| 429 |
-
violations.append(
|
| 430 |
-
f"⚠️ {d_label} {pos.label()}: リーダー{ld}/{min_leader}名不足"
|
| 431 |
-
)
|
| 432 |
-
|
| 433 |
if violations:
|
| 434 |
warn_label.setText(" ".join(violations))
|
| 435 |
warn_label.setVisible(True)
|
| 436 |
else:
|
| 437 |
warn_label.setVisible(False)
|
| 438 |
|
|
|
|
|
|
|
| 439 |
def _on_date_header_clicked(self, col: int, slot: TimeSlot, table: QTableWidget):
|
| 440 |
-
"""日付列ヘッダークリック → その日のタイムライン表示"""
|
| 441 |
if col == 0 or col >= table.columnCount() - 1:
|
| 442 |
-
return # 氏名列・計列は無視
|
| 443 |
-
header_text = table.horizontalHeaderItem(col)
|
| 444 |
-
if not header_text:
|
| 445 |
return
|
| 446 |
dates = self._period.date_range()
|
| 447 |
-
date_idx = col - 1
|
| 448 |
if date_idx < 0 or date_idx >= len(dates):
|
| 449 |
return
|
| 450 |
ds = dates[date_idx].isoformat()
|
| 451 |
dlg = DayTimetableDialog(
|
| 452 |
-
ds, self._employees, self._assignments,
|
| 453 |
-
self._raw_requests, parent=self
|
| 454 |
-
)
|
| 455 |
dlg.exec()
|
| 456 |
|
| 457 |
def _on_cell_clicked(self, row: int, col: int, table: QTableWidget, slot: TimeSlot):
|
|
@@ -459,7 +504,7 @@ class ScheduleView(QWidget):
|
|
| 459 |
if not item:
|
| 460 |
return
|
| 461 |
data = item.data(Qt.ItemDataRole.UserRole)
|
| 462 |
-
if not data or not isinstance(data, tuple)
|
| 463 |
return
|
| 464 |
|
| 465 |
state, emp_id, ds, slot_v = data
|
|
@@ -468,9 +513,11 @@ class ScheduleView(QWidget):
|
|
| 468 |
emp = next((e for e in self._employees if e.id == emp_id), None)
|
| 469 |
if not emp:
|
| 470 |
return
|
|
|
|
|
|
|
| 471 |
reply = QMessageBox.question(
|
| 472 |
self, "シフト削除",
|
| 473 |
-
f"{emp.name} の {ds} {slot.short_label()} のアサインを削除しますか?",
|
| 474 |
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
| 475 |
)
|
| 476 |
if reply == QMessageBox.StandardButton.Yes:
|
|
@@ -484,13 +531,37 @@ class ScheduleView(QWidget):
|
|
| 484 |
return
|
| 485 |
dlg = PositionSelectDialog(
|
| 486 |
emp, ds, slot, self._employees, self._assignments,
|
| 487 |
-
self._period.id, parent=self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
)
|
| 489 |
if dlg.exec() == QDialog.DialogCode.Accepted and dlg.selected_position:
|
| 490 |
-
|
| 491 |
-
|
| 492 |
repo.add_assignment(self._period.id, assignment)
|
| 493 |
-
self._assignments[(emp_id, ds, slot_v)] = dlg.selected_position.value
|
| 494 |
self._render_table()
|
| 495 |
|
| 496 |
def _on_output(self):
|
|
@@ -504,8 +575,6 @@ class ScheduleView(QWidget):
|
|
| 504 |
# ── タイムラインダイアログ ─────────────────────────────────────────────
|
| 505 |
|
| 506 |
class DayTimetableDialog(QDialog):
|
| 507 |
-
"""1日分の希望シフトをタイムライン形式で表示するダイアログ"""
|
| 508 |
-
|
| 509 |
def __init__(self, date_str: str, employees: list[Employee],
|
| 510 |
assignments: dict, raw_requests: dict, parent=None):
|
| 511 |
super().__init__(parent)
|
|
@@ -515,27 +584,24 @@ class DayTimetableDialog(QDialog):
|
|
| 515 |
self.setMinimumWidth(750)
|
| 516 |
self.setMinimumHeight(400)
|
| 517 |
|
| 518 |
-
|
|
|
|
| 519 |
layout.setSpacing(8)
|
| 520 |
|
| 521 |
-
# 説明ラベル
|
| 522 |
info = QLabel(
|
| 523 |
-
"■ 朝食帯(6-11時) ■ ディナー帯(17-23時)
|
| 524 |
-
"濃色=アサイン済 / 薄色=希望のみ / 赤
|
| 525 |
)
|
| 526 |
info.setStyleSheet("font-size:11px; color:#6b7280;")
|
| 527 |
layout.addWidget(info)
|
| 528 |
|
| 529 |
-
# タイムラインウィジェット(スクロール可)
|
| 530 |
scroll = QScrollArea()
|
| 531 |
scroll.setWidgetResizable(True)
|
| 532 |
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
| 533 |
-
|
| 534 |
tl = _TimetableWidget(date_str, employees, assignments, raw_requests)
|
| 535 |
scroll.setWidget(tl)
|
| 536 |
layout.addWidget(scroll)
|
| 537 |
|
| 538 |
-
# 凡例
|
| 539 |
legend_row = QHBoxLayout()
|
| 540 |
for color, text in [
|
| 541 |
("#3b82f6", "朝食アサイン"), ("#93c5fd", "朝食希望"),
|
|
@@ -555,25 +621,21 @@ class DayTimetableDialog(QDialog):
|
|
| 555 |
|
| 556 |
|
| 557 |
class _TimetableWidget(QWidget):
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
MARGIN_LEFT = 110
|
| 563 |
-
MARGIN_TOP = 28
|
| 564 |
MARGIN_RIGHT = 12
|
| 565 |
-
ROW_H
|
| 566 |
-
COVERAGE_H
|
| 567 |
|
| 568 |
-
def __init__(self, date_str
|
| 569 |
-
assignments: dict, raw_requests: dict, parent=None):
|
| 570 |
super().__init__(parent)
|
| 571 |
self._date_str = date_str
|
| 572 |
self._assignments = assignments
|
| 573 |
self._rows = self._build_rows(employees, assignments, raw_requests, date_str)
|
| 574 |
n = max(1, len(self._rows))
|
| 575 |
-
|
| 576 |
-
self.setMinimumHeight(total_h)
|
| 577 |
self.setMinimumWidth(700)
|
| 578 |
|
| 579 |
@staticmethod
|
|
@@ -587,6 +649,7 @@ class _TimetableWidget(QWidget):
|
|
| 587 |
@classmethod
|
| 588 |
def _build_rows(cls, employees, assignments, raw_requests, ds):
|
| 589 |
from utils.shift_patterns import PATTERN_MAP
|
|
|
|
| 590 |
rows = []
|
| 591 |
for emp in employees:
|
| 592 |
req = raw_requests.get((emp.id, ds))
|
|
@@ -594,216 +657,173 @@ class _TimetableWidget(QWidget):
|
|
| 594 |
continue
|
| 595 |
if not req.breakfast and not req.dinner:
|
| 596 |
continue
|
| 597 |
-
|
| 598 |
start_h, end_h = None, None
|
| 599 |
force_both = False
|
| 600 |
-
|
| 601 |
if req.pattern_id and req.pattern_id != "custom":
|
| 602 |
p = PATTERN_MAP.get(req.pattern_id)
|
| 603 |
if p:
|
| 604 |
if p.force_both:
|
| 605 |
force_both = True
|
| 606 |
-
start_h = 6.0
|
| 607 |
-
end_h = 23.0
|
| 608 |
else:
|
| 609 |
start_h = p.start_hour()
|
| 610 |
-
end_h
|
| 611 |
elif req.pattern_id == "custom":
|
| 612 |
-
if req.custom_start
|
| 613 |
-
|
| 614 |
-
if req.custom_end:
|
| 615 |
-
end_h = cls._parse_hour(req.custom_end)
|
| 616 |
-
|
| 617 |
if start_h is None:
|
| 618 |
start_h = 6.0 if req.breakfast else 17.0
|
| 619 |
if end_h is None:
|
| 620 |
end_h = 11.0 if not req.dinner else 23.0
|
| 621 |
-
|
| 622 |
-
assigned_b = (emp.id, ds, "breakfast") in {
|
| 623 |
-
(eid, d2, s) for (eid, d2, s) in assignments if d2 == ds
|
| 624 |
-
}
|
| 625 |
-
assigned_d = (emp.id, ds, "dinner") in {
|
| 626 |
-
(eid, d2, s) for (eid, d2, s) in assignments if d2 == ds
|
| 627 |
-
}
|
| 628 |
-
|
| 629 |
rows.append({
|
| 630 |
"emp": emp,
|
| 631 |
-
"start_h": start_h,
|
| 632 |
-
"
|
| 633 |
-
"breakfast": req.breakfast,
|
| 634 |
-
"dinner": req.dinner,
|
| 635 |
"force_both": force_both,
|
| 636 |
-
"assigned_b":
|
| 637 |
-
"assigned_d":
|
| 638 |
})
|
| 639 |
return rows
|
| 640 |
|
| 641 |
def _x(self, hour: float, width: int) -> int:
|
| 642 |
-
span = self.TIME_END - self.TIME_START
|
| 643 |
usable = width - self.MARGIN_LEFT - self.MARGIN_RIGHT
|
| 644 |
-
return self.MARGIN_LEFT + int((hour - self.TIME_START) /
|
| 645 |
|
| 646 |
def paintEvent(self, event):
|
| 647 |
painter = QPainter(self)
|
| 648 |
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
| 649 |
W = self.width()
|
| 650 |
c = theme.c
|
|
|
|
| 651 |
|
| 652 |
-
|
| 653 |
-
painter.fillRect(self.rect(), bg)
|
| 654 |
-
|
| 655 |
-
# 時間帯ゾーン背景
|
| 656 |
-
b_start_x = self._x(6, W)
|
| 657 |
-
b_end_x = self._x(11, W)
|
| 658 |
-
d_start_x = self._x(17, W)
|
| 659 |
-
d_end_x = self._x(23, W)
|
| 660 |
zone_h = self.MARGIN_TOP + len(self._rows) * self.ROW_H + self.COVERAGE_H
|
|
|
|
|
|
|
| 661 |
|
| 662 |
-
|
| 663 |
-
painter.
|
| 664 |
-
|
| 665 |
-
# 時間軸
|
| 666 |
-
painter.setPen(QPen(QColor(c["border"]), 1))
|
| 667 |
-
font_sm = QFont("", 8)
|
| 668 |
-
painter.setFont(font_sm)
|
| 669 |
for h in range(int(self.TIME_START), int(self.TIME_END) + 1):
|
| 670 |
x = self._x(h, W)
|
| 671 |
-
painter.
|
|
|
|
| 672 |
painter.setPen(QColor(c["text2"]))
|
| 673 |
painter.drawText(x - 10, self.MARGIN_TOP - 8, f"{h}:00")
|
| 674 |
-
painter.setPen(QPen(QColor(c["border"]), 1))
|
| 675 |
|
| 676 |
-
#
|
| 677 |
painter.setFont(QFont("", 9))
|
| 678 |
for i, row in enumerate(self._rows):
|
| 679 |
-
y
|
| 680 |
cy = y + self.ROW_H // 2
|
| 681 |
-
|
| 682 |
-
# 名前
|
| 683 |
painter.setPen(QColor(c["text"]))
|
| 684 |
painter.drawText(4, cy + 5, row["emp"].name)
|
| 685 |
|
| 686 |
-
|
| 687 |
-
is_b = row["breakfast"]
|
| 688 |
-
is_d = row["dinner"]
|
| 689 |
-
is_both = row["force_both"] or (is_b and is_d)
|
| 690 |
assigned = row["assigned_b"] or row["assigned_d"]
|
| 691 |
-
|
| 692 |
if is_both:
|
| 693 |
bar_color = QColor("#22c55e") if assigned else QColor("#86efac")
|
| 694 |
-
elif
|
| 695 |
bar_color = QColor("#3b82f6") if row["assigned_b"] else QColor("#93c5fd")
|
| 696 |
else:
|
| 697 |
bar_color = QColor("#ec4899") if row["assigned_d"] else QColor("#f9a8d4")
|
| 698 |
|
| 699 |
x1 = self._x(row["start_h"], W)
|
| 700 |
-
x2 = self._x(row["end_h"],
|
| 701 |
-
|
| 702 |
-
painter.fillRect(x1, y + 2, max(2, x2 - x1), bar_h, bar_color)
|
| 703 |
-
|
| 704 |
-
# バー上に時刻テキスト
|
| 705 |
-
start_str = f"{int(row['start_h'])}:{int((row['start_h'] % 1) * 60):02d}"
|
| 706 |
-
end_str = f"{int(row['end_h'])}:{int((row['end_h'] % 1) * 60):02d}"
|
| 707 |
-
painter.setPen(QColor("#ffffff") if assigned else QColor(c["text"]))
|
| 708 |
-
painter.setFont(QFont("", 8))
|
| 709 |
if x2 - x1 > 50:
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 714 |
cov_y = self.MARGIN_TOP + len(self._rows) * self.ROW_H + 4
|
| 715 |
painter.setPen(QColor(c["text2"]))
|
| 716 |
painter.setFont(QFont("", 8))
|
| 717 |
painter.drawText(4, cov_y + 14, "人数")
|
| 718 |
|
| 719 |
-
# 1時間ごとの在籍人数を計算
|
| 720 |
slot_hours = list(range(int(self.TIME_START), int(self.TIME_END)))
|
| 721 |
-
|
| 722 |
-
sum(
|
| 723 |
-
1 for row in self._rows
|
| 724 |
-
if row["start_h"] <= h < row["end_h"]
|
| 725 |
-
)
|
| 726 |
for h in slot_hours
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
# 朝食・ディナーの最小必要人数(ホール+キッチン合計)
|
| 730 |
b_min = sum(SHIFT_CONSTRAINTS.get((TimeSlot.BREAKFAST, pos), {}).get("min", 0) for pos in Position)
|
| 731 |
d_min = sum(SHIFT_CONSTRAINTS.get((TimeSlot.DINNER, pos), {}).get("min", 0) for pos in Position)
|
|
|
|
| 732 |
|
| 733 |
-
|
| 734 |
-
for h in slot_hours:
|
| 735 |
-
count = sum(
|
| 736 |
-
1 for row in self._rows
|
| 737 |
-
if row["start_h"] <= h < row["end_h"]
|
| 738 |
-
)
|
| 739 |
x1 = self._x(h, W)
|
| 740 |
x2 = self._x(h + 1, W)
|
| 741 |
-
bar_px = int(count / max(max_count, 1) *
|
| 742 |
-
|
| 743 |
-
# 不足判定
|
| 744 |
is_b_zone = 6 <= h < 11
|
| 745 |
is_d_zone = 17 <= h < 23
|
| 746 |
-
required
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
max(1, x2 - x1 - 2), bar_px, color)
|
| 752 |
-
|
| 753 |
-
# 人数テキスト
|
| 754 |
if count > 0:
|
| 755 |
painter.setPen(QColor(c["text"]))
|
| 756 |
-
painter.drawText(x1 + 2, cov_y +
|
| 757 |
|
| 758 |
painter.end()
|
| 759 |
|
| 760 |
|
| 761 |
-
# ── ポジション選択ダ
|
| 762 |
|
| 763 |
class PositionSelectDialog(QDialog):
|
| 764 |
-
def __init__(self, emp: Employee, ds: str, slot: TimeSlot,
|
|
|
|
|
|
|
| 765 |
super().__init__(parent)
|
| 766 |
self.selected_position = None
|
| 767 |
-
|
| 768 |
-
self.
|
|
|
|
| 769 |
|
| 770 |
-
layout = QVBoxLayout(self)
|
| 771 |
|
| 772 |
d = date.fromisoformat(ds)
|
| 773 |
dow = DAY_OF_WEEK_LABELS[d.weekday()]
|
| 774 |
layout.addWidget(QLabel(f"日付: {d.month}/{d.day}({dow}) {slot.short_label()}"))
|
| 775 |
layout.addWidget(QLabel(f"従業員: {emp.name}"))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 776 |
layout.addWidget(QLabel(""))
|
| 777 |
|
| 778 |
for pos in Position:
|
| 779 |
-
|
| 780 |
-
constraint = SHIFT_CONSTRAINTS.get(key, {})
|
| 781 |
current = sum(
|
| 782 |
-
1 for (eid, d2, s2), p in assignments.items()
|
| 783 |
if d2 == ds and s2 == slot.value and p == pos.value
|
| 784 |
)
|
| 785 |
leaders = sum(
|
| 786 |
-
1 for (eid, d2, s2), p in assignments.items()
|
| 787 |
if d2 == ds and s2 == slot.value and p == pos.value
|
| 788 |
and any(x.id == eid and x.is_leader(pos.value) for x in all_employees)
|
| 789 |
)
|
| 790 |
-
|
| 791 |
emp_skill = emp.skill_for(pos.value)
|
| 792 |
badge = SKILL_BADGE.get(emp_skill, "")
|
| 793 |
btn = QPushButton(
|
| 794 |
f"{pos.label()} [{current}/{constraint.get('max',3)}名] "
|
| 795 |
f"★リーダー:{leaders}/{constraint.get('min_leader',1)}名 "
|
| 796 |
-
f"自分
|
| 797 |
)
|
| 798 |
btn.setFixedHeight(40)
|
| 799 |
c = theme.c
|
| 800 |
-
if current >= constraint.get("max", 3):
|
| 801 |
btn.setEnabled(False)
|
| 802 |
btn.setToolTip("上限人数に達しています")
|
| 803 |
btn.setStyleSheet(f"color:{c['text2']};")
|
| 804 |
else:
|
| 805 |
btn.setStyleSheet(
|
| 806 |
-
f"QPushButton {{ text-align:left; padding:0 12px;
|
|
|
|
| 807 |
f" QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 808 |
)
|
| 809 |
btn.clicked.connect(lambda _, p=pos: self._select(p))
|
|
|
|
| 5 |
from PyQt6.QtWidgets import (
|
| 6 |
QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel,
|
| 7 |
QComboBox, QTableWidget, QTableWidgetItem, QHeaderView,
|
| 8 |
+
QDialog, QAbstractItemView, QTabWidget, QMessageBox,
|
| 9 |
+
QScrollBar, QFrame
|
|
|
|
| 10 |
)
|
| 11 |
from PyQt6.QtCore import Qt, pyqtSignal
|
| 12 |
+
from PyQt6.QtGui import QFont, QColor, QBrush, QPainter, QPen
|
| 13 |
from db import repositories as repo
|
| 14 |
from models.employee import Employee
|
| 15 |
from models.schedule import ShiftAssignment, ShiftRequest
|
| 16 |
from utils.constants import (
|
| 17 |
+
TimeSlot, Position, PrimaryPosition, SkillLevel,
|
| 18 |
+
DAY_OF_WEEK_LABELS, SHIFT_CONSTRAINTS
|
| 19 |
)
|
| 20 |
from utils.theme import theme
|
| 21 |
|
|
|
|
| 22 |
SKILL_BADGE = {
|
| 23 |
SkillLevel.LEADER: "★★",
|
| 24 |
SkillLevel.VETERAN: "★",
|
|
|
|
| 26 |
SkillLevel.BEGINNER: "▼",
|
| 27 |
}
|
| 28 |
|
| 29 |
+
# _assignments value: (position_str, is_reinforcement_bool)
|
| 30 |
+
AssignVal = tuple[str, bool]
|
|
|
|
|
|
|
| 31 |
|
| 32 |
|
| 33 |
class ScheduleView(QWidget):
|
|
|
|
| 35 |
super().__init__(parent)
|
| 36 |
self._period = None
|
| 37 |
self._employees: list[Employee] = []
|
| 38 |
+
# {(emp_id, date, slot_value): (position_value, is_reinforcement)}
|
| 39 |
+
self._assignments: dict[tuple[int, str, str], AssignVal] = {}
|
| 40 |
self._requests: dict[tuple[int, str], tuple[bool, bool]] = {}
|
| 41 |
self._raw_requests: dict[tuple[int, str], ShiftRequest] = {}
|
| 42 |
self._build_ui()
|
| 43 |
self._load_periods()
|
| 44 |
|
| 45 |
+
# ── UI構築 ─────────────────────────────────────────────────────────────
|
| 46 |
+
|
| 47 |
def _build_ui(self):
|
| 48 |
layout = QVBoxLayout(self)
|
| 49 |
layout.setContentsMargins(16, 16, 16, 16)
|
| 50 |
layout.setSpacing(10)
|
| 51 |
|
|
|
|
| 52 |
header = QHBoxLayout()
|
| 53 |
title = QLabel("シフト表 確認・編集")
|
| 54 |
title.setFont(QFont("", 16, QFont.Weight.Bold))
|
|
|
|
| 79 |
self._status_legend_labels.append((lbl, color_key))
|
| 80 |
legend.addWidget(lbl)
|
| 81 |
legend.addStretch()
|
| 82 |
+
legend.addWidget(QLabel("習熟度: ★★リーダー ★ベテラン ▼新人 "))
|
| 83 |
+
reinf_lbl = QLabel("■ 応援要員(希望外追加)")
|
| 84 |
+
reinf_lbl.setStyleSheet("background:#fed7aa; border-radius:3px; padding:2px 6px; font-size:11px;")
|
| 85 |
+
legend.addWidget(reinf_lbl)
|
| 86 |
layout.addLayout(legend)
|
| 87 |
|
| 88 |
+
# タブ
|
| 89 |
self._show_other: dict[TimeSlot, bool] = {
|
| 90 |
TimeSlot.BREAKFAST: False,
|
| 91 |
+
TimeSlot.DINNER: False,
|
| 92 |
}
|
| 93 |
self.tab_widget = QTabWidget()
|
| 94 |
+
|
| 95 |
+
(tab_b, self.emp_table_b, self.sum_table_b,
|
| 96 |
self._btn_other_b, self._warn_label_b) = self._make_tab_widget(TimeSlot.BREAKFAST)
|
| 97 |
+
(tab_d, self.emp_table_d, self.sum_table_d,
|
| 98 |
self._btn_other_d, self._warn_label_d) = self._make_tab_widget(TimeSlot.DINNER)
|
| 99 |
+
|
| 100 |
+
self.tab_widget.addTab(tab_b, "🌅 朝食")
|
| 101 |
+
self.tab_widget.addTab(tab_d, "🌆 ディナー")
|
| 102 |
layout.addWidget(self.tab_widget)
|
| 103 |
|
| 104 |
self.status_label = QLabel("")
|
|
|
|
| 107 |
self._apply_styles()
|
| 108 |
|
| 109 |
def _make_tab_widget(self, slot: TimeSlot):
|
| 110 |
+
"""タブの中身を生成。(container, emp_table, sum_table, toggle_btn, warn_label) を返す"""
|
| 111 |
container = QWidget()
|
| 112 |
vbox = QVBoxLayout(container)
|
| 113 |
vbox.setContentsMargins(0, 6, 0, 0)
|
| 114 |
+
vbox.setSpacing(2)
|
| 115 |
|
| 116 |
# 他スロット専任メンバー表示トグル
|
| 117 |
other_label = "ディナー専任" if slot == TimeSlot.BREAKFAST else "朝食専任"
|
|
|
|
| 134 |
)
|
| 135 |
vbox.addWidget(warn_label)
|
| 136 |
|
| 137 |
+
# 従業員テーブル(スクロール可)
|
| 138 |
+
emp_table = QTableWidget()
|
| 139 |
+
emp_table.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
| 140 |
+
emp_table.setSelectionMode(QAbstractItemView.SelectionMode.SingleSelection)
|
| 141 |
+
emp_table.verticalHeader().setVisible(False)
|
| 142 |
+
emp_table.setShowGrid(True)
|
| 143 |
+
emp_table.setAlternatingRowColors(False)
|
| 144 |
+
# 垂直スクロールバーを常に表示して幅を一定に保つ
|
| 145 |
+
emp_table.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
|
| 146 |
+
emp_table.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAsNeeded)
|
| 147 |
+
emp_table.cellClicked.connect(
|
| 148 |
+
lambda r, c, s=slot, t=emp_table: self._on_cell_clicked(r, c, t, s))
|
| 149 |
+
emp_table.horizontalHeader().sectionClicked.connect(
|
| 150 |
+
lambda col, s=slot, t=emp_table: self._on_date_header_clicked(col, s, t))
|
| 151 |
+
emp_table.horizontalHeader().sectionResized.connect(
|
| 152 |
+
lambda idx, old, new, s=slot: self._sync_col_width(idx, new, s))
|
| 153 |
+
vbox.addWidget(emp_table, stretch=1)
|
| 154 |
+
|
| 155 |
+
# 集計テーブル(常に下部に固定・スクロール非表示)
|
| 156 |
+
sum_table = QTableWidget()
|
| 157 |
+
sum_table.setEditTriggers(QTableWidget.EditTrigger.NoEditTriggers)
|
| 158 |
+
sum_table.setSelectionMode(QAbstractItemView.SelectionMode.NoSelection)
|
| 159 |
+
sum_table.verticalHeader().setVisible(False)
|
| 160 |
+
sum_table.horizontalHeader().setVisible(False)
|
| 161 |
+
sum_table.setShowGrid(True)
|
| 162 |
+
sum_table.setAlternatingRowColors(False)
|
| 163 |
+
sum_table.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
| 164 |
+
sum_table.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
| 165 |
+
sum_table.setFixedHeight(60) # 2行 × 28px + 余白
|
| 166 |
+
vbox.addWidget(sum_table)
|
| 167 |
+
|
| 168 |
+
# 水平スクロール同期
|
| 169 |
+
emp_table.horizontalScrollBar().valueChanged.connect(
|
| 170 |
+
sum_table.horizontalScrollBar().setValue)
|
| 171 |
+
|
| 172 |
+
# 区切り線(集計テーブル上部)
|
| 173 |
+
sep = QFrame()
|
| 174 |
+
sep.setFrameShape(QFrame.Shape.HLine)
|
| 175 |
+
vbox.insertWidget(vbox.count() - 1, sep) # sum_tableの直前に挿入
|
| 176 |
+
|
| 177 |
+
return container, emp_table, sum_table, btn, warn_label
|
| 178 |
+
|
| 179 |
+
def _sync_col_width(self, col_idx: int, new_width: int, slot: TimeSlot):
|
| 180 |
+
"""従業員テーブルの列幅変更を集計テーブルに反映"""
|
| 181 |
+
sum_t = self.sum_table_b if slot == TimeSlot.BREAKFAST else self.sum_table_d
|
| 182 |
+
if col_idx < sum_t.columnCount():
|
| 183 |
+
sum_t.setColumnWidth(col_idx, new_width)
|
| 184 |
|
| 185 |
def _on_toggle_other(self, slot: TimeSlot, checked: bool):
|
| 186 |
self._show_other[slot] = checked
|
| 187 |
+
emp_t = self.emp_table_b if slot == TimeSlot.BREAKFAST else self.emp_table_d
|
| 188 |
+
sum_t = self.sum_table_b if slot == TimeSlot.BREAKFAST else self.sum_table_d
|
| 189 |
+
warn = self._warn_label_b if slot == TimeSlot.BREAKFAST else self._warn_label_d
|
| 190 |
+
self._render_slot_table(emp_t, sum_t, slot, warn)
|
| 191 |
|
| 192 |
def _apply_styles(self):
|
| 193 |
c = theme.c
|
|
|
|
| 211 |
self._apply_styles()
|
| 212 |
self._render_table()
|
| 213 |
|
| 214 |
+
# ── データ読み込み ─────────────────────────────────────────────────────
|
| 215 |
+
|
| 216 |
def _load_periods(self):
|
| 217 |
periods = repo.get_all_periods()
|
| 218 |
self.period_combo.blockSignals(True)
|
|
|
|
| 235 |
def _on_period_changed(self, idx):
|
| 236 |
self._period = self.period_combo.currentData()
|
| 237 |
if not self._period:
|
| 238 |
+
for t in (self.emp_table_b, self.emp_table_d,
|
| 239 |
+
self.sum_table_b, self.sum_table_d):
|
| 240 |
t.setRowCount(0)
|
| 241 |
t.setColumnCount(0)
|
| 242 |
return
|
|
|
|
| 248 |
assignments = repo.get_assignments(self._period.id)
|
| 249 |
requests = repo.get_shift_requests(self._period.id)
|
| 250 |
self._assignments = {
|
| 251 |
+
(a.employee_id, a.date, a.time_slot.value): (a.position.value, a.is_reinforcement)
|
| 252 |
for a in assignments
|
| 253 |
}
|
| 254 |
self._requests = {
|
|
|
|
| 260 |
for r in requests
|
| 261 |
}
|
| 262 |
|
| 263 |
+
# ── 描画 ──────────────────────────────────────────────────────────────
|
| 264 |
+
|
| 265 |
def _render_table(self):
|
| 266 |
if not self._period or not self._employees:
|
| 267 |
return
|
| 268 |
+
self._render_slot_table(
|
| 269 |
+
self.emp_table_b, self.sum_table_b, TimeSlot.BREAKFAST, self._warn_label_b)
|
| 270 |
+
self._render_slot_table(
|
| 271 |
+
self.emp_table_d, self.sum_table_d, TimeSlot.DINNER, self._warn_label_d)
|
| 272 |
|
| 273 |
+
def _render_slot_table(self, emp_table: QTableWidget, sum_table: QTableWidget,
|
| 274 |
+
slot: TimeSlot, warn_label: QLabel):
|
| 275 |
dates = self._period.date_range()
|
| 276 |
|
| 277 |
col_headers = ["氏名"]
|
|
|
|
| 286 |
# 従業員フィルタリング
|
| 287 |
primary_emps = [e for e in self._employees
|
| 288 |
if e.primary_timeslot is None or e.primary_timeslot == slot]
|
| 289 |
+
other_emps = [e for e in self._employees
|
| 290 |
+
if e.primary_timeslot is not None and e.primary_timeslot != slot]
|
| 291 |
other_ids = {e.id for e in other_emps}
|
| 292 |
show_other = self._show_other.get(slot, False)
|
| 293 |
display_emps = primary_emps + (other_emps if show_other else [])
|
| 294 |
|
| 295 |
+
# ポジション別グループ
|
| 296 |
hall_emps = [e for e in display_emps
|
| 297 |
if e.primary_position is not None and e.primary_position.value == "hall"]
|
| 298 |
any_emps = [e for e in display_emps if e.primary_position is None]
|
| 299 |
kit_emps = [e for e in display_emps
|
| 300 |
if e.primary_position is not None and e.primary_position.value == "kitchen"]
|
| 301 |
|
| 302 |
+
emp_rows: list[tuple] = []
|
| 303 |
for group_label, group_emps in [
|
| 304 |
("ホール専任", hall_emps),
|
| 305 |
("どちらでも", any_emps),
|
|
|
|
| 307 |
]:
|
| 308 |
if not group_emps:
|
| 309 |
continue
|
| 310 |
+
emp_rows.append(("divider", group_label))
|
| 311 |
for emp in group_emps:
|
| 312 |
+
emp_rows.append(("employee", emp))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
# 集計
|
| 315 |
+
count_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 316 |
leader_map: dict[tuple[str, str], int] = defaultdict(int)
|
| 317 |
+
for (emp_id, ds, slot_v), (pos_v, _) in self._assignments.items():
|
| 318 |
if slot_v != slot.value:
|
| 319 |
continue
|
| 320 |
count_map[(ds, pos_v)] += 1
|
|
|
|
| 322 |
if emp and emp.is_leader(pos_v):
|
| 323 |
leader_map[(ds, pos_v)] += 1
|
| 324 |
|
| 325 |
+
n_cols = len(col_headers)
|
| 326 |
+
|
| 327 |
+
# ── 従業員テーブル ────────────────────────────────────────────────
|
| 328 |
+
emp_table.setRowCount(len(emp_rows))
|
| 329 |
+
emp_table.setColumnCount(n_cols)
|
| 330 |
+
emp_table.setHorizontalHeaderLabels(col_headers)
|
| 331 |
+
emp_table.setColumnWidth(0, 95)
|
| 332 |
+
for c_i in range(1, n_cols - 1):
|
| 333 |
+
emp_table.setColumnWidth(c_i, 50)
|
| 334 |
+
emp_table.setColumnWidth(n_cols - 1, 36)
|
| 335 |
+
emp_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Fixed)
|
| 336 |
+
|
| 337 |
+
for row_idx, (row_type, row_data) in enumerate(emp_rows):
|
| 338 |
if row_type == "employee":
|
| 339 |
+
self._fill_emp_row(emp_table, row_idx, row_data, slot, col_date_strs, other_ids)
|
| 340 |
+
emp_table.setRowHeight(row_idx, 28)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
else:
|
| 342 |
+
self._fill_divider_row(emp_table, row_idx, row_data, n_cols)
|
| 343 |
+
emp_table.setRowHeight(row_idx, 18)
|
| 344 |
+
|
| 345 |
+
# ── 集計テーブル ──────────────────────────────────────────────────
|
| 346 |
+
n_pos = len(list(Position))
|
| 347 |
+
sum_table.setRowCount(n_pos)
|
| 348 |
+
sum_table.setColumnCount(n_cols)
|
| 349 |
+
sum_table.setColumnWidth(0, 95)
|
| 350 |
+
for c_i in range(1, n_cols - 1):
|
| 351 |
+
sum_table.setColumnWidth(c_i, 50)
|
| 352 |
+
sum_table.setColumnWidth(n_cols - 1, 36)
|
| 353 |
+
|
| 354 |
+
for pi, pos in enumerate(Position):
|
| 355 |
+
self._fill_summary_row(sum_table, pi, pos, slot, col_date_strs, count_map, leader_map)
|
| 356 |
+
sum_table.setRowHeight(pi, 28)
|
| 357 |
+
|
| 358 |
+
# 警告更新
|
| 359 |
self._update_constraint_warnings(warn_label, slot, dates, count_map, leader_map)
|
| 360 |
|
| 361 |
def _fill_divider_row(self, table: QTableWidget, row: int, label: str, col_count: int):
|
|
|
|
| 362 |
c = theme.c
|
| 363 |
bg = QBrush(QColor(c["surface2"]))
|
| 364 |
for col in range(col_count):
|
|
|
|
| 366 |
item.setBackground(bg)
|
| 367 |
item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 368 |
item.setForeground(QBrush(QColor(c["text3"])))
|
| 369 |
+
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 370 |
table.setItem(row, col, item)
|
| 371 |
|
| 372 |
+
def _fill_emp_row(self, table: QTableWidget, row: int, emp: Employee,
|
| 373 |
+
slot: TimeSlot, col_date_strs: list, other_ids: set):
|
| 374 |
skill_b = SKILL_BADGE.get(emp.hall_skill, "")
|
| 375 |
skill_k = SKILL_BADGE.get(emp.kitchen_skill, "")
|
| 376 |
pp = f"[{emp.primary_position.label()[:1]}]" if emp.primary_position else ""
|
| 377 |
+
is_other = emp.id in other_ids
|
| 378 |
other_slot = TimeSlot.DINNER if slot == TimeSlot.BREAKFAST else TimeSlot.BREAKFAST
|
| 379 |
suffix = f" ↔{other_slot.short_label()}" if is_other else ""
|
| 380 |
name_item = QTableWidgetItem(f"{emp.name}{pp}{suffix}\nH:{skill_b} K:{skill_k}")
|
| 381 |
name_item.setFont(QFont("", 9))
|
| 382 |
name_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 383 |
|
|
|
|
| 384 |
c = theme.c
|
| 385 |
if is_other:
|
| 386 |
name_item.setBackground(QBrush(QColor(c["cell_other_slot"])))
|
|
|
|
| 395 |
for col_idx, ds in enumerate(col_date_strs):
|
| 396 |
if ds is None:
|
| 397 |
continue
|
| 398 |
+
result = self._assignments.get((emp.id, ds, slot_v))
|
| 399 |
+
pos_v = result[0] if result else None
|
| 400 |
+
is_reinf = result[1] if result else False
|
| 401 |
req = self._requests.get((emp.id, ds))
|
| 402 |
can_work = (req[0] if slot == TimeSlot.BREAKFAST else req[1]) if req else False
|
| 403 |
|
|
|
|
| 405 |
skill = emp.hall_skill if pos_v == "hall" else emp.kitchen_skill
|
| 406 |
badge = SKILL_BADGE.get(skill, "")
|
| 407 |
pos_label = "H" if pos_v == "hall" else "K"
|
| 408 |
+
prefix = "+" if is_reinf else ""
|
| 409 |
+
item = QTableWidgetItem(f"{prefix}{pos_label}{badge}")
|
| 410 |
+
bg_color = c["cell_reinforcement"] if is_reinf else c["cell_assigned"]
|
| 411 |
+
item.setBackground(QBrush(QColor(bg_color)))
|
| 412 |
item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 413 |
item.setData(Qt.ItemDataRole.UserRole, ("assigned", emp.id, ds, slot_v))
|
| 414 |
total += 1
|
|
|
|
| 430 |
total_item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
| 431 |
table.setItem(row, len(col_date_strs) - 1, total_item)
|
| 432 |
|
| 433 |
+
def _fill_summary_row(self, table: QTableWidget, row: int, pos: Position,
|
| 434 |
+
slot: TimeSlot, col_date_strs: list,
|
| 435 |
+
count_map: dict, leader_map: dict):
|
| 436 |
label_item = QTableWidgetItem(pos.label())
|
| 437 |
label_item.setFont(QFont("", 8, QFont.Weight.Bold))
|
| 438 |
label_item.setBackground(QBrush(QColor(theme.c["surface2"])))
|
|
|
|
| 440 |
table.setItem(row, 0, label_item)
|
| 441 |
|
| 442 |
constraint = SHIFT_CONSTRAINTS.get((slot, pos), {})
|
| 443 |
+
min_req = constraint.get("min", 0)
|
| 444 |
min_leader = constraint.get("min_leader", 0)
|
| 445 |
|
| 446 |
for col_idx, ds in enumerate(col_date_strs):
|
| 447 |
if ds is None:
|
| 448 |
continue
|
| 449 |
cnt = count_map[(ds, pos.value)]
|
| 450 |
+
ld = leader_map[(ds, pos.value)]
|
| 451 |
+
item = QTableWidgetItem(f"{cnt}名\n★{ld}")
|
|
|
|
| 452 |
item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
|
| 453 |
item.setFont(QFont("", 8))
|
| 454 |
item.setFlags(Qt.ItemFlag.ItemIsEnabled)
|
|
|
|
| 465 |
|
| 466 |
def _update_constraint_warnings(self, warn_label: QLabel, slot: TimeSlot,
|
| 467 |
dates: list, count_map: dict, leader_map: dict):
|
|
|
|
| 468 |
violations = []
|
| 469 |
for d in dates:
|
| 470 |
ds = d.isoformat()
|
| 471 |
d_label = f"{d.month}/{d.day}({DAY_OF_WEEK_LABELS[d.weekday()]})"
|
| 472 |
for pos in Position:
|
| 473 |
cnt = count_map[(ds, pos.value)]
|
| 474 |
+
ld = leader_map[(ds, pos.value)]
|
| 475 |
constraint = SHIFT_CONSTRAINTS.get((slot, pos), {})
|
| 476 |
+
min_req = constraint.get("min", 0)
|
| 477 |
min_leader = constraint.get("min_leader", 0)
|
| 478 |
if cnt < min_req:
|
| 479 |
+
violations.append(f"❌ {d_label} {pos.label()}: {cnt}/{min_req}名不足")
|
|
|
|
|
|
|
| 480 |
elif ld < min_leader:
|
| 481 |
+
violations.append(f"⚠️ {d_label} {pos.label()}: ★{ld}/{min_leader}名不足")
|
|
|
|
|
|
|
|
|
|
| 482 |
if violations:
|
| 483 |
warn_label.setText(" ".join(violations))
|
| 484 |
warn_label.setVisible(True)
|
| 485 |
else:
|
| 486 |
warn_label.setVisible(False)
|
| 487 |
|
| 488 |
+
# ── イベント ──────────────────────────────────────────────────────────
|
| 489 |
+
|
| 490 |
def _on_date_header_clicked(self, col: int, slot: TimeSlot, table: QTableWidget):
|
|
|
|
| 491 |
if col == 0 or col >= table.columnCount() - 1:
|
|
|
|
|
|
|
|
|
|
| 492 |
return
|
| 493 |
dates = self._period.date_range()
|
| 494 |
+
date_idx = col - 1
|
| 495 |
if date_idx < 0 or date_idx >= len(dates):
|
| 496 |
return
|
| 497 |
ds = dates[date_idx].isoformat()
|
| 498 |
dlg = DayTimetableDialog(
|
| 499 |
+
ds, self._employees, self._assignments, self._raw_requests, parent=self)
|
|
|
|
|
|
|
| 500 |
dlg.exec()
|
| 501 |
|
| 502 |
def _on_cell_clicked(self, row: int, col: int, table: QTableWidget, slot: TimeSlot):
|
|
|
|
| 504 |
if not item:
|
| 505 |
return
|
| 506 |
data = item.data(Qt.ItemDataRole.UserRole)
|
| 507 |
+
if not data or not isinstance(data, tuple):
|
| 508 |
return
|
| 509 |
|
| 510 |
state, emp_id, ds, slot_v = data
|
|
|
|
| 513 |
emp = next((e for e in self._employees if e.id == emp_id), None)
|
| 514 |
if not emp:
|
| 515 |
return
|
| 516 |
+
_, is_reinf = self._assignments.get((emp_id, ds, slot_v), ("", False))
|
| 517 |
+
reinf_note = "(応援要員)" if is_reinf else ""
|
| 518 |
reply = QMessageBox.question(
|
| 519 |
self, "シフト削除",
|
| 520 |
+
f"{emp.name}{reinf_note} の {ds} {slot.short_label()} のアサインを削除しますか?",
|
| 521 |
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
| 522 |
)
|
| 523 |
if reply == QMessageBox.StandardButton.Yes:
|
|
|
|
| 531 |
return
|
| 532 |
dlg = PositionSelectDialog(
|
| 533 |
emp, ds, slot, self._employees, self._assignments,
|
| 534 |
+
self._period.id, is_reinforcement=False, parent=self
|
| 535 |
+
)
|
| 536 |
+
if dlg.exec() == QDialog.DialogCode.Accepted and dlg.selected_position:
|
| 537 |
+
assignment = ShiftAssignment(emp_id, ds, slot, dlg.selected_position,
|
| 538 |
+
is_reinforcement=False)
|
| 539 |
+
repo.add_assignment(self._period.id, assignment)
|
| 540 |
+
self._assignments[(emp_id, ds, slot_v)] = (dlg.selected_position.value, False)
|
| 541 |
+
self._render_table()
|
| 542 |
+
|
| 543 |
+
elif state == "unavailable":
|
| 544 |
+
# 応援要員として追加
|
| 545 |
+
emp = next((e for e in self._employees if e.id == emp_id), None)
|
| 546 |
+
if not emp:
|
| 547 |
+
return
|
| 548 |
+
reply = QMessageBox.question(
|
| 549 |
+
self, "応援要員追加",
|
| 550 |
+
f"「{emp.name}」はこの時間帯の希望を出していませんが、\n"
|
| 551 |
+
f"応援要員として {ds} {slot.short_label()} に追加しますか?",
|
| 552 |
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
| 553 |
+
)
|
| 554 |
+
if reply != QMessageBox.StandardButton.Yes:
|
| 555 |
+
return
|
| 556 |
+
dlg = PositionSelectDialog(
|
| 557 |
+
emp, ds, slot, self._employees, self._assignments,
|
| 558 |
+
self._period.id, is_reinforcement=True, parent=self
|
| 559 |
)
|
| 560 |
if dlg.exec() == QDialog.DialogCode.Accepted and dlg.selected_position:
|
| 561 |
+
assignment = ShiftAssignment(emp_id, ds, slot, dlg.selected_position,
|
| 562 |
+
is_reinforcement=True)
|
| 563 |
repo.add_assignment(self._period.id, assignment)
|
| 564 |
+
self._assignments[(emp_id, ds, slot_v)] = (dlg.selected_position.value, True)
|
| 565 |
self._render_table()
|
| 566 |
|
| 567 |
def _on_output(self):
|
|
|
|
| 575 |
# ── タイムラインダイアログ ─────────────────────────────────────────────
|
| 576 |
|
| 577 |
class DayTimetableDialog(QDialog):
|
|
|
|
|
|
|
| 578 |
def __init__(self, date_str: str, employees: list[Employee],
|
| 579 |
assignments: dict, raw_requests: dict, parent=None):
|
| 580 |
super().__init__(parent)
|
|
|
|
| 584 |
self.setMinimumWidth(750)
|
| 585 |
self.setMinimumHeight(400)
|
| 586 |
|
| 587 |
+
from PyQt6.QtWidgets import QScrollArea
|
| 588 |
+
layout = __import__("PyQt6.QtWidgets", fromlist=["QVBoxLayout"]).QVBoxLayout(self)
|
| 589 |
layout.setSpacing(8)
|
| 590 |
|
|
|
|
| 591 |
info = QLabel(
|
| 592 |
+
"■ 朝食帯(6-11時) ■ ディナー帯(17-23時) "
|
| 593 |
+
"濃色=アサイン済 / 薄色=希望のみ / 赤バー=不足時間帯"
|
| 594 |
)
|
| 595 |
info.setStyleSheet("font-size:11px; color:#6b7280;")
|
| 596 |
layout.addWidget(info)
|
| 597 |
|
|
|
|
| 598 |
scroll = QScrollArea()
|
| 599 |
scroll.setWidgetResizable(True)
|
| 600 |
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
|
|
|
| 601 |
tl = _TimetableWidget(date_str, employees, assignments, raw_requests)
|
| 602 |
scroll.setWidget(tl)
|
| 603 |
layout.addWidget(scroll)
|
| 604 |
|
|
|
|
| 605 |
legend_row = QHBoxLayout()
|
| 606 |
for color, text in [
|
| 607 |
("#3b82f6", "朝食アサイン"), ("#93c5fd", "朝食希望"),
|
|
|
|
| 621 |
|
| 622 |
|
| 623 |
class _TimetableWidget(QWidget):
|
| 624 |
+
TIME_START = 5.0
|
| 625 |
+
TIME_END = 24.0
|
| 626 |
+
MARGIN_LEFT = 110
|
| 627 |
+
MARGIN_TOP = 28
|
|
|
|
|
|
|
| 628 |
MARGIN_RIGHT = 12
|
| 629 |
+
ROW_H = 22
|
| 630 |
+
COVERAGE_H = 52
|
| 631 |
|
| 632 |
+
def __init__(self, date_str, employees, assignments, raw_requests, parent=None):
|
|
|
|
| 633 |
super().__init__(parent)
|
| 634 |
self._date_str = date_str
|
| 635 |
self._assignments = assignments
|
| 636 |
self._rows = self._build_rows(employees, assignments, raw_requests, date_str)
|
| 637 |
n = max(1, len(self._rows))
|
| 638 |
+
self.setMinimumHeight(self.MARGIN_TOP + n * self.ROW_H + self.COVERAGE_H + 20)
|
|
|
|
| 639 |
self.setMinimumWidth(700)
|
| 640 |
|
| 641 |
@staticmethod
|
|
|
|
| 649 |
@classmethod
|
| 650 |
def _build_rows(cls, employees, assignments, raw_requests, ds):
|
| 651 |
from utils.shift_patterns import PATTERN_MAP
|
| 652 |
+
assigned_keys = {(eid, d2, s) for (eid, d2, s) in assignments if d2 == ds}
|
| 653 |
rows = []
|
| 654 |
for emp in employees:
|
| 655 |
req = raw_requests.get((emp.id, ds))
|
|
|
|
| 657 |
continue
|
| 658 |
if not req.breakfast and not req.dinner:
|
| 659 |
continue
|
|
|
|
| 660 |
start_h, end_h = None, None
|
| 661 |
force_both = False
|
|
|
|
| 662 |
if req.pattern_id and req.pattern_id != "custom":
|
| 663 |
p = PATTERN_MAP.get(req.pattern_id)
|
| 664 |
if p:
|
| 665 |
if p.force_both:
|
| 666 |
force_both = True
|
| 667 |
+
start_h, end_h = 6.0, 23.0
|
|
|
|
| 668 |
else:
|
| 669 |
start_h = p.start_hour()
|
| 670 |
+
end_h = p.end_hour()
|
| 671 |
elif req.pattern_id == "custom":
|
| 672 |
+
start_h = cls._parse_hour(req.custom_start) if req.custom_start else 6.0
|
| 673 |
+
end_h = cls._parse_hour(req.custom_end) if req.custom_end else 23.0
|
|
|
|
|
|
|
|
|
|
| 674 |
if start_h is None:
|
| 675 |
start_h = 6.0 if req.breakfast else 17.0
|
| 676 |
if end_h is None:
|
| 677 |
end_h = 11.0 if not req.dinner else 23.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 678 |
rows.append({
|
| 679 |
"emp": emp,
|
| 680 |
+
"start_h": start_h, "end_h": end_h,
|
| 681 |
+
"breakfast": req.breakfast, "dinner": req.dinner,
|
|
|
|
|
|
|
| 682 |
"force_both": force_both,
|
| 683 |
+
"assigned_b": (emp.id, ds, "breakfast") in assigned_keys,
|
| 684 |
+
"assigned_d": (emp.id, ds, "dinner") in assigned_keys,
|
| 685 |
})
|
| 686 |
return rows
|
| 687 |
|
| 688 |
def _x(self, hour: float, width: int) -> int:
|
|
|
|
| 689 |
usable = width - self.MARGIN_LEFT - self.MARGIN_RIGHT
|
| 690 |
+
return self.MARGIN_LEFT + int((hour - self.TIME_START) / (self.TIME_END - self.TIME_START) * usable)
|
| 691 |
|
| 692 |
def paintEvent(self, event):
|
| 693 |
painter = QPainter(self)
|
| 694 |
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
| 695 |
W = self.width()
|
| 696 |
c = theme.c
|
| 697 |
+
painter.fillRect(self.rect(), QColor(c["bg"]))
|
| 698 |
|
| 699 |
+
# ゾーン背景
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
zone_h = self.MARGIN_TOP + len(self._rows) * self.ROW_H + self.COVERAGE_H
|
| 701 |
+
painter.fillRect(self._x(6, W), 0, self._x(11, W) - self._x(6, W), zone_h, QColor("#eff6ff"))
|
| 702 |
+
painter.fillRect(self._x(17, W), 0, self._x(23, W) - self._x(17, W), zone_h, QColor("#fdf2f8"))
|
| 703 |
|
| 704 |
+
# 時間グリッド
|
| 705 |
+
painter.setFont(QFont("", 8))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 706 |
for h in range(int(self.TIME_START), int(self.TIME_END) + 1):
|
| 707 |
x = self._x(h, W)
|
| 708 |
+
painter.setPen(QPen(QColor(c["border"]), 1))
|
| 709 |
+
painter.drawLine(x, self.MARGIN_TOP - 6, x, zone_h)
|
| 710 |
painter.setPen(QColor(c["text2"]))
|
| 711 |
painter.drawText(x - 10, self.MARGIN_TOP - 8, f"{h}:00")
|
|
|
|
| 712 |
|
| 713 |
+
# 従業員バー
|
| 714 |
painter.setFont(QFont("", 9))
|
| 715 |
for i, row in enumerate(self._rows):
|
| 716 |
+
y = self.MARGIN_TOP + i * self.ROW_H
|
| 717 |
cy = y + self.ROW_H // 2
|
|
|
|
|
|
|
| 718 |
painter.setPen(QColor(c["text"]))
|
| 719 |
painter.drawText(4, cy + 5, row["emp"].name)
|
| 720 |
|
| 721 |
+
is_both = row["force_both"] or (row["breakfast"] and row["dinner"])
|
|
|
|
|
|
|
|
|
|
| 722 |
assigned = row["assigned_b"] or row["assigned_d"]
|
|
|
|
| 723 |
if is_both:
|
| 724 |
bar_color = QColor("#22c55e") if assigned else QColor("#86efac")
|
| 725 |
+
elif row["breakfast"]:
|
| 726 |
bar_color = QColor("#3b82f6") if row["assigned_b"] else QColor("#93c5fd")
|
| 727 |
else:
|
| 728 |
bar_color = QColor("#ec4899") if row["assigned_d"] else QColor("#f9a8d4")
|
| 729 |
|
| 730 |
x1 = self._x(row["start_h"], W)
|
| 731 |
+
x2 = self._x(row["end_h"], W)
|
| 732 |
+
painter.fillRect(x1, y + 2, max(2, x2 - x1), self.ROW_H - 4, bar_color)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
if x2 - x1 > 50:
|
| 734 |
+
sh = int(row["start_h"]); sm = int((row["start_h"] % 1) * 60)
|
| 735 |
+
eh = int(row["end_h"]); em = int((row["end_h"] % 1) * 60)
|
| 736 |
+
painter.setPen(QColor("#ffffff") if assigned else QColor(c["text"]))
|
| 737 |
+
painter.setFont(QFont("", 8))
|
| 738 |
+
painter.drawText(x1 + 3, cy + 4, f"{sh}:{sm:02d}〜{eh}:{em:02d}")
|
| 739 |
+
painter.setFont(QFont("", 9))
|
| 740 |
+
|
| 741 |
+
# カバレッジバー
|
| 742 |
cov_y = self.MARGIN_TOP + len(self._rows) * self.ROW_H + 4
|
| 743 |
painter.setPen(QColor(c["text2"]))
|
| 744 |
painter.setFont(QFont("", 8))
|
| 745 |
painter.drawText(4, cov_y + 14, "人数")
|
| 746 |
|
|
|
|
| 747 |
slot_hours = list(range(int(self.TIME_START), int(self.TIME_END)))
|
| 748 |
+
all_counts = [
|
| 749 |
+
sum(1 for r in self._rows if r["start_h"] <= h < r["end_h"])
|
|
|
|
|
|
|
|
|
|
| 750 |
for h in slot_hours
|
| 751 |
+
]
|
| 752 |
+
max_count = max(all_counts) if all_counts else 1
|
|
|
|
| 753 |
b_min = sum(SHIFT_CONSTRAINTS.get((TimeSlot.BREAKFAST, pos), {}).get("min", 0) for pos in Position)
|
| 754 |
d_min = sum(SHIFT_CONSTRAINTS.get((TimeSlot.DINNER, pos), {}).get("min", 0) for pos in Position)
|
| 755 |
+
bar_h = self.COVERAGE_H - 22
|
| 756 |
|
| 757 |
+
for h, count in zip(slot_hours, all_counts):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
x1 = self._x(h, W)
|
| 759 |
x2 = self._x(h + 1, W)
|
| 760 |
+
bar_px = int(count / max(max_count, 1) * bar_h) if count > 0 else 0
|
|
|
|
|
|
|
| 761 |
is_b_zone = 6 <= h < 11
|
| 762 |
is_d_zone = 17 <= h < 23
|
| 763 |
+
required = b_min if is_b_zone else (d_min if is_d_zone else 0)
|
| 764 |
+
color = QColor("#ef4444") if (required > 0 and count < required) else QColor("#60a5fa")
|
| 765 |
+
if bar_px > 0:
|
| 766 |
+
painter.fillRect(x1 + 1, cov_y + bar_h - bar_px + 4,
|
| 767 |
+
max(1, x2 - x1 - 2), bar_px, color)
|
|
|
|
|
|
|
|
|
|
| 768 |
if count > 0:
|
| 769 |
painter.setPen(QColor(c["text"]))
|
| 770 |
+
painter.drawText(x1 + 2, cov_y + bar_h + 18, str(count))
|
| 771 |
|
| 772 |
painter.end()
|
| 773 |
|
| 774 |
|
| 775 |
+
# ── ポジション選択ダ��アログ ──────────────────────────────────────────────
|
| 776 |
|
| 777 |
class PositionSelectDialog(QDialog):
|
| 778 |
+
def __init__(self, emp: Employee, ds: str, slot: TimeSlot,
|
| 779 |
+
all_employees, assignments: dict, period_id: int,
|
| 780 |
+
is_reinforcement: bool = False, parent=None):
|
| 781 |
super().__init__(parent)
|
| 782 |
self.selected_position = None
|
| 783 |
+
suffix = "(応援要員)" if is_reinforcement else ""
|
| 784 |
+
self.setWindowTitle(f"{emp.name} のポジション選択{suffix}")
|
| 785 |
+
self.setFixedWidth(340)
|
| 786 |
|
| 787 |
+
layout = __import__("PyQt6.QtWidgets", fromlist=["QVBoxLayout"]).QVBoxLayout(self)
|
| 788 |
|
| 789 |
d = date.fromisoformat(ds)
|
| 790 |
dow = DAY_OF_WEEK_LABELS[d.weekday()]
|
| 791 |
layout.addWidget(QLabel(f"日付: {d.month}/{d.day}({dow}) {slot.short_label()}"))
|
| 792 |
layout.addWidget(QLabel(f"従業員: {emp.name}"))
|
| 793 |
+
if is_reinforcement:
|
| 794 |
+
warn = QLabel("⚠️ この従業員は希望を出していません(応援要員として追加)")
|
| 795 |
+
warn.setStyleSheet("color:#b45309; font-size:11px;")
|
| 796 |
+
layout.addWidget(warn)
|
| 797 |
layout.addWidget(QLabel(""))
|
| 798 |
|
| 799 |
for pos in Position:
|
| 800 |
+
constraint = SHIFT_CONSTRAINTS.get((slot, pos), {})
|
|
|
|
| 801 |
current = sum(
|
| 802 |
+
1 for (eid, d2, s2), (p, _) in assignments.items()
|
| 803 |
if d2 == ds and s2 == slot.value and p == pos.value
|
| 804 |
)
|
| 805 |
leaders = sum(
|
| 806 |
+
1 for (eid, d2, s2), (p, _) in assignments.items()
|
| 807 |
if d2 == ds and s2 == slot.value and p == pos.value
|
| 808 |
and any(x.id == eid and x.is_leader(pos.value) for x in all_employees)
|
| 809 |
)
|
|
|
|
| 810 |
emp_skill = emp.skill_for(pos.value)
|
| 811 |
badge = SKILL_BADGE.get(emp_skill, "")
|
| 812 |
btn = QPushButton(
|
| 813 |
f"{pos.label()} [{current}/{constraint.get('max',3)}名] "
|
| 814 |
f"★リーダー:{leaders}/{constraint.get('min_leader',1)}名 "
|
| 815 |
+
f"自分:{emp_skill.label()}{badge}"
|
| 816 |
)
|
| 817 |
btn.setFixedHeight(40)
|
| 818 |
c = theme.c
|
| 819 |
+
if not is_reinforcement and current >= constraint.get("max", 3):
|
| 820 |
btn.setEnabled(False)
|
| 821 |
btn.setToolTip("上限人数に達しています")
|
| 822 |
btn.setStyleSheet(f"color:{c['text2']};")
|
| 823 |
else:
|
| 824 |
btn.setStyleSheet(
|
| 825 |
+
f"QPushButton {{ text-align:left; padding:0 12px; "
|
| 826 |
+
f"border:1px solid {c['border2']}; border-radius:5px; }}"
|
| 827 |
f" QPushButton:hover {{ background:{c['surface2']}; }}"
|
| 828 |
)
|
| 829 |
btn.clicked.connect(lambda _, p=pos: self._select(p))
|
utils/theme.py
CHANGED
|
@@ -58,6 +58,8 @@ LIGHT: dict[str, str] = {
|
|
| 58 |
"scroll_handle": "#cbd5e1",
|
| 59 |
# 他スロット専任メンバーの行背景(薄い黄)
|
| 60 |
"cell_other_slot": "#fef9c3",
|
|
|
|
|
|
|
| 61 |
# サイドバー(ダークのまま固定)
|
| 62 |
"sidebar_bg": "#1e293b",
|
| 63 |
"sidebar_active": "#2563eb",
|
|
@@ -118,6 +120,8 @@ DARK: dict[str, str] = {
|
|
| 118 |
"scroll_handle": "#475569",
|
| 119 |
# 他スロット専任メンバーの行背景(ダーク:暗い黄)
|
| 120 |
"cell_other_slot": "#3d3200",
|
|
|
|
|
|
|
| 121 |
# サイドバー
|
| 122 |
"sidebar_bg": "#020617",
|
| 123 |
"sidebar_active": "#2563eb",
|
|
|
|
| 58 |
"scroll_handle": "#cbd5e1",
|
| 59 |
# 他スロット専任メンバーの行背景(薄い黄)
|
| 60 |
"cell_other_slot": "#fef9c3",
|
| 61 |
+
# 応援要員セル(オレンジ)
|
| 62 |
+
"cell_reinforcement": "#fed7aa",
|
| 63 |
# サイドバー(ダークのまま固定)
|
| 64 |
"sidebar_bg": "#1e293b",
|
| 65 |
"sidebar_active": "#2563eb",
|
|
|
|
| 120 |
"scroll_handle": "#475569",
|
| 121 |
# 他スロット専任メンバーの行背景(ダーク:暗い黄)
|
| 122 |
"cell_other_slot": "#3d3200",
|
| 123 |
+
# 応援要員セル(ダーク:暗いオレンジ)
|
| 124 |
+
"cell_reinforcement": "#7c2d12",
|
| 125 |
# サイドバー
|
| 126 |
"sidebar_bg": "#020617",
|
| 127 |
"sidebar_active": "#2563eb",
|
utils/version.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""アプリバージョン管理とアップデートチェック"""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
# ビルド時に CI が上書きする (_version.py を生成)
|
| 5 |
+
try:
|
| 6 |
+
from utils._version import APP_VERSION # type: ignore
|
| 7 |
+
except ImportError:
|
| 8 |
+
APP_VERSION = "dev"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def get_build_number() -> int:
|
| 12 |
+
"""'build-42' → 42 に変換。dev / 解析不能なら 0"""
|
| 13 |
+
try:
|
| 14 |
+
return int(APP_VERSION.split("-")[1])
|
| 15 |
+
except (IndexError, ValueError):
|
| 16 |
+
return 0
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def check_for_update() -> tuple[bool, str, str]:
|
| 20 |
+
"""
|
| 21 |
+
GitHub Releases API で最新ビルドを確認する。
|
| 22 |
+
戻り値: (is_newer, latest_tag, release_url)
|
| 23 |
+
ネットワークエラー時は (False, "", "") を返す。
|
| 24 |
+
"""
|
| 25 |
+
import urllib.request
|
| 26 |
+
import json
|
| 27 |
+
api_url = "https://api.github.com/repos/Richiesss/shift-tool/releases/latest"
|
| 28 |
+
try:
|
| 29 |
+
req = urllib.request.Request(
|
| 30 |
+
api_url, headers={"User-Agent": "SDU-Shift-UpdateChecker"})
|
| 31 |
+
with urllib.request.urlopen(req, timeout=6) as resp:
|
| 32 |
+
data = json.loads(resp.read())
|
| 33 |
+
tag = data.get("tag_name", "")
|
| 34 |
+
html_url = data.get("html_url", "")
|
| 35 |
+
try:
|
| 36 |
+
latest_n = int(tag.split("-")[1])
|
| 37 |
+
current_n = get_build_number()
|
| 38 |
+
return latest_n > current_n, tag, html_url
|
| 39 |
+
except (IndexError, ValueError):
|
| 40 |
+
return False, tag, html_url
|
| 41 |
+
except Exception:
|
| 42 |
+
return False, "", ""
|