from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify from jinja2_fragments import render_block from werkzeug.security import generate_password_hash, check_password_hash from flask_login import current_user, login_required from extensions import db, htmx, environment from datetime import datetime, timezone, timedelta from lib.mithril import Mithril import json test = Blueprint('test', __name__) @test.route('/mithril/') @login_required def mithril(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 } return Mithril.render('DiffView', args) #return render_template('mithril_loader.html', args=args)