Compare commits
No commits in common. "776420b6b80f48459d59ccf31b5052b32f9e9d54" and "09c8e029264c1748b73f4acb6906ebd22dae1612" have entirely different histories.
776420b6b8
...
09c8e02926
@ -13,9 +13,7 @@ A containerized web application that visualizes geographic data from NocoDB on a
|
||||
- 👤 User authentication with login system
|
||||
- ⚙️ Admin panel for system configuration
|
||||
- 🎯 Configurable map start location
|
||||
- <20> Walk Sheet generator for door-to-door canvassing
|
||||
- 🔗 QR code integration for digital resources
|
||||
- <20>🐳 Docker containerization for easy deployment
|
||||
- 🐳 Docker containerization for easy deployment
|
||||
- 🆓 100% open source (no proprietary dependencies)
|
||||
|
||||
## Quick Start
|
||||
@ -28,45 +26,28 @@ A containerized web application that visualizes geographic data from NocoDB on a
|
||||
|
||||
### NocoDB Table Setup
|
||||
|
||||
1. **Main Locations Table** - Create a table with these required columns. The format here is `Column Name - Column Type - Other Settings`:
|
||||
|
||||
- `Geo-Location` (Geo-Data): Format "latitude;longitude"
|
||||
1. **Main Locations Table** - Create a table with these required columns:
|
||||
- `Geo-Location` (Text): Format "latitude;longitude"
|
||||
- `latitude` (Decimal): Precision 10, Scale 8
|
||||
- `longitude` (Decimal): Precision 11, Scale 8
|
||||
- `First Name` (Single Line Text): Person's first name
|
||||
- `Last Name` (Single Line Text): Person's last name
|
||||
- `Email` (Email): Email address
|
||||
- `Phone` (Single Line Text): Phone number
|
||||
- `Unit Number` (Single Line Text): Unit or apartment number
|
||||
- `Support Level` (Single Select): Options: "1", "2", "3", "4" (1=Strong Support/Green, 2=Moderate Support/Yellow, 3=Low Support/Orange, 4=No Support/Red)
|
||||
- `Address` (Single Line Text): Street address
|
||||
- `Sign` (Checkbox): Has campaign sign
|
||||
- `Sign Size` (Single Select): Options: "Small", "Medium", "Large"
|
||||
- `Notes` (Long Text): Additional details and comments
|
||||
- `title` (Text): Location name (legacy field)
|
||||
- `category` (Single Select): Classification (legacy field)
|
||||
- `title` (Text): Location name
|
||||
- `category` (Single Select): Classification
|
||||
|
||||
2. **Login Table** - Create a table for user authentication:
|
||||
|
||||
- `Email` (Email): User email address
|
||||
- `Name` (Single Line Text): User display name
|
||||
- `Admin` (Checkbox): Admin privileges
|
||||
|
||||
3. **Settings Table** - Create a table for admin configuration:
|
||||
|
||||
- `key` (Single Line Text): Setting identifier
|
||||
- `title` (Single Line Text): Display name
|
||||
- `value` (Long Text): Setting value
|
||||
- `Geo-Location` (Text): Format "latitude;longitude"
|
||||
- `latitude` (Decimal): Precision 10, Scale 8
|
||||
- `longitude` (Decimal): Precision 11, Scale 8
|
||||
- `zoom` (Number): Map zoom level
|
||||
- `category` (Single Select): Setting category
|
||||
- `category` (Single Select): "system_setting"
|
||||
- `updated_by` (Single Line Text): Last updater email
|
||||
- `updated_at` (DateTime): Last update time
|
||||
- `qr_code_1_image` (Attachment): QR code 1 image
|
||||
- `qr_code_2_image` (Attachment): QR code 2 image
|
||||
- `qr_code_3_image` (Attachment): QR code 3 image
|
||||
|
||||
### Installation
|
||||
|
||||
@ -96,20 +77,17 @@ A containerized web application that visualizes geographic data from NocoDB on a
|
||||
## Finding NocoDB IDs
|
||||
|
||||
### API Token
|
||||
|
||||
1. Click user icon → Account Settings
|
||||
2. Go to "API Tokens" tab
|
||||
3. Create new token with read/write permissions
|
||||
|
||||
### Project and Table IDs
|
||||
|
||||
- Simply provide the full NocoDB view URL in `NOCODB_VIEW_URL`
|
||||
- The system will automatically extract the project and table IDs
|
||||
|
||||
## API Endpoints
|
||||
|
||||
### Public Endpoints
|
||||
|
||||
- `GET /api/locations` - Fetch all locations (requires auth)
|
||||
- `POST /api/locations` - Create new location (requires auth)
|
||||
- `GET /api/locations/:id` - Get single location (requires auth)
|
||||
@ -119,49 +97,30 @@ A containerized web application that visualizes geographic data from NocoDB on a
|
||||
- `GET /health` - Health check
|
||||
|
||||
### Authentication Endpoints
|
||||
|
||||
- `POST /api/auth/login` - User login
|
||||
- `GET /api/auth/check` - Check authentication status
|
||||
- `POST /api/auth/logout` - User logout
|
||||
|
||||
### Admin Endpoints (requires admin privileges)
|
||||
|
||||
- `GET /api/admin/start-location` - Get start location with source info
|
||||
- `POST /api/admin/start-location` - Update map start location
|
||||
- `GET /api/admin/walk-sheet-config` - Get walk sheet configuration
|
||||
- `POST /api/admin/walk-sheet-config` - Save walk sheet configuration
|
||||
|
||||
## Admin Panel
|
||||
|
||||
Users with admin privileges can access the admin panel at `/admin.html` to configure system settings.
|
||||
|
||||
### Features
|
||||
|
||||
#### Start Location Configuration
|
||||
|
||||
- **Start Location Configuration**: Set the default map center and zoom level for all users
|
||||
- **Interactive Map**: Visual interface for selecting coordinates
|
||||
- **Real-time Preview**: See changes immediately on the admin map
|
||||
- **Validation**: Built-in coordinate and zoom level validation
|
||||
|
||||
#### Walk Sheet Generator
|
||||
|
||||
- **Printable Forms**: Generate 8.5x11 walk sheets for door-to-door canvassing
|
||||
- **QR Code Integration**: Add up to 3 QR codes with custom URLs and labels
|
||||
- **Form Field Matching**: Automatically matches fields from the main location form
|
||||
- **Live Preview**: See changes as you type
|
||||
- **Print Optimization**: Proper formatting for printing or PDF export
|
||||
- **Persistent Storage**: All QR codes and settings saved to NocoDB
|
||||
- **Real-time Preview**: See changes immediately on the admin map
|
||||
- **Validation**: Built-in coordinate and zoom level validation
|
||||
|
||||
### Access Control
|
||||
|
||||
- Admin access is controlled via the `Admin` checkbox in the Login table
|
||||
- Only authenticated users with admin privileges can access `/admin.html`
|
||||
- Admin status is checked on every request to admin endpoints
|
||||
|
||||
### Start Location Priority
|
||||
|
||||
The system uses a cascading fallback system for map start location:
|
||||
1. **Database**: Admin-configured location stored in Settings table (highest priority)
|
||||
2. **Environment**: Default values from .env file (medium priority)
|
||||
@ -209,19 +168,16 @@ To run in development mode:
|
||||
## Troubleshooting
|
||||
|
||||
### Locations not showing
|
||||
|
||||
- Verify table has `geodata`, `latitude`, and `longitude` columns
|
||||
- Check that coordinates are valid numbers
|
||||
- Ensure API token has read permissions
|
||||
|
||||
### Cannot add locations
|
||||
|
||||
- Verify API token has write permissions
|
||||
- Check browser console for errors
|
||||
- Ensure coordinates are within valid ranges
|
||||
|
||||
### Connection errors
|
||||
|
||||
- Verify NocoDB instance is accessible
|
||||
- Check API URL format
|
||||
- Confirm network connectivity
|
||||
|
||||
414
map/app/package-lock.json
generated
414
map/app/package-lock.json
generated
@ -16,10 +16,7 @@
|
||||
"express": "^4.18.2",
|
||||
"express-rate-limit": "^7.1.4",
|
||||
"express-session": "^1.18.1",
|
||||
"form-data": "^4.0.0",
|
||||
"helmet": "^7.1.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"qrcode": "^1.5.3",
|
||||
"winston": "^3.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -68,44 +65,6 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-regex": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
|
||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"dependencies": {
|
||||
"color-convert": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-styles/node_modules/color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"dependencies": {
|
||||
"color-name": "~1.1.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ansi-styles/node_modules/color-name": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||
},
|
||||
"node_modules/anymatch": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz",
|
||||
@ -120,11 +79,6 @@
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/append-field": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz",
|
||||
"integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw=="
|
||||
},
|
||||
"node_modules/array-flatten": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
@ -222,22 +176,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ=="
|
||||
},
|
||||
"node_modules/busboy": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
|
||||
"integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
|
||||
"dependencies": {
|
||||
"streamsearch": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes": {
|
||||
"version": "3.1.2",
|
||||
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
|
||||
@ -276,14 +214,6 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/camelcase": {
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz",
|
||||
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/chokidar": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||
@ -309,16 +239,6 @@
|
||||
"fsevents": "~2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/cliui": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
|
||||
"integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==",
|
||||
"dependencies": {
|
||||
"string-width": "^4.2.0",
|
||||
"strip-ansi": "^6.0.0",
|
||||
"wrap-ansi": "^6.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/color": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/color/-/color-3.2.1.tgz",
|
||||
@ -383,47 +303,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/concat-stream": {
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz",
|
||||
"integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==",
|
||||
"engines": [
|
||||
"node >= 0.8"
|
||||
],
|
||||
"dependencies": {
|
||||
"buffer-from": "^1.0.0",
|
||||
"inherits": "^2.0.3",
|
||||
"readable-stream": "^2.2.2",
|
||||
"typedarray": "^0.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-stream/node_modules/readable-stream": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz",
|
||||
"integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==",
|
||||
"dependencies": {
|
||||
"core-util-is": "~1.0.0",
|
||||
"inherits": "~2.0.3",
|
||||
"isarray": "~1.0.0",
|
||||
"process-nextick-args": "~2.0.0",
|
||||
"safe-buffer": "~5.1.1",
|
||||
"string_decoder": "~1.1.1",
|
||||
"util-deprecate": "~1.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/concat-stream/node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||
},
|
||||
"node_modules/concat-stream/node_modules/string_decoder": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
|
||||
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
|
||||
"dependencies": {
|
||||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/content-disposition": {
|
||||
"version": "0.5.4",
|
||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||
@ -482,11 +361,6 @@
|
||||
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
|
||||
},
|
||||
"node_modules/cors": {
|
||||
"version": "2.8.5",
|
||||
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
|
||||
@ -509,14 +383,6 @@
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/decamelize": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
|
||||
"integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
@ -545,11 +411,6 @@
|
||||
"npm": "1.2.8000 || >= 1.4.16"
|
||||
}
|
||||
},
|
||||
"node_modules/dijkstrajs": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dijkstrajs/-/dijkstrajs-1.0.3.tgz",
|
||||
"integrity": "sha512-qiSlmBq9+BCdCA/L46dw8Uy93mloxsPSbwnm5yrKn2vMPiy8KyAskTF6zuV/j5BMsmOGZDPs7KjU+mjb670kfA=="
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.5.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.5.0.tgz",
|
||||
@ -582,11 +443,6 @@
|
||||
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/emoji-regex": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
|
||||
},
|
||||
"node_modules/enabled": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/enabled/-/enabled-2.0.0.tgz",
|
||||
@ -794,18 +650,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/find-up": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz",
|
||||
"integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==",
|
||||
"dependencies": {
|
||||
"locate-path": "^5.0.0",
|
||||
"path-exists": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/fn.name": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/fn.name/-/fn.name-1.1.0.tgz",
|
||||
@ -890,14 +734,6 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/get-caller-file": {
|
||||
"version": "2.0.5",
|
||||
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
|
||||
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
|
||||
"engines": {
|
||||
"node": "6.* || 8.* || >= 10.*"
|
||||
}
|
||||
},
|
||||
"node_modules/get-intrinsic": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
|
||||
@ -1097,14 +933,6 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/is-fullwidth-code-point": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/is-glob": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
|
||||
@ -1140,28 +968,12 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ=="
|
||||
},
|
||||
"node_modules/kuler": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/kuler/-/kuler-2.0.0.tgz",
|
||||
"integrity": "sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/locate-path": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz",
|
||||
"integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==",
|
||||
"dependencies": {
|
||||
"p-locate": "^4.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/logform": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/logform/-/logform-2.7.0.tgz",
|
||||
@ -1267,49 +1079,12 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/minimist": {
|
||||
"version": "1.2.8",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
|
||||
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/mkdirp": {
|
||||
"version": "0.5.6",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz",
|
||||
"integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==",
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.6"
|
||||
},
|
||||
"bin": {
|
||||
"mkdirp": "bin/cmd.js"
|
||||
}
|
||||
},
|
||||
"node_modules/ms": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/multer": {
|
||||
"version": "1.4.5-lts.2",
|
||||
"resolved": "https://registry.npmjs.org/multer/-/multer-1.4.5-lts.2.tgz",
|
||||
"integrity": "sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==",
|
||||
"deprecated": "Multer 1.x is impacted by a number of vulnerabilities, which have been patched in 2.x. You should upgrade to the latest 2.x version.",
|
||||
"dependencies": {
|
||||
"append-field": "^1.0.0",
|
||||
"busboy": "^1.0.0",
|
||||
"concat-stream": "^1.5.2",
|
||||
"mkdirp": "^0.5.4",
|
||||
"object-assign": "^4.1.1",
|
||||
"type-is": "^1.6.4",
|
||||
"xtend": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/negotiator": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
|
||||
@ -1434,39 +1209,6 @@
|
||||
"fn.name": "1.x.x"
|
||||
}
|
||||
},
|
||||
"node_modules/p-limit": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
|
||||
"integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
|
||||
"dependencies": {
|
||||
"p-try": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-locate": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz",
|
||||
"integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==",
|
||||
"dependencies": {
|
||||
"p-limit": "^2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||
"integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/parseurl": {
|
||||
"version": "1.3.3",
|
||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||
@ -1476,14 +1218,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-exists": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
|
||||
"integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/path-to-regexp": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
|
||||
@ -1503,19 +1237,6 @@
|
||||
"url": "https://github.com/sponsors/jonschlinkert"
|
||||
}
|
||||
},
|
||||
"node_modules/pngjs": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",
|
||||
"integrity": "sha512-40QW5YalBNfQo5yRYmiw7Yz6TKKVr3h6970B2YE+3fQpsWcrbj1PzJgxeJ19DRQjhMbKPIuMY8rFaXc8moolVw==",
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
||||
},
|
||||
"node_modules/proxy-addr": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
|
||||
@ -1542,22 +1263,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/qrcode": {
|
||||
"version": "1.5.4",
|
||||
"resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz",
|
||||
"integrity": "sha512-1ca71Zgiu6ORjHqFBDpnSMTR2ReToX4l1Au1VFLyVeBTFavzQnv5JxMFr3ukHVKpSrSA2MCk0lNJSykjUfz7Zg==",
|
||||
"dependencies": {
|
||||
"dijkstrajs": "^1.0.1",
|
||||
"pngjs": "^5.0.0",
|
||||
"yargs": "^15.3.1"
|
||||
},
|
||||
"bin": {
|
||||
"qrcode": "bin/qrcode"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.13.0"
|
||||
}
|
||||
},
|
||||
"node_modules/qs": {
|
||||
"version": "6.13.0",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
|
||||
@ -1633,19 +1338,6 @@
|
||||
"node": ">=8.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-directory": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||
"integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==",
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/require-main-filename": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz",
|
||||
"integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg=="
|
||||
},
|
||||
"node_modules/safe-buffer": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||
@ -1748,11 +1440,6 @@
|
||||
"node": ">= 0.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/set-blocking": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
|
||||
"integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw=="
|
||||
},
|
||||
"node_modules/setprototypeof": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||
@ -1871,14 +1558,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/streamsearch": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
|
||||
"integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
@ -1888,30 +1567,6 @@
|
||||
"safe-buffer": "~5.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/string-width": {
|
||||
"version": "4.2.3",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
|
||||
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
|
||||
"dependencies": {
|
||||
"emoji-regex": "^8.0.0",
|
||||
"is-fullwidth-code-point": "^3.0.0",
|
||||
"strip-ansi": "^6.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/strip-ansi": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
|
||||
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||
@ -1985,11 +1640,6 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/typedarray": {
|
||||
"version": "0.0.6",
|
||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA=="
|
||||
},
|
||||
"node_modules/uid-safe": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz",
|
||||
@ -2042,11 +1692,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/which-module": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz",
|
||||
"integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ=="
|
||||
},
|
||||
"node_modules/winston": {
|
||||
"version": "3.17.0",
|
||||
"resolved": "https://registry.npmjs.org/winston/-/winston-3.17.0.tgz",
|
||||
@ -2082,65 +1727,6 @@
|
||||
"engines": {
|
||||
"node": ">= 12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/wrap-ansi": {
|
||||
"version": "6.2.0",
|
||||
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz",
|
||||
"integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==",
|
||||
"dependencies": {
|
||||
"ansi-styles": "^4.0.0",
|
||||
"string-width": "^4.1.0",
|
||||
"strip-ansi": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/xtend": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
||||
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/y18n": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
|
||||
"integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ=="
|
||||
},
|
||||
"node_modules/yargs": {
|
||||
"version": "15.4.1",
|
||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz",
|
||||
"integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==",
|
||||
"dependencies": {
|
||||
"cliui": "^6.0.0",
|
||||
"decamelize": "^1.2.0",
|
||||
"find-up": "^4.1.0",
|
||||
"get-caller-file": "^2.0.1",
|
||||
"require-directory": "^2.1.1",
|
||||
"require-main-filename": "^2.0.0",
|
||||
"set-blocking": "^2.0.0",
|
||||
"string-width": "^4.2.0",
|
||||
"which-module": "^2.0.0",
|
||||
"y18n": "^4.0.0",
|
||||
"yargs-parser": "^18.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/yargs-parser": {
|
||||
"version": "18.1.3",
|
||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz",
|
||||
"integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==",
|
||||
"dependencies": {
|
||||
"camelcase": "^5.0.0",
|
||||
"decamelize": "^1.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,10 +25,7 @@
|
||||
"express": "^4.18.2",
|
||||
"express-rate-limit": "^7.1.4",
|
||||
"express-session": "^1.18.1",
|
||||
"form-data": "^4.0.0",
|
||||
"helmet": "^7.1.0",
|
||||
"multer": "^1.4.5-lts.1",
|
||||
"qrcode": "^1.5.3",
|
||||
"winston": "^3.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
<h2>Settings</h2>
|
||||
<nav class="admin-nav">
|
||||
<a href="#start-location" class="active">Start Location</a>
|
||||
<a href="#walk-sheet">Walk Sheet</a>
|
||||
<!-- Future menu items can go here -->
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
@ -76,104 +76,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Walk Sheet Section -->
|
||||
<section id="walk-sheet" class="admin-section" style="display: none;">
|
||||
<h2>Walk Sheet Configuration</h2>
|
||||
<p>Design and configure printable walk sheets for door-to-door canvassing.</p>
|
||||
|
||||
<div class="walk-sheet-container">
|
||||
<div class="walk-sheet-config">
|
||||
<h3>Sheet Information</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="walk-sheet-title">Sheet Title</label>
|
||||
<input type="text" id="walk-sheet-title" placeholder="Campaign Walk Sheet">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="walk-sheet-subtitle">Subtitle</label>
|
||||
<input type="text" id="walk-sheet-subtitle" placeholder="Door-to-Door Canvassing Form">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="walk-sheet-footer">Footer Text</label>
|
||||
<textarea id="walk-sheet-footer" rows="3" placeholder="Contact info, legal text, etc."></textarea>
|
||||
</div>
|
||||
|
||||
<h3>QR Codes</h3>
|
||||
<p class="help-text-inline">Add up to 3 QR codes for quick access to digital resources.</p>
|
||||
|
||||
<!-- QR Code 1 -->
|
||||
<div class="qr-code-group">
|
||||
<h4>QR Code 1</h4>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="qr-code-1-url">URL</label>
|
||||
<input type="url" id="qr-code-1-url" placeholder="https://example.com/signup">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="qr-code-1-label">Label</label>
|
||||
<input type="text" id="qr-code-1-label" placeholder="Sign Up">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- QR Code 2 -->
|
||||
<div class="qr-code-group">
|
||||
<h4>QR Code 2</h4>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="qr-code-2-url">URL</label>
|
||||
<input type="url" id="qr-code-2-url" placeholder="https://example.com/donate">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="qr-code-2-label">Label</label>
|
||||
<input type="text" id="qr-code-2-label" placeholder="Donate">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- QR Code 3 -->
|
||||
<div class="qr-code-group">
|
||||
<h4>QR Code 3</h4>
|
||||
<div class="form-row">
|
||||
<div class="form-group">
|
||||
<label for="qr-code-3-url">URL</label>
|
||||
<input type="url" id="qr-code-3-url" placeholder="https://example.com/volunteer">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="qr-code-3-label">Label</label>
|
||||
<input type="text" id="qr-code-3-label" placeholder="Volunteer">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-actions">
|
||||
<button id="save-walk-sheet" class="btn btn-primary">
|
||||
Save Configuration
|
||||
</button>
|
||||
<button id="preview-walk-sheet" class="btn btn-secondary">
|
||||
Preview Sheet
|
||||
</button>
|
||||
<button id="print-walk-sheet" class="btn btn-secondary">
|
||||
🖨️ Print Sheet
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="walk-sheet-preview">
|
||||
<h3>Preview</h3>
|
||||
<div class="preview-controls">
|
||||
<button id="refresh-preview" class="btn btn-sm btn-secondary">Refresh</button>
|
||||
<span class="preview-info">8.5" x 11" format</span>
|
||||
</div>
|
||||
<div id="walk-sheet-preview-content" class="walk-sheet-page">
|
||||
<!-- Preview content will be generated here -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -186,9 +88,6 @@
|
||||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
||||
crossorigin=""></script>
|
||||
|
||||
<!-- QR Code Library -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/build/qrcode.min.js"></script>
|
||||
|
||||
<!-- Admin JavaScript -->
|
||||
<script src="js/admin.js"></script>
|
||||
</body>
|
||||
|
||||
@ -228,271 +228,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* Walk Sheet Styles */
|
||||
.walk-sheet-container {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.walk-sheet-config {
|
||||
background-color: #f9f9f9;
|
||||
padding: 20px;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.walk-sheet-config h3 {
|
||||
font-size: 16px;
|
||||
margin-bottom: 15px;
|
||||
color: var(--dark-color);
|
||||
}
|
||||
|
||||
.qr-code-group {
|
||||
background-color: white;
|
||||
padding: 15px;
|
||||
border-radius: var(--border-radius);
|
||||
margin-bottom: 15px;
|
||||
border: 1px solid #e0e0e0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.qr-code-group h4 {
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 1fr;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.help-text-inline {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
/* Walk Sheet Preview */
|
||||
.walk-sheet-preview {
|
||||
background-color: #f5f5f5;
|
||||
padding: 20px;
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
|
||||
.walk-sheet-preview h3 {
|
||||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
color: var(--dark-color);
|
||||
}
|
||||
|
||||
.preview-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.preview-info {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* Walk Sheet Page (8.5 x 11 preview) */
|
||||
.walk-sheet-page {
|
||||
width: 100%;
|
||||
max-width: 425px; /* Half of 8.5 inches at 100dpi */
|
||||
aspect-ratio: 8.5 / 11;
|
||||
background: white;
|
||||
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
||||
padding: 20px;
|
||||
margin: 0 auto;
|
||||
overflow: auto;
|
||||
font-size: 10px;
|
||||
line-height: 1.4;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Walk Sheet Print Styles */
|
||||
@media print {
|
||||
body * {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.walk-sheet-page, .walk-sheet-page * {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
.walk-sheet-page {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 8.5in;
|
||||
height: 11in;
|
||||
max-width: none;
|
||||
padding: 0.5in;
|
||||
margin: 0;
|
||||
box-shadow: none;
|
||||
font-size: 12pt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Walk Sheet Content Styles */
|
||||
.ws-header {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
border-bottom: 2px solid #333;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.ws-title {
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ws-subtitle {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin: 5px 0 0 0;
|
||||
}
|
||||
|
||||
.ws-qr-section {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin: 20px 0;
|
||||
padding: 15px;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.ws-qr-item {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ws-qr-code {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.ws-qr-code img {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
image-rendering: crisp-edges;
|
||||
image-rendering: -webkit-crisp-edges;
|
||||
image-rendering: pixelated;
|
||||
image-rendering: -moz-crisp-edges;
|
||||
}
|
||||
|
||||
.ws-qr-label {
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.ws-form-section {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.ws-form-row {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.ws-form-group {
|
||||
border-bottom: 1px solid #ccc;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.ws-form-label {
|
||||
font-size: 9px;
|
||||
color: #666;
|
||||
display: block;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.ws-form-field {
|
||||
height: 20px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.ws-notes-section {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.ws-notes-label {
|
||||
font-size: 10px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.ws-notes-area {
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
border: 1px solid #ccc;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.ws-footer {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
text-align: center;
|
||||
font-size: 9px;
|
||||
color: #666;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid #ccc;
|
||||
}
|
||||
|
||||
/* QR Code Generation Status */
|
||||
.qr-code-group.generating::after {
|
||||
content: 'Generating QR Code...';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
font-size: 12px;
|
||||
color: var(--primary-color);
|
||||
background: white;
|
||||
padding: 2px 8px;
|
||||
border-radius: 3px;
|
||||
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
/* Loading state for save button */
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* QR code stored indicator */
|
||||
.qr-status {
|
||||
font-size: 12px;
|
||||
color: var(--success-color);
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.qr-status.stored {
|
||||
color: var(--success-color);
|
||||
}
|
||||
|
||||
.qr-status.pending {
|
||||
color: var(--warning-color);
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 1200px) {
|
||||
.walk-sheet-container {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.walk-sheet-preview {
|
||||
order: -1;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.admin-container {
|
||||
flex-direction: column;
|
||||
@ -519,15 +255,6 @@
|
||||
.admin-section {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.form-row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.walk-sheet-page {
|
||||
font-size: 8px;
|
||||
padding: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
/* CSS Variables (define these in style.css if not already defined) */
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
// Admin panel JavaScript
|
||||
let adminMap = null;
|
||||
let startMarker = null;
|
||||
let storedQRCodes = {};
|
||||
|
||||
// Initialize when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
@ -9,8 +8,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
initializeAdminMap();
|
||||
loadCurrentStartLocation();
|
||||
setupEventListeners();
|
||||
setupNavigation();
|
||||
loadWalkSheetConfig();
|
||||
});
|
||||
|
||||
// Check if user is authenticated as admin
|
||||
@ -147,38 +144,6 @@ function setupEventListeners() {
|
||||
document.getElementById('start-lat').addEventListener('change', updateMapFromInputs);
|
||||
document.getElementById('start-lng').addEventListener('change', updateMapFromInputs);
|
||||
document.getElementById('start-zoom').addEventListener('change', updateMapFromInputs);
|
||||
|
||||
// Walk Sheet buttons
|
||||
document.getElementById('save-walk-sheet').addEventListener('click', saveWalkSheetConfig);
|
||||
document.getElementById('preview-walk-sheet').addEventListener('click', generateWalkSheetPreview);
|
||||
document.getElementById('print-walk-sheet').addEventListener('click', printWalkSheet);
|
||||
document.getElementById('refresh-preview').addEventListener('click', generateWalkSheetPreview);
|
||||
|
||||
// Auto-update preview on input change
|
||||
const walkSheetInputs = document.querySelectorAll(
|
||||
'#walk-sheet-title, #walk-sheet-subtitle, #walk-sheet-footer, ' +
|
||||
'[id^="qr-code-"][id$="-url"], [id^="qr-code-"][id$="-label"]'
|
||||
);
|
||||
|
||||
walkSheetInputs.forEach(input => {
|
||||
input.addEventListener('input', debounce(() => {
|
||||
generateWalkSheetPreview();
|
||||
}, 500));
|
||||
});
|
||||
|
||||
// Add URL change listeners to detect when QR codes need regeneration
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
const urlInput = document.getElementById(`qr-code-${i}-url`);
|
||||
let previousUrl = urlInput.value;
|
||||
|
||||
urlInput.addEventListener('change', () => {
|
||||
if (urlInput.value !== previousUrl) {
|
||||
// URL changed, clear stored QR code
|
||||
delete storedQRCodes[i];
|
||||
previousUrl = urlInput.value;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Update map from input fields
|
||||
@ -242,276 +207,6 @@ async function saveStartLocation() {
|
||||
}
|
||||
}
|
||||
|
||||
// Save walk sheet configuration
|
||||
async function saveWalkSheetConfig() {
|
||||
const config = {
|
||||
walk_sheet_title: document.getElementById('walk-sheet-title').value,
|
||||
walk_sheet_subtitle: document.getElementById('walk-sheet-subtitle').value,
|
||||
walk_sheet_footer: document.getElementById('walk-sheet-footer').value,
|
||||
qr_code_1_url: document.getElementById('qr-code-1-url').value,
|
||||
qr_code_1_label: document.getElementById('qr-code-1-label').value,
|
||||
qr_code_2_url: document.getElementById('qr-code-2-url').value,
|
||||
qr_code_2_label: document.getElementById('qr-code-2-label').value,
|
||||
qr_code_3_url: document.getElementById('qr-code-3-url').value,
|
||||
qr_code_3_label: document.getElementById('qr-code-3-label').value
|
||||
};
|
||||
|
||||
// Show loading state
|
||||
const saveButton = document.getElementById('save-walk-sheet');
|
||||
const originalText = saveButton.textContent;
|
||||
saveButton.textContent = 'Saving...';
|
||||
saveButton.disabled = true;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/admin/walk-sheet-config', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(config)
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
showStatus('Walk sheet configuration saved successfully!', 'success');
|
||||
|
||||
// Update stored QR codes if new ones were generated
|
||||
if (data.qrCodes) {
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
if (data.qrCodes[`qr_code_${i}_image`]) {
|
||||
storedQRCodes[i] = data.qrCodes[`qr_code_${i}_image`];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh preview with new QR codes
|
||||
generateWalkSheetPreview();
|
||||
} else {
|
||||
throw new Error(data.error || 'Failed to save');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Save error:', error);
|
||||
showStatus(error.message || 'Failed to save walk sheet configuration', 'error');
|
||||
} finally {
|
||||
saveButton.textContent = originalText;
|
||||
saveButton.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate walk sheet preview
|
||||
function generateWalkSheetPreview() {
|
||||
const title = document.getElementById('walk-sheet-title').value || 'Campaign Walk Sheet';
|
||||
const subtitle = document.getElementById('walk-sheet-subtitle').value || 'Door-to-Door Canvassing Form';
|
||||
const footer = document.getElementById('walk-sheet-footer').value || 'Thank you for your support!';
|
||||
|
||||
let previewHTML = `
|
||||
<div class="ws-header">
|
||||
<h1 class="ws-title">${escapeHtml(title)}</h1>
|
||||
<p class="ws-subtitle">${escapeHtml(subtitle)}</p>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Add QR codes section
|
||||
const qrCodesHTML = [];
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
const url = document.getElementById(`qr-code-${i}-url`).value;
|
||||
const label = document.getElementById(`qr-code-${i}-label`).value;
|
||||
|
||||
if (url) {
|
||||
// Check if we have a stored QR code image
|
||||
if (storedQRCodes[i] && storedQRCodes[i].url) {
|
||||
// Use stored QR code image
|
||||
qrCodesHTML.push(`
|
||||
<div class="ws-qr-item">
|
||||
<div class="ws-qr-code">
|
||||
<img src="${storedQRCodes[i].url}" alt="QR Code ${i}" style="width: 80px; height: 80px;">
|
||||
</div>
|
||||
<div class="ws-qr-label">${escapeHtml(label) || `QR Code ${i}`}</div>
|
||||
</div>
|
||||
`);
|
||||
} else {
|
||||
// Generate QR code client-side as fallback
|
||||
qrCodesHTML.push(`
|
||||
<div class="ws-qr-item">
|
||||
<div class="ws-qr-code" id="preview-qr-${i}"></div>
|
||||
<div class="ws-qr-label">${escapeHtml(label) || `QR Code ${i}`}</div>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qrCodesHTML.length > 0) {
|
||||
previewHTML += `
|
||||
<div class="ws-qr-section">
|
||||
${qrCodesHTML.join('')}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
// Add form fields based on the main map form
|
||||
previewHTML += `
|
||||
<div class="ws-form-section">
|
||||
<div class="ws-form-row">
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">First Name</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Last Name</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ws-form-row">
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Email</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Phone</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ws-form-row">
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Address</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Unit Number</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ws-form-row">
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Support Level (1-4)</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Sign Request ☐ Yes ☐ No</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ws-form-row">
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Category</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
<div class="ws-form-group">
|
||||
<label class="ws-form-label">Visited Date</label>
|
||||
<div class="ws-form-field"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="ws-notes-section">
|
||||
<div class="ws-notes-label">Notes & Comments</div>
|
||||
<div class="ws-notes-area"></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Update preview
|
||||
const previewContent = document.getElementById('walk-sheet-preview-content');
|
||||
previewContent.innerHTML = previewHTML;
|
||||
|
||||
// Add footer (positioned absolutely in CSS)
|
||||
if (footer) {
|
||||
const footerDiv = document.createElement('div');
|
||||
footerDiv.className = 'ws-footer';
|
||||
footerDiv.innerHTML = escapeHtml(footer);
|
||||
previewContent.appendChild(footerDiv);
|
||||
}
|
||||
|
||||
// Generate client-side QR codes for items without stored images
|
||||
setTimeout(() => {
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
const url = document.getElementById(`qr-code-${i}-url`).value;
|
||||
if (url && !storedQRCodes[i]) {
|
||||
const qrContainer = document.getElementById(`preview-qr-${i}`);
|
||||
if (qrContainer && typeof QRCode !== 'undefined') {
|
||||
qrContainer.innerHTML = '';
|
||||
new QRCode(qrContainer, {
|
||||
text: url,
|
||||
width: 80,
|
||||
height: 80,
|
||||
correctLevel: QRCode.CorrectLevel.M
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// Print walk sheet
|
||||
function printWalkSheet() {
|
||||
// First generate fresh preview
|
||||
generateWalkSheetPreview();
|
||||
|
||||
// Wait for QR codes to generate
|
||||
setTimeout(() => {
|
||||
window.print();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// Setup navigation between sections
|
||||
function setupNavigation() {
|
||||
const navLinks = document.querySelectorAll('.admin-nav a');
|
||||
const sections = document.querySelectorAll('.admin-section');
|
||||
|
||||
navLinks.forEach(link => {
|
||||
link.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const targetId = link.getAttribute('href').substring(1);
|
||||
|
||||
// Update active states
|
||||
navLinks.forEach(l => l.classList.remove('active'));
|
||||
link.classList.add('active');
|
||||
|
||||
// Show/hide sections
|
||||
sections.forEach(section => {
|
||||
section.style.display = section.id === targetId ? 'block' : 'none';
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Load walk sheet configuration
|
||||
async function loadWalkSheetConfig() {
|
||||
try {
|
||||
const response = await fetch('/api/admin/walk-sheet-config');
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success && data.config) {
|
||||
// Populate form fields
|
||||
document.getElementById('walk-sheet-title').value = data.config.walk_sheet_title || '';
|
||||
document.getElementById('walk-sheet-subtitle').value = data.config.walk_sheet_subtitle || '';
|
||||
document.getElementById('walk-sheet-footer').value = data.config.walk_sheet_footer || '';
|
||||
|
||||
// QR codes
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
document.getElementById(`qr-code-${i}-url`).value = data.config[`qr_code_${i}_url`] || '';
|
||||
document.getElementById(`qr-code-${i}-label`).value = data.config[`qr_code_${i}_label`] || '';
|
||||
|
||||
// Store QR code image data if available
|
||||
if (data.config[`qr_code_${i}_image`]) {
|
||||
storedQRCodes[i] = data.config[`qr_code_${i}_image`];
|
||||
}
|
||||
}
|
||||
|
||||
// Generate preview
|
||||
generateWalkSheetPreview();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load walk sheet config:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle logout
|
||||
async function handleLogout() {
|
||||
if (!confirm('Are you sure you want to logout?')) {
|
||||
@ -562,16 +257,3 @@ function escapeHtml(text) {
|
||||
div.textContent = String(text);
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Debounce function for input events
|
||||
function debounce(func, wait) {
|
||||
let timeout;
|
||||
return function executedFunction(...args) {
|
||||
const later = () => {
|
||||
clearTimeout(timeout);
|
||||
func(...args);
|
||||
};
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
};
|
||||
}
|
||||
|
||||
@ -12,9 +12,6 @@ require('dotenv').config();
|
||||
// Import geocoding routes
|
||||
const geocodingRoutes = require('./routes/geocoding');
|
||||
|
||||
// Import QR code service
|
||||
const { generateAndUploadQRCode, deleteQRCodeFromNocoDB } = require('./services/qrcode');
|
||||
|
||||
// Parse project and table IDs from view URL
|
||||
function parseNocoDBUrl(url) {
|
||||
if (!url) return { projectId: null, tableId: null };
|
||||
@ -677,216 +674,6 @@ app.get('/api/config/start-location', async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Get walk sheet configuration
|
||||
app.get('/api/admin/walk-sheet-config', requireAdmin, async (req, res) => {
|
||||
try {
|
||||
if (!SETTINGS_SHEET_ID) {
|
||||
return res.json({
|
||||
success: true,
|
||||
config: null,
|
||||
source: 'defaults'
|
||||
});
|
||||
}
|
||||
|
||||
// Get all settings
|
||||
const response = await axios.get(
|
||||
`${process.env.NOCODB_API_URL}/api/v1/base/${process.env.NOCODB_PROJECT_ID}/tables/${SETTINGS_SHEET_ID}/rows`,
|
||||
{
|
||||
headers: {
|
||||
'xc-auth': process.env.NOCODB_API_TOKEN
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.data?.list || response.data.list.length === 0) {
|
||||
return res.json({
|
||||
success: true,
|
||||
config: null,
|
||||
source: 'defaults'
|
||||
});
|
||||
}
|
||||
|
||||
// Find walk sheet settings
|
||||
const walkSheetSettings = {};
|
||||
const settingKeys = [
|
||||
'walk_sheet_title', 'walk_sheet_subtitle', 'walk_sheet_footer',
|
||||
'qr_code_1_url', 'qr_code_1_label', 'qr_code_1_image',
|
||||
'qr_code_2_url', 'qr_code_2_label', 'qr_code_2_image',
|
||||
'qr_code_3_url', 'qr_code_3_label', 'qr_code_3_image'
|
||||
];
|
||||
|
||||
for (const setting of response.data.list) {
|
||||
if (settingKeys.includes(setting.key)) {
|
||||
if (setting.key.includes('_image') && setting.value) {
|
||||
// Parse image data if stored as JSON string
|
||||
try {
|
||||
walkSheetSettings[setting.key] = JSON.parse(setting.value);
|
||||
} catch {
|
||||
walkSheetSettings[setting.key] = setting.value;
|
||||
}
|
||||
} else {
|
||||
walkSheetSettings[setting.key] = setting.value || setting.title || '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
config: walkSheetSettings,
|
||||
source: 'database'
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Failed to get walk sheet config:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: 'Failed to retrieve walk sheet configuration'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Save walk sheet configuration
|
||||
app.post('/api/admin/walk-sheet-config', requireAdmin, async (req, res) => {
|
||||
try {
|
||||
if (!SETTINGS_SHEET_ID) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
error: 'Settings sheet not configured'
|
||||
});
|
||||
}
|
||||
|
||||
const config = req.body;
|
||||
const userEmail = req.session.userEmail;
|
||||
const timestamp = new Date().toISOString();
|
||||
|
||||
// NocoDB configuration
|
||||
const nocodbConfig = {
|
||||
apiUrl: process.env.NOCODB_API_URL,
|
||||
apiToken: process.env.NOCODB_API_TOKEN,
|
||||
projectId: process.env.NOCODB_PROJECT_ID,
|
||||
tableId: SETTINGS_SHEET_ID
|
||||
};
|
||||
|
||||
// Get existing settings
|
||||
const getResponse = await axios.get(
|
||||
`${process.env.NOCODB_API_URL}/api/v1/base/${process.env.NOCODB_PROJECT_ID}/tables/${SETTINGS_SHEET_ID}/rows`,
|
||||
{
|
||||
headers: {
|
||||
'xc-auth': process.env.NOCODB_API_TOKEN
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const existingSettings = getResponse.data?.list || [];
|
||||
|
||||
// Process QR codes
|
||||
const qrCodeUploads = {};
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
const url = config[`qr_code_${i}_url`];
|
||||
const label = config[`qr_code_${i}_label`] || `QR Code ${i}`;
|
||||
|
||||
if (url) {
|
||||
try {
|
||||
// Check if URL has changed
|
||||
const existingUrlSetting = existingSettings.find(s => s.key === `qr_code_${i}_url`);
|
||||
const urlChanged = !existingUrlSetting || existingUrlSetting.value !== url;
|
||||
|
||||
if (urlChanged) {
|
||||
// Generate and upload new QR code
|
||||
const uploadResult = await generateAndUploadQRCode(url, label, nocodbConfig);
|
||||
if (uploadResult) {
|
||||
qrCodeUploads[`qr_code_${i}_image`] = uploadResult;
|
||||
|
||||
// Delete old QR code if exists
|
||||
const existingImageSetting = existingSettings.find(s => s.key === `qr_code_${i}_image`);
|
||||
if (existingImageSetting?.value) {
|
||||
await deleteQRCodeFromNocoDB(existingImageSetting.value, nocodbConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`Failed to process QR code ${i}:`, error);
|
||||
}
|
||||
} else {
|
||||
// If URL is empty, delete existing QR code
|
||||
const existingImageSetting = existingSettings.find(s => s.key === `qr_code_${i}_image`);
|
||||
if (existingImageSetting?.value) {
|
||||
await deleteQRCodeFromNocoDB(existingImageSetting.value, nocodbConfig);
|
||||
}
|
||||
qrCodeUploads[`qr_code_${i}_image`] = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Update or create each setting
|
||||
const allSettings = { ...config, ...qrCodeUploads };
|
||||
|
||||
for (const [key, value] of Object.entries(allSettings)) {
|
||||
const existingSetting = existingSettings.find(s => s.key === key);
|
||||
|
||||
let settingData = {
|
||||
key: key,
|
||||
title: typeof value === 'string' ? value : '',
|
||||
category: 'walk_sheet_setting',
|
||||
updated_by: userEmail,
|
||||
updated_at: timestamp
|
||||
};
|
||||
|
||||
// Handle different value types
|
||||
if (key.includes('_image') && value) {
|
||||
// For image attachments
|
||||
settingData.value = JSON.stringify(value);
|
||||
settingData[key] = value; // Also set the attachment field directly
|
||||
} else {
|
||||
settingData.value = value || '';
|
||||
}
|
||||
|
||||
if (existingSetting) {
|
||||
// Update existing
|
||||
await axios.put(
|
||||
`${process.env.NOCODB_API_URL}/api/v1/base/${process.env.NOCODB_PROJECT_ID}/tables/${SETTINGS_SHEET_ID}/rows/${existingSetting.Id}`,
|
||||
settingData,
|
||||
{
|
||||
headers: {
|
||||
'xc-auth': process.env.NOCODB_API_TOKEN,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// Create new
|
||||
await axios.post(
|
||||
`${process.env.NOCODB_API_URL}/api/v1/base/${process.env.NOCODB_PROJECT_ID}/tables/${SETTINGS_SHEET_ID}/rows`,
|
||||
settingData,
|
||||
{
|
||||
headers: {
|
||||
'xc-auth': process.env.NOCODB_API_TOKEN,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Walk sheet configuration saved successfully',
|
||||
qrCodes: Object.keys(qrCodeUploads).reduce((acc, key) => {
|
||||
if (qrCodeUploads[key]) {
|
||||
acc[key] = qrCodeUploads[key];
|
||||
}
|
||||
return acc;
|
||||
}, {})
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Failed to save walk sheet config:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: 'Failed to save walk sheet configuration'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Debug session endpoint
|
||||
app.get('/api/debug/session', (req, res) => {
|
||||
res.json({
|
||||
|
||||
@ -1,155 +0,0 @@
|
||||
const QRCode = require('qrcode');
|
||||
const axios = require('axios');
|
||||
const FormData = require('form-data');
|
||||
const winston = require('winston');
|
||||
|
||||
// Configure logger
|
||||
const logger = winston.createLogger({
|
||||
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.json()
|
||||
),
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
format: winston.format.simple()
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* Generate QR code as PNG buffer
|
||||
* @param {string} text - Text/URL to encode
|
||||
* @param {Object} options - QR code options
|
||||
* @returns {Promise<Buffer>} PNG buffer
|
||||
*/
|
||||
async function generateQRCode(text, options = {}) {
|
||||
const defaultOptions = {
|
||||
type: 'png',
|
||||
width: 256,
|
||||
margin: 1,
|
||||
color: {
|
||||
dark: '#000000',
|
||||
light: '#FFFFFF'
|
||||
},
|
||||
errorCorrectionLevel: 'M'
|
||||
};
|
||||
|
||||
const qrOptions = { ...defaultOptions, ...options };
|
||||
|
||||
try {
|
||||
const buffer = await QRCode.toBuffer(text, qrOptions);
|
||||
return buffer;
|
||||
} catch (error) {
|
||||
logger.error('Failed to generate QR code:', error);
|
||||
throw new Error('Failed to generate QR code');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload QR code to NocoDB storage
|
||||
* @param {Buffer} buffer - PNG buffer
|
||||
* @param {string} filename - Filename for the upload
|
||||
* @param {Object} config - NocoDB configuration
|
||||
* @returns {Promise<Object>} Upload response
|
||||
*/
|
||||
async function uploadQRCodeToNocoDB(buffer, filename, config) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', buffer, {
|
||||
filename: filename,
|
||||
contentType: 'image/png'
|
||||
});
|
||||
|
||||
try {
|
||||
const response = await axios({
|
||||
url: `${config.apiUrl}/api/v2/storage/upload`,
|
||||
method: 'post',
|
||||
data: formData,
|
||||
headers: {
|
||||
...formData.getHeaders(),
|
||||
'xc-token': config.apiToken
|
||||
},
|
||||
params: {
|
||||
path: 'qrcodes'
|
||||
}
|
||||
});
|
||||
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logger.error('Failed to upload QR code to NocoDB:', error);
|
||||
throw new Error('Failed to upload QR code');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and upload QR code
|
||||
* @param {string} url - URL to encode
|
||||
* @param {string} label - Label for the QR code
|
||||
* @param {Object} config - NocoDB configuration
|
||||
* @returns {Promise<Object>} Upload result
|
||||
*/
|
||||
async function generateAndUploadQRCode(url, label, config) {
|
||||
if (!url) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// Generate QR code
|
||||
const buffer = await generateQRCode(url);
|
||||
|
||||
// Create filename
|
||||
const timestamp = Date.now();
|
||||
const safeLabel = label.replace(/[^a-z0-9]/gi, '_').toLowerCase();
|
||||
const filename = `qr_${safeLabel}_${timestamp}.png`;
|
||||
|
||||
// Upload to NocoDB
|
||||
const uploadResult = await uploadQRCodeToNocoDB(buffer, filename, config);
|
||||
|
||||
return uploadResult;
|
||||
} catch (error) {
|
||||
logger.error('Failed to generate and upload QR code:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete QR code from NocoDB storage
|
||||
* @param {string} fileUrl - File URL to delete
|
||||
* @param {Object} config - NocoDB configuration
|
||||
* @returns {Promise<boolean>} Success status
|
||||
*/
|
||||
async function deleteQRCodeFromNocoDB(fileUrl, config) {
|
||||
if (!fileUrl) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
// Extract file path from URL
|
||||
const urlParts = fileUrl.split('/');
|
||||
const filePath = urlParts.slice(-2).join('/');
|
||||
|
||||
await axios({
|
||||
url: `${config.apiUrl}/api/v2/storage/upload`,
|
||||
method: 'delete',
|
||||
headers: {
|
||||
'xc-token': config.apiToken
|
||||
},
|
||||
params: {
|
||||
path: filePath
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error('Failed to delete QR code from NocoDB:', error);
|
||||
// Don't throw error for deletion failures
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateQRCode,
|
||||
uploadQRCodeToNocoDB,
|
||||
generateAndUploadQRCode,
|
||||
deleteQRCodeFromNocoDB
|
||||
};
|
||||
@ -1,394 +0,0 @@
|
||||
# NocoDB Automation Script Development Summary
|
||||
|
||||
## Overview
|
||||
This document summarizes the development of an automated NocoDB table creation script (`build-nocodb.sh`) for the Map Viewer project. The script automates the creation of three required tables: `locations`, `login`, and `settings` with proper schemas and default data.
|
||||
|
||||
## Project Requirements
|
||||
Based on the README.md analysis, the project needed:
|
||||
- **locations** table: Main map data storage
|
||||
- **login** table: User authentication
|
||||
- **settings** table: System configuration and QR codes
|
||||
- Default admin user and start location records
|
||||
- Idempotent script (safe to re-run)
|
||||
|
||||
## NocoDB API Research
|
||||
|
||||
### API Versions
|
||||
- **v1 API**: `/api/v1/` - Legacy, limited functionality
|
||||
- **v2 API**: `/api/v2/` - Modern, full-featured (recommended)
|
||||
|
||||
### Key API Endpoints Discovered
|
||||
|
||||
#### Base/Project Management
|
||||
```
|
||||
GET /api/v2/meta/bases # List all bases
|
||||
POST /api/v2/meta/bases # Create new base
|
||||
GET /api/v2/meta/bases/{id} # Get base details
|
||||
```
|
||||
|
||||
#### Table Management
|
||||
```
|
||||
GET /api/v2/meta/bases/{base_id}/tables # List tables in base
|
||||
POST /api/v2/meta/bases/{base_id}/tables # Create table
|
||||
GET /api/v2/meta/bases/{base_id}/tables/{table_id} # Get table details
|
||||
```
|
||||
|
||||
#### Record Management
|
||||
```
|
||||
GET /api/v2/tables/{table_id}/records # List records
|
||||
POST /api/v2/tables/{table_id}/records # Create record
|
||||
PUT /api/v2/tables/{table_id}/records/{record_id} # Update record
|
||||
```
|
||||
|
||||
### Authentication
|
||||
All API calls require the `xc-token` header:
|
||||
```bash
|
||||
curl -H "xc-token: YOUR_TOKEN" -H "Content-Type: application/json"
|
||||
```
|
||||
|
||||
## Table Schemas Implemented
|
||||
|
||||
### 1. Locations Table
|
||||
Primary table for map data storage:
|
||||
```json
|
||||
{
|
||||
"table_name": "locations",
|
||||
"columns": [
|
||||
{"column_name": "id", "uidt": "ID", "pk": true, "ai": true},
|
||||
{"column_name": "title", "uidt": "SingleLineText"},
|
||||
{"column_name": "description", "uidt": "LongText"},
|
||||
{"column_name": "category", "uidt": "SingleSelect", "colOptions": {
|
||||
"options": [
|
||||
{"title": "Important", "color": "#ff0000"},
|
||||
{"title": "Event", "color": "#00ff00"},
|
||||
{"title": "Business", "color": "#0000ff"},
|
||||
{"title": "Other", "color": "#ffff00"}
|
||||
]
|
||||
}},
|
||||
{"column_name": "geo_location", "uidt": "LongText"},
|
||||
{"column_name": "latitude", "uidt": "Decimal"},
|
||||
{"column_name": "longitude", "uidt": "Decimal"},
|
||||
{"column_name": "address", "uidt": "LongText"},
|
||||
{"column_name": "contact_info", "uidt": "LongText"},
|
||||
{"column_name": "created_at", "uidt": "DateTime"},
|
||||
{"column_name": "updated_at", "uidt": "DateTime"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Login Table
|
||||
User authentication table:
|
||||
```json
|
||||
{
|
||||
"table_name": "login",
|
||||
"columns": [
|
||||
{"column_name": "id", "uidt": "ID", "pk": true, "ai": true},
|
||||
{"column_name": "username", "uidt": "SingleLineText", "rqd": true},
|
||||
{"column_name": "email", "uidt": "Email", "rqd": true},
|
||||
{"column_name": "password", "uidt": "SingleLineText", "rqd": true},
|
||||
{"column_name": "admin", "uidt": "Checkbox"},
|
||||
{"column_name": "active", "uidt": "Checkbox"},
|
||||
{"column_name": "created_at", "uidt": "DateTime"},
|
||||
{"column_name": "last_login", "uidt": "DateTime"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 3. Settings Table
|
||||
System configuration with QR code support:
|
||||
```json
|
||||
{
|
||||
"table_name": "settings",
|
||||
"columns": [
|
||||
{"column_name": "id", "uidt": "ID", "pk": true, "ai": true},
|
||||
{"column_name": "key", "uidt": "SingleLineText", "rqd": true},
|
||||
{"column_name": "title", "uidt": "SingleLineText"},
|
||||
{"column_name": "geo_location", "uidt": "LongText"},
|
||||
{"column_name": "latitude", "uidt": "Decimal"},
|
||||
{"column_name": "longitude", "uidt": "Decimal"},
|
||||
{"column_name": "zoom", "uidt": "Number"},
|
||||
{"column_name": "category", "uidt": "SingleSelect", "colOptions": {
|
||||
"options": [
|
||||
{"title": "system_setting", "color": "#4CAF50"},
|
||||
{"title": "user_setting", "color": "#2196F3"},
|
||||
{"title": "app_config", "color": "#FF9800"}
|
||||
]
|
||||
}},
|
||||
{"column_name": "updated_by", "uidt": "SingleLineText"},
|
||||
{"column_name": "updated_at", "uidt": "DateTime"},
|
||||
{"column_name": "qr_code_1_url", "uidt": "URL"},
|
||||
{"column_name": "qr_code_1_label", "uidt": "SingleLineText"},
|
||||
{"column_name": "qr_code_1_image", "uidt": "Attachment"},
|
||||
{"column_name": "qr_code_2_url", "uidt": "URL"},
|
||||
{"column_name": "qr_code_2_label", "uidt": "SingleLineText"},
|
||||
{"column_name": "qr_code_2_image", "uidt": "Attachment"},
|
||||
{"column_name": "qr_code_3_url", "uidt": "URL"},
|
||||
{"column_name": "qr_code_3_label", "uidt": "SingleLineText"},
|
||||
{"column_name": "qr_code_3_image", "uidt": "Attachment"}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## NocoDB Column Types (UIdt)
|
||||
Discovered column types and their usage:
|
||||
- `ID` - Auto-incrementing primary key
|
||||
- `SingleLineText` - Short text field
|
||||
- `LongText` - Multi-line text area
|
||||
- `Email` - Email validation
|
||||
- `URL` - URL validation
|
||||
- `Decimal` - Decimal numbers
|
||||
- `Number` - Integer numbers
|
||||
- `DateTime` - Date and time
|
||||
- `Checkbox` - Boolean true/false
|
||||
- `SingleSelect` - Dropdown with predefined options
|
||||
- `Attachment` - File upload field
|
||||
|
||||
## Script Development Process
|
||||
|
||||
### Initial Implementation
|
||||
1. Created basic structure with environment variable loading
|
||||
2. Implemented API connectivity testing
|
||||
3. Added base/project creation functionality
|
||||
4. Created table creation functions
|
||||
|
||||
### Key Challenges Solved
|
||||
|
||||
#### 1. Environment Variable Loading
|
||||
**Issue**: Standard `source .env` wasn't exporting variables
|
||||
**Solution**: Use `set -a; source .env; set +a` pattern
|
||||
```bash
|
||||
set -a # Auto-export all variables
|
||||
source .env # Load environment file
|
||||
set +a # Disable auto-export
|
||||
```
|
||||
|
||||
#### 2. API Version Compatibility
|
||||
**Issue**: Mixed v1/v2 endpoint usage causing errors
|
||||
**Solution**: Standardized on v2 API with proper URL construction
|
||||
```bash
|
||||
BASE_URL=$(echo "$NOCODB_API_URL" | sed 's|/api/v1||')
|
||||
API_BASE_V2="${BASE_URL}/api/v2"
|
||||
```
|
||||
|
||||
#### 3. Duplicate Table Error
|
||||
**Issue**: Script failed when tables already existed
|
||||
**Solution**: Added idempotent table checking
|
||||
```bash
|
||||
get_table_id_by_name() {
|
||||
local base_id=$1
|
||||
local table_name=$2
|
||||
|
||||
# Check if table exists by name
|
||||
local tables_response
|
||||
tables_response=$(make_api_call "GET" "/meta/bases/$base_id/tables" "" "Fetching tables")
|
||||
|
||||
# Parse JSON to find table ID
|
||||
local table_id
|
||||
table_id=$(echo "$tables_response" | grep -o '"id":"[^"]*","table_name":"'"$table_name"'"' | grep -o '"id":"[^"]*"' | head -1 | sed 's/"id":"//;s/"//')
|
||||
|
||||
if [ -n "$table_id" ]; then
|
||||
echo "$table_id"
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
#### 4. JSON Response Parsing
|
||||
**Issue**: Complex JSON parsing for table IDs
|
||||
**Solution**: Used grep with regex patterns
|
||||
```bash
|
||||
# Extract table ID from JSON response
|
||||
table_id=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
|
||||
```
|
||||
|
||||
## Default Data Records
|
||||
|
||||
### Admin User
|
||||
```json
|
||||
{
|
||||
"username": "admin",
|
||||
"email": "admin@example.com",
|
||||
"password": "changeme123",
|
||||
"admin": true,
|
||||
"active": true,
|
||||
"created_at": "2025-07-05 12:00:00"
|
||||
}
|
||||
```
|
||||
|
||||
### Start Location Setting
|
||||
```json
|
||||
{
|
||||
"key": "start_location",
|
||||
"title": "Map Start Location",
|
||||
"geo_location": "53.5461;-113.4938",
|
||||
"latitude": 53.5461,
|
||||
"longitude": -113.4938,
|
||||
"zoom": 11,
|
||||
"category": "system_setting",
|
||||
"updated_by": "system",
|
||||
"updated_at": "2025-07-05 12:00:00"
|
||||
}
|
||||
```
|
||||
|
||||
## Error Handling Patterns
|
||||
|
||||
### API Call Wrapper
|
||||
```bash
|
||||
make_api_call() {
|
||||
local method=$1
|
||||
local endpoint=$2
|
||||
local data=$3
|
||||
local description=$4
|
||||
local api_version=${5:-"v2"}
|
||||
|
||||
# Construct full URL
|
||||
if [[ "$api_version" == "v1" ]]; then
|
||||
full_url="$API_BASE_V1$endpoint"
|
||||
else
|
||||
full_url="$API_BASE_V2$endpoint"
|
||||
fi
|
||||
|
||||
# Make request with timeout
|
||||
response=$(curl -s -w "%{http_code}" -X "$method" \
|
||||
-H "xc-token: $NOCODB_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
--max-time 30 \
|
||||
-d "$data" \
|
||||
"$full_url" 2>/dev/null)
|
||||
|
||||
# Parse HTTP code and response
|
||||
http_code="${response: -3}"
|
||||
response_body="${response%???}"
|
||||
|
||||
# Check for success
|
||||
if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then
|
||||
echo "$response_body"
|
||||
return 0
|
||||
else
|
||||
print_error "API call failed: $http_code - $response_body"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
```
|
||||
|
||||
## Final Script Features
|
||||
|
||||
### Idempotent Operation
|
||||
- Checks for existing base/project
|
||||
- Validates table existence before creation
|
||||
- Uses existing table IDs when found
|
||||
- Safe to run multiple times
|
||||
|
||||
### Robust Error Handling
|
||||
- Network timeout protection
|
||||
- HTTP status code validation
|
||||
- JSON parsing error handling
|
||||
- Colored output for status messages
|
||||
|
||||
### Environment Integration
|
||||
- Loads configuration from `.env` file
|
||||
- Supports custom default coordinates
|
||||
- Validates required variables
|
||||
|
||||
## Usage Instructions
|
||||
|
||||
1. **Setup Environment**:
|
||||
```bash
|
||||
# Update .env with your NocoDB details
|
||||
NOCODB_API_URL=https://your-nocodb.com/api/v1
|
||||
NOCODB_API_TOKEN=your_token_here
|
||||
```
|
||||
|
||||
2. **Run Script**:
|
||||
```bash
|
||||
chmod +x build-nocodb.sh
|
||||
./build-nocodb.sh
|
||||
```
|
||||
|
||||
3. **Post-Setup**:
|
||||
- Update `.env` with generated table URLs
|
||||
- Change default admin password
|
||||
- Verify tables in NocoDB interface
|
||||
|
||||
## Lessons Learned
|
||||
|
||||
1. **API Documentation**: Always verify API endpoints with actual testing
|
||||
2. **JSON Parsing**: Shell-based JSON parsing requires careful regex patterns
|
||||
3. **Idempotency**: Essential for automation scripts in production
|
||||
4. **Error Handling**: Comprehensive error handling prevents silent failures
|
||||
5. **Environment Variables**: Proper loading patterns are crucial for script reliability
|
||||
|
||||
## Future Enhancements
|
||||
|
||||
- Add support for custom table schemas via configuration
|
||||
- Implement data migration features
|
||||
- Add backup/restore functionality
|
||||
- Support for multiple environment configurations
|
||||
- Integration with CI/CD pipelines
|
||||
|
||||
## Script Updates - July 2025
|
||||
|
||||
### Column Type Improvements
|
||||
Updated the build-nocodb.sh script to use proper NocoDB column types based on the official documentation:
|
||||
|
||||
#### Locations Table Updates
|
||||
- **`geo_location`**: Changed from `LongText` to `GeoData` (proper geographic data type)
|
||||
- **`latitude`**: Added precision (10) and scale (8) for proper decimal handling
|
||||
- **`longitude`**: Added precision (11) and scale (8) for proper decimal handling
|
||||
- **`phone`**: Changed from `SingleLineText` to `PhoneNumber` (proper phone validation)
|
||||
- **`email`**: Using `Email` type for proper email validation
|
||||
- **Updated field names**: Added proper fields from README.md:
|
||||
- `first_name`, `last_name` (SingleLineText)
|
||||
- `unit_number` (SingleLineText)
|
||||
- `support_level` (SingleSelect with colors: 1=Green, 2=Yellow, 3=Orange, 4=Red)
|
||||
- `sign` (Checkbox)
|
||||
- `sign_size` (SingleSelect: Small, Medium, Large)
|
||||
- `notes` (LongText)
|
||||
- `address` (SingleLineText instead of LongText)
|
||||
|
||||
#### Login Table Updates
|
||||
- **Simplified structure**: Removed username/password fields per README.md specification
|
||||
- **Core fields**: `email` (Email), `name` (SingleLineText), `admin` (Checkbox)
|
||||
- **Authentication note**: This is a simplified table - proper authentication should be implemented separately
|
||||
|
||||
#### Settings Table Updates
|
||||
- **`geo_location`**: Changed from `LongText` to `GeoData` for proper geographic data handling
|
||||
- **`latitude`/`longitude`**: Added precision and scale parameters
|
||||
- **`value`**: Added missing `value` field from README.md specification
|
||||
- **QR Code fields**: Simplified to just attachment fields (removed URL/label fields not in README.md)
|
||||
|
||||
### Benefits of Proper Column Types
|
||||
|
||||
1. **GeoData Type**:
|
||||
- Proper latitude;longitude format validation
|
||||
- Better integration with mapping libraries
|
||||
- Consistent data storage format
|
||||
|
||||
2. **PhoneNumber Type**:
|
||||
- Built-in phone number validation
|
||||
- Proper formatting and display
|
||||
- International number support
|
||||
|
||||
3. **Email Type**:
|
||||
- Email format validation
|
||||
- Prevents invalid email addresses
|
||||
- Better UI experience
|
||||
|
||||
4. **Decimal Precision**:
|
||||
- Latitude: 10 digits, 8 decimal places (±90.12345678)
|
||||
- Longitude: 11 digits, 8 decimal places (±180.12345678)
|
||||
- Provides GPS-level precision for mapping
|
||||
|
||||
5. **SingleSelect with Colors**:
|
||||
- Support Level: Color-coded options for visual feedback
|
||||
- Sign Size: Consistent option selection
|
||||
- Category: Organized classification system
|
||||
|
||||
### Backward Compatibility
|
||||
The script maintains backward compatibility while using proper column types. Existing data migration may be needed if upgrading from the old schema.
|
||||
|
||||
---
|
||||
*Generated: July 5, 2025*
|
||||
*Script Version: Column Type Optimized*
|
||||
@ -1,780 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NocoDB Auto-Setup Script
|
||||
# This script automatically creates the necessary base and tables for the NocoDB Map Viewer
|
||||
# Based on requirements from README.md and using proper NocoDB column types
|
||||
#
|
||||
# Creates three tables:
|
||||
# 1. locations - Main table with GeoData, proper field types per README.md
|
||||
# 2. login - Simple authentication table with Email, Name, Admin fields
|
||||
# 3. settings - Configuration table with GeoData and attachment fields for QR codes
|
||||
#
|
||||
# Updated: July 2025 - Using proper NocoDB column types (GeoData, PhoneNumber, etc.)
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to print colored output
|
||||
print_status() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1" >&2
|
||||
}
|
||||
|
||||
print_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1" >&2
|
||||
}
|
||||
|
||||
print_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1" >&2
|
||||
}
|
||||
|
||||
print_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1" >&2
|
||||
}
|
||||
|
||||
# Load environment variables
|
||||
if [ -f ".env" ]; then
|
||||
# Use set -a to automatically export variables
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
print_success "Environment variables loaded from .env"
|
||||
else
|
||||
print_error ".env file not found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate required environment variables
|
||||
if [ -z "$NOCODB_API_URL" ] || [ -z "$NOCODB_API_TOKEN" ]; then
|
||||
print_error "Required environment variables NOCODB_API_URL and NOCODB_API_TOKEN not set!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Extract base URL from API URL and set up v2 API endpoints
|
||||
BASE_URL=$(echo "$NOCODB_API_URL" | sed 's|/api/v1||')
|
||||
API_BASE_V1="$NOCODB_API_URL"
|
||||
API_BASE_V2="${BASE_URL}/api/v2"
|
||||
|
||||
print_status "Using NocoDB instance: $BASE_URL"
|
||||
|
||||
# Function to make API calls with proper error handling
|
||||
make_api_call() {
|
||||
local method=$1
|
||||
local endpoint=$2
|
||||
local data=$3
|
||||
local description=$4
|
||||
local api_version=${5:-"v2"} # Default to v2
|
||||
|
||||
print_status "$description"
|
||||
|
||||
local response
|
||||
local http_code
|
||||
local full_url
|
||||
|
||||
if [[ "$api_version" == "v1" ]]; then
|
||||
full_url="$API_BASE_V1$endpoint"
|
||||
else
|
||||
full_url="$API_BASE_V2$endpoint"
|
||||
fi
|
||||
|
||||
print_status "Making $method request to: $full_url"
|
||||
|
||||
if [ "$method" = "GET" ]; then
|
||||
response=$(curl -s -w "%{http_code}" -H "xc-token: $NOCODB_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
--max-time 30 \
|
||||
"$full_url" 2>/dev/null)
|
||||
curl_exit_code=$?
|
||||
else
|
||||
response=$(curl -s -w "%{http_code}" -X "$method" \
|
||||
-H "xc-token: $NOCODB_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
--max-time 30 \
|
||||
-d "$data" \
|
||||
"$full_url" 2>/dev/null)
|
||||
curl_exit_code=$?
|
||||
fi
|
||||
|
||||
if [[ $curl_exit_code -ne 0 ]]; then
|
||||
print_error "Network error occurred while making API call (curl exit code: $curl_exit_code)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "$response" ]]; then
|
||||
print_error "Empty response from API call"
|
||||
return 1
|
||||
fi
|
||||
|
||||
http_code="${response: -3}"
|
||||
response_body="${response%???}"
|
||||
|
||||
print_status "HTTP Code: $http_code"
|
||||
print_status "Response preview: ${response_body:0:200}..."
|
||||
|
||||
if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then
|
||||
print_success "$description completed successfully"
|
||||
echo "$response_body"
|
||||
else
|
||||
print_error "$description failed with HTTP code: $http_code"
|
||||
print_error "Full URL: $full_url"
|
||||
print_error "Response: $response_body"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create a project/base
|
||||
create_project() {
|
||||
local project_name="$1"
|
||||
local project_data='{
|
||||
"title": "'"$project_name"'",
|
||||
"description": "Auto-generated project for NocoDB Map Viewer",
|
||||
"color": "#24716E"
|
||||
}'
|
||||
|
||||
make_api_call "POST" "/meta/bases" "$project_data" "Creating project: $project_name" "v2"
|
||||
}
|
||||
|
||||
# Function to create a table or get existing table ID
|
||||
create_table() {
|
||||
local base_id=$1
|
||||
local table_name=$2
|
||||
local table_data=$3
|
||||
local description=$4
|
||||
|
||||
# First check if table already exists
|
||||
local existing_id
|
||||
existing_id=$(get_table_id_by_name "$base_id" "$table_name")
|
||||
|
||||
if [[ -n "$existing_id" ]]; then
|
||||
print_success "Table '$table_name' already exists with ID: $existing_id"
|
||||
echo "$existing_id"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Table doesn't exist, create it
|
||||
local response
|
||||
response=$(make_api_call "POST" "/meta/bases/$base_id/tables" "$table_data" "Creating table: $table_name ($description)" "v2")
|
||||
|
||||
if [[ $? -eq 0 && -n "$response" ]]; then
|
||||
# Extract table ID from response
|
||||
local table_id
|
||||
table_id=$(echo "$response" | grep -o '"id":"[^"]*"' | head -1 | cut -d'"' -f4)
|
||||
|
||||
if [[ -n "$table_id" ]]; then
|
||||
print_success "Table '$table_name' created with ID: $table_id"
|
||||
echo "$table_id"
|
||||
else
|
||||
print_error "Failed to extract table ID from response"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "Failed to create table: $table_name"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create columns for a table
|
||||
create_column() {
|
||||
local project_id=$1
|
||||
local table_id=$2
|
||||
local column_data=$3
|
||||
local column_name=$4
|
||||
|
||||
make_api_call "POST" "/meta/projects/$project_id/tables/$table_id/columns" "$column_data" "Creating column: $column_name"
|
||||
}
|
||||
|
||||
# Function to test API connectivity
|
||||
test_api_connectivity() {
|
||||
print_status "Testing API connectivity..."
|
||||
|
||||
# Test basic connectivity first
|
||||
if ! curl -s --max-time 10 -I "$BASE_URL" > /dev/null 2>&1; then
|
||||
print_error "Cannot reach NocoDB instance at $BASE_URL"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Test API with token using v2 endpoint
|
||||
local test_response
|
||||
test_response=$(curl -s --max-time 10 -w "%{http_code}" -H "xc-token: $NOCODB_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
"$API_BASE_V2/meta/bases" 2>/dev/null || echo "CURL_ERROR")
|
||||
|
||||
if [[ "$test_response" == "CURL_ERROR" ]]; then
|
||||
print_error "Network error when testing API"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local http_code="${test_response: -3}"
|
||||
local response_body="${test_response%???}"
|
||||
|
||||
if [[ "$http_code" -ge 200 && "$http_code" -lt 300 ]]; then
|
||||
print_success "API connectivity test successful"
|
||||
return 0
|
||||
else
|
||||
print_error "API test failed with HTTP code: $http_code"
|
||||
print_error "Response: $response_body"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to extract project ID from existing URLs
|
||||
extract_project_from_urls() {
|
||||
print_status "Checking for existing project IDs in URLs..."
|
||||
|
||||
local project_id=""
|
||||
|
||||
# Try to extract from view URL
|
||||
if [[ -n "$NOCODB_VIEW_URL" ]]; then
|
||||
project_id=$(echo "$NOCODB_VIEW_URL" | sed -n 's/.*\/nc\/\([^\/]*\)\/.*/\1/p')
|
||||
if [[ -n "$project_id" ]]; then
|
||||
print_success "Found project ID from VIEW_URL: $project_id"
|
||||
echo "$project_id"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to extract from login sheet
|
||||
if [[ -n "$NOCODB_LOGIN_SHEET" ]]; then
|
||||
project_id=$(echo "$NOCODB_LOGIN_SHEET" | sed -n 's/.*\/nc\/\([^\/]*\)\/.*/\1/p')
|
||||
if [[ -n "$project_id" ]]; then
|
||||
print_success "Found project ID from LOGIN_SHEET: $project_id"
|
||||
echo "$project_id"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to extract from settings sheet
|
||||
if [[ -n "$NOCODB_SETTINGS_SHEET" ]]; then
|
||||
project_id=$(echo "$NOCODB_SETTINGS_SHEET" | sed -n 's/.*\/nc\/\([^\/]*\)\/.*/\1/p')
|
||||
if [[ -n "$project_id" ]]; then
|
||||
print_success "Found project ID from SETTINGS_SHEET: $project_id"
|
||||
echo "$project_id"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_warning "No existing project ID found in URLs"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Function to get or create project
|
||||
get_or_create_project() {
|
||||
local project_name="Map Viewer Project"
|
||||
|
||||
# First test API connectivity
|
||||
if ! test_api_connectivity; then
|
||||
print_error "API connectivity test failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Since the URLs are empty, we need to create new tables
|
||||
# Check if we have any existing bases first
|
||||
print_status "Checking for existing bases..."
|
||||
|
||||
local bases_response
|
||||
bases_response=$(make_api_call "GET" "/meta/bases" "" "Fetching existing bases" "v2")
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
# Try to find existing project (look for our project name or use first available)
|
||||
local existing_base_id
|
||||
existing_base_id=$(echo "$bases_response" | grep -o '"id":"[^"]*"' | head -1 | sed 's/"id":"//;s/"//')
|
||||
|
||||
if [ -n "$existing_base_id" ]; then
|
||||
print_success "Using existing base with ID: $existing_base_id"
|
||||
echo "$existing_base_id"
|
||||
return 0
|
||||
else
|
||||
print_status "No existing base found, creating new base..."
|
||||
local new_base_response
|
||||
new_base_response=$(create_project "$project_name")
|
||||
local new_base_id
|
||||
new_base_id=$(echo "$new_base_response" | grep -o '"id":"[^"]*"' | head -1 | sed 's/"id":"//;s/"//')
|
||||
|
||||
if [ -n "$new_base_id" ]; then
|
||||
print_success "Created new base with ID: $new_base_id"
|
||||
echo "$new_base_id"
|
||||
return 0
|
||||
else
|
||||
print_error "Failed to create or find base"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
print_error "Failed to fetch bases from API"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to create the main locations table
|
||||
create_locations_table() {
|
||||
local base_id=$1
|
||||
|
||||
local table_data='{
|
||||
"table_name": "locations",
|
||||
"title": "Locations",
|
||||
"columns": [
|
||||
{
|
||||
"column_name": "id",
|
||||
"title": "ID",
|
||||
"uidt": "ID",
|
||||
"pk": true,
|
||||
"ai": true,
|
||||
"rqd": true
|
||||
},
|
||||
{
|
||||
"column_name": "geo_location",
|
||||
"title": "Geo-Location",
|
||||
"uidt": "GeoData",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "latitude",
|
||||
"title": "latitude",
|
||||
"uidt": "Decimal",
|
||||
"rqd": false,
|
||||
"precision": 10,
|
||||
"scale": 8
|
||||
},
|
||||
{
|
||||
"column_name": "longitude",
|
||||
"title": "longitude",
|
||||
"uidt": "Decimal",
|
||||
"rqd": false,
|
||||
"precision": 11,
|
||||
"scale": 8
|
||||
},
|
||||
{
|
||||
"column_name": "first_name",
|
||||
"title": "First Name",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "last_name",
|
||||
"title": "Last Name",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "email",
|
||||
"title": "Email",
|
||||
"uidt": "Email",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "phone",
|
||||
"title": "Phone",
|
||||
"uidt": "PhoneNumber",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "unit_number",
|
||||
"title": "Unit Number",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "support_level",
|
||||
"title": "Support Level",
|
||||
"uidt": "SingleSelect",
|
||||
"rqd": false,
|
||||
"colOptions": {
|
||||
"options": [
|
||||
{"title": "1", "color": "#4CAF50"},
|
||||
{"title": "2", "color": "#FFEB3B"},
|
||||
{"title": "3", "color": "#FF9800"},
|
||||
{"title": "4", "color": "#F44336"}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"column_name": "address",
|
||||
"title": "Address",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "sign",
|
||||
"title": "Sign",
|
||||
"uidt": "Checkbox",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "sign_size",
|
||||
"title": "Sign Size",
|
||||
"uidt": "SingleSelect",
|
||||
"rqd": false,
|
||||
"colOptions": {
|
||||
"options": [
|
||||
{"title": "Small", "color": "#2196F3"},
|
||||
{"title": "Medium", "color": "#FF9800"},
|
||||
{"title": "Large", "color": "#4CAF50"}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"column_name": "notes",
|
||||
"title": "Notes",
|
||||
"uidt": "LongText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "title",
|
||||
"title": "title",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "category",
|
||||
"title": "category",
|
||||
"uidt": "SingleSelect",
|
||||
"rqd": false,
|
||||
"colOptions": {
|
||||
"options": [
|
||||
{"title": "Important", "color": "#F44336"},
|
||||
{"title": "Event", "color": "#4CAF50"},
|
||||
{"title": "Business", "color": "#2196F3"},
|
||||
{"title": "Other", "color": "#FF9800"}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"column_name": "created_at",
|
||||
"title": "Created At",
|
||||
"uidt": "DateTime",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "updated_at",
|
||||
"title": "Updated At",
|
||||
"uidt": "DateTime",
|
||||
"rqd": false
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
create_table "$base_id" "locations" "$table_data" "Main locations table for map data"
|
||||
}
|
||||
|
||||
# Function to create the login table
|
||||
create_login_table() {
|
||||
local base_id=$1
|
||||
|
||||
local table_data='{
|
||||
"table_name": "login",
|
||||
"title": "Login",
|
||||
"columns": [
|
||||
{
|
||||
"column_name": "id",
|
||||
"title": "ID",
|
||||
"uidt": "ID",
|
||||
"pk": true,
|
||||
"ai": true,
|
||||
"rqd": true
|
||||
},
|
||||
{
|
||||
"column_name": "email",
|
||||
"title": "Email",
|
||||
"uidt": "Email",
|
||||
"rqd": true
|
||||
},
|
||||
{
|
||||
"column_name": "name",
|
||||
"title": "Name",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "admin",
|
||||
"title": "Admin",
|
||||
"uidt": "Checkbox",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "created_at",
|
||||
"title": "Created At",
|
||||
"uidt": "DateTime",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "last_login",
|
||||
"title": "Last Login",
|
||||
"uidt": "DateTime",
|
||||
"rqd": false
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
create_table "$base_id" "login" "$table_data" "User authentication table"
|
||||
}
|
||||
|
||||
# Function to create the settings table
|
||||
create_settings_table() {
|
||||
local base_id=$1
|
||||
|
||||
local table_data='{
|
||||
"table_name": "settings",
|
||||
"title": "Settings",
|
||||
"columns": [
|
||||
{
|
||||
"column_name": "id",
|
||||
"title": "ID",
|
||||
"uidt": "ID",
|
||||
"pk": true,
|
||||
"ai": true,
|
||||
"rqd": true
|
||||
},
|
||||
{
|
||||
"column_name": "key",
|
||||
"title": "key",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": true
|
||||
},
|
||||
{
|
||||
"column_name": "title",
|
||||
"title": "title",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "value",
|
||||
"title": "value",
|
||||
"uidt": "LongText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "geo_location",
|
||||
"title": "Geo-Location",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "latitude",
|
||||
"title": "latitude",
|
||||
"uidt": "Decimal",
|
||||
"rqd": false,
|
||||
"precision": 10,
|
||||
"scale": 8
|
||||
},
|
||||
{
|
||||
"column_name": "longitude",
|
||||
"title": "longitude",
|
||||
"uidt": "Decimal",
|
||||
"rqd": false,
|
||||
"precision": 11,
|
||||
"scale": 8
|
||||
},
|
||||
{
|
||||
"column_name": "zoom",
|
||||
"title": "zoom",
|
||||
"uidt": "Number",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "category",
|
||||
"title": "category",
|
||||
"uidt": "SingleSelect",
|
||||
"rqd": false,
|
||||
"colOptions": {
|
||||
"options": [
|
||||
{"title": "system_setting", "color": "#4CAF50"},
|
||||
{"title": "user_setting", "color": "#2196F3"},
|
||||
{"title": "app_config", "color": "#FF9800"}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"column_name": "updated_by",
|
||||
"title": "updated_by",
|
||||
"uidt": "SingleLineText",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "updated_at",
|
||||
"title": "updated_at",
|
||||
"uidt": "DateTime",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "qr_code_1_image",
|
||||
"title": "QR Code 1 Image",
|
||||
"uidt": "Attachment",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "qr_code_2_image",
|
||||
"title": "QR Code 2 Image",
|
||||
"uidt": "Attachment",
|
||||
"rqd": false
|
||||
},
|
||||
{
|
||||
"column_name": "qr_code_3_image",
|
||||
"title": "QR Code 3 Image",
|
||||
"uidt": "Attachment",
|
||||
"rqd": false
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
create_table "$base_id" "settings" "$table_data" "System configuration and QR codes"
|
||||
}
|
||||
|
||||
# Function to create default admin user
|
||||
create_default_admin() {
|
||||
local base_id=$1
|
||||
local login_table_id=$2
|
||||
|
||||
print_status "Creating default admin user..."
|
||||
|
||||
local admin_data='{
|
||||
"email": "admin@example.com",
|
||||
"name": "Administrator",
|
||||
"admin": true,
|
||||
"created_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'"
|
||||
}'
|
||||
|
||||
make_api_call "POST" "/tables/$login_table_id/records" "$admin_data" "Creating default admin user" "v2"
|
||||
|
||||
print_warning "Default admin user created:"
|
||||
print_warning " Email: admin@example.com"
|
||||
print_warning " Name: Administrator"
|
||||
print_warning " Admin: true"
|
||||
print_warning " Note: This is a simplified login table for demonstration."
|
||||
print_warning " You may need to implement proper authentication separately."
|
||||
}
|
||||
|
||||
# Function to create default start location setting
|
||||
create_default_start_location() {
|
||||
local base_id=$1
|
||||
local settings_table_id=$2
|
||||
|
||||
print_status "Creating default start location setting..."
|
||||
|
||||
local start_location_data='{
|
||||
"key": "start_location",
|
||||
"title": "Map Start Location",
|
||||
"geo_location": "'"${DEFAULT_LAT:-53.5461}"';'"${DEFAULT_LNG:--113.4938}"'",
|
||||
"latitude": '"${DEFAULT_LAT:-53.5461}"',
|
||||
"longitude": '"${DEFAULT_LNG:--113.4938}"',
|
||||
"zoom": '"${DEFAULT_ZOOM:-11}"',
|
||||
"category": "system_setting",
|
||||
"updated_by": "system",
|
||||
"updated_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'"
|
||||
}'
|
||||
|
||||
make_api_call "POST" "/tables/$settings_table_id/records" "$start_location_data" "Creating default start location" "v2"
|
||||
}
|
||||
|
||||
# Function to get table ID from table name
|
||||
get_table_id() {
|
||||
local project_id=$1
|
||||
local table_name=$2
|
||||
|
||||
local tables_response
|
||||
tables_response=$(make_api_call "GET" "/meta/projects/$project_id/tables" "" "Fetching tables for project")
|
||||
|
||||
local table_id
|
||||
table_id=$(echo "$tables_response" | grep -A 5 -B 5 "\"table_name\":\"$table_name\"" | grep -o '"id":"[^"]*"' | head -1 | sed 's/"id":"//;s/"//')
|
||||
|
||||
if [ -n "$table_id" ]; then
|
||||
echo "$table_id"
|
||||
else
|
||||
print_error "Could not find table ID for table: $table_name"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to get table ID from table name
|
||||
get_table_id_by_name() {
|
||||
local base_id=$1
|
||||
local table_name=$2
|
||||
|
||||
print_status "Checking if table '$table_name' exists..."
|
||||
|
||||
local tables_response
|
||||
tables_response=$(make_api_call "GET" "/meta/bases/$base_id/tables" "" "Fetching tables for base" "v2")
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
# Parse JSON to find table by name
|
||||
local table_id
|
||||
table_id=$(echo "$tables_response" | grep -o '"id":"[^"]*","table_name":"'"$table_name"'"' | grep -o '"id":"[^"]*"' | head -1 | sed 's/"id":"//;s/"//')
|
||||
|
||||
if [ -n "$table_id" ]; then
|
||||
print_success "Found existing table '$table_name' with ID: $table_id"
|
||||
echo "$table_id"
|
||||
return 0
|
||||
else
|
||||
print_status "Table '$table_name' does not exist"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "Failed to fetch tables for base"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
print_status "Starting NocoDB Auto-Setup..."
|
||||
print_status "================================"
|
||||
|
||||
# Get or create project
|
||||
print_status "Getting or creating base..."
|
||||
BASE_ID=$(get_or_create_project)
|
||||
|
||||
if [ -z "$BASE_ID" ]; then
|
||||
print_error "Failed to get or create base"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_status "Working with base ID: $BASE_ID"
|
||||
|
||||
# Create tables
|
||||
print_status "Creating tables..."
|
||||
|
||||
# Create locations table
|
||||
LOCATIONS_TABLE_ID=$(create_locations_table "$BASE_ID")
|
||||
|
||||
# Create login table
|
||||
LOGIN_TABLE_ID=$(create_login_table "$BASE_ID")
|
||||
|
||||
# Create settings table
|
||||
SETTINGS_TABLE_ID=$(create_settings_table "$BASE_ID")
|
||||
|
||||
# Wait a moment for tables to be fully created
|
||||
sleep 3
|
||||
|
||||
# Create default data
|
||||
print_status "Setting up default data..."
|
||||
|
||||
# Create default admin user
|
||||
create_default_admin "$BASE_ID" "$LOGIN_TABLE_ID"
|
||||
|
||||
# Create default start location
|
||||
create_default_start_location "$BASE_ID" "$SETTINGS_TABLE_ID"
|
||||
|
||||
print_status "================================"
|
||||
print_success "NocoDB Auto-Setup completed successfully!"
|
||||
print_status "================================"
|
||||
|
||||
print_status "Next steps:"
|
||||
print_status "1. Login to your NocoDB instance and verify the tables were created"
|
||||
print_status "2. Find the table URLs in NocoDB and update your .env file:"
|
||||
print_status " - Go to each table > Details > Copy the view URL"
|
||||
print_status " - Update NOCODB_VIEW_URL, NOCODB_LOGIN_SHEET, and NOCODB_SETTINGS_SHEET"
|
||||
print_status "3. Set up proper authentication for the admin user (admin@example.com)"
|
||||
print_status "4. Start adding your location data"
|
||||
|
||||
print_warning "Important: Please update your .env file with the actual table URLs from NocoDB!"
|
||||
print_warning "The current .env file has empty URLs - you need to populate them with the correct table URLs."
|
||||
}
|
||||
|
||||
# Check if script is being run directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
main "$@"
|
||||
fi
|
||||
Loading…
x
Reference in New Issue
Block a user