- Changes to the list views - now using tabulator with filtering and sorting, client-side pagination, ...

- Adaptation of all list views in the app
This commit is contained in:
Josako
2025-07-14 18:58:54 +02:00
parent acad28b623
commit 000636a229
50 changed files with 2162 additions and 2174 deletions

View File

@@ -25,9 +25,10 @@ from common.utils.middleware import mw_before_request
from common.utils.celery_utils import current_celery
from common.utils.nginx_utils import prefixed_url_for
from common.utils.view_assistants import form_validation_failed, prepare_table_for_macro
from eveai_app.views.list_views.document_list_view import DocumentListView
from eveai_app.views.list_views.document_version_list_view import DocumentVersionListView
from eveai_app.views.list_views.full_document_list_view import FullDocumentListView
from eveai_app.views.list_views.list_view_utils import render_list_view
from eveai_app.views.list_views.document_list_views import get_catalogs_list_view, get_processors_list_view, \
get_retrievers_list_view, get_documents_list_view, get_documents_processing_list_view
from eveai_app.views.list_views.list_view_utils import render_list_view
document_bp = Blueprint('document_bp', __name__, url_prefix='/document')
@@ -86,19 +87,9 @@ def catalog():
@document_bp.route('/catalogs', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def catalogs():
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 10, type=int)
query = Catalog.query.order_by(Catalog.id)
pagination = query.paginate(page=page, per_page=per_page)
the_catalogs = pagination.items
# prepare table data
rows = prepare_table_for_macro(the_catalogs, [('id', ''), ('name', ''), ('type', '')])
# Render the catalogs in a template
return render_template('document/catalogs.html', rows=rows, pagination=pagination)
# Haal configuratie op en render de lijst-weergave
config = get_catalogs_list_view()
return render_list_view('list_view.html', **config)
@document_bp.route('/handle_catalog_selection', methods=['POST'])
@@ -234,25 +225,14 @@ def edit_processor(processor_id):
@document_bp.route('/processors', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def processors():
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 10, type=int)
catalog_id = session.get('catalog_id', None)
if not catalog_id:
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
return redirect(prefixed_url_for('document_bp.catalogs'))
query = Processor.query.filter_by(catalog_id=catalog_id).order_by(Processor.id)
pagination = query.paginate(page=page, per_page=per_page)
the_processors = pagination.items
# prepare table data
rows = prepare_table_for_macro(the_processors,
[('id', ''), ('name', ''), ('type', ''), ('active', '')])
# Render the catalogs in a template
return render_template('document/processors.html', rows=rows, pagination=pagination)
# Get configuration and render the list view
config = get_processors_list_view(catalog_id)
return render_list_view('list_view.html', **config)
@document_bp.route('/handle_processor_selection', methods=['POST'])
@@ -345,25 +325,14 @@ def edit_retriever(retriever_id):
@document_bp.route('/retrievers', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def retrievers():
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 10, type=int)
catalog_id = session.get('catalog_id', None)
if not catalog_id:
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
return redirect(prefixed_url_for('document_bp.catalogs'))
query = Retriever.query.filter_by(catalog_id=catalog_id).order_by(Retriever.id)
pagination = query.paginate(page=page, per_page=per_page)
the_retrievers = pagination.items
# prepare table data
rows = prepare_table_for_macro(the_retrievers,
[('id', ''), ('name', ''), ('type', '')])
# Render the catalogs in a template
return render_template('document/retrievers.html', rows=rows, pagination=pagination)
# Get configuration and render the list view
config = get_retrievers_list_view(catalog_id)
return render_list_view('list_view.html', **config)
@document_bp.route('/handle_retriever_selection', methods=['POST'])
@@ -502,20 +471,20 @@ def documents():
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
return redirect(prefixed_url_for('document_bp.catalogs'))
view = DocumentListView(Document, 'document/documents.html', per_page=10)
return view.get()
config = get_documents_list_view(catalog_id)
return render_list_view('list_view.html', **config)
@document_bp.route('/full_documents', methods=['GET', 'POST'])
@document_bp.route('/documents_processing', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def full_documents():
def documents_processing():
catalog_id = session.get('catalog_id', None)
if not catalog_id:
flash('You need to set a Session Catalog before viewing Full Documents', 'warning')
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
return redirect(prefixed_url_for('document_bp.catalogs'))
view = FullDocumentListView(Document, 'document/full_documents.html', per_page=10)
return view.get()
config = get_documents_processing_list_view(catalog_id)
return render_list_view('list_view.html', **config)
@document_bp.route('/handle_document_selection', methods=['POST'])
@@ -536,14 +505,23 @@ def handle_document_selection():
match action:
case 'edit_document':
return redirect(prefixed_url_for('document_bp.edit_document_view', document_id=doc_id))
case 'document_versions':
return redirect(prefixed_url_for('document_bp.document_versions', document_id=doc_id))
case 'refresh_document':
return redirect(prefixed_url_for('document_bp.edit_document', document_id=doc_id))
case 'refresh':
refresh_document_view(doc_id)
return redirect(prefixed_url_for('document_bp.document_versions', document_id=doc_id))
case 're_embed_latest_versions':
re_embed_latest_versions()
return redirect(prefixed_url_for('document_bp.documents', document_id=doc_id))
case 're_process':
document = Document.query.get_or_404(doc_id)
doc_vers_id = document.latest_version.id
process_version(doc_vers_id)
case 'view_document_markdown':
document = Document.query.get_or_404(doc_id)
doc_vers_id = document.latest_version.id
return redirect(prefixed_url_for('document_bp.view_document_version_markdown',
document_version_id=doc_vers_id))
case 'edit_document_version':
document = Document.query.get_or_404(doc_id)
doc_vers_id = document.latest_version.id
return redirect(prefixed_url_for('document_bp.edit_document_version', document_version_id=doc_vers_id))
# Add more conditions for other actions
return redirect(prefixed_url_for('document_bp.documents'))
@@ -551,7 +529,7 @@ def handle_document_selection():
@document_bp.route('/edit_document/<int:document_id>', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def edit_document_view(document_id):
def edit_document(document_id):
# Use an alias for the Catalog to avoid column name conflicts
CatalogAlias = aliased(Catalog)
@@ -592,7 +570,7 @@ def edit_document_view(document_id):
@document_bp.route('/edit_document_version/<int:document_version_id>', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def edit_document_version_view(document_version_id):
def edit_document_version(document_version_id):
doc_vers = DocumentVersion.query.get_or_404(document_version_id)
form = EditDocumentVersionForm(request.form, obj=doc_vers)
@@ -630,119 +608,6 @@ def edit_document_version_view(document_version_id):
doc_details=f'Document {doc_vers.document.name}')
@document_bp.route('/document_versions/<int:document_id>', methods=['GET', 'POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def document_versions(document_id):
doc = Document.query.get_or_404(document_id)
doc_desc = f'{doc.name}'
page = request.args.get('page', 1, type=int)
per_page = request.args.get('per_page', 10, type=int)
query = (DocumentVersion.query.filter_by(doc_id=document_id)
.order_by(DocumentVersion.language)
.order_by(desc(DocumentVersion.id)))
pagination = query.paginate(page=page, per_page=per_page, error_out=False)
doc_langs = pagination.items
rows = prepare_table_for_macro(doc_langs, [('id', ''), ('file_type', ''), ('file_size', ''),
('processing', ''), ('processing_started_at', ''),
('processing_finished_at', ''), ('processing_error', '')])
return render_template('document/document_versions.html', rows=rows, pagination=pagination, document=doc_desc)
@document_bp.route('/handle_document_version_selection', methods=['POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def handle_document_version_selection():
document_version_identification = request.form['selected_row']
if isinstance(document_version_identification, int) or document_version_identification.isdigit():
doc_vers_id = int(document_version_identification)
else:
# If it's not an integer, assume it's a string representation of a dictionary
try:
doc_vers_id = ast.literal_eval(document_version_identification).get('value')
except (ValueError, AttributeError):
flash('Invalid document version selection.', 'error')
return redirect(prefixed_url_for('document_bp.document_versions_list'))
action = request.form['action']
match action:
case 'edit_document_version':
return redirect(prefixed_url_for('document_bp.edit_document_version_view', document_version_id=doc_vers_id))
case 'process_document_version':
process_version(doc_vers_id)
# Add more conditions for other actions
case 'view_document_version_markdown':
return redirect(prefixed_url_for('document_bp.view_document_version_markdown',
document_version_id=doc_vers_id))
doc_vers = DocumentVersion.query.get_or_404(doc_vers_id)
return redirect(prefixed_url_for('document_bp.document_versions', document_id=doc_vers.doc_id))
@document_bp.route('/handle_full_document_selection', methods=['POST'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def handle_full_document_selection():
selected_row = request.form['selected_row']
action = request.form['action']
try:
# Parse the selected row to get document ID (first column) and version ID (fifth column)
row_data = ast.literal_eval(selected_row)
selected_doc_id = row_data.get('value')
# We need to retrieve the corresponding row data to get the version ID
# This is a bit complex with the current structure, so we'll use a different approach
if action in ['edit_document', 'document_versions', 'refresh_document']:
# Actions that need document ID
match action:
case 'edit_document':
return redirect(prefixed_url_for('document_bp.edit_document_view', document_id=selected_doc_id))
case 'document_versions':
return redirect(prefixed_url_for('document_bp.document_versions', document_id=selected_doc_id))
case 'refresh_document':
refresh_document_view(selected_doc_id)
return redirect(prefixed_url_for('document_bp.full_documents'))
else:
# Actions that need version ID
# We need to get the version ID from the selected row in the table
# We'll extract it from the form data and the version ID is in the 5th cell (index 4)
version_id_cell = int(request.form.get('version_id', 0))
# If we couldn't get a version ID, try to find the latest version for this document
if not version_id_cell:
doc_version = DocumentVersion.query.filter_by(doc_id=selected_doc_id).order_by(desc(DocumentVersion.id)).first()
if doc_version:
version_id_cell = doc_version.id
else:
flash('No document version found for this document.', 'error')
return redirect(prefixed_url_for('document_bp.full_documents'))
match action:
case 'edit_document_version':
return redirect(prefixed_url_for('document_bp.edit_document_version_view', document_version_id=version_id_cell))
case 'process_document_version':
process_version(version_id_cell)
return redirect(prefixed_url_for('document_bp.full_documents'))
case 'view_document_version_markdown':
return redirect(prefixed_url_for('document_bp.view_document_version_markdown', document_version_id=version_id_cell))
except (ValueError, AttributeError, KeyError) as e:
current_app.logger.error(f"Error processing full document selection: {str(e)}")
flash('Invalid selection or action. Please try again.', 'error')
return redirect(prefixed_url_for('document_bp.full_documents'))
@document_bp.route('/document_versions_list', methods=['GET'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def document_versions_list():
view = DocumentVersionListView(DocumentVersion, 'document/document_versions_list_view.html', per_page=20)
return view.get()
@document_bp.route('/view_document_version_markdown/<int:document_version_id>', methods=['GET'])
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
def view_document_version_markdown(document_version_id):