From cbd0c5b68a1d9b4fadc80cae287c1ff9469076fc Mon Sep 17 00:00:00 2001 From: solocla Date: Wed, 6 May 2026 16:44:42 +0200 Subject: [PATCH] annotation color and clone templates --- public/userarea/annotationsModal.js | 23 +- public/userarea/clone_template.php | 228 ++++++++++++++++++ public/userarea/modal_annotations.php | 10 + public/userarea/schema_dettagli_response.json | 2 +- public/userarea/templates_dashboard.php | 69 +++++- 5 files changed, 318 insertions(+), 14 deletions(-) create mode 100644 public/userarea/clone_template.php diff --git a/public/userarea/annotationsModal.js b/public/userarea/annotationsModal.js index 8f4a79f..a9443f1 100644 --- a/public/userarea/annotationsModal.js +++ b/public/userarea/annotationsModal.js @@ -22,6 +22,8 @@ $(document).ready(function () { let partsListData = []; // DIMENSIONE GLOBALE MARKER let globalMarkerSize = 16; + // COLORE TESTO LISTA DESCRIZIONI + let globalDescriptionColor = "#000000"; // =================== // MODAL INITIALIZATION @@ -138,6 +140,7 @@ $(document).ready(function () { descriptionTextbox = null; markerObjects = {}; globalMarkerSize = 16; + globalDescriptionColor = "#000000"; $("#photoSelectorContainerAnnotations").empty().hide(); $("#samplePhotoAnnotations").attr("src", ""); $("#partsListAnnotations").empty(); @@ -177,7 +180,25 @@ $(document).ready(function () { updateMarkers(); markUnsaved(); }); + // =================== + // COLORE LISTA DESCRIZIONI + // =================== + $(document) + .off("input.descriptionColor", "#descriptionColorPickerAnnotations") + .on( + "input.descriptionColor", + "#descriptionColorPickerAnnotations", + function () { + globalDescriptionColor = $(this).val(); + if (descriptionTextbox && fabricCanvas) { + descriptionTextbox.set("fill", globalDescriptionColor); + fabricCanvas.renderAll(); + } + + markUnsaved(); + }, + ); // =================== // PHOTO LOADERS // =================== @@ -1130,7 +1151,7 @@ $(document).ready(function () { backgroundColor: "transparent", fontFamily: "Arial", fontSize: Math.max(16, Math.round(globalMarkerSize * 0.8)), - fill: "#000000", + fill: globalDescriptionColor, padding: 10, editable: false, selectable: true, diff --git a/public/userarea/clone_template.php b/public/userarea/clone_template.php new file mode 100644 index 0000000..4f75640 --- /dev/null +++ b/public/userarea/clone_template.php @@ -0,0 +1,228 @@ +getConnection(); + + $pdo->beginTransaction(); + + // 1. Get source template + $stmt = $pdo->prepare(" + SELECT + name, + source_type, + header_row, + start_column, + description, + target_table, + sample_xlsx, + button_size, + button_bg_color, + button_text_color, + button_label, + status, + client_specific_fields, + idclient, + clientname, + schemaname, + idschema, + schemajson, + xls_headers, + api_sample_json, + json_nodes, + idroutine + FROM excel_templates + WHERE id = ? + LIMIT 1 + "); + $stmt->execute([$sourceTemplateId]); + $template = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$template) { + throw new Exception("Template not found."); + } + + // 2. Generate unique clone name + $baseName = 'Copia di ' . $template['name']; + $newName = $baseName; + + $checkStmt = $pdo->prepare("SELECT COUNT(*) FROM excel_templates WHERE name = ?"); + $checkStmt->execute([$newName]); + + if ((int)$checkStmt->fetchColumn() > 0) { + $counter = 2; + + do { + $newName = $baseName . ' (' . $counter . ')'; + $checkStmt->execute([$newName]); + $exists = (int)$checkStmt->fetchColumn() > 0; + $counter++; + } while ($exists); + } + + // 3. Insert cloned template + $insertTemplate = $pdo->prepare(" + INSERT INTO excel_templates ( + name, + source_type, + created_at, + updated_at, + header_row, + start_column, + description, + target_table, + sample_xlsx, + button_size, + button_bg_color, + button_text_color, + button_label, + status, + client_specific_fields, + idclient, + clientname, + schemaname, + idschema, + schemajson, + xls_headers, + api_sample_json, + json_nodes, + idroutine + ) VALUES ( + :name, + :source_type, + NOW(), + NOW(), + :header_row, + :start_column, + :description, + :target_table, + :sample_xlsx, + :button_size, + :button_bg_color, + :button_text_color, + :button_label, + :status, + :client_specific_fields, + :idclient, + :clientname, + :schemaname, + :idschema, + :schemajson, + :xls_headers, + :api_sample_json, + :json_nodes, + :idroutine + ) + "); + + $insertTemplate->execute([ + ':name' => $newName, + ':source_type' => $template['source_type'], + ':header_row' => $template['header_row'], + ':start_column' => $template['start_column'], + ':description' => $template['description'], + ':target_table' => $template['target_table'], + ':sample_xlsx' => $template['sample_xlsx'], + ':button_size' => $template['button_size'], + ':button_bg_color' => $template['button_bg_color'], + ':button_text_color' => $template['button_text_color'], + ':button_label' => $template['button_label'], + ':status' => $template['status'], + ':client_specific_fields' => $template['client_specific_fields'], + ':idclient' => $template['idclient'], + ':clientname' => $template['clientname'], + ':schemaname' => $template['schemaname'], + ':idschema' => $template['idschema'], + ':schemajson' => $template['schemajson'], + ':xls_headers' => $template['xls_headers'], + ':api_sample_json' => $template['api_sample_json'], + ':json_nodes' => $template['json_nodes'], + ':idroutine' => $template['idroutine'] + ]); + + $newTemplateId = (int)$pdo->lastInsertId(); + + if ($newTemplateId <= 0) { + throw new Exception("Unable to create cloned template."); + } + + // 4. Clone template_mapping rows + $cloneMappings = $pdo->prepare(" + INSERT INTO template_mapping ( + template_id, + schema_id, + field_id, + excel_column, + json_node, + is_manual, + manual_default, + auto_value, + data_type, + is_required, + default_value, + has_list, + length, + decimals, + min_value, + max_value, + default_curr_date, + tablename, + field_label, + main_field, + is_visible_import, + is_visible_parts + ) + SELECT + :new_template_id, + schema_id, + field_id, + excel_column, + json_node, + is_manual, + manual_default, + auto_value, + data_type, + is_required, + default_value, + has_list, + length, + decimals, + min_value, + max_value, + default_curr_date, + tablename, + field_label, + main_field, + is_visible_import, + is_visible_parts + FROM template_mapping + WHERE template_id = :source_template_id + "); + + $cloneMappings->execute([ + ':new_template_id' => $newTemplateId, + ':source_template_id' => $sourceTemplateId + ]); + + $pdo->commit(); + + header("Location: templates_dashboard.php?cloned=1&new_id=" . $newTemplateId); + exit; +} catch (Exception $e) { + if (isset($pdo) && $pdo->inTransaction()) { + $pdo->rollBack(); + } + + die("Clone error: " . htmlspecialchars($e->getMessage(), ENT_QUOTES, 'UTF-8')); +} diff --git a/public/userarea/modal_annotations.php b/public/userarea/modal_annotations.php index 35f5135..47fb077 100644 --- a/public/userarea/modal_annotations.php +++ b/public/userarea/modal_annotations.php @@ -46,6 +46,16 @@