Compare commits

...

4 Commits

Author SHA1 Message Date
36bb905f99 Add edit modal and diverse polling settings UI
- Add Edit button for each poll source
- Modal dialog for editing all source settings
- Add max_posts, fetch_comments, priority fields to add form
- Display source settings in source list
- JavaScript modal management for editing

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 18:36:53 -05:00
f477a074a2 Add poll source editing and expanded settings
- Update admin_polling_add to accept max_posts, fetch_comments, priority
- Enhance admin_polling_update to modify all configurable fields
- Support editing display_name, interval, max_posts, fetch_comments, priority

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 18:36:43 -05:00
99d51fe14a Use source-specific polling settings in collection
- Read max_posts from source.max_posts (fallback to 100)
- Read fetch_comments from source settings
- Allows customizing collection per source

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 18:36:32 -05:00
5d3b01926c Add polling configuration fields to PollSource model
- Add max_posts field (default 100)
- Add fetch_comments boolean (default true)
- Add priority field (low/medium/high, default medium)
- Enables per-source control of collection settings

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-11 18:36:17 -05:00
4 changed files with 140 additions and 8 deletions

27
app.py
View File

@@ -1350,6 +1350,9 @@ def admin_polling_add():
custom_source_id = request.form.get('custom_source_id')
display_name = request.form.get('display_name')
poll_interval = int(request.form.get('poll_interval', 60))
max_posts = int(request.form.get('max_posts', 100))
fetch_comments = request.form.get('fetch_comments', 'true') == 'true'
priority = request.form.get('priority', 'medium')
# Use custom source if provided, otherwise use dropdown
if custom_source_id and custom_source_id.strip():
@@ -1371,6 +1374,9 @@ def admin_polling_add():
source_id=source_id,
display_name=display_name,
poll_interval_minutes=poll_interval,
max_posts=max_posts,
fetch_comments=fetch_comments,
priority=priority,
enabled=False,
created_by=current_user.id
)
@@ -1423,11 +1429,24 @@ def admin_polling_update(source_id):
flash('Source not found', 'error')
return redirect(url_for('admin_polling'))
poll_interval = request.form.get('poll_interval')
if poll_interval:
source.poll_interval_minutes = int(poll_interval)
# Update all configurable fields
if request.form.get('poll_interval'):
source.poll_interval_minutes = int(request.form.get('poll_interval'))
if request.form.get('max_posts'):
source.max_posts = int(request.form.get('max_posts'))
if request.form.get('fetch_comments') is not None:
source.fetch_comments = request.form.get('fetch_comments') == 'true'
if request.form.get('priority'):
source.priority = request.form.get('priority')
if request.form.get('display_name'):
source.display_name = request.form.get('display_name')
db.session.commit()
flash(f'Updated interval for {source.display_name}', 'success')
flash(f'Updated settings for {source.display_name}', 'success')
return redirect(url_for('admin_polling'))

View File

@@ -140,6 +140,9 @@ class PollSource(db.Model):
# Polling configuration
enabled = db.Column(db.Boolean, default=True, nullable=False)
poll_interval_minutes = db.Column(db.Integer, default=60, nullable=False) # How often to poll
max_posts = db.Column(db.Integer, default=100, nullable=False) # Max posts per poll
fetch_comments = db.Column(db.Boolean, default=True, nullable=False) # Whether to fetch comments
priority = db.Column(db.String(20), default='medium', nullable=False) # low, medium, high
# Status tracking
last_poll_time = db.Column(db.DateTime, nullable=True)

View File

@@ -161,14 +161,14 @@ class PollingService:
end_iso = end_date.isoformat()
try:
# Call the existing collect_platform function
# Call the existing collect_platform function using source settings
posts_collected = collect_platform(
platform=source.platform,
community=source.source_id,
start_date=start_iso,
end_date=end_iso,
max_posts=100, # Default limit
fetch_comments=True,
max_posts=source.max_posts or 100,
fetch_comments=source.fetch_comments if hasattr(source, 'fetch_comments') else True,
index=index,
dirs=dirs
)

View File

@@ -251,6 +251,35 @@
</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>
@@ -315,6 +344,8 @@
{% 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 %}
@@ -387,6 +418,85 @@
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>