diff --git a/modules/conssheets/routes.py b/modules/conssheets/routes.py index 9c3aa03..c97556b 100644 --- a/modules/conssheets/routes.py +++ b/modules/conssheets/routes.py @@ -619,7 +619,17 @@ def register_routes(bp): LIMIT 1 ''', [process_id], one=True) - + def strip_title_prefix(label): + """Strip [title] prefix from field label for display""" + if label and label.startswith('[title]'): + return label[7:] + return label + + def is_title_field(label): + """Check if field label has [title] prefix""" + return label and label.startswith('[title]') + + @bp.route('/') @login_required def index(): @@ -689,7 +699,7 @@ def register_routes(bp): except: sess_dict['scan_count'] = 0 - # Get first 5 required header fields with their values + # Get header fields with their values header_fields = query_db(''' SELECT cpf.field_label, cshv.field_value FROM cons_process_fields cpf @@ -697,13 +707,26 @@ def register_routes(bp): ON cpf.id = cshv.field_id AND cshv.session_id = ? WHERE cpf.process_id = ? AND cpf.table_type = 'header' - AND cpf.is_required = 1 AND cpf.is_active = 1 ORDER BY cpf.sort_order, cpf.id - LIMIT 5 ''', [sess['id'], sess['process_id']]) - sess_dict['header_preview'] = header_fields + # Build title from [title] fields, strip prefix for display + title_parts = [] + preview_fields = [] + for hf in header_fields: + hf_dict = dict(hf) + if is_title_field(hf_dict['field_label']): + clean_label = strip_title_prefix(hf_dict['field_label']) + hf_dict['field_label'] = clean_label + if hf_dict['field_value']: + title_parts.append(f"{clean_label} {hf_dict['field_value']}") + preview_fields.append(hf_dict) + else: + preview_fields.append(hf_dict) + + sess_dict['header_preview'] = preview_fields[:5] + sess_dict['session_title'] = f"{sess['process_name']} — {', '.join(title_parts)}" if title_parts else sess['process_name'] sessions_with_counts.append(sess_dict) # Get available process types for creating new sessions @@ -879,14 +902,24 @@ def register_routes(bp): flash('This session has been archived', 'warning') return redirect(url_for('conssheets.index')) - # Get header values for display - header_values = query_db(''' - SELECT cpf.field_label, cpf.field_name, cshv.field_value - FROM cons_session_header_values cshv - JOIN cons_process_fields cpf ON cshv.field_id = cpf.id - WHERE cshv.session_id = ? + # Get header values for display, stripping [title] prefix + header_values_raw = query_db(''' + SELECT cpf.id as field_id, cpf.field_label, cpf.field_name, + cpf.field_type, cpf.is_required, cpf.max_length, + cshv.field_value + FROM cons_process_fields cpf + LEFT JOIN cons_session_header_values cshv + ON cpf.id = cshv.field_id AND cshv.session_id = ? + WHERE cpf.process_id = ? AND cpf.table_type = 'header' AND cpf.is_active = 1 ORDER BY cpf.sort_order, cpf.id - ''', [session_id]) + ''', [session_id, sess['process_id']]) + + # Strip [title] prefix for display + header_values = [] + for hv in header_values_raw: + hv_dict = dict(hv) + hv_dict['field_label'] = strip_title_prefix(hv_dict['field_label']) + header_values.append(hv_dict) # Get detail fields for this process (convert to dicts for JSON serialization) detail_fields_rows = query_db(''' diff --git a/modules/conssheets/templates/conssheets/staff_index.html b/modules/conssheets/templates/conssheets/staff_index.html index 44a699d..05a5784 100644 --- a/modules/conssheets/templates/conssheets/staff_index.html +++ b/modules/conssheets/templates/conssheets/staff_index.html @@ -42,7 +42,7 @@
-

{{ s.process_name }}

+

{{ s.session_title }}

Started: {{ s.created_at[:16] }}