4.6 KiB
Admin Panel Implementation Summary
Overview
Successfully implemented a complete admin panel with start location management feature for the NocoDB Map Viewer application.
Files Created/Modified
Backend Changes
- server.js:
- Added
SETTINGS_SHEET_IDparsing - Updated login endpoint to include admin status
- Updated auth check endpoint to return admin status
- Added
requireAdminmiddleware - Added admin routes for start location management
- Added public config endpoint for start location
- Added
Frontend Changes
- map.js:
- Added
loadStartLocation()function - Updated initialization to load start location first
- Updated
displayUserInfo()to show admin link for admin users
- Added
New Files Created
- admin.html: Admin panel interface with interactive map
- admin.css: Styling for the admin panel
- admin.js: JavaScript functionality for admin panel
Configuration
- .env: Added
NOCODB_SETTINGS_SHEETenvironment variable - README.md: Updated with admin panel documentation
Database Schema
Settings Table (New)
Required columns for NocoDB Settings table:
key(Single Line Text): Setting identifiertitle(Single Line Text): Display nameGeo-Location(Text): Format "latitude;longitude"latitude(Decimal): Precision 10, Scale 8longitude(Decimal): Precision 11, Scale 8zoom(Number): Map zoom levelcategory(Single Select): "system_setting"updated_by(Single Line Text): Last updater emailupdated_at(DateTime): Last update time
Login Table (Existing - Updated)
Ensure the existing login table has:
Admin(Checkbox): Admin privileges column
Features Implemented
Admin Authentication
- Admin status determined by
Admincheckbox in login table - Session-based authentication with admin flag
- Protected admin routes with
requireAdminmiddleware - Automatic redirect to login for non-admin users
Start Location Management
- Interactive map interface for setting coordinates
- Manual coordinate input with validation
- "Use Current Map View" button for easy positioning
- Real-time map updates when coordinates change
- Draggable marker for precise positioning
Data Persistence
- Start location stored in NocoDB Settings table
- Same geographic data format as main locations table
- Automatic creation/update of settings records
- Audit trail with
updated_byandupdated_atfields
Cascading Fallback System
- Database (highest priority): Admin-configured location
- Environment (medium priority): .env file defaults
- Hardcoded (lowest priority): Edmonton coordinates
User Experience
- All users automatically see admin-configured start location
- Admin users see ⚙️ Admin button in header
- Seamless navigation between main map and admin panel
- Real-time validation and feedback
API Endpoints
Admin Endpoints (require admin auth)
GET /admin.html- Serve admin panel pageGET /api/admin/start-location- Get start location with source infoPOST /api/admin/start-location- Save new start location
Public Endpoints
GET /api/config/start-location- Get start location for all users
Security Features
- Admin-only access to configuration endpoints
- Input validation for coordinates and zoom levels
- Session-based authentication
- CSRF protection through proper HTTP methods
- HTML escaping to prevent XSS
Next Steps
-
Setup Database Tables:
- Create the Settings table in NocoDB with required columns
- Ensure Login table has Admin checkbox column
-
Configure Environment:
- Add
NOCODB_SETTINGS_SHEETURL to .env file
- Add
-
Test Admin Functionality:
- Login with admin user
- Access
/admin.html - Set start location and verify it appears for all users
-
Future Enhancements (ready for implementation):
- Additional admin settings (map themes, marker styles, etc.)
- Bulk location management
- User management interface
- System monitoring dashboard
Benefits Achieved
✅ Centralized Control: Admins can change default map view for all users
✅ Persistent Storage: Settings survive server restarts and deployments
✅ User-Friendly Interface: Interactive map for easy configuration
✅ Data Consistency: Uses same format as main location data
✅ Security: Proper authentication and authorization
✅ Scalability: Easy to extend with additional admin features
✅ Reliability: Multiple fallback options ensure map always loads
The implementation provides a robust foundation for administrative control while maintaining the existing user experience and security standards.