delete button and function implemented, help page

This commit is contained in:
santa
2026-01-10 14:22:27 +01:00
parent ed5a86dce0
commit 12f99e9f2b
4 changed files with 120 additions and 71 deletions
+89 -51
View File
@@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="de"> <html lang="de">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -21,7 +22,7 @@
padding: 30px; padding: 30px;
margin-top: 50px; margin-top: 50px;
border-radius: 12px; border-radius: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.1); box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
width: 90%; width: 90%;
max-width: 600px; max-width: 600px;
} }
@@ -38,7 +39,9 @@
color: #555; color: #555;
} }
input[type="text"], textarea, select { input[type="text"],
textarea,
select {
width: 100%; width: 100%;
padding: 10px; padding: 10px;
margin-top: 5px; margin-top: 5px;
@@ -59,7 +62,7 @@
} }
.hidden { .hidden {
visibility: hidden; visibility: hidden;
} }
button { button {
@@ -81,6 +84,7 @@
.buttons { .buttons {
flex-direction: column; flex-direction: column;
} }
.buttons button { .buttons button {
width: 100%; width: 100%;
margin-top: 10px; margin-top: 10px;
@@ -94,6 +98,7 @@
} }
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h1>Manage document types</h1> <h1>Manage document types</h1>
@@ -105,8 +110,8 @@
</select> </select>
<div id="docNameWrapper"> <div id="docNameWrapper">
<label for="docName">Dokumentname:</label> <label for="docName">Dokumentname:</label>
<input type="text" id="docName" placeholder="Gib hier den Dokumentnamen ein"> <input type="text" id="docName" placeholder="Gib hier den Dokumentnamen ein">
</div> </div>
<label for="prompt">Dein Prompt:</label> <label for="prompt">Dein Prompt:</label>
@@ -116,6 +121,7 @@
<a href="index.html"> <a href="index.html">
<button id="goBackBtn">Abbrechen</button> <button id="goBackBtn">Abbrechen</button>
</a> </a>
<button id="deleteBtn">Dokument löschen</button>
<button id="generateBtn">Dokument speichern</button> <button id="generateBtn">Dokument speichern</button>
</div> </div>
@@ -126,85 +132,117 @@
<script> <script>
const goBackBtn = document.getElementById("goBackBtn"); const goBackBtn = document.getElementById("goBackBtn");
const generateBtn = document.getElementById("generateBtn"); const generateBtn = document.getElementById("generateBtn");
const deleteBtn = document.getElementById("deleteBtn");
const existingDocs = document.getElementById("existingDocs"); const existingDocs = document.getElementById("existingDocs");
const docNameInput = document.getElementById("docName"); const docNameInput = document.getElementById("docName");
const promptInput = document.getElementById("prompt"); const promptInput = document.getElementById("prompt");
const resultDiv = document.getElementById("result"); const resultDiv = document.getElementById("result");
const exampleText = ""; const exampleText = "";
// Zurück zur Haupt-GUI
goBackBtn.addEventListener("click", () => {
window.electronAPI.goBackToMain();
});
// dokumente speichern // dokumente speichern
generateBtn.addEventListener("click", () => { generateBtn.addEventListener("click", () => {
const name = docNameInput.value.trim(); const name = docNameInput.value.trim();
const content = promptInput.value.trim(); const content = promptInput.value.trim();
if (!name || !content) { if (!name || !content) {
resultDiv.textContent = "Bitte Dokumentname und Prompt ausfüllen."; resultDiv.textContent = "Bitte Dokumentname und Prompt ausfüllen.";
setTimeout(() => { setTimeout(() => {
resultDiv.textContent = ""; resultDiv.textContent = "";
}, 3000); }, 3000);
return; return;
} }
window.api.saveTxtFile(name, content).then(); window.api.saveTxtFile(name, content).then();
resultDiv.textContent = "Dokument erfolgreich gespeichert!"; resultDiv.textContent = "Dokument erfolgreich gespeichert!";
setTimeout(() => { setTimeout(() => {
resultDiv.textContent = ""; resultDiv.textContent = "";
}, 3000); }, 3000);
reloadDocuments(); reloadDocuments();
}); });
// dokumente löschen
deleteBtn.addEventListener("click", () => {
const name = docNameInput.value.trim();
if (!name) {
resultDiv.textContent = "Bitte Dokumentname angeben.";
setTimeout(() => {
resultDiv.textContent = "";
}, 3000);
return;
}
const confirmDelete = confirm(
`Möchtest du das Dokument "${name}" wirklich löschen?`
);
if (!confirmDelete) return;
window.api.deleteTxtFile(name).then((success) => {
if (success) {
resultDiv.textContent = "Dokument erfolgreich gelöscht!";
reloadDocuments();
existingDocs.value = "newDoc";
existingDocs.dispatchEvent(new Event("change"));
} else {
resultDiv.textContent = "Dokument konnte nicht gelöscht werden.";
}
setTimeout(() => {
resultDiv.textContent = "";
}, 3000);
});
});
//function to load existingDoc options to the drop down list //function to load existingDoc options to the drop down list
const select = document.getElementById('existingDocs'); const select = document.getElementById('existingDocs');
window.api.getTxtFiles().then(files => { window.api.getTxtFiles().then(files => {
reloadDocuments(); reloadDocuments();
}); });
//content anzeigen //content anzeigen
const docNameWrapper = document.getElementById("docNameWrapper"); const docNameWrapper = document.getElementById("docNameWrapper");
existingDocs.addEventListener("change", async () => { existingDocs.addEventListener("change", async () => {
const selected = existingDocs.value; const selected = existingDocs.value;
if (selected === "newDoc") { if (selected === "newDoc") {
docNameWrapper.classList.remove("hidden"); docNameWrapper.classList.remove("hidden");
docNameInput.value = ""; docNameInput.value = "";
promptInput.value = exampleText; promptInput.value = exampleText;
return; return;
} }
docNameWrapper.classList.add("hidden"); docNameWrapper.classList.add("hidden");
const content = await window.api.readTxtFile(selected); const content = await window.api.readTxtFile(selected);
promptInput.value = content; promptInput.value = content;
docNameInput.value = selected.replace(".txt", ""); docNameInput.value = selected.replace(".txt", "");
}); });
//reload drop down //reload drop down
function reloadDocuments() { function reloadDocuments() {
[...existingDocs.querySelectorAll('option:not([value="newDoc"])')] [...existingDocs.querySelectorAll('option:not([value="newDoc"])')]
.forEach(o => o.remove()); .forEach(o => o.remove());
window.api.getTxtFiles().then(files => { window.api.getTxtFiles().then(files => {
files.forEach(file => { files.forEach(file => {
const option = document.createElement('option'); const option = document.createElement('option');
option.value = file; option.value = file;
option.textContent = file option.textContent = file
.replace('.txt', '') // Endung entfernen .replace('.txt', '') // Endung entfernen
.replace(/_/g, ' ') // Leerzeichen ersetzen .replace(/_/g, ' ') // Leerzeichen ersetzen
.replace(/\b\w/g, c => c.toUpperCase()) // ersten Buchstaben groß .replace(/\b\w/g, c => c.toUpperCase()) // ersten Buchstaben groß
existingDocs.appendChild(option); existingDocs.appendChild(option);
//customDocumentTypes.appendChild(option);
});
}); });
});
} }
</script> </script>
<script src="./renderer.js"></script> <script src="./renderer.js"></script>
</body> </body>
</html> </html>
+2 -3
View File
@@ -20,7 +20,7 @@
<nav class="menu1"> <nav class="menu1">
<a href="custom_document.html" class="li1">Manage document types</a> <a href="custom_document.html" class="li1">Manage document types</a>
<a href="" class="li1">Help</a> <a href="help_page.html" class="li1">Help</a>
</nav> </nav>
</nav> </nav>
</section> </section>
@@ -105,8 +105,7 @@
</div> </div>
<div class="checkbox-container"> <div class="checkbox-container">
<input type="checkbox" name="docFormat" id="docFormatCustom" value="custom"> <input type="checkbox" name="docFormat" id="docFormatCustom" value="custom">
<select name="ai_type" id="ai_type"> <select name="customDocumentTypes" id="customDocumentTypes">
<option>nichts</option>
</select> </select>
</div> </div>
</div> </div>
+12 -13
View File
@@ -5,10 +5,10 @@ try {
onFileDrop: (file) => webUtils.getPathForFile(file) onFileDrop: (file) => webUtils.getPathForFile(file)
}) })
contextBridge.exposeInMainWorld("submit", { contextBridge.exposeInMainWorld("submit", {
submit: (meeting_specifications) => {ipcRenderer.send("file_submit", meeting_specifications)} submit: (meeting_specifications) => { ipcRenderer.send("file_submit", meeting_specifications) }
}) })
contextBridge.exposeInMainWorld("electronAPI", { contextBridge.exposeInMainWorld("electronAPI", {
getFilePath: (file) => {return webUtils.getPathForFile(file)} getFilePath: (file) => { return webUtils.getPathForFile(file) }
}) })
contextBridge.exposeInMainWorld("onStartup", { contextBridge.exposeInMainWorld("onStartup", {
@@ -23,27 +23,26 @@ try {
speakerAudios: (callback) => ipcRenderer.on('speakerAudios', callback) speakerAudios: (callback) => ipcRenderer.on('speakerAudios', callback)
}) })
contextBridge.exposeInMainWorld("submitSpeaker", { contextBridge.exposeInMainWorld("submitSpeaker", {
speaker_submit: (speaker_names) => {ipcRenderer.send("speaker_submit", speaker_names)} speaker_submit: (speaker_names) => { ipcRenderer.send("speaker_submit", speaker_names) }
}) })
contextBridge.exposeInMainWorld("download", { contextBridge.exposeInMainWorld("download", {
file_download: () => {ipcRenderer.send("file_download")} file_download: () => { ipcRenderer.send("file_download") }
}) })
//documenttypes //documenttypes
contextBridge.exposeInMainWorld('api', { contextBridge.exposeInMainWorld('api', {
getTxtFiles: () => ipcRenderer.invoke('get-txt-files'), getTxtFiles: () => ipcRenderer.invoke('get-txt-files'),
saveTxtFile: (name, content) => saveTxtFile: (name, content) =>
ipcRenderer.invoke('save-txt-file', name, content), ipcRenderer.invoke('save-txt-file', name, content),
readTxtFile: (fileName) => readTxtFile: (fileName) =>
ipcRenderer.invoke('read-txt-file', fileName) ipcRenderer.invoke('read-txt-file', fileName),
deleteTxtFile: (fileName) =>
ipcRenderer.invoke('delete-txt-file', fileName)
}); });
ipcRenderer.on("error", (event, err) => {alert(err)}) ipcRenderer.on("error", (event, err) => { alert(err) })
} catch (error) { } catch (error) {
console.log("Error in preload.js"); console.log("Error in preload.js");
} }
+14 -1
View File
@@ -281,8 +281,21 @@ electron.ipcMain.handle('save-txt-file', (event, fileName, content) => {
return true; return true;
}); });
// //read file content
electron.ipcMain.handle('read-txt-file', (event, fileName) => { electron.ipcMain.handle('read-txt-file', (event, fileName) => {
const filePath = `${mainDir}/storage/documentType/${fileName}`; const filePath = `${mainDir}/storage/documentType/${fileName}`;
return fs.readFileSync(filePath, 'utf8'); return fs.readFileSync(filePath, 'utf8');
}); });
//delete documentfiles
electron.ipcMain.handle('delete-txt-file', (event, fileName) => {
const filePath = `${mainDir}/storage/documentType/${fileName}.txt`;
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
return true;
} else {
return false;
}
});