# 🚀 Frontend Refactoring & Optimization Roadmap
**Equipment Maintenance System (EMS) — DHA Bahawalpur**  
*Document Version: 1.0 | Date: 24 October 2026*  
*Objective: Eliminate Frontend Code Duplication, Enhance Maintainability, and Maximize Speed without breaking existing functionality.*

---

## 🎯 Guiding Principles (Must Not Break)
1. **Zero Functional Regression:** Koi bhi existing workflow (Clerk demand, Technician inspection, Director/Secretary approval, IT Admin assignment) affect nahi hoga.
2. **Role & Ability Driven:** Har user ko wahi columns, buttons, aur actions dikhenge jo unke Role aur Abilities (`can(...)`) k mutabiq allowed hain.
3. **Step-by-Step Execution:** Pehle low-risk shared components (Status Badges), phir Universal History Table, aur aakhir mein Dashboard modularization.

---

## 📋 Task Checklist & Progress

### Phase 1: Centralized Status Badges & Colors
- [x] **Task 1.1:** Create unified `<StatusBadge :status="ticket.status" :mode="'pill' | 'badge'" />` component in `resources/js/Components/StatusBadge.vue`.
  - Sabhi 15+ statuses k colors, background, glowing dots, aur human-readable labels ek jagah define hon.
  - Ability-aware labels (e.g. Technician ko "Action Required", Approver ko "Pending Review").
- [x] **Task 1.2:** Replace inline duplicate status badge code across:
  - `resources/js/Pages/Technician/Dashboard.vue`
  - `resources/js/Pages/Technician/History.vue`
  - `resources/js/Pages/ItAdmin/History.vue`
  - `resources/js/Pages/Clerk/History.vue`
  - `resources/js/Pages/Approver/History.vue`
  - `resources/js/Pages/ItDirector/History.vue`
  - `resources/js/Pages/SuperAdmin/AllPerformaHistory.vue`

---

### Phase 2: Universal Ticket History Table Component
- [x] **Task 2.1:** Create reusable `<TicketHistoryTable />` component in `resources/js/Components/TicketHistoryTable.vue`.
  - **Shared Features:**
    - Live Search (Performa ID, Asset Tag, Employee, Branch, Directorate).
    - Filters Grid (Directorate, Category, Status, Cost, Date Order).
    - Sortable table columns with clean responsive layout.
    - Pagination (10, 25, 50, 100 per page).
    - Performa View & Print modal integration.
    - Export Report dropdown (Excel CSV with UTF-8 BOM, Word DOC table, PDF Print).
  - **Role & Ability Columns (Conditional):**
    - `can('edit-ticket-dates')` -> SweetAlert date editing modal & PUT request.
    - `Role == Clerk` -> Interactive verification & rejection actions inside modal.
    - `Role == Technician` -> Links to technician inspection/detail workflow.
    - `Role == Approver / Director` -> Integrated Performa view modal.
    - `Role == IT_Admin / Super_Admin` -> Complete financial & action controls with direct ICT route linking.
- [x] **Task 2.2:** Refactor existing history pages to consume the Universal component:
  - `resources/js/Pages/Technician/History.vue` (Reduced from 378 lines to 29 lines)
  - `resources/js/Pages/Clerk/History.vue` (Reduced from 365 lines to 48 lines)
  - `resources/js/Pages/Approver/History.vue` (Reduced from 279 lines to 48 lines)
  - `resources/js/Pages/ItDirector/History.vue` (Reduced from 299 lines to 29 lines)
  - `resources/js/Pages/ItAdmin/History.vue` (Reduced from 991 lines to 48 lines)

---

### Phase 3: Dashboard Architecture Strategy
- [x] **Task 3.1:** Architectural Evaluation:
  - *Single Monolithic Dashboard File:* ❌ (Rejected: High risk of cross-role regressions).
  - *Component-Driven Modular Dashboard:* ✅ (Adopted: Shared reusable blocks like `<KpiCardsGrid />`, `<WorkflowTabsBar />`, `<TicketQuickFilter />`).
- [x] **Task 3.2:** Build Reusable Dashboard Blocks in `resources/js/Components/Dashboard/`:
  - `<KpiCardsGrid :cards="cards" />` (Responsive metric cards with SVG icons, color coding, and click filtering).
  - `<WorkflowTabsBar v-model="activeTab" :tabs="tabs" :variant="'pills' | 'underline'" />` (Unified tab navigation with counter badges, pulse animations, and `#right` slot).
  - `<TicketQuickFilter v-model="filters" :directorates="directorates" :categories="categories" ... />` (Unified multi-field reactive filter bar with live search, dropdowns, cost options, date order, and clear button).
  - **Integrated across Dashboards:**
    - `resources/js/Pages/Approver/Dashboard.vue`
    - `resources/js/Pages/Technician/Dashboard.vue`
    - `resources/js/Pages/Clerk/Dashboard.vue`
    - `resources/js/Pages/ItAdmin/Dashboard.vue`

---

### Phase 4: Performance & Speed Tuning
- [x] **Task 4.1:** Client-side bundle optimization (Code splitting verified; SweetAlert2 split into independent 78kB chunk; dashboard bundles reduced).
- [ ] **Task 4.2:** Lazy loading of large historical attachments (load attachment preview images on modal open rather than eager load).
- [x] **Task 4.3:** Build asset verification and caching validation (`npm run build` passes with code 0).

---

## 🔍 Change Log & Completed Milestones

| Date | Task ID | Description | Status |
| :--- | :--- | :--- | :--- |
| 24-Oct-2026 | Initial | Roadmap document created & committed | Completed |
| 24-Oct-2026 | Phase 1 | `<StatusBadge.vue>` created & integrated across dashboards & history | Completed |
| 24-Oct-2026 | Phase 2 | `<TicketHistoryTable.vue>` created; eliminated ~2,000 duplicate lines across all role history pages | Completed |
| 24-Oct-2026 | Testing | Automated role route test: All 13 history routes return HTTP 200 | Verified |
| 24-Oct-2026 | Fix | IT Director history route wired directly to `ItDirector/History.vue` | Fixed |
| 24-Oct-2026 | Fix | "Export Report" button restricted strictly to IT Admin (hidden for all other roles) | Fixed |
| 24-Oct-2026 | Fix | Addl Dir IT (`/addl-dir-it/history`), Dir IT (`/it-director/history`), and Secretary (`/secretary/history`) given dedicated URLs, titles, and Vue components | Fixed |
| 24-Oct-2026 | Fix | Strict Role History Isolation: History queries now exclusively return tickets where the logged-in role has personal approval/rejection actions; zero cross-role leakage | Fixed |
| 25-Oct-2026 | Phase 3 | Created `<KpiCardsGrid.vue>`, `<WorkflowTabsBar.vue>`, and `<TicketQuickFilter.vue>` in `Components/Dashboard/` | Completed |
| 25-Oct-2026 | Phase 3 | Refactored Approver, Technician, Clerk, and IT Admin dashboards with shared blocks | Completed |
| 25-Oct-2026 | Testing | Browser Subagent live UI & reactive filter testing verified with 0 console errors | Verified |

