From 71d9c224fd6c9d870522b826b64c3a2d8f2d3586 Mon Sep 17 00:00:00 2001 From: NguyenND Date: Mon, 12 Jan 2026 12:12:40 -0500 Subject: [PATCH] Enhanced default columns export as and order --- app.py | 18 ++--- static/js/export_configuration.js | 127 +++++++++++++++++++++++++----- 2 files changed, 117 insertions(+), 28 deletions(-) diff --git a/app.py b/app.py index e510a01..f755ed6 100644 --- a/app.py +++ b/app.py @@ -5989,15 +5989,15 @@ def export_configuration(): # Define all available columns with their default settings available_columns = [ - {'key': 'employee_id', 'label': 'Employee ID', 'default_name': 'Employee ID', 'enabled': True}, - {'key': 'employee_name', 'label': 'Employee Name', 'default_name': 'Employee Name', 'enabled': False}, # NEW COLUMN ADDED - {'key': 'location_name', 'label': 'Location', 'default_name': 'Location', 'enabled': True}, - {'key': 'status', 'label': 'Event', 'default_name': 'Event', 'enabled': True}, + {'key': 'employee_id', 'label': 'Employee ID', 'default_name': 'ID', 'enabled': True}, + {'key': 'employee_name', 'label': 'Employee Name', 'default_name': 'Employee Name', 'enabled': False}, + {'key': 'location_name', 'label': 'Location', 'default_name': 'Location Name', 'enabled': True}, + {'key': 'status', 'label': 'Event', 'default_name': 'Action Description', 'enabled': True}, {'key': 'check_in_date', 'label': 'Date', 'default_name': 'Date', 'enabled': True}, {'key': 'check_in_time', 'label': 'Time', 'default_name': 'Time', 'enabled': True}, - {'key': 'qr_address', 'label': 'QR Address', 'default_name': 'QR Code Address', 'enabled': False}, - {'key': 'address', 'label': 'Check-in Address', 'default_name': 'Check-in Address', 'enabled': False}, - {'key': 'device_info', 'label': 'Device', 'default_name': 'Device Information', 'enabled': False}, + {'key': 'qr_address', 'label': 'QR Address', 'default_name': 'Event Description', 'enabled': True}, + {'key': 'address', 'label': 'Check-in Address', 'default_name': 'Recorded Address', 'enabled': True}, + {'key': 'device_info', 'label': 'Device', 'default_name': 'Platform', 'enabled': True}, {'key': 'ip_address', 'label': 'IP Address', 'default_name': 'IP Address', 'enabled': False}, {'key': 'user_agent', 'label': 'User Agent', 'default_name': 'Browser/User Agent', 'enabled': False}, {'key': 'latitude', 'label': 'Latitude', 'default_name': 'GPS Latitude', 'enabled': False}, @@ -6010,8 +6010,8 @@ def export_configuration(): available_columns.append({ 'key': 'location_accuracy', 'label': 'Location Accuracy', - 'default_name': 'Location Accuracy (miles)', - 'enabled': False + 'default_name': 'Distance', + 'enabled': True # Changed from False to True }) print(f"📊 Rendering export configuration with {len(available_columns)} columns") diff --git a/static/js/export_configuration.js b/static/js/export_configuration.js index e399b46..3a2af13 100644 --- a/static/js/export_configuration.js +++ b/static/js/export_configuration.js @@ -3,6 +3,31 @@ * Handles column selection, preview updates, drag & drop reordering, and preference management */ +// Default column configuration +const DEFAULT_COLUMN_ORDER = [ + 'employee_id', // ID + 'device_info', // Platform + 'check_in_date', // Date + 'check_in_time', // Time + 'location_name', // Location Name + 'status', // Action Description + 'qr_address', // Event Description + 'address', // Recorded Address + 'location_accuracy' // Distance +]; + +const DEFAULT_COLUMNS = { + 'employee_id': { selected: true, name: 'ID' }, + 'location_name': { selected: true, name: 'Location Name' }, + 'status': { selected: true, name: 'Action Description' }, + 'check_in_date': { selected: true, name: 'Date' }, + 'check_in_time': { selected: true, name: 'Time' }, + 'qr_address': { selected: true, name: 'Event Description' }, + 'address': { selected: true, name: 'Recorded Address' }, + 'device_info': { selected: true, name: 'Platform' }, + 'location_accuracy': { selected: true, name: 'Distance' } +}; + // Global variables let availableColumns = []; let sortableInstance = null; @@ -444,43 +469,107 @@ function deselectAllColumns() { function resetToDefaults() { try { - // Reset to default selections - availableColumns.forEach(column => { - const checkbox = document.getElementById('col_' + column.key); - const nameInput = document.getElementById('name_' + column.key); - const columnItem = checkbox ? checkbox.closest('.column-item') : null; + console.log('🔄 Resetting to default settings...'); + + // First, deselect all columns and reset to defaults + const allCheckboxes = document.querySelectorAll('input[name="selected_columns"]'); + allCheckboxes.forEach(checkbox => { + const key = checkbox.value; + const nameInput = document.getElementById('name_' + key); + const columnItem = checkbox.closest('.column-item'); - if (checkbox) { - checkbox.checked = column.enabled; - if (column.enabled) { - columnItem?.classList.add('selected'); - } else { - columnItem?.classList.remove('selected'); - } - toggleColumnName(column.key); + // Check if this column should be selected by default + const isDefaultSelected = DEFAULT_COLUMNS.hasOwnProperty(key) && DEFAULT_COLUMNS[key].selected; + + // Set checkbox state + checkbox.checked = isDefaultSelected; + + // Update visual state + if (isDefaultSelected) { + columnItem?.classList.add('selected'); + } else { + columnItem?.classList.remove('selected'); } + // Set the export name if (nameInput) { - nameInput.value = column.defaultName; + if (DEFAULT_COLUMNS[key]) { + nameInput.value = DEFAULT_COLUMNS[key].name; + } else { + // Use the original default name from availableColumns if not in DEFAULT_COLUMNS + const columnData = availableColumns.find(col => col.key === key); + nameInput.value = columnData ? columnData.defaultName : nameInput.value; + } } + + // Toggle visibility + toggleColumnName(key); }); - // Clear saved order - savedColumnOrder = []; + // Set the saved order to the default order + savedColumnOrder = [...DEFAULT_COLUMN_ORDER]; + // Update the display with the default order updateSelectedColumnsList(); + + // Apply the default order to the selected columns list + applyDefaultOrder(); + + // Update preview updatePreview(); - // Clear saved preferences + // Clear saved preferences from localStorage try { localStorage.removeItem('exportPreferences'); } catch (storageError) { console.warn('Could not clear saved preferences:', storageError); } - console.log('Reset to default settings'); + console.log('✅ Reset to default settings complete'); } catch (error) { - console.error('Error resetting to defaults:', error); + console.error('❌ Error resetting to defaults:', error); + } +} + +/** + * Apply the default column order to the selected columns list + */ +function applyDefaultOrder() { + try { + const selectedList = document.getElementById('selectedColumnsList'); + if (!selectedList) return; + + const items = Array.from(selectedList.children); + if (items.length === 0) return; + + // Sort items based on DEFAULT_COLUMN_ORDER + items.sort((a, b) => { + const keyA = a.dataset.columnKey; + const keyB = b.dataset.columnKey; + const indexA = DEFAULT_COLUMN_ORDER.indexOf(keyA); + const indexB = DEFAULT_COLUMN_ORDER.indexOf(keyB); + + // If key not in default order, put it at the end + if (indexA === -1 && indexB === -1) return 0; + if (indexA === -1) return 1; + if (indexB === -1) return -1; + + return indexA - indexB; + }); + + // Clear and re-append in sorted order + selectedList.innerHTML = ''; + items.forEach(item => selectedList.appendChild(item)); + + // Update order numbers + updateColumnOrderNumbers(); + + // Update the hidden column order field + updateColumnOrderField(); + + console.log('📋 Applied default column order'); + } catch (error) { + console.error('Error applying default order:', error); } }