Files
Super-HomeworkManager/web/templates/assignments/index.html
2025-12-30 21:47:39 +09:00

270 lines
13 KiB
HTML

{{template "base" .}}
{{define "content"}}
<div class="d-flex justify-content-between align-items-center mb-3">
<div class="d-flex align-items-center">
<h4 class="mb-0 fw-bold"><i class="bi bi-list-task me-2"></i>課題一覧</h4>
</div>
<div class="d-flex gap-2">
<button class="btn btn-sm btn-secondary text-white" onclick="toggleCountdown()" id="toggleCountdownBtn">
<i class="bi bi-clock me-1"></i><span id="countdownBtnText">カウントダウン表示中</span>
</button>
<a href="/assignments/new" class="btn btn-sm btn-primary">
<i class="bi bi-plus-lg me-1"></i>新規登録
</a>
</div>
</div>
<!-- Tabs -->
<ul class="nav nav-tabs border-0 mb-2" id="assignmentTabs">
<li class="nav-item">
<a class="nav-link py-2 rounded-0 border-0 {{if eq .filter " pending"}}fw-bold border-bottom border-dark
border-3{{else}}text-muted{{end}}" href="/assignments?filter=pending&q={{.query}}&priority={{.priority}}"
style="{{if eq .filter " pending"}}color: black !important;{{end}}">未完了</a>
</li>
<li class="nav-item">
<a class="nav-link py-2 rounded-0 border-0 {{if eq .filter " completed"}}fw-bold border-bottom border-dark
border-3{{else}}text-muted{{end}}" href="/assignments?filter=completed&q={{.query}}&priority={{.priority}}"
style="{{if eq .filter " completed"}}color: black !important;{{end}}">完了済み</a>
</li>
<li class="nav-item">
<a class="nav-link py-2 rounded-0 border-0 {{if eq .filter " overdue"}}fw-bold border-bottom border-dark
border-3{{else}}text-muted{{end}}" href="/assignments?filter=overdue&q={{.query}}&priority={{.priority}}"
style="{{if eq .filter " overdue"}}color: black !important;{{end}}">期限切れ</a>
</li>
</ul>
<hr class="mt-0 mb-3 text-muted" style="opacity: 0.1;">
<!-- Filter Section -->
<form action="/assignments" method="GET" class="row g-2 mb-3 align-items-center">
<input type="hidden" name="filter" value="{{.filter}}">
<div class="col-md-5">
<div class="input-group input-group-sm">
<span class="input-group-text bg-white border-end-0 text-muted"><i class="bi bi-search"></i></span>
<input type="text" class="form-control border-start-0 ps-0 bg-white" name="q" placeholder="検索..."
value="{{.query}}">
</div>
</div>
<div class="col-md-4">
<select class="form-select form-select-sm bg-white" name="priority" onchange="this.form.submit()">
<option value="">全ての重要度</option>
<option value="high" {{if eq .priority "high" }}selected{{end}}></option>
<option value="medium" {{if eq .priority "medium" }}selected{{end}}></option>
<option value="low" {{if eq .priority "low" }}selected{{end}}></option>
</select>
</div>
<div class="col-md-3">
<a href="/assignments?filter={{.filter}}" class="btn btn-sm btn-outline-secondary w-100 bg-white">
クリア
</a>
</div>
</form>
<!-- Table -->
<div class="card shadow-sm border-0 rounded-0">
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover align-middle mb-0 custom-table">
<thead class="bg-secondary-subtle">
<tr>
<th style="width: 50px;" class="ps-3 text-center text-dark fw-bold">状態</th>
<th class="text-dark fw-bold">タイトル</th>
<th style="width: 120px;" class="text-dark fw-bold">科目</th>
<th style="width: 80px;" class="text-dark fw-bold">重要度</th>
<th style="width: 140px;" class="text-dark fw-bold">期限</th>
<th style="width: 120px;" class="countdown-col text-dark fw-bold">残り</th>
<th style="width: 80px;" class="text-end pe-3 text-dark fw-bold">操作</th>
</tr>
</thead>
<tbody>
{{range .assignments}}
<tr class="assignment-row border-bottom" data-due-ts="{{.DueDate.Unix}}"
data-completed="{{.IsCompleted}}">
<td class="ps-3 text-center">
{{if .IsCompleted}}
<form action="/assignments/{{.ID}}/toggle" method="POST" class="d-inline">
<input type="hidden" name="_csrf" value="{{$.csrfToken}}">
<button type="submit"
class="btn btn-link p-0 text-success text-decoration-none hover-dark"
title="未完了に戻す">
<i class="bi bi-check-circle-fill"></i>
</button>
</form>
{{else}}
<form action="/assignments/{{.ID}}/toggle" method="POST" class="d-inline">
<input type="hidden" name="_csrf" value="{{$.csrfToken}}">
<button type="submit"
class="btn btn-link p-0 text-secondary text-decoration-none hover-dark"
title="完了にする">
<i class="bi bi-circle"></i>
</button>
</form>
{{end}}
</td>
<td>
<div class="fw-bold text-dark text-truncate" style="max-width: 300px;">{{.Title}}</div>
</td>
<td><span class="badge bg-secondary text-white border-0 fw-bold">{{.Subject}}</span></td>
<td>
{{if eq .Priority "high"}}
<span class="badge bg-danger text-white border-0 fw-bold small"></span>
{{else if eq .Priority "medium"}}
<span class="badge bg-warning text-dark border-0 fw-bold small"></span>
{{else}}
<span class="badge bg-dark text-white border-0 fw-bold small"></span>
{{end}}
</td>
<td>
<div class="small fw-bold text-dark user-select-all">{{.DueDate.Format "2006/01/02 15:04"}}
</div>
</td>
<td class="countdown-col">
{{if not .IsCompleted}}
<span class="countdown small fw-bold font-monospace text-dark">...</span>
{{else}}
<span class="text-secondary small fw-bold">-</span>
{{end}}
</td>
<td class="text-end pe-3">
<div class="btn-group">
<a href="/assignments/{{.ID}}/edit" class="text-primary me-3 text-decoration-none">
<i class="bi bi-pencil-fill"></i>
</a>
<form action="/assignments/{{.ID}}/delete" method="POST" class="d-inline"
onsubmit="return confirm('削除しますか?');">
<input type="hidden" name="_csrf" value="{{$.csrfToken}}">
<button type="submit"
class="btn btn-link p-0 text-danger text-decoration-none border-0 bg-transparent">
<i class="bi bi-trash-fill"></i>
</button>
</form>
</div>
</td>
</tr>
{{else}}
<tr>
<td colspan="7" class="text-center py-4 text-secondary fw-bold small">
課題なし
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
{{if gt .totalPages 1}}
<div class="card-footer bg-white border-top-0 py-2">
<nav>
<ul class="pagination pagination-sm justify-content-center mb-0">
<li class="page-item {{if not .hasPrev}}disabled{{end}}">
<a class="page-link border-0 text-secondary"
href="/assignments?page={{.prevPage}}&filter={{.filter}}&q={{.query}}&priority={{.priority}}">
<i class="bi bi-chevron-left"></i>
</a>
</li>
<li class="page-item disabled">
<span class="page-link border-0 text-dark fw-bold">{{.currentPage}} / {{.totalPages}}</span>
</li>
<li class="page-item {{if not .hasNext}}disabled{{end}}">
<a class="page-link border-0 text-secondary"
href="/assignments?page={{.nextPage}}&filter={{.filter}}&q={{.query}}&priority={{.priority}}">
<i class="bi bi-chevron-right"></i>
</a>
</li>
</ul>
</nav>
</div>
{{end}}
</div>
<script>
function updateCountdowns() {
const now = new Date();
document.querySelectorAll('.assignment-row').forEach(row => {
if (row.getAttribute('data-completed') === 'true') return;
const dueTs = row.getAttribute('data-due-ts');
if (!dueTs) return;
// Fix: Use timestamp directly to avoid parsing issues
const due = new Date(parseInt(dueTs) * 1000);
if (isNaN(due.getTime())) return;
const diff = due - now;
const countdownEl = row.querySelector('.countdown');
// Reset classes
row.classList.remove('anxiety-danger', 'anxiety-warning', 'bg-danger-subtle');
if (countdownEl) countdownEl.className = 'countdown small fw-bold font-monospace';
if (diff < 0) {
if (countdownEl) {
countdownEl.textContent = "期限切れ";
countdownEl.classList.add('text-danger');
}
row.classList.add('bg-danger-subtle');
return;
}
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
let text = "";
let remainingHours = (days * 24) + hours;
if (days > 0) {
text += `${days}`;
}
text += `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
if (countdownEl) countdownEl.textContent = text;
// Anxiety Logic
if (remainingHours < 24) {
row.classList.add('anxiety-danger');
if (countdownEl) {
countdownEl.classList.add('text-danger', 'countdown-urgent');
countdownEl.innerHTML = '<i class="bi bi-exclamation-triangle-fill me-1"></i>' + text;
}
} else if (days < 7) {
row.classList.add('anxiety-warning');
if (countdownEl) {
countdownEl.classList.add('text-dark');
countdownEl.innerHTML = '<i class="bi bi-exclamation-triangle-fill text-warning me-1"></i>' + text;
}
} else {
if (countdownEl) countdownEl.classList.add('text-secondary');
}
});
}
function toggleCountdown() {
const cols = document.querySelectorAll('.countdown-col');
const btnText = document.getElementById('countdownBtnText');
const isHidden = cols[0] && cols[0].style.display === 'none';
cols.forEach(col => {
col.style.display = isHidden ? '' : 'none';
});
btnText.textContent = isHidden ? 'カウントダウン表示中' : 'カウントダウン非表示中';
localStorage.setItem('countdownHidden', !isHidden);
}
// Init with higher frequency for smooth panic
setInterval(updateCountdowns, 1000);
updateCountdowns();
// Check preference
const isHidden = localStorage.getItem('countdownHidden') === 'true';
if (isHidden) {
document.querySelectorAll('.countdown-col').forEach(col => {
col.style.display = 'none';
});
const btnText = document.getElementById('countdownBtnText');
if (btnText) btnText.textContent = 'カウントダウン非表示中';
}
</script>
{{end}}