Add version history view for timer functions
- Implement `/history/<function_id>` route in timer routes to fetch and display function versions - Create new Mithril `DiffView` component for comparing script versions - Add new history template for timer functions with version comparison - Include version diff functionality using AceDiff library - Update header and edit templates to include history URL for timer functions
This commit is contained in:
@@ -402,4 +402,41 @@ def logs(function_id):
|
||||
return render_block(environment, 'dashboard/timer_functions/logs.html', 'page', **args)
|
||||
return render_template('dashboard/timer_functions/logs.html', **args)
|
||||
|
||||
@timer.route('/history/<int:function_id>')
|
||||
@login_required
|
||||
def history(function_id):
|
||||
# Fetch the timer function to verify ownership
|
||||
timer_function = db.execute("""
|
||||
SELECT id, name, code, version_number
|
||||
FROM timer_functions
|
||||
WHERE id = %s AND user_id = %s
|
||||
""", [function_id, current_user.id], one=True)
|
||||
|
||||
if not timer_function:
|
||||
flash('Timer function not found', 'error')
|
||||
return redirect(url_for('timer.overview'))
|
||||
|
||||
# Fetch all versions
|
||||
versions = db.execute("""
|
||||
SELECT version_number, script, versioned_at
|
||||
FROM timer_function_versions
|
||||
WHERE timer_function_id = %s
|
||||
ORDER BY version_number DESC
|
||||
""", [function_id])
|
||||
|
||||
# Convert datetime objects to ISO format strings
|
||||
for version in versions:
|
||||
version['versioned_at'] = version['versioned_at'].isoformat() if version['versioned_at'] else None
|
||||
|
||||
args = {
|
||||
'user_id': current_user.id,
|
||||
'function_id': function_id,
|
||||
'timer_function': timer_function,
|
||||
'versions': versions
|
||||
}
|
||||
|
||||
if htmx:
|
||||
return render_block(environment, 'dashboard/timer_functions/history.html', 'page', **args)
|
||||
return render_template('dashboard/timer_functions/history.html', **args)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user