buletomato25 commited on
Commit
527491b
·
2 Parent(s): ad89020 02a600b

Merge branch 'name_reset'

Browse files
Files changed (3) hide show
  1. app.py +32 -16
  2. static/reset.js +82 -8
  3. templates/reset.html +9 -13
app.py CHANGED
@@ -55,25 +55,41 @@ def reset_html():
55
  #メンバー削除&累積音声削除
56
  @app.route('/reset_member', methods=['GET', 'POST'])
57
  def reset_member():
58
- global users # ←これを追加!
59
- #data = request.get_json()
60
- #name = data['name'] # 名前を取得
61
  global total_audio
62
  print(total_audio)
63
  process.delete_files_in_directory(total_audio)
64
- base_audio_dir = "/tmp/data/base_audio"
65
- for name in users:
66
- file_path = os.path.join(base_audio_dir, f"{name}.wav")
67
- if os.path.exists(file_path):
68
- try:
69
- os.remove(file_path)
70
- print(f"{file_path} を削除しました。")
71
- except Exception as e:
72
- print(f"削除中にエラーが発生しました: {e}")
73
- else:
74
- print(f"ファイルが存在しません: {file_path}")
75
- users.clear()
76
- return render_template('index.html', users = users)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
  # 書き起こし作成エンドポイント
79
  @app.route('/transcription',methods =['GET','POST'])
 
55
  #メンバー削除&累積音声削除
56
  @app.route('/reset_member', methods=['GET', 'POST'])
57
  def reset_member():
58
+ global users
 
 
59
  global total_audio
60
  print(total_audio)
61
  process.delete_files_in_directory(total_audio)
62
+ try:
63
+ data = request.get_json()
64
+ if not data or "names" not in data:
65
+ return jsonify({"status": "error", "message": "Invalid request body"}), 400 # 400 Bad Request
66
+
67
+ names = data.get("names", [])
68
+ base_audio_dir = "/tmp/data/base_audio"
69
+
70
+ for name in names:
71
+ file_path = os.path.join(base_audio_dir, f"{name}.wav")
72
+ if os.path.exists(file_path):
73
+ try:
74
+ os.remove(file_path)
75
+ print(f"{file_path} を削除しました。")
76
+ except Exception as e:
77
+ print(f"削除中にエラーが発生しました: {e}")
78
+ # ファイル削除に失敗した場合も、エラーを返す
79
+ return jsonify({"status": "error", "message": f"Failed to delete {name}: {e}"}), 500
80
+
81
+ else:
82
+ print(f"ファイルが存在しません: {file_path}")
83
+
84
+ # usersリストを更新
85
+ users = [u for u in users if u not in names]
86
+
87
+ # 成功した場合のレスポンス
88
+ return jsonify({"status": "success", "message": "Members deleted successfully", "users": users}), 200 # 200 OK
89
+
90
+ except Exception as e:
91
+ print(f"An unexpected error occurred: {e}")
92
+ return jsonify({"status": "error", "message": f"Internal server error: {e}"}), 500 # 500 Internal Server Error
93
 
94
  # 書き起こし作成エンドポイント
95
  @app.route('/transcription',methods =['GET','POST'])
static/reset.js CHANGED
@@ -1,23 +1,97 @@
1
- // サーバーからメンバー情報を取得してチャートを更新する関数
2
- async function updateChartFrom() {
3
  try {
4
  const response = await fetch("/confirm");
5
  if (!response.ok) {
6
  throw new Error(`HTTP error! status: ${response.status}`);
7
  }
 
8
  const data = await response.json();
9
  if (!data || !data.members || !Array.isArray(data.members)) {
10
  console.error("Invalid member data received:", data);
11
- members = ["member1"];
12
  return;
13
  }
14
- members = data.members;
15
- } catch (error) {}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  }
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  function showRecorder() {
19
  window.location.href = "/index";
20
  }
21
- function showReset() {
22
- window.location.href = "/reset_member";
23
- }
 
1
+ async function fetchAndRenderMembers() {
 
2
  try {
3
  const response = await fetch("/confirm");
4
  if (!response.ok) {
5
  throw new Error(`HTTP error! status: ${response.status}`);
6
  }
7
+
8
  const data = await response.json();
9
  if (!data || !data.members || !Array.isArray(data.members)) {
10
  console.error("Invalid member data received:", data);
 
11
  return;
12
  }
13
+
14
+ const members = data.members;
15
+ console.log(members);
16
+ const container = document.getElementById("memberCheckboxes");
17
+ container.innerHTML = ""; // 既存の中身を消去
18
+
19
+ members.forEach((name) => {
20
+ const newItem = document.createElement("div");
21
+ newItem.className = "flex items-center gap-3 mb-2";
22
+ console.log(name);
23
+ newItem.innerHTML = `
24
+ <input
25
+ type="checkbox"
26
+ name="members"
27
+ value="${name}"
28
+ id="checkbox-${name}"
29
+ class="px-4 py-2 border rounded focus:outline-none focus:ring-2 focus:ring-blue-500 bg-gray-700 text-white"
30
+ />
31
+ <lavel for="checkbox-${name}" class="text-white text-lg">${name}</label>
32
+ `;
33
+
34
+ container.appendChild(newItem);
35
+ });
36
+ } catch (error) {
37
+ console.error("Error fetching members:", error);
38
+ }
39
  }
40
 
41
+ // メンバー削除ボタンのイベントリスナー(修正箇所)
42
+ document.getElementById("reset_btn").addEventListener("click", () => {
43
+ // メンバー送信処理
44
+
45
+ const checkboxes = document.querySelectorAll(
46
+ '#memberCheckboxes input[type="checkbox"]:checked'
47
+ );
48
+
49
+ const selectedNames = Array.from(checkboxes).map((cb) => cb.value);
50
+
51
+ if (selectedNames.length === 0) {
52
+ alert("メンバーを1人以上選択してください。");
53
+ return;
54
+ }
55
+
56
+ fetch("/reset_member", {
57
+ method: "POST",
58
+ headers: {
59
+ "Content-Type": "application/json",
60
+ },
61
+ body: JSON.stringify({ names: selectedNames }),
62
+ })
63
+ .then((response) => {
64
+ if (!response.ok) {
65
+ throw new Error("送信に失敗しました");
66
+ }
67
+ // サーバーからのJSONレスポンスを期待する
68
+ return response.json();
69
+ })
70
+ .then((data) => {
71
+ alert("選択されたメンバーを削除しました。");
72
+ fetchAndRenderMembers(); // 再描画
73
+ })
74
+ .catch((error) => {
75
+ console.error("送信エラー:", error);
76
+ // エラーメッセージを表示する
77
+ alert(`送信エラー: ${error.message}`);
78
+ });
79
+ });
80
+
81
+ // ページが表示されたときにチェックボックスを生成
82
+ window.addEventListener("DOMContentLoaded", fetchAndRenderMembers);
83
+
84
+ // 「全選択」ボタン処理
85
+ document.getElementById("select-all").addEventListener("click", () => {
86
+ const checkboxes = document.querySelectorAll(
87
+ '#memberCheckboxes input[type="checkbox"]'
88
+ );
89
+ checkboxes.forEach((checkbox) => {
90
+ checkbox.checked = true;
91
+ });
92
+ });
93
+
94
+ // 他のページに移動する関数
95
  function showRecorder() {
96
  window.location.href = "/index";
97
  }
 
 
 
templates/reset.html CHANGED
@@ -13,14 +13,19 @@
13
  class="container mx-auto p-6 bg-white dark:bg-gray-800 shadow-lg rounded-2xl"
14
  >
15
  <h2 class="text-2xl font-semibold mb-4">メンバーを消去しますか?</h2>
 
 
 
 
16
 
17
  <div class="flex justify-center gap-4">
18
  <button
19
- class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
20
- onclick="showReset()"
21
  >
22
- メンバーを消去
23
  </button>
 
24
  <button
25
  class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
26
  onclick="showRecorder()"
@@ -29,15 +34,6 @@
29
  </button>
30
  </div>
31
  </div>
32
- <script>
33
- function showRecorder() {
34
- window.location.href = "/index";
35
- }
36
- function showReset() {
37
- window.location.href = "/reset_member";
38
- }
39
- </script>
40
- <!--<script src="{{ url_for('static', filename='reset.js') }}"></script>
41
- -->
42
  </body>
43
  </html>
 
13
  class="container mx-auto p-6 bg-white dark:bg-gray-800 shadow-lg rounded-2xl"
14
  >
15
  <h2 class="text-2xl font-semibold mb-4">メンバーを消去しますか?</h2>
16
+ <input type="button" id="select-all" value="全選択" />
17
+ <div id="memberCheckboxes">
18
+ <!--ここにチャックボックスを表示してほしい-->
19
+ </div>
20
 
21
  <div class="flex justify-center gap-4">
22
  <button
23
+ id="reset_btn"
24
+ class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded"
25
  >
26
+ メンバー削除
27
  </button>
28
+
29
  <button
30
  class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
31
  onclick="showRecorder()"
 
34
  </button>
35
  </div>
36
  </div>
37
+ <script src="{{ url_for('static', filename='reset.js') }}"></script>
 
 
 
 
 
 
 
 
 
38
  </body>
39
  </html>