Skip to content
forms-raw_singleitemedit-icon
navigation
modification_btn
docs
messages
flatprojectmap.handlebars
Plug-in Control Management
modificationbutton
docs_htmltables.handlebars

Plug-in Control Management

docs_html.handlebars
documentation.handlebars

1. Overview

1.1 Plugin Name

Harrier – a controls oversight and RAG roll-up dashboard.

1.2 Purpose

Harrier provides a Controls Registry and Controls Dashboard for the Shiftbulk ecosystem:

  • A CRUD interface for defining “controls” (e.g. Fire water ring main, Blocked chute probe, Deluge system, E-room segregation).
  • A 3-level classification hierarchy (e.g. Domain → Subdomain → Control).
  • A RAG status per control and roll-up RAG aggregation at each level.
  • A dashboard view showing overall control health with drill-down from high level (Level 1) to granular (Level 3).

Harrier integrates into the existing Shiftbulk app:

  • Express + Handlebars
  • Tailwind CSS (via parent layout)
  • MongoDB + Mongoose
  • Existing layout: views/harrier/main.handlebars

1.3 Mount Point

  • Plugin root router: plugins/harrier/index.js
  • Mount path in main app:
                    const harrier = require('./plugins/harrier');
                    app.use('/harrier', harrier);

2. Goals & Non-Goals

2.1 Goals

  1. Provide a central registry of controls with:
    • Name
    • Description
    • RAG status
    • 3-level classification
  2. Provide a control dashboard with:
    • Global RAG counts (red / amber / green).
    • Level 1 roll-ups and drill-down to Level 2 and Level 3.
  3. Provide full CRUD:
    • List
    • Create
    • Edit
    • View detail
    • Archive / soft delete
  4. Use Tailwind CSS and Shiftbulk main layout:
    • No Bootstrap classes in Harrier templates.
  5. Define everything clearly so an LLM can generate a complete plugin code tree and provide it as a downloadable zip for the user.

2.2 Non-Goals

  • No complicated charting integration (just Tailwind-styled HTML and simple counts).
  • No advanced permissions model (this is a secondary requirement).
  • No real-time / websocket updates (plain HTTP is sufficient).
  • No deep cross-plugin joins (hooks can be designed, but complex cross-queries are out of scope for v1).

4. Data Model

4.1 Mongoose Model: Control

File: plugins/harrier/models/Control.js

Collection naming: All collections must be prefixed with harrier_.

Collection name: harrier_controls (default Mongoose naming).

Fields

  • _id – ObjectId
  • name – String, required, max length ~200
  • description – String, optional, long text
  • ragStatus – String, enum: 'red' | 'amber' | 'green' | 'unknown', default 'unknown'
  • Hierarchy classification (3 levels):
    • level1 – String, required (e.g. “Fire Protection”)
    • level2 – String, optional (e.g. “Water Supply”)
    • level3 – String, optional (e.g. “Ring Main Isolation Valves”)
  • Context links (optional, future-proof):
    • siteId – ObjectId, ref 'Site', nullable
    • areaId – ObjectId, ref 'Area', nullable
    • equipmentId – ObjectId, ref 'Equipment', nullable
  • owner – String or ObjectId (for v1, can be a simple String username)
  • tags – [String], optional
  • isActive – Boolean, default true
  • createdAt / updatedAt – Date (via timestamps: true)

4.2 RAG Aggregation Model (In Memory)

  • No separate DB model for aggregated RAG.
  • Aggregation is computed on the fly in the controller:
    • By level1 for high-level dashboard cards.
    • By level1 + level2 + level3 for drill-down lists.
  • Helper function to derive aggregated RAG from a set of child controls:
    • If any child red → aggregated red.
    • Else if any child amber → aggregated amber.
    • Else if any child green → aggregated green.
    • Else → unknown/grey.

5. Navigation & Routes

5.1 Router File

File: plugins/harrier/index.js

Exports an Express router.

5.2 Middleware

  • bodyParser.urlencoded({ extended: true })
  • bodyParser.json()
  • cookieParser and CSRF can be applied at the router level, consistent with other plugins (optional but recommended).
  • Set res.locals.basePath = req.baseUrl || '/harrier' for URL generation in views.

5.3 Route List

Dashboard & Browsing

  • GET /harrier → Harrier Dashboard – global RAG summary and Level 1 aggregated list.
  • GET /harrier/level/:level1 → Level 1 detail view (aggregated view of all Level 2 under the given Level 1).
  • GET /harrier/level/:level1/:level2 → Level 2 detail view (aggregated by Level 3 under that Level 1/Level 2).
  • GET /harrier/level/:level1/:level2/:level3 → Level 3 detail view (list of controls matching that classification).

Controls CRUD

  • GET /harrier/controls → List view of all controls with filters.
  • GET /harrier/controls/new → New control form.
  • POST /harrier/controls → Create control.
  • GET /harrier/controls/:id → Control detail page.
  • GET /harrier/controls/:id/edit → Edit control form.
  • POST /harrier/controls/:id or POST /harrier/controls/:id?_method=PUT → Update control.
  • POST /harrier/controls/:id/delete or POST /harrier/controls/:id?_method=DELETE → Soft delete (set isActive = false).

Optional Export Routes

  • GET /harrier/export/json → Return JSON of all controls (Content-Disposition: attachment).
  • GET /harrier/export/csv → Return CSV of all controls.
  • Export routes are optional, not mandatory for v1.

6. Controllers

File: plugins/harrier/controllers/harrierController.js

You may split into dashboardController and controlsController, but a single controller file is acceptable for v1.

6.1 Helper: aggregateRagStatus(controls)

Input: Array of Control documents or simplified objects with .ragStatus.

Output:

                    {
                      status: 'red' | 'amber' | 'green' | 'unknown',
                      counts: {
                        red: Number,
                        amber: Number,
                        green: Number,
                        unknown: Number
                      }
                    }

Logic

  • Initialise counts for each status to zero.
  • Iterate through controls and increment counts based on ragStatus.
  • Determine aggregated status with priority:
    • If red > 0 → 'red'
    • Else if amber > 0 → 'amber'
    • Else if green > 0 → 'green'
    • Else → 'unknown'

6.2 Controller Methods

dashboard(req, res, next)

  • Route: GET /harrier
  • Query active controls only ({ isActive: true }).
  • Compute global aggregated RAG using aggregateRagStatus.
  • Group controls by level1:
    • Use Array.prototype.reduce or a Mongoose aggregate pipeline.
    • For each unique level1, aggregate RAG and counts.
  • Map RAG to Tailwind classes (example):
    • red → bg-red-500 text-white
    • amber → bg-amber-400 text-black
    • green → bg-green-500 text-white
    • unknown → bg-slate-400 text-white
  • Render harrier/dashboard with:
                    {
                      title: 'Harrier Controls Dashboard',
                      summary: { status, counts, cssClass },
                      level1Groups: [
                        {
                          level1: 'Fire Protection',
                          status: 'amber',
                          cssClass: '...',
                          counts: { red, amber, green, unknown },
                          totalControls: Number
                        },
                        ...
                      ]
                    }

level1Detail(req, res, next)

  • Route: GET /harrier/level/:level1
  • Filter controls by isActive: true and the given level1.
  • Group by level2 and aggregate each group’s RAG.
  • Compute overall summary for this level1.
  • Render harrier/level1.

level2Detail(req, res, next)

  • Route: GET /harrier/level/:level1/:level2
  • Filter by level1 and level2.
  • Group by level3 and aggregate RAG for each group.
  • Render harrier/level2.

level3Detail(req, res, next)

  • Route: GET /harrier/level/:level1/:level2/:level3
  • Filter by all three levels.
  • Show a list of individual controls matching that classification.
  • Render harrier/level3.

listControls(req, res, next)

  • Route: GET /harrier/controls
  • Support optional query filters:
    • level1, level2, level3
    • ragStatus
    • search (text search on name/description)
  • Return list and counts; display a simple table.
  • Render harrier/controls/index.

newControlForm(req, res)

  • Route: GET /harrier/controls/new
  • Render harrier/controls/new with an empty control object.
  • Default ragStatus may be 'green' or 'unknown'.

createControl(req, res, next)

  • Route: POST /harrier/controls
  • Validate required fields: name and level1.
  • Normalize empty strings for level2, level3, and tags.
  • Set ragStatus from form (fallback to 'unknown' if invalid).
  • Call Control.create.
  • On success: redirect to /harrier/controls or /harrier/controls/:id.
  • On validation error: re-render new with errors and entered data.

showControl(req, res, next)

  • Route: GET /harrier/controls/:id
  • Fetch control by id; check isActive if appropriate.
  • Map RAG status to a CSS class for the badge.
  • Render harrier/controls/show.

editControlForm(req, res, next)

  • Route: GET /harrier/controls/:id/edit
  • Fetch the control and pre-populate form fields.
  • Render harrier/controls/edit.

updateControl(req, res, next)

  • Route: POST /harrier/controls/:id (or PUT with method override)
  • Fetch control by id.
  • Update editable fields:
    • name, description
    • level1, level2, level3
    • ragStatus, tags, owner
  • Save and redirect to the show or list page.
  • On validation error: re-render edit.

deleteControl(req, res, next)

  • Route: POST /harrier/controls/:id/delete
  • Soft delete: set control.isActive = false and control.save().
  • Redirect to the list page and optionally show a flash message.

7. Views & Tailwind Layout

All views are located under: plugins/harrier/views/harrier/...

  • Use Tailwind CSS classes only.
  • Extend Shiftbulk main layout:
                    {{#extends 'main'}}
                      {{#block 'content'}}
                        ...
                      {{/block}}
                    {{/extends}}

7.1 Dashboard View

File: plugins/harrier/views/harrier/dashboard.handlebars

Sections:

  1. Header: Title “Harrier Controls Dashboard” and a short subtitle.
  2. Global Summary Card: Aggregated RAG pill and counts.
  3. Level 1 Table / Grid: For each Level 1:
    • Level 1 name
    • Aggregated RAG badge
    • Counts by RAG
    • Link to Level 1 detail view
  4. Quick Actions:
    • “View All Controls” → /harrier/controls
    • “New Control” → /harrier/controls/new (if permitted)

7.2 Level 1 View

File: plugins/harrier/views/harrier/level1.handlebars

  • Breadcrumb: Harrier > {{level1}}
  • Summary card for this level1.
  • Table grouping by level2 with aggregated RAG and counts.
  • Links to /harrier/level/{{level1}}/{{level2}}.

7.3 Level 2 View

File: plugins/harrier/views/harrier/level2.handlebars

  • Breadcrumb: Harrier > {{level1}} > {{level2}}
  • Summary for this slice of the hierarchy.
  • Table grouping by level3.
  • Links to /harrier/level/{{level1}}/{{level2}}/{{level3}}.

7.4 Level 3 View

File: plugins/harrier/views/harrier/level3.handlebars

  • Breadcrumb: Harrier > {{level1}} > {{level2}} > {{level3}}
  • Summary card plus list of controls (table or cards).
  • Links from each control to its detail page.

7.5 Controls List View

File: plugins/harrier/views/harrier/controls/index.handlebars

  • Filters (compact filter bar):
    • Level1 / Level2 / Level3 (text inputs or selects)
    • RAG status select
    • Search text input
  • Table columns:
    • Name
    • Level1
    • Level2
    • Level3
    • RAG badge
    • Owner
    • Actions (view / edit / delete)

7.6 Controls New / Edit Views

Files:

  • plugins/harrier/views/harrier/controls/new.handlebars
  • plugins/harrier/views/harrier/controls/edit.handlebars

Form fields:

  • Text input: name
  • Textarea: description
  • Text inputs or selects: level1, level2, level3
  • RAG select with 4 options: Green, Amber, Red, Unknown
  • owner (text or select, depending on available data)
  • tags (comma-separated string)

Use Tailwind form styles similar to the falcon/finding_edit template.

7.7 Control Show View

File: plugins/harrier/views/harrier/controls/show.handlebars

  • Display control details in a panel:
    • Name + RAG badge
    • Hierarchy: level1 / level2 / level3
    • Description
    • Owner
    • Tags
  • Buttons:
    • “Edit”
    • “Back to list”

8. Integration Points

8.1 Views Root

In the main app’s app.set('views', [...]), append:

                    path.join(__dirname, 'plugins/harrier/views')

8.2 Partials

If Harrier defines partials (e.g. a RAG badge component):

  • Directory: plugins/harrier/views/harrier/partials
  • Add to partialsDir array in main app:
                    {
                      dir: path.join(__dirname, 'plugins', 'harrier', 'views', 'harrier', 'partials'),
                      namespace: 'harrier'
                    }
  • Optionally call the app’s helper to register the directory as a namespace.

8.3 Tailwind

  • Harrier views rely on Tailwind being included in the main layout.
  • No additional CSS or JS is strictly required in v1.

9. Validation & Error Handling

9.1 Server-Side Validation

  • name must be non-empty.
  • ragStatus must be one of the allowed values.
  • level1 must be non-empty.

9.2 On Validation Failure

  • Re-render the same form with error messages (simple <div> text is sufficient).

9.3 404 Handling

  • If a control is not found, use the main app’s 404 handler or redirect to /harrier/controls.

10. LLM Implementation Instructions (Meta)

10.1 Overall

  • Use CommonJS (require, module.exports).
  • Add "use strict"; at the top of each JS file.
  • Do not output diffs; output complete file contents.
  • Structure all code under plugins/harrier.

10.2 File Structure

                    plugins/
                      harrier/
                        index.js                       // Express router
                        models/
                          Control.js                   // Mongoose model
                        controllers/
                          harrierController.js         // All controller logic
                        views/
                          harrier/
                            dashboard.handlebars
                            level1.handlebars
                            level2.handlebars
                            level3.handlebars
                            controls/
                              index.handlebars
                              new.handlebars
                              edit.handlebars
                              show.handlebars
                            partials/                  // optional, e.g. RAG badge
                              rag_badge.handlebars
                    

10.3 index.js Requirements

  • Create an Express router.
  • Apply bodyParser middleware.
  • Set res.locals.basePath for all requests.
  • Wire up controller methods for all routes described in Section 5.
  • Export the router.

10.4 Controller Requirements

  • Implement all methods listed in Section 6.
  • Use the Control model for DB operations.
  • Centralize RAG aggregation logic in helper function(s).
  • Compute CSS class strings in the controller and pass them to views (e.g. item.statusClass).

10.5 Model Requirements

  • Implement the schema exactly as described in Section 4.
  • Use timestamps: true.
  • Export Mongoose model as:
                    module.exports = mongoose.model('Control', ControlSchema);

10.6 View Requirements

  • All views must:
    • Extend the 'main' layout.
    • Use Tailwind classes only (no Bootstrap).
    • Follow visual patterns from falcon/finding_edit (spacing, card containers, headings, etc.).

10.7 Packaging as Downloadable Files

  • Bundle everything under plugins/harrier into a zip archive (e.g. harrier-plugin.zip).
  • Provide a link or reference for the user to download the zip (depending on execution environment).
  • Preserve directory structure exactly inside the archive.
modal1
modal2
modal3
docs_javascript
new_issue_button.handlebars
shortcut_edit