- Create reusable _nav.html navigation include - Add topbar to all settings pages (settings, profile, communities, filters, experience) - Add topbar to all admin pages (admin, polling, polling_logs, setup) - Replace hardcoded nav in dashboard with include - Wrap logo in link to index page (fixes clicking logo to go home) Fixes #14, #13
504 lines
21 KiB
HTML
504 lines
21 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Polling Management - Admin - BalanceBoard</title>
|
|
<link rel="stylesheet" href="{{ url_for('serve_theme', filename='modern-card-ui/styles.css') }}">
|
|
<style>
|
|
.admin-container {
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
padding: 24px;
|
|
}
|
|
|
|
.admin-header {
|
|
background: linear-gradient(135deg, var(--primary-dark) 0%, #2a5068 100%);
|
|
color: white;
|
|
padding: 32px;
|
|
border-radius: 12px;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-block;
|
|
padding: 4px 12px;
|
|
border-radius: 12px;
|
|
font-size: 0.85rem;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.status-enabled {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.status-disabled {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.status-success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.status-error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.source-card {
|
|
background: var(--surface-color);
|
|
border: 1px solid var(--divider-color);
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.source-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.source-title {
|
|
font-size: 1.2rem;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.source-meta {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 16px;
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.meta-item {
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.meta-label {
|
|
font-size: 0.85rem;
|
|
color: var(--text-secondary);
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.meta-value {
|
|
font-weight: 500;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.source-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.btn {
|
|
padding: 8px 16px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-weight: 500;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: var(--primary-color);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
background: var(--primary-dark);
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: var(--divider-color);
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: #d0d0d0;
|
|
}
|
|
|
|
.btn-danger {
|
|
background: #dc3545;
|
|
color: white;
|
|
}
|
|
|
|
.btn-danger:hover {
|
|
background: #c82333;
|
|
}
|
|
|
|
.add-source-form {
|
|
background: var(--surface-color);
|
|
border: 2px dashed var(--divider-color);
|
|
border-radius: 12px;
|
|
padding: 24px;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.form-label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
font-weight: 500;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.form-input, .form-select {
|
|
width: 100%;
|
|
padding: 10px;
|
|
border: 1px solid var(--divider-color);
|
|
border-radius: 6px;
|
|
font-size: 1rem;
|
|
}
|
|
|
|
.scheduler-status {
|
|
background: var(--surface-color);
|
|
border: 1px solid var(--divider-color);
|
|
border-radius: 12px;
|
|
padding: 16px;
|
|
margin-bottom: 24px;
|
|
}
|
|
|
|
.no-sources {
|
|
text-align: center;
|
|
padding: 48px;
|
|
color: var(--text-secondary);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
{% include '_nav.html' %}
|
|
<div class="admin-container">
|
|
<div class="admin-header">
|
|
<h1>📡 Polling Management</h1>
|
|
<p>Configure automatic data collection from content sources</p>
|
|
</div>
|
|
|
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
|
{% if messages %}
|
|
{% for category, message in messages %}
|
|
<div class="alert alert-{{ category }}">{{ message }}</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endwith %}
|
|
|
|
<!-- Scheduler Status -->
|
|
<div class="scheduler-status">
|
|
<h3>Scheduler Status</h3>
|
|
<p><strong>Status:</strong>
|
|
{% if scheduler_status.running %}
|
|
<span class="status-badge status-enabled">Running</span>
|
|
{% else %}
|
|
<span class="status-badge status-disabled">Stopped</span>
|
|
{% endif %}
|
|
</p>
|
|
<p><strong>Active Jobs:</strong> {{ scheduler_status.jobs|length }}</p>
|
|
</div>
|
|
|
|
<!-- Add New Source Form -->
|
|
<div class="add-source-form">
|
|
<h3>Add New Source</h3>
|
|
<form action="{{ url_for('admin_polling_add') }}" method="POST">
|
|
<div class="form-group">
|
|
<label class="form-label" for="platform">Platform</label>
|
|
<select class="form-select" name="platform" id="platform" required onchange="updateSourceOptions()">
|
|
<option value="">Select platform...</option>
|
|
{% for platform_id, platform_data in platform_config.platforms.items() %}
|
|
<option value="{{ platform_id }}">{{ platform_data.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="source_id">Source</label>
|
|
<select class="form-select" name="source_id" id="source_id" required onchange="updateDisplayName()">
|
|
<option value="">Select source...</option>
|
|
</select>
|
|
<p class="help-text">Or enter custom source below</p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="custom_source_id">Custom Source (optional)</label>
|
|
<input type="text" class="form-input" name="custom_source_id" id="custom_source_id" placeholder="e.g., r/technology or https://example.com/feed.xml">
|
|
<p class="help-text">For Reddit: r/subreddit | For RSS: full URL | Leave blank to use dropdown</p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="display_name">Display Name</label>
|
|
<input type="text" class="form-input" name="display_name" id="display_name" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="poll_interval">Poll Interval</label>
|
|
<select class="form-select" name="poll_interval" id="poll_interval" required>
|
|
<option value="15">15 minutes</option>
|
|
<option value="30">30 minutes</option>
|
|
<option value="60" selected>1 hour</option>
|
|
<option value="120">2 hours</option>
|
|
<option value="240">4 hours</option>
|
|
<option value="360">6 hours</option>
|
|
<option value="720">12 hours</option>
|
|
<option value="1440">24 hours</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="max_posts">Max Posts Per Poll</label>
|
|
<select class="form-select" name="max_posts" id="max_posts">
|
|
<option value="25">25 posts</option>
|
|
<option value="50">50 posts</option>
|
|
<option value="100" selected>100 posts</option>
|
|
<option value="200">200 posts</option>
|
|
<option value="500">500 posts</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="fetch_comments">Fetch Comments</label>
|
|
<select class="form-select" name="fetch_comments" id="fetch_comments">
|
|
<option value="true" selected>Yes - Fetch comments</option>
|
|
<option value="false">No - Posts only</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label" for="priority">Priority</label>
|
|
<select class="form-select" name="priority" id="priority">
|
|
<option value="low">Low</option>
|
|
<option value="medium" selected>Medium</option>
|
|
<option value="high">High</option>
|
|
</select>
|
|
<p class="help-text">Higher priority sources poll more reliably during load</p>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Add Source</button>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- Existing Sources -->
|
|
<h3>Configured Sources ({{ sources|length }})</h3>
|
|
|
|
{% if sources %}
|
|
{% for source in sources %}
|
|
<div class="source-card">
|
|
<div class="source-header">
|
|
<div>
|
|
<div class="source-title">{{ source.display_name }}</div>
|
|
<small>{{ source.platform }}:{{ source.source_id }}</small>
|
|
</div>
|
|
<div>
|
|
{% if source.enabled %}
|
|
<span class="status-badge status-enabled">Enabled</span>
|
|
{% else %}
|
|
<span class="status-badge status-disabled">Disabled</span>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="source-meta">
|
|
<div class="meta-item">
|
|
<span class="meta-label">Poll Interval</span>
|
|
<span class="meta-value">{{ source.poll_interval_minutes }} minutes</span>
|
|
</div>
|
|
<div class="meta-item">
|
|
<span class="meta-label">Last Poll</span>
|
|
<span class="meta-value">
|
|
{% if source.last_poll_time %}
|
|
{{ source.last_poll_time.strftime('%Y-%m-%d %H:%M:%S') }}
|
|
{% else %}
|
|
Never
|
|
{% endif %}
|
|
</span>
|
|
</div>
|
|
<div class="meta-item">
|
|
<span class="meta-label">Status</span>
|
|
<span class="meta-value">
|
|
{% if source.last_poll_status == 'success' %}
|
|
<span class="status-badge status-success">Success</span>
|
|
{% elif source.last_poll_status == 'error' %}
|
|
<span class="status-badge status-error">Error</span>
|
|
{% else %}
|
|
<span class="status-badge">{{ source.last_poll_status or 'N/A' }}</span>
|
|
{% endif %}
|
|
</span>
|
|
</div>
|
|
<div class="meta-item">
|
|
<span class="meta-label">Posts Collected</span>
|
|
<span class="meta-value">{{ source.posts_collected }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{% if source.last_poll_error %}
|
|
<div style="background: #fff3cd; padding: 12px; border-radius: 6px; margin-bottom: 16px;">
|
|
<strong>Last Error:</strong> {{ source.last_poll_error }}
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="source-actions">
|
|
<button onclick="openEditModal('{{ source.id }}', '{{ source.display_name }}', {{ source.poll_interval_minutes }}, {{ source.max_posts or 100 }}, {{ 'true' if source.fetch_comments else 'false' }}, '{{ source.priority or 'medium' }}')" class="btn btn-secondary">⚙️ Edit</button>
|
|
|
|
<form action="{{ url_for('admin_polling_toggle', source_id=source.id) }}" method="POST" style="display: inline;">
|
|
<button type="submit" class="btn btn-secondary">
|
|
{% if source.enabled %}Disable{% else %}Enable{% endif %}
|
|
</button>
|
|
</form>
|
|
|
|
<form action="{{ url_for('admin_polling_poll_now', source_id=source.id) }}" method="POST" style="display: inline;">
|
|
<button type="submit" class="btn btn-primary">Poll Now</button>
|
|
</form>
|
|
|
|
<a href="{{ url_for('admin_polling_logs', source_id=source.id) }}" class="btn btn-secondary">View Logs</a>
|
|
|
|
<form action="{{ url_for('admin_polling_delete', source_id=source.id) }}" method="POST" style="display: inline;" onsubmit="return confirm('Are you sure you want to delete this source?');">
|
|
<button type="submit" class="btn btn-danger">Delete</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
{% else %}
|
|
<div class="no-sources">
|
|
<p>No polling sources configured yet.</p>
|
|
<p>Add your first source above to start collecting content!</p>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div style="margin-top: 24px;">
|
|
<a href="{{ url_for('admin_panel') }}" class="btn btn-secondary">← Back to Admin Panel</a>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const platformConfig = {{ platform_config|tojson }};
|
|
|
|
function updateSourceOptions() {
|
|
const platformSelect = document.getElementById('platform');
|
|
const sourceSelect = document.getElementById('source_id');
|
|
const selectedPlatform = platformSelect.value;
|
|
|
|
// Clear existing options
|
|
sourceSelect.innerHTML = '<option value="">Select source...</option>';
|
|
|
|
if (selectedPlatform && platformConfig.platforms[selectedPlatform]) {
|
|
const communities = platformConfig.platforms[selectedPlatform].communities || [];
|
|
communities.forEach(community => {
|
|
const option = document.createElement('option');
|
|
option.value = community.id;
|
|
option.textContent = community.display_name || community.name;
|
|
option.dataset.displayName = community.display_name || community.name;
|
|
sourceSelect.appendChild(option);
|
|
});
|
|
}
|
|
}
|
|
|
|
function updateDisplayName() {
|
|
const sourceSelect = document.getElementById('source_id');
|
|
const displayNameInput = document.getElementById('display_name');
|
|
const selectedOption = sourceSelect.options[sourceSelect.selectedIndex];
|
|
|
|
if (selectedOption && selectedOption.dataset.displayName) {
|
|
displayNameInput.value = selectedOption.dataset.displayName;
|
|
}
|
|
}
|
|
|
|
// Handle custom source input - make dropdown optional when custom is filled
|
|
document.getElementById('custom_source_id').addEventListener('input', function() {
|
|
const sourceSelect = document.getElementById('source_id');
|
|
if (this.value.trim()) {
|
|
sourceSelect.removeAttribute('required');
|
|
} else {
|
|
sourceSelect.setAttribute('required', 'required');
|
|
}
|
|
});
|
|
|
|
function openEditModal(sourceId, displayName, interval, maxPosts, fetchComments, priority) {
|
|
const modal = document.getElementById('edit-modal');
|
|
if (!modal) {
|
|
// Create modal HTML
|
|
const modalHTML = `
|
|
<div id="edit-modal" style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000;">
|
|
<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 24px; border-radius: 8px; max-width: 500px; width: 90%;">
|
|
<h3>Edit Poll Source</h3>
|
|
<form id="edit-form" action="" method="POST">
|
|
<div class="form-group">
|
|
<label>Display Name</label>
|
|
<input type="text" name="display_name" id="edit_display_name" class="form-input" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Poll Interval</label>
|
|
<select name="poll_interval" id="edit_interval" class="form-select">
|
|
<option value="15">15 minutes</option>
|
|
<option value="30">30 minutes</option>
|
|
<option value="60">1 hour</option>
|
|
<option value="120">2 hours</option>
|
|
<option value="240">4 hours</option>
|
|
<option value="360">6 hours</option>
|
|
<option value="720">12 hours</option>
|
|
<option value="1440">24 hours</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Max Posts</label>
|
|
<select name="max_posts" id="edit_max_posts" class="form-select">
|
|
<option value="25">25 posts</option>
|
|
<option value="50">50 posts</option>
|
|
<option value="100">100 posts</option>
|
|
<option value="200">200 posts</option>
|
|
<option value="500">500 posts</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Fetch Comments</label>
|
|
<select name="fetch_comments" id="edit_fetch_comments" class="form-select">
|
|
<option value="true">Yes</option>
|
|
<option value="false">No</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Priority</label>
|
|
<select name="priority" id="edit_priority" class="form-select">
|
|
<option value="low">Low</option>
|
|
<option value="medium">Medium</option>
|
|
<option value="high">High</option>
|
|
</select>
|
|
</div>
|
|
<div style="display: flex; gap: 8px; margin-top: 16px;">
|
|
<button type="submit" class="btn btn-primary">Save Changes</button>
|
|
<button type="button" onclick="closeEditModal()" class="btn btn-secondary">Cancel</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
`;
|
|
document.body.insertAdjacentHTML('beforeend', modalHTML);
|
|
}
|
|
|
|
// Fill form with current values
|
|
const modal2 = document.getElementById('edit-modal');
|
|
const form = document.getElementById('edit-form');
|
|
form.action = `/admin/polling/${sourceId}/update`;
|
|
document.getElementById('edit_display_name').value = displayName;
|
|
document.getElementById('edit_interval').value = interval;
|
|
document.getElementById('edit_max_posts').value = maxPosts;
|
|
document.getElementById('edit_fetch_comments').value = fetchComments;
|
|
document.getElementById('edit_priority').value = priority;
|
|
|
|
modal2.style.display = 'block';
|
|
}
|
|
|
|
function closeEditModal() {
|
|
document.getElementById('edit-modal').style.display = 'none';
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|