From 79cee4efe959ab820ded419255c0d0a979a8dbb3 Mon Sep 17 00:00:00 2001
From: ColinJakob <colin.jakob@student.reutlingen-university.de>
Date: Thu, 19 Jun 2025 19:31:33 +0200
Subject: [PATCH] Function for cloning requirements
---
templates/project/_requirements-list.go.html | 55 +++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/templates/project/_requirements-list.go.html b/templates/project/_requirements-list.go.html
index c4c6b1e..d485ca1 100644
--- a/templates/project/_requirements-list.go.html
+++ b/templates/project/_requirements-list.go.html
@@ -78,7 +78,9 @@
<td>
<div class="btn-group btn-group-sm">
<!-- Clone requirement button -->
- <button class="btn btn-outline-secondary" title="Klonen">
+ <button onclick="cloneRequirement('{{ .ID.Hex }}', '{{ .RequirementID }}')"
+ class="btn btn-outline-secondary"
+ title="Klonen">
📋
</button>
<!-- Delete requirement button -->
@@ -94,4 +96,55 @@
</div>
{{ end }}
</div>
+
+<script>
+function cloneRequirement(reqId, reqName) {
+ // Get list of available projects from the current page context
+ const projects = [
+ {{ range $.Data.Project.Project.CreatedBy }}
+ // This won't work, we need to get projects differently
+ {{ end }}
+ ];
+
+ // Simple prompt-based solution for now
+ const targetProjectId = prompt(`Anforderung "${reqName}" klonen.\n\nGeben Sie die Projekt-ID des Zielprojekts ein:`);
+ if (!targetProjectId) return;
+
+ const newName = prompt(`Neuer Name für die geklonte Anforderung:`, `${reqName}-kopie`);
+ if (!newName) return;
+
+ // Debug: Log the request details
+ console.log('Making clone request:', {
+ url: `/requirement/${reqId}/clone`,
+ targetProjectId: targetProjectId,
+ newName: newName
+ });
+
+ // Make the clone request
+ fetch(`/requirement/${reqId}/clone`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ },
+ body: `ProjectID=${encodeURIComponent(targetProjectId)}&Name=${encodeURIComponent(newName)}`
+ })
+ .then(response => {
+ console.log('Response status:', response.status);
+ console.log('Response headers:', response.headers);
+ return response.text().then(text => {
+ console.log('Response body:', text);
+ if (response.ok) {
+ alert(`Anforderung erfolgreich nach Projekt "${targetProjectId}" geklont!`);
+ location.reload(); // Refresh to show changes
+ } else {
+ alert(`Fehler beim Klonen der Anforderung: ${response.status} - ${text}`);
+ }
+ });
+ })
+ .catch(error => {
+ console.error('Error:', error);
+ alert('Fehler beim Klonen der Anforderung: ' + error.message);
+ });
+}
+</script>
{{ end }}
\ No newline at end of file
--
GitLab