- Item 10: Convert to ES modules with import/export, single module entry point - Item 11: Replace inline styles with CSS classes (background overlay, card animations, highlight effect, config modal form elements) - Item 12: Move ConfigManager modal HTML from JS template literal to <template> element in index.html - Item 13: Replace deprecated url.parse() with new URL() in server.js and update route handlers to use searchParams - Item 14: Replace JSON.parse/stringify deep clone with structuredClone() - Item 15: Remove dead JSON-fixing regex code from departures.js route Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.3 KiB
JavaScript
93 lines
2.3 KiB
JavaScript
/**
|
|
* Application constants and configuration values
|
|
* Centralizes magic numbers, API endpoints, and default settings
|
|
*/
|
|
|
|
const Constants = {
|
|
// Server configuration
|
|
PORT: 3002,
|
|
API_BASE_URL: 'http://localhost:3002',
|
|
|
|
// API Endpoints
|
|
ENDPOINTS: {
|
|
DEPARTURES: '/api/departures',
|
|
SITES_SEARCH: '/api/sites/search',
|
|
SITES_NEARBY: '/api/sites/nearby',
|
|
CONFIG_UPDATE: '/api/config/update'
|
|
},
|
|
|
|
// External API URLs
|
|
EXTERNAL_APIS: {
|
|
SL_TRANSPORT_BASE: 'https://transport.integration.sl.se/v1',
|
|
OPENWEATHERMAP_BASE: 'https://api.openweathermap.org/data/2.5'
|
|
},
|
|
|
|
// Refresh intervals (in milliseconds)
|
|
REFRESH: {
|
|
DEPARTURES: 30000, // 30 seconds
|
|
WEATHER: 30 * 60 * 1000, // 30 minutes
|
|
DARK_MODE_CHECK: 60000 // 1 minute
|
|
},
|
|
|
|
// Default location (Stockholm, Sweden)
|
|
DEFAULT_LOCATION: {
|
|
LATITUDE: 59.3293,
|
|
LONGITUDE: 18.0686,
|
|
NAME: 'Stockholm'
|
|
},
|
|
|
|
// Default site configuration
|
|
DEFAULT_SITE: {
|
|
ID: '1411',
|
|
NAME: 'Ambassaderna'
|
|
},
|
|
|
|
// Default search radius (in meters)
|
|
DEFAULT_SEARCH_RADIUS: 5000, // 5km
|
|
|
|
// Transport mode identifiers
|
|
TRANSPORT_MODES: {
|
|
BUS: 'bus',
|
|
METRO: 'metro',
|
|
TRAIN: 'train',
|
|
TRAM: 'tram',
|
|
SHIP: 'ship'
|
|
},
|
|
|
|
// CSS class names (for consistency)
|
|
CSS_CLASSES: {
|
|
DARK_MODE: 'dark-mode',
|
|
ORIENTATION_NORMAL: 'normal',
|
|
ORIENTATION_LANDSCAPE: 'landscape',
|
|
ORIENTATION_VERTICAL: 'vertical',
|
|
ORIENTATION_UPSIDE_DOWN: 'upsidedown',
|
|
ORIENTATION_VERTICAL_REVERSE: 'vertical-reverse'
|
|
},
|
|
|
|
// Time thresholds (in minutes)
|
|
TIME_THRESHOLDS: {
|
|
URGENT: 5, // Less than 5 minutes is urgent (red)
|
|
WITHIN_HOUR: 60 // Within next hour
|
|
},
|
|
|
|
// LocalStorage keys
|
|
STORAGE_KEYS: {
|
|
CONFIG: 'sl-departures-config'
|
|
},
|
|
|
|
// Timezone
|
|
TIMEZONE: 'Europe/Stockholm',
|
|
|
|
// Date/time formats
|
|
DATE_FORMAT: {
|
|
TIMEZONE: 'Europe/Stockholm',
|
|
LOCALE: 'sv-SE'
|
|
}
|
|
};
|
|
|
|
// ES module export
|
|
export { Constants };
|
|
|
|
// Keep window reference for backward compatibility with inline scripts
|
|
window.Constants = Constants;
|