quantum-ai-v3/weather_reporter/templates/detail.html
Claude 1aac14f44b Implement individual agent architecture with simplified template structure
- Replace legacy agents system with modular individual agent apps
- Add agent_base framework for BaseAgent, processors, and management commands
- Create weather_reporter as example individual agent with API integration
- Implement simplified template structure: agent_name/templates/detail.html
- Fix marketplace to display actual agents instead of placeholder
- Add proper authentication flow with login redirect for agent access
- Organize project structure: move tests to tests/, docs to docs/
- Update all documentation to reflect new simplified architecture
- Fix URL namespace issues throughout templates and views

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-10 09:01:11 +05:30

933 lines
40 KiB
HTML

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Reporter Agent - NetCop AI Hub</title>
<style>
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
font-family: system-ui, -apple-system, sans-serif;
overflow-x: hidden;
}
/* Responsive utilities */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 clamp(16px, 4vw, 24px);
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(350px, 100%), 1fr));
gap: clamp(16px, 4vw, 24px);
align-items: start;
}
.card {
background: rgba(255, 255, 255, 0.9);
border-radius: clamp(12px, 3vw, 16px);
padding: clamp(16px, 4vw, 24px);
border: 1px solid rgba(255, 255, 255, 0.3);
backdrop-filter: blur(20px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
margin-bottom: clamp(16px, 4vw, 24px);
}
.form-group {
margin-bottom: clamp(12px, 3vw, 16px);
}
.form-group label {
display: block;
font-weight: 600;
color: #1f2937;
margin-bottom: clamp(6px, 2vw, 8px);
font-size: clamp(14px, 3.5vw, 16px);
}
.form-control {
width: 100%;
padding: clamp(12px, 3vw, 16px) clamp(16px, 4vw, 20px);
border: 2px solid #e5e7eb;
border-radius: clamp(8px, 2vw, 12px);
font-size: clamp(14px, 3.5vw, 16px);
transition: border-color 0.2s ease;
min-height: 48px;
}
.form-control:focus {
outline: none;
border-color: #3b82f6;
}
.btn {
padding: clamp(12px, 3vw, 16px) clamp(20px, 5vw, 32px);
border: none;
border-radius: clamp(8px, 2vw, 12px);
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
font-size: clamp(14px, 3.5vw, 16px);
min-height: 48px;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.btn-primary {
background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}
.btn-primary:disabled {
background: #9ca3af;
cursor: not-allowed;
transform: none;
}
.radio-group {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
gap: clamp(8px, 2vw, 12px);
}
.radio-option {
display: flex;
align-items: center;
gap: clamp(8px, 2vw, 12px);
padding: clamp(12px, 3vw, 16px);
border: 2px solid #e5e7eb;
border-radius: clamp(8px, 2vw, 12px);
cursor: pointer;
background: white;
transition: all 0.2s ease;
min-height: 44px;
}
.radio-option:hover {
border-color: #3b82f6;
}
.radio-option.selected {
border-color: #3b82f6;
background: #eff6ff;
}
.radio-option input[type="radio"] {
margin: 0;
}
.processing-status {
padding: clamp(16px, 4vw, 20px);
background: #eff6ff;
border: 1px solid #3b82f6;
border-radius: clamp(8px, 2vw, 12px);
color: #1e40af;
font-weight: 600;
text-align: center;
margin-bottom: clamp(16px, 4vw, 24px);
}
.weather-results {
background: rgba(255, 255, 255, 0.9);
border-radius: 16px;
padding: 24px;
border: 1px solid rgba(255, 255, 255, 0.3);
backdrop-filter: blur(20px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
margin-top: 24px;
}
.weather-header {
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
color: white;
padding: 20px;
border-radius: 12px;
text-align: center;
margin-bottom: 20px;
}
.weather-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 20px;
}
.weather-card {
background: white;
padding: 16px;
border-radius: 8px;
border: 1px solid #e5e7eb;
text-align: center;
}
.forecast-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 12px;
}
.help-text {
font-size: clamp(12px, 3vw, 14px);
color: #6b7280;
margin-top: 8px;
}
.section-title {
font-size: clamp(16px, 4vw, 18px);
font-weight: 600;
color: #1f2937;
margin-bottom: clamp(12px, 3vw, 16px);
}
.error-message {
background: #fef2f2;
border: 1px solid #fca5a5;
color: #dc2626;
padding: 12px;
border-radius: 8px;
margin-bottom: 16px;
}
.success-message {
background: #f0fdf4;
border: 1px solid #86efac;
color: #166534;
padding: 12px;
border-radius: 8px;
margin-bottom: 16px;
}
/* Mobile optimizations */
@media (max-width: 768px) {
.grid {
grid-template-columns: 1fr;
}
.radio-group {
grid-template-columns: 1fr;
}
.weather-grid {
grid-template-columns: 1fr;
}
.forecast-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 480px) {
.forecast-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div style="
min-height: 100vh;
background: linear-gradient(135deg, #f6f8ff 0%, #e8f0fe 50%, #f0f7ff 100%);
padding: clamp(20px, 5vw, 40px) 0;
">
<!-- Header -->
<nav style="
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(20px);
padding: 16px 0;
margin-bottom: 24px;
border-bottom: 1px solid rgba(255, 255, 255, 0.2);
">
<div class="container">
<div style="display: flex; align-items: center; justify-content: space-between;">
<div style="display: flex; align-items: center; gap: 16px;">
<a href="{% url 'core:homepage' %}" style="
font-size: 24px;
font-weight: 700;
color: #3b82f6;
text-decoration: none;
">
🚀 NetCop AI Hub
</a>
</div>
<div style="display: flex; align-items: center; gap: 16px;">
<a href="{% url 'core:marketplace' %}" style="color: #374151; text-decoration: none; font-weight: 500;">Marketplace</a>
{% if user.is_authenticated %}
<a href="{% url 'core:wallet' %}" style="color: #374151; text-decoration: none; font-weight: 500;">Wallet</a>
<span style="color: #6b7280;">{{ user.wallet_balance|floatformat:2 }} AED</span>
{% else %}
<a href="{% url 'authentication:login' %}" style="color: #3b82f6; text-decoration: none; font-weight: 600;">Login</a>
{% endif %}
</div>
</div>
</div>
</nav>
<div class="container">
<!-- Page Title -->
<div style="text-align: center; margin-bottom: clamp(24px, 6vw, 40px);">
<h1 style="
font-size: clamp(28px, 7vw, 36px);
font-weight: 700;
color: #1f2937;
margin: 0 0 clamp(12px, 3vw, 16px) 0;
">
🌤️ Weather Reporter Agent
</h1>
<p style="
font-size: clamp(16px, 4vw, 18px);
color: #6b7280;
margin: 0;
max-width: 600px;
margin: 0 auto;
">
Get detailed weather reports for any location worldwide with current conditions, forecasts, and weather alerts.
</p>
<div style="
background: rgba(59, 130, 246, 0.1);
color: #1e40af;
padding: 8px 16px;
border-radius: 20px;
display: inline-block;
margin-top: 12px;
font-size: clamp(14px, 3.5vw, 16px);
font-weight: 600;
">
💰 Cost: {{ agent.price }} AED
</div>
</div>
<!-- Messages -->
{% if messages %}
{% for message in messages %}
<div class="{% if message.tags == 'error' %}error-message{% else %}success-message{% endif %}">
{{ message }}
</div>
{% endfor %}
{% endif %}
<!-- Main Content -->
<div class="grid">
<!-- Weather Form -->
<div>
<form method="POST" id="weatherForm">
{% csrf_token %}
<!-- Location Input -->
<div class="card">
<h3 class="section-title">📍 Enter Location</h3>
<div class="form-group">
<input
type="text"
name="location"
id="location"
class="form-control"
placeholder="Enter city name, address, or coordinates..."
value="{{ form.location.value|default:'' }}"
required
/>
<div class="help-text">
Examples: "New York", "London, UK", "Tokyo, Japan", "37.7749,-122.4194"
</div>
</div>
</div>
<!-- Report Type Selection -->
<div class="card">
<h3 class="section-title">📊 Report Type</h3>
<div class="radio-group">
<label class="radio-option {% if form.report_type.value == 'current' or not form.report_type.value %}selected{% endif %}" onclick="selectReportType('current')">
<input type="radio" name="report_type" value="current" {% if form.report_type.value == 'current' or not form.report_type.value %}checked{% endif %} />
<div style="font-size: clamp(16px, 4vw, 20px);">🌡️</div>
<div>
<div style="font-weight: 600; margin-bottom: clamp(2px, 1vw, 4px); font-size: clamp(14px, 3.5vw, 16px);">
Current Weather
</div>
<div style="font-size: clamp(12px, 3vw, 14px); color: #6b7280;">
Real-time conditions
</div>
</div>
</label>
<label class="radio-option {% if form.report_type.value == 'forecast' %}selected{% endif %}" onclick="selectReportType('forecast')">
<input type="radio" name="report_type" value="forecast" {% if form.report_type.value == 'forecast' %}checked{% endif %} />
<div style="font-size: clamp(16px, 4vw, 20px);">📅</div>
<div>
<div style="font-weight: 600; margin-bottom: clamp(2px, 1vw, 4px); font-size: clamp(14px, 3.5vw, 16px);">
5-Day Forecast
</div>
<div style="font-size: clamp(12px, 3vw, 14px); color: #6b7280;">
Extended weather outlook
</div>
</div>
</label>
<label class="radio-option {% if form.report_type.value == 'detailed' %}selected{% endif %}" onclick="selectReportType('detailed')">
<input type="radio" name="report_type" value="detailed" {% if form.report_type.value == 'detailed' %}checked{% endif %} />
<div style="font-size: clamp(16px, 4vw, 20px);">📋</div>
<div>
<div style="font-weight: 600; margin-bottom: clamp(2px, 1vw, 4px); font-size: clamp(14px, 3.5vw, 16px);">
Detailed Report
</div>
<div style="font-size: clamp(12px, 3vw, 14px); color: #6b7280;">
Current + forecast combined
</div>
</div>
</label>
</div>
</div>
<!-- Processing Status -->
{% if processing %}
<div class="processing-status">
<div style="font-size: clamp(16px, 4vw, 18px); margin-bottom: 8px;">
⏳ Processing...
</div>
<div style="font-size: clamp(14px, 3.5vw, 16px);">
{{ processing_status|default:"Getting weather data..." }}
</div>
</div>
{% endif %}
</form>
</div>
<!-- Sidebar -->
<div>
<!-- Wallet Balance Card -->
<div class="card">
<h3 class="section-title">💳 Your Wallet</h3>
<div style="margin-bottom: clamp(16px, 4vw, 20px);">
<div style="font-size: clamp(24px, 6vw, 28px); font-weight: 700; color: #1f2937;">
{% if user.is_authenticated %}
{{ user.wallet_balance|floatformat:2 }} AED
{% else %}
0.00 AED
{% endif %}
</div>
<div style="font-size: clamp(14px, 3.5vw, 16px); color: #6b7280;">
Available Balance
</div>
</div>
{% if user.is_authenticated %}
{% if user.wallet_balance >= agent.price %}
<button
type="submit"
form="weatherForm"
class="btn btn-primary"
style="width: 100%; margin-bottom: 12px;"
{% if processing %}disabled{% endif %}
>
{% if processing %}
⏳ Processing...
{% else %}
🌤️ Get Weather Report ({{ agent.price }} AED)
{% endif %}
</button>
{% else %}
<div style="
background: #fef2f2;
border: 1px solid #fca5a5;
color: #dc2626;
padding: 12px;
border-radius: 8px;
text-align: center;
font-size: clamp(14px, 3.5vw, 16px);
margin-bottom: 12px;
">
Insufficient balance! You need {{ agent.price }} AED.
</div>
<a href="{% url 'core:wallet_topup' %}" class="btn btn-primary" style="width: 100%; text-decoration: none;">
💰 Top Up Wallet
</a>
{% endif %}
{% else %}
<a href="{% url 'authentication:login' %}" class="btn btn-primary" style="width: 100%; text-decoration: none;">
🔑 Login to Continue
</a>
{% endif %}
</div>
<!-- Usage Info -->
<div style="
padding: 16px;
background: rgba(245, 158, 11, 0.1);
border-radius: 12px;
border: 1px solid rgba(245, 158, 11, 0.2);
">
<h4 style="margin: 0 0 8px 0; font-size: 14px; font-weight: 600; color: #d97706;">
💡 How it works
</h4>
<ul style="margin: 0; font-size: 12px; color: #374151; line-height: 1.4; list-style: none; padding-left: 0;">
<li style="margin: 4px 0; padding-left: 16px; position: relative;">
<span style="position: absolute; left: 0; color: #f59e0b;"></span>
Enter any location worldwide
</li>
<li style="margin: 4px 0; padding-left: 16px; position: relative;">
<span style="position: absolute; left: 0; color: #f59e0b;"></span>
Choose your report type
</li>
<li style="margin: 4px 0; padding-left: 16px; position: relative;">
<span style="position: absolute; left: 0; color: #f59e0b;"></span>
Get real-time weather data
</li>
<li style="margin: 4px 0; padding-left: 16px; position: relative;">
<span style="position: absolute; left: 0; color: #f59e0b;"></span>
Download or copy results
</li>
</ul>
</div>
</div>
</div>
<!-- Weather Results -->
{% if weather_results %}
<div class="weather-results">
<!-- Status Header -->
<div style="display: flex; align-items: center; gap: 12px; margin-bottom: 20px;">
<div style="font-size: 24px;"></div>
<h3 style="font-size: 20px; font-weight: 600; color: #1f2937; margin: 0;">
Weather Report
</h3>
<div style="
background: #10b981;
color: white;
padding: 6px 12px;
border-radius: 6px;
font-size: 14px;
font-weight: 600;
margin-left: auto;
">
✅ Complete
</div>
</div>
<!-- Location Header -->
<div class="weather-header">
<h3 style="font-size: 24px; font-weight: 700; margin: 0 0 8px 0;">
🌍 {{ weather_results.location }}
</h3>
<div style="font-size: 14px; opacity: 0.9;">
Generated at {{ weather_results.generated_at|date:"F j, Y g:i A" }}
</div>
</div>
<!-- Current Weather -->
{% if weather_results.current %}
<div style="
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 12px;
padding: 24px;
margin-bottom: 20px;
">
<h4 style="
font-size: 18px;
font-weight: 600;
color: #1f2937;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
">
🌡️ Current Weather
</h4>
<div class="weather-grid">
<div class="weather-card">
<div style="font-size: 32px; margin-bottom: 8px;">
<img src="https://openweathermap.org/img/w/{{ weather_results.current.icon }}.png" alt="weather" style="width: 50px; height: 50px;" />
</div>
<div style="font-size: 24px; font-weight: 700; color: #1f2937;">
{{ weather_results.current.temperature }}°C
</div>
<div style="font-size: 14px; color: #6b7280; text-transform: capitalize;">
{{ weather_results.current.weather_description }}
</div>
</div>
<div class="weather-card">
<div style="font-size: 14px; color: #6b7280; margin-bottom: 4px;">Feels Like</div>
<div style="font-size: 20px; font-weight: 600;">{{ weather_results.current.feels_like }}°C</div>
</div>
<div class="weather-card">
<div style="font-size: 14px; color: #6b7280; margin-bottom: 4px;">Humidity</div>
<div style="font-size: 20px; font-weight: 600;">{{ weather_results.current.humidity }}%</div>
</div>
<div class="weather-card">
<div style="font-size: 14px; color: #6b7280; margin-bottom: 4px;">Wind Speed</div>
<div style="font-size: 20px; font-weight: 600;">{{ weather_results.current.wind_speed }} km/h</div>
</div>
<div class="weather-card">
<div style="font-size: 14px; color: #6b7280; margin-bottom: 4px;">Pressure</div>
<div style="font-size: 20px; font-weight: 600;">{{ weather_results.current.pressure }} hPa</div>
</div>
<div class="weather-card">
<div style="font-size: 14px; color: #6b7280; margin-bottom: 4px;">Visibility</div>
<div style="font-size: 20px; font-weight: 600;">{{ weather_results.current.visibility }} km</div>
</div>
</div>
</div>
{% endif %}
<!-- 5-Day Forecast -->
{% if weather_results.forecast %}
<div style="
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 12px;
padding: 24px;
margin-bottom: 20px;
">
<h4 style="
font-size: 18px;
font-weight: 600;
color: #1f2937;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
">
📅 5-Day Forecast
</h4>
<div class="forecast-grid">
{% for day in weather_results.forecast|slice:":5" %}
<div class="weather-card">
<div style="font-size: 14px; color: #6b7280; margin-bottom: 8px;">
{{ day.date|date:"D" }}
</div>
<img src="https://openweathermap.org/img/w/{{ day.icon }}.png" alt="weather" style="width: 40px; height: 40px; margin: 0 auto 8px auto;" />
<div style="font-size: 16px; font-weight: 600;">
{{ day.temp }}°C
</div>
<div style="font-size: 12px; color: #6b7280; text-transform: capitalize;">
{{ day.description }}
</div>
</div>
{% endfor %}
</div>
</div>
{% endif %}
<!-- Download/Copy Actions -->
<div style="
margin-top: 20px;
padding-top: 20px;
border-top: 1px solid #e5e7eb;
display: flex;
gap: 12px;
flex-wrap: wrap;
">
<button
onclick="copyWeatherReport()"
class="btn btn-primary"
style="flex: 1; min-width: 120px;"
>
📋 Copy Report
</button>
<button
onclick="downloadWeatherReport()"
class="btn"
style="
flex: 1;
min-width: 120px;
background: white;
color: #374151;
border: 2px solid #e5e7eb;
"
>
💾 Download Report
</button>
</div>
</div>
{% endif %}
</div>
<!-- Footer -->
<footer style="
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(20px);
padding: 24px 0;
margin-top: 48px;
border-top: 1px solid rgba(255, 255, 255, 0.2);
text-align: center;
color: #6b7280;
">
<div class="container">
<p style="margin: 0; font-size: 14px;">
© 2024 NetCop AI Hub. Powered by AI agents.
</p>
</div>
</footer>
</div>
<script>
// Report type selection
function selectReportType(type) {
// Remove selected class from all options
document.querySelectorAll('.radio-option').forEach(option => {
option.classList.remove('selected');
});
// Add selected class to clicked option
event.currentTarget.classList.add('selected');
// Update radio button
document.querySelector(`input[value="${type}"]`).checked = true;
}
// Copy weather report to clipboard
function copyWeatherReport() {
const reportText = generateReportText();
navigator.clipboard.writeText(reportText).then(() => {
showToast('📋 Report copied to clipboard!', 'success');
}).catch(() => {
showToast('Failed to copy report', 'error');
});
}
// Download weather report as text file
function downloadWeatherReport() {
const reportText = generateReportText();
const blob = new Blob([reportText], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `weather-report-${Date.now()}.txt`;
a.click();
URL.revokeObjectURL(url);
showToast('💾 Report downloaded!', 'success');
}
// Generate report text for copy/download
function generateReportText() {
{% if weather_results %}
const location = "{{ weather_results.location|default:'' }}";
const generatedAt = "{{ weather_results.generated_at|date:'F j, Y g:i A' }}";
let report = `Weather Report for ${location}\n`;
report += `Generated: ${generatedAt}\n\n`;
{% if weather_results.current %}
report += `Current Weather:\n`;
report += `Temperature: {{ weather_results.current.temperature }}°C (feels like {{ weather_results.current.feels_like }}°C)\n`;
report += `Condition: {{ weather_results.current.weather_description }}\n`;
report += `Humidity: {{ weather_results.current.humidity }}%\n`;
report += `Wind Speed: {{ weather_results.current.wind_speed }} km/h\n`;
report += `Pressure: {{ weather_results.current.pressure }} hPa\n`;
report += `Visibility: {{ weather_results.current.visibility }} km\n\n`;
{% endif %}
{% if weather_results.forecast %}
report += `5-Day Forecast:\n`;
{% for day in weather_results.forecast|slice:":5" %}
report += `{{ day.date|date:"l" }}: {{ day.temp }}°C - {{ day.description }}\n`;
{% endfor %}
{% endif %}
report += `\nGenerated by NetCop AI Weather Reporter Agent`;
return report;
{% else %}
return 'No weather data available';
{% endif %}
}
// Simple toast notification
function showToast(message, type = 'info') {
const toast = document.createElement('div');
toast.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
border-radius: 8px;
color: white;
font-weight: 600;
z-index: 1000;
${type === 'success' ? 'background: #10b981;' : 'background: #ef4444;'}
`;
toast.textContent = message;
document.body.appendChild(toast);
setTimeout(() => {
toast.remove();
}, 3000);
}
// Handle form submission with AJAX
document.getElementById('weatherForm').addEventListener('submit', function(e) {
e.preventDefault(); // Always prevent default form submission
const location = document.getElementById('location').value.trim();
if (!location) {
showToast('Please enter a location', 'error');
return;
}
// Check user authentication
{% if not user.is_authenticated %}
window.location.href = "{% url 'authentication:login' %}";
return;
{% endif %}
// Check wallet balance
const balance = {{ user.wallet_balance|default:0 }};
if (balance < {{ agent.price }}) {
showToast('Insufficient balance! You need {{ agent.price }} AED.', 'error');
setTimeout(() => {
window.location.href = "{% url 'core:wallet_topup' %}";
}, 2000);
return;
}
// Get form data
const reportType = document.querySelector('input[name="report_type"]:checked').value;
// Show processing status
showProcessingStatus('Sending request to weather service...');
// Disable submit button
const submitBtn = document.querySelector('button[type="submit"]');
if (submitBtn) {
submitBtn.disabled = true;
submitBtn.innerHTML = '⏳ Processing...';
}
// Send AJAX request to process endpoint
fetch('{% url "weather_reporter:process" %}', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': document.querySelector('[name=csrfmiddlewaretoken]').value
},
body: JSON.stringify({
location: location,
report_type: reportType
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast('Weather request submitted successfully!', 'success');
showProcessingStatus('Processing weather data...');
// Poll for results
pollForResults(data.request_id);
} else {
throw new Error(data.error || 'Request failed');
}
})
.catch(error => {
console.error('Error:', error);
showToast('Error: ' + error.message, 'error');
hideProcessingStatus();
// Re-enable submit button
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.innerHTML = '🌤️ Get Weather Report ({{ agent.price }} AED)';
}
});
});
// Show processing status
function showProcessingStatus(message) {
let statusDiv = document.getElementById('processingStatus');
if (!statusDiv) {
statusDiv = document.createElement('div');
statusDiv.id = 'processingStatus';
statusDiv.className = 'processing-status';
document.querySelector('#weatherForm').appendChild(statusDiv);
}
statusDiv.innerHTML = `
<div style="font-size: clamp(16px, 4vw, 18px); margin-bottom: 8px;">
⏳ Processing...
</div>
<div style="font-size: clamp(14px, 3.5vw, 16px);">
${message}
</div>
`;
statusDiv.style.display = 'block';
}
// Hide processing status
function hideProcessingStatus() {
const statusDiv = document.getElementById('processingStatus');
if (statusDiv) {
statusDiv.style.display = 'none';
}
}
// Poll for results
function pollForResults(requestId, attempts = 0) {
const maxAttempts = 30; // 30 seconds max
if (attempts >= maxAttempts) {
showToast('Request timed out. Please try again.', 'error');
hideProcessingStatus();
resetForm();
return;
}
fetch(`/agents/weather-reporter/result/${requestId}/`)
.then(response => response.json())
.then(data => {
if (data.success && data.status === 'completed') {
// Success - reload page to show results
showToast('Weather report generated successfully!', 'success');
setTimeout(() => {
window.location.reload();
}, 1000);
} else if (data.status === 'failed') {
throw new Error(data.error_message || 'Weather request failed');
} else {
// Still processing - poll again
setTimeout(() => {
pollForResults(requestId, attempts + 1);
}, 1000);
}
})
.catch(error => {
console.error('Polling error:', error);
showToast('Error checking results: ' + error.message, 'error');
hideProcessingStatus();
resetForm();
});
}
// Reset form state
function resetForm() {
const submitBtn = document.querySelector('button[type="submit"]');
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.innerHTML = '🌤️ Get Weather Report ({{ agent.price }} AED)';
}
}
</script>
</body>
</html>