From 0495cf252c09dcec0f2bf483af2b4d714ab49f63 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 28 Jul 2025 22:33:04 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Implement=20shared=20utility=20func?= =?UTF-8?q?tions=20across=20all=20agents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added copyResults(), downloadResults(), resetForm() to WorkflowsCore class - Removed duplicate functions from data-analyzer template - All agents now automatically get consistent copy/download/reset functionality - Social ads generator and other agents now have these features without code duplication - Enhanced error handling and toast notifications - Maintains backward compatibility with global convenience functions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- static/js/workflows-core.js | 81 ++ .../templates/workflows/data-analyzer.html | 1031 +++++++++++++++++ 2 files changed, 1112 insertions(+) create mode 100644 workflows/templates/workflows/data-analyzer.html diff --git a/static/js/workflows-core.js b/static/js/workflows-core.js index 410b427..bb0af11 100644 --- a/static/js/workflows-core.js +++ b/static/js/workflows-core.js @@ -349,6 +349,74 @@ class WorkflowsCore { this.hideProcessing(); } + /** + * Copy agent results to clipboard (common agent function) + */ + static copyResults() { + const content = document.getElementById('resultsContent') || document.querySelector('.results-content'); + if (content) { + const text = content.textContent || content.innerText || ''; + this.copyToClipboard(text, 'Results copied to clipboard!'); + } else { + this.showToast('❌ No results to copy', 'error'); + } + } + + /** + * Download agent results as file (common agent function) + */ + static downloadResults(filename = 'analysis-results.txt') { + const content = document.getElementById('resultsContent') || document.querySelector('.results-content'); + if (content) { + const text = content.textContent || content.innerText || ''; + this.downloadAsFile(text, filename, 'Results downloaded!'); + } else { + this.showToast('❌ No results to download', 'error'); + } + } + + /** + * Reset agent form and hide results (common agent function) + */ + static resetForm() { + const form = document.getElementById('agentForm'); + if (form) { + form.reset(); + } + + const resultsContainer = document.getElementById('resultsContainer'); + const processingStatus = document.getElementById('processingStatus'); + + if (resultsContainer) resultsContainer.style.display = 'none'; + if (processingStatus) processingStatus.style.display = 'none'; + + // Reset file upload areas + const uploadAreas = document.querySelectorAll('.file-upload-area'); + uploadAreas.forEach(area => { + area.classList.remove('file-selected'); + const uploadText = area.querySelector('.upload-text'); + if (uploadText) { + uploadText.innerHTML = ` +
📁
+
Click to upload or drag and drop
+
PDF files only
+ `; + } + }); + + // Reset radio selections to first option + const radioCards = document.querySelectorAll('.radio-card'); + radioCards.forEach(card => card.classList.remove('selected')); + const firstCard = document.querySelector('.radio-card'); + if (firstCard) { + firstCard.classList.add('selected'); + const input = firstCard.querySelector('input[type="radio"]'); + if (input) input.checked = true; + } + + this.showToast('🔄 Form reset', 'info'); + } + /** * Setup drag and drop for file inputs (enhanced from prototype) */ @@ -461,6 +529,19 @@ function downloadAsFile(content, filename, successMessage) { WorkflowsCore.downloadAsFile(content, filename, successMessage); } +// Global convenience functions for common agent actions +function copyResults() { + WorkflowsCore.copyResults(); +} + +function downloadResults(filename) { + WorkflowsCore.downloadResults(filename); +} + +function resetForm() { + WorkflowsCore.resetForm(); +} + // Initialize on DOM load document.addEventListener('DOMContentLoaded', function() { // Initialize form validation for all forms diff --git a/workflows/templates/workflows/data-analyzer.html b/workflows/templates/workflows/data-analyzer.html new file mode 100644 index 0000000..44e8ebd --- /dev/null +++ b/workflows/templates/workflows/data-analyzer.html @@ -0,0 +1,1031 @@ +{% extends 'base.html' %} +{% load static %} + +{# +AGENT TEMPLATE STARTER - Copy this file and customize for new agents + +REPLACE THE FOLLOWING: +1. "Agent Template Starter" -> Your agent name +2. "YOUR_AGENT_SLUG" -> your-agent-slug +3. Form fields in the widget-content section +4. How it works steps (optional) +5. Agent-specific JavaScript (optional) + +KEEP THE FOLLOWING: +- All include statements for shared components +- Basic template structure and CSS links +- Processing and results components +#} + +{% block title %}Data Analyzer - Quantum Tasks AI{% endblock %} + +{% block extra_css %} + + +{% endblock %} + +{% block content %} + + +
+ + {% include "workflows/components/agent_header.html" with agent_title=agent_config.name agent_subtitle=agent_config.description %} + + + {% include "workflows/components/quick_agents_panel.html" %} + + +
+ +
+
+

+ {{ agent_config.icon }} + {# CUSTOMIZE: Change "Details" to something specific like "Configuration", "Input", etc. #} + {{ agent_config.name }} Details +

+
+
+
+ {% csrf_token %} + + +
+ +
+
+
📁
+
Click to upload or drag and drop
+
PDF files only
+
+
+ +
Supported format: PDF files only. Max size: 10MB
+
+ + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ {# END CUSTOMIZE SECTION #} + + +
+ {% if user.is_authenticated %} + {% if user.wallet_balance >= agent_config.price %} + + {% else %} +
+ Insufficient balance! You need {{ agent_config.price }} AED. +
+ + 💰 Top Up Wallet + + {% endif %} + {% else %} + + 🔐 Login to Continue + + {% endif %} +
+
+
+
+ + + +
+
+

+ â„šī¸ + How It Works +

+
+
+
    +
  1. Upload your PDF file
  2. +
  3. Choose analysis type and preferences
  4. +
  5. Our AI analyzes your data
  6. +
  7. Get comprehensive insights and reports
  8. +
+ + + +
+
+
+ + + {% include "workflows/components/processing_status.html" with status_title="Analyzing Your Data..." status_text="Please wait while our AI processes your file..." %} + + + {% include "workflows/components/results_container.html" with results_title="Analysis Results" %} +
+{% endblock %} + +{% block extra_js %} + +{# CUSTOMIZE: Add agent-specific JavaScript file if needed #} +{# #} + +{# CUSTOMIZE: Add agent-specific JavaScript inline if needed #} + +{% endblock %} \ No newline at end of file