ツール管理へ戻る

v2 → v3 の差分

--- v2
+++ v3
@@ -21,7 +21,7 @@
     }
 
     main {
-      max-width: 760px;
+      max-width: 900px;
       margin: 0 auto;
       padding: 28px;
       background: #fff;
@@ -33,6 +33,11 @@
     h1 {
       margin: 0 0 8px;
       font-size: 1.6rem;
+    }
+
+    h2 {
+      margin: 0 0 14px;
+      font-size: 1.2rem;
     }
 
     .description {
@@ -76,7 +81,7 @@
     }
 
     textarea {
-      min-height: 82px;
+      min-height: 76px;
       resize: vertical;
     }
 
@@ -113,14 +118,24 @@
       margin: 0;
     }
 
-    .error {
+    .error,
+    .notice {
       display: none;
       margin: 0 0 16px;
       padding: 11px 13px;
+      border-radius: 7px;
+    }
+
+    .error {
       color: #9b1c1c;
       background: #fff1f1;
       border: 1px solid #f0b8b8;
-      border-radius: 7px;
+    }
+
+    .notice {
+      color: #14532d;
+      background: #f0fdf4;
+      border: 1px solid #bbf7d0;
     }
 
     .actions {
@@ -143,6 +158,12 @@
       filter: brightness(0.96);
     }
 
+    button:disabled {
+      opacity: 0.5;
+      cursor: not-allowed;
+      filter: none;
+    }
+
     .primary {
       color: #fff;
       background: #2563eb;
@@ -153,27 +174,58 @@
       background: #e8edf3;
     }
 
-    .result {
-      display: none;
-      margin-top: 24px;
-      padding: 16px;
-      border: 1px solid #b9dec4;
-      border-radius: 9px;
-      background: #f2fbf4;
-    }
-
-    .result h2 {
-      margin: 0 0 8px;
-      font-size: 1.1rem;
-    }
-
-    .result p {
-      margin: 0;
-      line-height: 1.6;
+    .records-section {
+      margin-top: 30px;
+      padding-top: 24px;
+      border-top: 1px solid #dce3ec;
+    }
+
+    .record-count {
+      margin: 0 0 12px;
+      color: #526174;
+    }
+
+    .table-wrap {
+      overflow-x: auto;
+      border: 1px solid #dce3ec;
+      border-radius: 8px;
+    }
+
+    table {
+      width: 100%;
+      border-collapse: collapse;
+      min-width: 680px;
+    }
+
+    th,
+    td {
+      padding: 9px 10px;
+      text-align: left;
+      vertical-align: top;
+      border-bottom: 1px solid #dce3ec;
+      overflow-wrap: anywhere;
+    }
+
+    th {
+      background: #f3f6fa;
+      white-space: nowrap;
+    }
+
+    tbody tr:last-child td {
+      border-bottom: 0;
+    }
+
+    .empty-row td {
+      color: #64748b;
+      text-align: center;
     }
 
     .notice {
-      margin-top: 18px;
+      margin-top: 16px;
+    }
+
+    .privacy-note {
+      margin: 18px 0 0;
       color: #64748b;
       font-size: 0.9rem;
       line-height: 1.5;
@@ -194,7 +246,7 @@
   <main>
     <h1>回答待ち時間の記録</h1>
     <p class="description">
-      入力した内容を、Excelで開けるCSVファイルとしてダウンロードできます。
+      1件ずつ記録を追加し、最後にすべての記録をCSVでダウンロードできます。
     </p>
 
     <form id="recordForm" novalidate>
@@ -266,21 +318,50 @@
       </div>
 
       <p class="error" id="errorMessage" role="alert"></p>
+      <p class="notice" id="noticeMessage" role="status"></p>
 
       <div class="actions">
-        <button class="primary" type="submit">CSVをダウンロード</button>
-        <button class="secondary" type="reset">入力を初期化</button>
+        <button class="primary" type="submit">記録を追加</button>
+        <button class="secondary" type="reset">入力欄を初期化</button>
       </div>
     </form>
 
-    <section class="result" id="resultMessage" aria-live="polite">
-      <h2>CSVを作成しました</h2>
-      <p>入力した5項目を1行にまとめたCSVファイルをダウンロードしました。</p>
+    <section class="records-section" aria-labelledby="recordsHeading">
+      <h2 id="recordsHeading">記録一覧</h2>
+      <p class="record-count" id="recordCount" aria-live="polite">記録件数:0件</p>
+
+      <div class="table-wrap">
+        <table>
+          <thead>
+            <tr>
+              <th>待ち時間(分)</th>
+              <th>相手の区分</th>
+              <th>依頼内容</th>
+              <th>作業状況</th>
+              <th>影響</th>
+            </tr>
+          </thead>
+          <tbody id="recordsBody">
+            <tr class="empty-row">
+              <td colspan="5">まだ記録はありません。</td>
+            </tr>
+          </tbody>
+        </table>
+      </div>
+
+      <div class="actions">
+        <button class="primary" id="downloadButton" type="button" disabled>
+          全記録をCSVでダウンロード
+        </button>
+        <button class="secondary" id="clearRecordsButton" type="button" disabled>
+          記録一覧を初期化
+        </button>
+      </div>
     </section>
 
-    <p class="notice">
-      このページはブラウザ内だけで動作し、入力内容の保存や外部への送信は行いません。
-      ダウンロードしたCSVファイルは、お使いのパソコンで適切に管理してください。
+    <p class="privacy-note">
+      記録はページを開いている間だけブラウザ内に保持されます。
+      ページを閉じると消去され、外部への送信や自動保存は行いません。
     </p>
   </main>
 
@@ -289,10 +370,18 @@
 
     const form = document.getElementById("recordForm");
     const errorMessage = document.getElementById("errorMessage");
-    const resultMessage = document.getElementById("resultMessage");
+    const noticeMessage = document.getElementById("noticeMessage");
+    const recordsBody = document.getElementById("recordsBody");
+    const recordCount = document.getElementById("recordCount");
+    const downloadButton = document.getElementById("downloadButton");
+    const clearRecordsButton = document.getElementById("clearRecordsButton");
+
+    const records = [];
 
     function getFormData() {
-      const selectedStatus = form.querySelector('input[name="workStatus"]:checked');
+      const selectedStatus = form.querySelector(
+        'input[name="workStatus"]:checked'
+      );
 
       return {
         waitMinutes: document.getElementById("waitMinutes").value.trim(),
@@ -333,10 +422,68 @@
       return "";
     }
 
+    function showError(message) {
+      errorMessage.textContent = message;
+      errorMessage.style.display = "block";
+      noticeMessage.textContent = "";
+      noticeMessage.style.display = "none";
+    }
+
+    function showNotice(message) {
+      noticeMessage.textContent = message;
+      noticeMessage.style.display = "block";
+      errorMessage.textContent = "";
+      errorMessage.style.display = "none";
+    }
+
+    function clearMessages() {
+      errorMessage.textContent = "";
+      errorMessage.style.display = "none";
+      noticeMessage.textContent = "";
+      noticeMessage.style.display = "none";
+    }
+
+    function createCell(value) {
+      const cell = document.createElement("td");
+      cell.textContent = value;
+      return cell;
+    }
+
+    function renderRecords() {
+      recordsBody.replaceChildren();
+
+      if (records.length === 0) {
+        const row = document.createElement("tr");
+        row.className = "empty-row";
+
+        const cell = document.createElement("td");
+        cell.colSpan = 5;
+        cell.textContent = "まだ記録はありません。";
+
+        row.appendChild(cell);
+        recordsBody.appendChild(row);
+      } else {
+        records.forEach(function (record) {
+          const row = document.createElement("tr");
+
+          row.appendChild(createCell(record.waitMinutes));
+          row.appendChild(createCell(record.counterparty));
+          row.appendChild(createCell(record.request));
+          row.appendChild(createCell(record.workStatus));
+          row.appendChild(createCell(record.impact));
+
+          recordsBody.appendChild(row);
+        });
+      }
+
+      recordCount.textContent = "記録件数:" + records.length + "件";
+      downloadButton.disabled = records.length === 0;
+      clearRecordsButton.disabled = records.length === 0;
+    }
+
     function escapeCsvCell(value) {
       let safeValue = String(value);
 
-      // Excelで開いた際に、数式として解釈される可能性のある文字を無効化する
       if (/^[\s]*[=+\-@]/.test(safeValue)) {
         safeValue = "'" + safeValue;
       }
@@ -344,7 +491,7 @@
       return '"' + safeValue.replace(/"/g, '""') + '"';
     }
 
-    function createCsv(data) {
+    function createCsv() {
       const headers = [
         "待ち時間(分)",
         "相手の区分",
@@ -353,23 +500,31 @@
         "影響"
       ];
 
-      const values = [
-        data.waitMinutes,
-        data.counterparty,
-        data.request,
-        data.workStatus,
-        data.impact
-      ];
-
-      return [
-        headers.map(escapeCsvCell).join(","),
-        values.map(escapeCsvCell).join(",")
-      ].join("\r\n");
-    }
-
-    function downloadCsv(csvText) {
-      const bom = "\uFEFF";
-      const blob = new Blob([bom, csvText], {
+      const lines = [headers.map(escapeCsvCell).join(",")];
+
+      records.forEach(function (record) {
+        const values = [
+          record.waitMinutes,
+          record.counterparty,
+          record.request,
+          record.workStatus,
+          record.impact
+        ];
+
+        lines.push(values.map(escapeCsvCell).join(","));
+      });
+
+      return lines.join("\r\n");
+    }
+
+    function downloadCsv() {
+      if (records.length === 0) {
+        showError("CSVに出力する記録がありません。");
+        return;
+      }
+
+      const csvText = "\uFEFF" + createCsv();
+      const blob = new Blob([csvText], {
         type: "text/csv;charset=utf-8"
       });
       const downloadUrl = URL.createObjectURL(blob);
@@ -384,18 +539,26 @@
       window.setTimeout(function () {
         URL.revokeObjectURL(downloadUrl);
       }, 1000);
-    }
-
-    function showError(message) {
-      errorMessage.textContent = message;
-      errorMessage.style.display = "block";
-      resultMessage.style.display = "none";
-    }
-
-    function clearMessages() {
-      errorMessage.textContent = "";
-      errorMessage.style.display = "none";
-      resultMessage.style.display = "none";
+
+      showNotice(records.length + "件の記録をCSVでダウンロードしました。");
+    }
+
+    function clearRecords() {
+      if (records.length === 0) {
+        return;
+      }
+
+      const confirmed = window.confirm(
+        "記録一覧をすべて消去します。よろしいですか?"
+      );
+
+      if (!confirmed) {
+        return;
+      }
+
+      records.length = 0;
+      renderRecords();
+      clearMessages();
     }
 
     form.addEventListener("submit", function (event) {
@@ -410,14 +573,22 @@
         return;
       }
 
-      const csvText = createCsv(data);
-      downloadCsv(csvText);
-      resultMessage.style.display = "block";
+      records.push(data);
+      renderRecords();
+
+      form.reset();
+      document.getElementById("waitMinutes").focus();
+      showNotice("記録を追加しました。続けて入力するか、CSVをダウンロードしてください。");
     });
 
     form.addEventListener("reset", function () {
       window.setTimeout(clearMessages, 0);
     });
+
+    downloadButton.addEventListener("click", downloadCsv);
+    clearRecordsButton.addEventListener("click", clearRecords);
+
+    renderRecords();
   </script>
 </body>
 </html>