|
| 1 | +# Navigation Area Management |
| 2 | + |
| 3 | +This document describes how to reset and reseed navigation areas in the Better Together Community Engine. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The NavigationBuilder provides methods to reset and reseed navigation areas without affecting pages. This is useful when you need to update navigation structure or fix navigation issues without losing page content. |
| 8 | + |
| 9 | +## Available Rake Tasks |
| 10 | + |
| 11 | +All tasks are under the `better_together:generate` namespace: |
| 12 | + |
| 13 | +```bash |
| 14 | +# List all navigation areas and items |
| 15 | +bin/dc-run rails better_together:generate:list_navigation |
| 16 | + |
| 17 | +# Reset all navigation areas (preserves pages) |
| 18 | +bin/dc-run rails better_together:generate:reset_navigation |
| 19 | + |
| 20 | +# Reset specific navigation area |
| 21 | +bin/dc-run rails better_together:generate:reset_navigation_area[platform-header] |
| 22 | + |
| 23 | +# Full rebuild (DESTRUCTIVE - deletes pages too!) |
| 24 | +bin/dc-run rails better_together:generate:navigation_and_pages |
| 25 | +``` |
| 26 | + |
| 27 | +## Detailed Methods |
| 28 | + |
| 29 | +### 1. Reset All Navigation Areas |
| 30 | + |
| 31 | +**Ruby Console:** |
| 32 | +```ruby |
| 33 | +BetterTogether::NavigationBuilder.reset_navigation_areas |
| 34 | +``` |
| 35 | + |
| 36 | +**Rake Task:** |
| 37 | +```bash |
| 38 | +bin/dc-run rails better_together:generate:reset_navigation |
| 39 | +``` |
| 40 | + |
| 41 | +**What it does:** |
| 42 | +- Deletes all navigation items |
| 43 | +- Deletes all navigation areas |
| 44 | +- Rebuilds all four navigation areas: |
| 45 | + - Platform Header |
| 46 | + - Platform Host |
| 47 | + - Better Together |
| 48 | + - Platform Footer |
| 49 | +- **Preserves all pages** (pages are not deleted) |
| 50 | + |
| 51 | +### 2. Reset Specific Navigation Area |
| 52 | + |
| 53 | +**Ruby Console:** |
| 54 | +```ruby |
| 55 | +BetterTogether::NavigationBuilder.reset_navigation_area('platform-header') |
| 56 | +``` |
| 57 | + |
| 58 | +**Rake Task:** |
| 59 | +```bash |
| 60 | +bin/dc-run rails better_together:generate:reset_navigation_area[platform-header] |
| 61 | +``` |
| 62 | + |
| 63 | +**Available slugs:** |
| 64 | +- `platform-header` - Main navigation menu |
| 65 | +- `platform-host` - Host admin dropdown menu |
| 66 | +- `better-together` - Better Together dropdown |
| 67 | +- `platform-footer` - Footer links |
| 68 | + |
| 69 | +**What it does:** |
| 70 | +- Deletes navigation items for the specified area |
| 71 | +- Deletes the navigation area |
| 72 | +- Rebuilds only that specific navigation area |
| 73 | +- **Preserves all pages** |
| 74 | + |
| 75 | +### 3. List Navigation Areas |
| 76 | + |
| 77 | +**Rake Task:** |
| 78 | +```bash |
| 79 | +bin/dc-run rails better_together:generate:list_navigation |
| 80 | +``` |
| 81 | + |
| 82 | +**What it does:** |
| 83 | +- Shows all navigation areas with their details |
| 84 | +- Lists all navigation items in each area |
| 85 | +- Shows parent-child relationships |
| 86 | +- Displays visibility and protection status |
| 87 | + |
| 88 | +**Example output:** |
| 89 | +``` |
| 90 | +Navigation Areas: |
| 91 | +================================================================================ |
| 92 | +
|
| 93 | +Area: Platform Header |
| 94 | + Slug: platform-header |
| 95 | + Visible: true |
| 96 | + Protected: true |
| 97 | + Items: 3 |
| 98 | + Navigation Items: |
| 99 | + - About (link) |
| 100 | + - Events (link) |
| 101 | + - Exchange Hub (link) |
| 102 | +... |
| 103 | +``` |
| 104 | + |
| 105 | +### 4. Full Rebuild (Includes Pages) |
| 106 | + |
| 107 | +**Rake Task:** |
| 108 | +```bash |
| 109 | +bin/dc-run rails better_together:generate:navigation_and_pages |
| 110 | +``` |
| 111 | + |
| 112 | +**What it does:** |
| 113 | +- Deletes all pages |
| 114 | +- Deletes all navigation items |
| 115 | +- Deletes all navigation areas |
| 116 | +- Rebuilds everything from scratch |
| 117 | +- **WARNING:** This deletes all pages including custom content |
| 118 | + |
| 119 | +## Navigation Areas Structure |
| 120 | + |
| 121 | +### Platform Header |
| 122 | +- **Purpose:** Main site navigation at top of page |
| 123 | +- **Contains:** |
| 124 | + - About page link |
| 125 | + - Events link (route-based) |
| 126 | + - Exchange Hub link (route-based) |
| 127 | + |
| 128 | +### Platform Host |
| 129 | +- **Purpose:** Admin/host management dropdown |
| 130 | +- **Contains:** |
| 131 | + - Dashboard |
| 132 | + - Communities |
| 133 | + - Navigation Areas |
| 134 | + - Pages |
| 135 | + - People |
| 136 | + - Platforms |
| 137 | + - Roles |
| 138 | + - Resource Permissions |
| 139 | + |
| 140 | +### Better Together |
| 141 | +- **Purpose:** Information about the platform software |
| 142 | +- **Contains:** |
| 143 | + - What is Better Together? |
| 144 | + - About the Community Engine |
| 145 | + |
| 146 | +### Platform Footer |
| 147 | +- **Purpose:** Footer links for policies and info |
| 148 | +- **Contains:** |
| 149 | + - FAQ |
| 150 | + - Privacy Policy |
| 151 | + - Terms of Service |
| 152 | + - Code of Conduct |
| 153 | + - Accessibility |
| 154 | + - Cookie Policy |
| 155 | + - Code Contributor Agreement |
| 156 | + - Content Contributor Agreement |
| 157 | + - Contact |
| 158 | + |
| 159 | +## Common Use Cases |
| 160 | + |
| 161 | +### Update Navigation After Adding New Pages |
| 162 | + |
| 163 | +If you've added new pages to footer_pages in NavigationBuilder: |
| 164 | + |
| 165 | +```bash |
| 166 | +# Reset just the footer area |
| 167 | +bin/dc-run rails navigation:reset_area[platform-footer] |
| 168 | +``` |
| 169 | + |
| 170 | +### Fix Broken Navigation |
| 171 | + |
| 172 | +If navigation items are missing or duplicated: |
| 173 | + |
| 174 | +```bash |
| 175 | +# Reset all navigation areas |
| 176 | +bin/dc-run rails navigation:reset |
| 177 | +``` |
| 178 | + |
| 179 | +### Development: Fresh Start |
| 180 | + |
| 181 | +For a completely fresh navigation setup: |
| 182 | + |
| 183 | +```bash |
| 184 | +# Full rebuild (careful - deletes pages!) |
| 185 | +bin/dc-run rails navigation:rebuild |
| 186 | +``` |
| 187 | + |
| 188 | +### Check Current Navigation State |
| 189 | + |
| 190 | +```bash |
| 191 | +# List all areas and items |
| 192 | +bin/dc-run rails navigation:list |
| 193 | +``` |
| 194 | + |
| 195 | +## Programmatic Usage |
| 196 | + |
| 197 | +### In Seeds or Migrations |
| 198 | + |
| 199 | +```ruby |
| 200 | +# Reset all navigation (safe for pages) |
| 201 | +BetterTogether::NavigationBuilder.reset_navigation_areas |
| 202 | + |
| 203 | +# Reset specific area |
| 204 | +BetterTogether::NavigationBuilder.reset_navigation_area('platform-footer') |
| 205 | + |
| 206 | +# Full rebuild (destructive) |
| 207 | +BetterTogether::NavigationBuilder.build(clear: true) |
| 208 | +``` |
| 209 | + |
| 210 | +### In Rails Console |
| 211 | + |
| 212 | +```ruby |
| 213 | +# Reset navigation |
| 214 | +BetterTogether::NavigationBuilder.reset_navigation_areas |
| 215 | + |
| 216 | +# Check what areas exist |
| 217 | +BetterTogether::NavigationArea.pluck(:name, :slug) |
| 218 | + |
| 219 | +# See items in an area |
| 220 | +area = BetterTogether::NavigationArea.find_by(slug: 'platform-footer') |
| 221 | +area.navigation_items.pluck(:title, :item_type, :position) |
| 222 | +``` |
| 223 | + |
| 224 | +## Important Notes |
| 225 | + |
| 226 | +### Protected Records |
| 227 | + |
| 228 | +All navigation areas and items created by the builder are marked as `protected: true`. This means: |
| 229 | +- They cannot be deleted through the UI |
| 230 | +- They are considered system records |
| 231 | +- Manual database edits may be needed to modify protection status |
| 232 | + |
| 233 | +### Localization |
| 234 | + |
| 235 | +All navigation building happens within `I18n.with_locale(:en)`. If you need other locales: |
| 236 | +- Pages support multi-locale attributes (title_en, title_es, etc.) |
| 237 | +- Navigation items also support multi-locale attributes |
| 238 | +- Update the builder methods to include additional locales |
| 239 | + |
| 240 | +### Page Preservation |
| 241 | + |
| 242 | +The `reset_navigation_areas` and `reset_navigation_area` methods preserve pages because: |
| 243 | +- Pages may contain user-generated content |
| 244 | +- Pages may have been customized |
| 245 | +- Navigation can be rebuilt without affecting page content |
| 246 | +- Pages are referenced by navigation items but not dependent on them |
| 247 | + |
| 248 | +### Safe Order of Operations |
| 249 | + |
| 250 | +When resetting navigation: |
| 251 | +1. Child navigation items are deleted first |
| 252 | +2. Parent navigation items are deleted second |
| 253 | +3. Navigation areas are deleted last |
| 254 | +4. This respects foreign key constraints |
| 255 | + |
| 256 | +## Troubleshooting |
| 257 | + |
| 258 | +### "Navigation area with slug 'X' not found" |
| 259 | + |
| 260 | +The area doesn't exist. Check available slugs: |
| 261 | +```ruby |
| 262 | +BetterTogether::NavigationArea.pluck(:slug) |
| 263 | +``` |
| 264 | + |
| 265 | +### Duplicate Navigation Items |
| 266 | + |
| 267 | +Run a reset: |
| 268 | +```bash |
| 269 | +bin/dc-run rails navigation:reset |
| 270 | +``` |
| 271 | + |
| 272 | +### Pages Missing After Reset |
| 273 | + |
| 274 | +If you used `navigation:rebuild`, pages were deleted. Restore from backup or reseed: |
| 275 | +```bash |
| 276 | +bin/dc-run rails db:seed |
| 277 | +``` |
| 278 | + |
| 279 | +### Permission Errors in UI |
| 280 | + |
| 281 | +Navigation areas and items are protected. To modify through UI: |
| 282 | +1. Unprotect in console: `area.update(protected: false)` |
| 283 | +2. Make changes in UI |
| 284 | +3. Re-protect: `area.update(protected: true)` |
| 285 | + |
| 286 | +## Related Files |
| 287 | + |
| 288 | +- Builder: `app/builders/better_together/navigation_builder.rb` |
| 289 | +- Rake tasks: `lib/tasks/navigation.rake` |
| 290 | +- Seeds: `db/seeds.rb` |
| 291 | +- Models: |
| 292 | + - `app/models/better_together/navigation_area.rb` |
| 293 | + - `app/models/better_together/navigation_item.rb` |
| 294 | + - `app/models/better_together/page.rb` |
0 commit comments