m1m02530125 Claude Sonnet 4.6 commited on
Commit
4c8af4e
·
1 Parent(s): 9445768

シフト表にスタッフ個別コメント機能を追加

Browse files

- cell_notes テーブル新設(period_id, employee_id, date, note)
- get_cell_notes / save_cell_note をリポジトリに追加
- POST /schedule/<id>/cell_note エンドポイントを追加
- 担当編集モーダルにコメント欄を追加(閉じる時に自動保存)
- セルにコメントバッジを表示(先頭8文字 + アイコン)、リロードなしで即時反映

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

db/database.py CHANGED
@@ -250,6 +250,14 @@ _CREATE_TABLES = [
250
  action TEXT NOT NULL,
251
  changed_at TEXT NOT NULL DEFAULT (datetime('now','localtime'))
252
  )""",
 
 
 
 
 
 
 
 
253
  ]
254
 
255
  _MIGRATIONS = [
@@ -283,6 +291,7 @@ _INDEXES = [
283
  "CREATE INDEX IF NOT EXISTS idx_reservation_period ON reservation_counts(period_id)",
284
  "CREATE INDEX IF NOT EXISTS idx_schedule_notes_period ON schedule_notes(period_id)",
285
  "CREATE INDEX IF NOT EXISTS idx_assignment_log_period ON assignment_log(period_id)",
 
286
  ]
287
 
288
 
 
250
  action TEXT NOT NULL,
251
  changed_at TEXT NOT NULL DEFAULT (datetime('now','localtime'))
252
  )""",
253
+ """CREATE TABLE IF NOT EXISTS cell_notes (
254
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
255
+ period_id INTEGER NOT NULL REFERENCES schedule_periods(id) ON DELETE CASCADE,
256
+ employee_id INTEGER NOT NULL,
257
+ date TEXT NOT NULL,
258
+ note TEXT NOT NULL DEFAULT '',
259
+ UNIQUE(period_id, employee_id, date)
260
+ )""",
261
  ]
262
 
263
  _MIGRATIONS = [
 
291
  "CREATE INDEX IF NOT EXISTS idx_reservation_period ON reservation_counts(period_id)",
292
  "CREATE INDEX IF NOT EXISTS idx_schedule_notes_period ON schedule_notes(period_id)",
293
  "CREATE INDEX IF NOT EXISTS idx_assignment_log_period ON assignment_log(period_id)",
294
+ "CREATE INDEX IF NOT EXISTS idx_cell_notes_period ON cell_notes(period_id)",
295
  ]
296
 
297
 
db/repositories.py CHANGED
@@ -679,6 +679,36 @@ def save_schedule_note(period_id: int, date_str: str, note: str):
679
  conn.close()
680
 
681
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
682
  # ── シフト制約 ──────────────────────────────────────────────────────────
683
 
684
  @cache.memoize(timeout=300)
 
679
  conn.close()
680
 
681
 
682
+ def get_cell_notes(period_id: int) -> dict[tuple[int, str], str]:
683
+ """スタッフ個別コメントを {(employee_id, date): note} で返す"""
684
+ conn = get_connection()
685
+ rows = conn.execute(
686
+ "SELECT employee_id, date, note FROM cell_notes WHERE period_id=? ORDER BY date",
687
+ (period_id,)
688
+ ).fetchall()
689
+ conn.close()
690
+ return {(r["employee_id"], r["date"]): r["note"] for r in rows if r["note"]}
691
+
692
+
693
+ def save_cell_note(period_id: int, employee_id: int, date_str: str, note: str):
694
+ """スタッフ個別コメントを保存。空文字の場合は削除。100文字以内に制限"""
695
+ note = note.strip()[:100]
696
+ conn = get_connection()
697
+ if note:
698
+ conn.execute(
699
+ """INSERT INTO cell_notes (period_id, employee_id, date, note) VALUES (?,?,?,?)
700
+ ON CONFLICT(period_id, employee_id, date) DO UPDATE SET note=excluded.note""",
701
+ (period_id, employee_id, date_str, note)
702
+ )
703
+ else:
704
+ conn.execute(
705
+ "DELETE FROM cell_notes WHERE period_id=? AND employee_id=? AND date=?",
706
+ (period_id, employee_id, date_str)
707
+ )
708
+ conn.commit()
709
+ conn.close()
710
+
711
+
712
  # ── シフト制約 ──────────────────────────────────────────────────────────
713
 
714
  @cache.memoize(timeout=300)
routes/schedule.py CHANGED
@@ -201,6 +201,7 @@ def index(period_id):
201
 
202
  needs_regen = repo.get_period_gen_status(period_id).get("needs_regen", False)
203
 
 
204
  submitted_ids = {r.employee_id for r in shift_requests}
205
  unsubmitted_count = sum(1 for e in all_employees if e.id not in submitted_ids)
206
 
@@ -249,6 +250,7 @@ def index(period_id):
249
  unsubmitted_count=unsubmitted_count,
250
  reservation_counts=reservation_counts,
251
  ft_off_dates=ft_off_dates,
 
252
  today=today,
253
  ft_times=ft_times,
254
  holidays=holidays,
@@ -307,6 +309,18 @@ def assign(period_id):
307
  return jsonify({"ok": False, "error": str(e)}), 400
308
 
309
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  @bp.post("/<int:period_id>/note")
311
  def save_note(period_id):
312
  data = request.get_json()
 
201
 
202
  needs_regen = repo.get_period_gen_status(period_id).get("needs_regen", False)
203
 
204
+ cell_notes = repo.get_cell_notes(period_id)
205
  submitted_ids = {r.employee_id for r in shift_requests}
206
  unsubmitted_count = sum(1 for e in all_employees if e.id not in submitted_ids)
207
 
 
250
  unsubmitted_count=unsubmitted_count,
251
  reservation_counts=reservation_counts,
252
  ft_off_dates=ft_off_dates,
253
+ cell_notes=cell_notes,
254
  today=today,
255
  ft_times=ft_times,
256
  holidays=holidays,
 
309
  return jsonify({"ok": False, "error": str(e)}), 400
310
 
311
 
312
+ @bp.post("/<int:period_id>/cell_note")
313
+ def save_cell_note(period_id):
314
+ data = request.get_json()
315
+ emp_id = data.get("employee_id")
316
+ date_str = data.get("date", "")
317
+ note = data.get("note", "")
318
+ if not emp_id or not date_str:
319
+ return jsonify({"ok": False, "error": "パラメータが不足しています"}), 400
320
+ repo.save_cell_note(period_id, emp_id, date_str, note)
321
+ return jsonify({"ok": True})
322
+
323
+
324
  @bp.post("/<int:period_id>/note")
325
  def save_note(period_id):
326
  data = request.get_json()
templates/schedule/index.html CHANGED
@@ -121,6 +121,12 @@
121
  .chip-empty { color: #cbd5e1; }
122
  /* 正社員の希望休:赤塗りつぶし */
123
  .ft-off { background-color: #FCA5A5 !important; }
 
 
 
 
 
 
124
  /* スタッフ名リンク */
125
  .emp-name-link {
126
  color: inherit; text-decoration: none; display: block;
@@ -413,6 +419,7 @@
413
  {% set req_time = time_map.get((emp.id, ds, slot), '') %}
414
  {% set display_time = req_time if req_time else (default_slot_time if is_ft else '') %}
415
  {% set is_ft_off = (emp.id, ds) in ft_off_dates %}
 
416
  <td class="text-center {{ 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' }} {{ 'today-col' if ds == today else '' }} assign-cell {{ 'ft-off' if is_ft_off else '' }}"
417
  style="cursor:pointer"
418
  data-emp-id="{{ emp.id }}"
@@ -426,6 +433,7 @@
426
  data-reinf-end="{{ emp_asgn.reinf_end if emp_asgn and emp_asgn.reinf_end else '' }}"
427
  data-shift-time="{{ display_time }}"
428
  data-has-request="{{ 'true' if is_ft or time_map.get((emp.id, ds, slot)) is not none else 'false' }}"
 
429
  onclick="openAssignModal(this)">
430
  {% if emp_asgn %}
431
  {% set pos_label = 'H' if pos == 'hall' else 'K' %}
@@ -444,6 +452,11 @@
444
  {% else %}
445
  <span class="chip-empty">+</span>
446
  {% endif %}
 
 
 
 
 
447
  </td>
448
  {% endfor %}
449
  </tr>
@@ -546,7 +559,17 @@
546
  </button>
547
  </div>
548
 
549
- <!-- ④ 担当を外す(割当済みの場合のみ) -->
 
 
 
 
 
 
 
 
 
 
550
  <div id="remove-section" class="asgn-section" style="display:none">
551
  <button class="btn btn-outline-danger w-100 btn-sm" onclick="doRemove()">
552
  <i class="bi bi-x-circle me-1"></i>担当を外す
@@ -559,9 +582,16 @@
559
  </div>
560
 
561
  <script>
562
- const IS_CONFIRMED = {{ 'true' if period.status == 'confirmed' else 'false' }};
563
- const TOTAL_SHORTAGE = {{ total_shortage }};
564
  const UNSUBMITTED_COUNT = {{ unsubmitted_count }};
 
 
 
 
 
 
 
565
 
566
  // ── タイムライン ─────────────────────────────────────
567
  const TL_ASGN = {
@@ -791,7 +821,15 @@ function openAssignModal(cell) {
791
  document.getElementById('btn-submit').innerHTML =
792
  `<i class="bi bi-person-check me-1"></i>${assigned === 'true' ? '担当を変更する' : '担当として追加'}`;
793
 
794
- if (!_modal) _modal = new bootstrap.Modal(document.getElementById('assignModal'));
 
 
 
 
 
 
 
 
795
  _modal.show();
796
  }
797
 
@@ -822,8 +860,39 @@ function doRemove() {
822
  callAssign({ employee_id: +d.empId, date: d.date, time_slot: d.slot, position: d.pos, action: 'remove' });
823
  }
824
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
825
  function callAssign(payload) {
826
- const periodId = {{ period.id if period else 0 }};
827
  // スクロール位置を保存してリロード後に復元
828
  const grid = document.querySelector('.sched-grid');
829
  if (grid) sessionStorage.setItem('schedScroll',
 
121
  .chip-empty { color: #cbd5e1; }
122
  /* 正社員の希望休:赤塗りつぶし */
123
  .ft-off { background-color: #FCA5A5 !important; }
124
+ /* スタッフ個別コメント表示 */
125
+ .cell-note-badge {
126
+ display: block; font-size: .6rem; color: #f59e0b; line-height: 1.2;
127
+ margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
128
+ max-width: 58px;
129
+ }
130
  /* スタッフ名リンク */
131
  .emp-name-link {
132
  color: inherit; text-decoration: none; display: block;
 
419
  {% set req_time = time_map.get((emp.id, ds, slot), '') %}
420
  {% set display_time = req_time if req_time else (default_slot_time if is_ft else '') %}
421
  {% set is_ft_off = (emp.id, ds) in ft_off_dates %}
422
+ {% set cell_note = cell_notes.get((emp.id, ds), '') %}
423
  <td class="text-center {{ 'sun' if (dow == 6 or is_holiday) else 'sat' if dow == 5 else '' }} {{ 'today-col' if ds == today else '' }} assign-cell {{ 'ft-off' if is_ft_off else '' }}"
424
  style="cursor:pointer"
425
  data-emp-id="{{ emp.id }}"
 
433
  data-reinf-end="{{ emp_asgn.reinf_end if emp_asgn and emp_asgn.reinf_end else '' }}"
434
  data-shift-time="{{ display_time }}"
435
  data-has-request="{{ 'true' if is_ft or time_map.get((emp.id, ds, slot)) is not none else 'false' }}"
436
+ data-cell-note="{{ cell_note }}"
437
  onclick="openAssignModal(this)">
438
  {% if emp_asgn %}
439
  {% set pos_label = 'H' if pos == 'hall' else 'K' %}
 
452
  {% else %}
453
  <span class="chip-empty">+</span>
454
  {% endif %}
455
+ {% if cell_note %}
456
+ <span class="cell-note-badge" title="{{ cell_note }}">
457
+ <i class="bi bi-chat-fill" style="font-size:.55rem"></i> {{ cell_note[:8] }}{% if cell_note|length > 8 %}…{% endif %}
458
+ </span>
459
+ {% endif %}
460
  </td>
461
  {% endfor %}
462
  </tr>
 
559
  </button>
560
  </div>
561
 
562
+ <!-- ④ コメント -->
563
+ <div class="asgn-section">
564
+ <div class="asgn-section-label">コメント(任意)</div>
565
+ <textarea id="cell-note-input" rows="2"
566
+ class="form-control form-control-sm"
567
+ style="background:#0f172a;border-color:#334155;color:#e2e8f0;resize:none;font-size:.82rem"
568
+ placeholder="初日・オムレツ担当・休憩15:00〜 など(100文字以内)"
569
+ maxlength="100"></textarea>
570
+ </div>
571
+
572
+ <!-- ⑤ 担当を外す(割当済みの場合のみ) -->
573
  <div id="remove-section" class="asgn-section" style="display:none">
574
  <button class="btn btn-outline-danger w-100 btn-sm" onclick="doRemove()">
575
  <i class="bi bi-x-circle me-1"></i>担当を外す
 
582
  </div>
583
 
584
  <script>
585
+ const IS_CONFIRMED = {{ 'true' if period.status == 'confirmed' else 'false' }};
586
+ const TOTAL_SHORTAGE = {{ total_shortage }};
587
  const UNSUBMITTED_COUNT = {{ unsubmitted_count }};
588
+ const PERIOD_ID = {{ period.id }};
589
+ // スタッフ個別コメントキャッシュ {empId_date: note}
590
+ const CELL_NOTES = {
591
+ {% for (emp_id, date), note in cell_notes.items() %}
592
+ "{{ emp_id }}_{{ date }}": {{ note | tojson }},
593
+ {% endfor %}
594
+ };
595
 
596
  // ── タイムライン ─────────────────────────────────────
597
  const TL_ASGN = {
 
821
  document.getElementById('btn-submit').innerHTML =
822
  `<i class="bi bi-person-check me-1"></i>${assigned === 'true' ? '担当を変更する' : '担当として追加'}`;
823
 
824
+ // コメント欄初期化
825
+ const noteKey = `${cell.dataset.empId}_${cell.dataset.date}`;
826
+ document.getElementById('cell-note-input').value = CELL_NOTES[noteKey] || cell.dataset.cellNote || '';
827
+
828
+ if (!_modal) {
829
+ _modal = new bootstrap.Modal(document.getElementById('assignModal'));
830
+ // モーダルを閉じる時にコメントを保存
831
+ document.getElementById('assignModal').addEventListener('hide.bs.modal', _saveCellNote);
832
+ }
833
  _modal.show();
834
  }
835
 
 
860
  callAssign({ employee_id: +d.empId, date: d.date, time_slot: d.slot, position: d.pos, action: 'remove' });
861
  }
862
 
863
+ function _saveCellNote() {
864
+ if (!_cell) return;
865
+ const note = document.getElementById('cell-note-input').value.trim();
866
+ const empId = +_cell.dataset.empId;
867
+ const date = _cell.dataset.date;
868
+ const noteKey = `${empId}_${date}`;
869
+ const prev = CELL_NOTES[noteKey] || _cell.dataset.cellNote || '';
870
+ if (note === prev) return; // 変更なしはスキップ
871
+ CELL_NOTES[noteKey] = note;
872
+ fetch(`/schedule/${PERIOD_ID}/cell_note`, {
873
+ method: 'POST', headers: {'Content-Type': 'application/json'},
874
+ body: JSON.stringify({ employee_id: empId, date, note })
875
+ }).then(() => {
876
+ // セル内のバッジを即時更新(リロードなし)
877
+ const badge = _cell.querySelector('.cell-note-badge');
878
+ if (note) {
879
+ const icon = '<i class="bi bi-chat-fill" style="font-size:.55rem"></i> ';
880
+ const text = note.length > 8 ? note.slice(0, 8) + '…' : note;
881
+ if (badge) { badge.innerHTML = icon + text; badge.title = note; }
882
+ else {
883
+ const s = document.createElement('span');
884
+ s.className = 'cell-note-badge'; s.title = note;
885
+ s.innerHTML = icon + text;
886
+ _cell.appendChild(s);
887
+ }
888
+ } else {
889
+ if (badge) badge.remove();
890
+ }
891
+ });
892
+ }
893
+
894
  function callAssign(payload) {
895
+ const periodId = PERIOD_ID;
896
  // スクロール位置を保存してリロード後に復元
897
  const grid = document.querySelector('.sched-grid');
898
  if (grid) sessionStorage.setItem('schedScroll',