Back to Help | Back to login

CHANGE TRACKING FEASIBILITY

Central Business Platform (CBP)

Access: The CBP platform is available at https://cbp.africacdc.org/staff/apm. You must have a valid account to sign in.
No matching content found. Try different keywords.

Change Tracking Implementation - Feasibility Analysis

Summary

Frontend JavaScript detection is highly recommended for better UX, with server-side validation as backup.

Current Implementation (Server-Side Only)

Location: ChangeRequestController::detectChanges()

Pros

  • ✅ Single source of truth
  • ✅ Secure - can't be bypassed
  • ✅ Works with all form submissions

Cons

  • ❌ No user feedback until submission
  • ❌ Users don't know what changed before submitting
  • ❌ Poor UX for validation

Architecture

┌─────────────────────────────────────────────────┐
│  Frontend (JavaScript)                          │
│  - Real-time change detection                  │
│  - Visual feedback for users                   │
│  - Change summary before submission            │
└─────────────────────────────────────────────────┘
                    ↓ submits
┌─────────────────────────────────────────────────┐
│  Backend (Controller)                          │
│  - Receives form data                          │
│  - Performs server-side validation             │
│  - Saves to database                           │
└─────────────────────────────────────────────────┘

Implementation Plan

Phase 1: Frontend Change Detection (JavaScript)

File: resources/views/change-requests/create.blade.php (needs to be created)

Features:

  1. Track Original Values

```javascript

const originalValues = {

activityTitle: '{{ $parentMemo->activity_title }}',

memoDate: '{{ $parentMemo->memo_date ?? $parentMemo->date_to }}',

participants: {}, // JSON parsed

budget: {}, // JSON parsed

// ... etc

};

```

  1. Detect Changes on Input

```javascript

$('input, select, textarea').on('change', function() {

const changes = detectChanges();

displayChangeSummary(changes);

});

```

  1. Display Change Summary

- Show which fields changed

- Highlight changed fields

- Warn about significant changes (e.g., quarter change)

Phase 2: Keep Server-Side Logic (PHP)

Why keep it?

  • Security: Can't trust client-side data
  • Reliability: Server always has correct data
  • Consistency: Single source of truth

Current Implementation:

ChangeRequestController::detectChanges() ✅ Keep as-is


Detailed Comparison

Option A: Frontend Only ⚠️

Not Recommended

  • ❌ Security risk (could be manipulated)
  • ❌ No backup if JavaScript fails
  • ❌ Hard to maintain

Option B: Server-Side Only (Current) ⚠️

Functional but poor UX

  • ✅ Secure
  • ✅ Reliable
  • ❌ No user feedback
  • ❌ Users submit without knowing changes

Best of both worlds

  • ✅ Real-time user feedback
  • ✅ Secure server-side validation
  • ✅ Better UX
  • ✅ Reliable

Implementation Complexity

Frontend Change Detection

Complexity: Medium (2-4 hours)

Required Skills:

  • JavaScript DOM manipulation
  • Event handlers
  • JSON comparison
  • Form data extraction

Challenges:

  1. Date Comparison (quarters)

```javascript

function getQuarter(date) {

const month = new Date(date).getMonth() + 1;

if (month <= 3) return 'Q1';

if (month <= 6) return 'Q2';

if (month <= 9) return 'Q3';

return 'Q4';

}

```

  1. Budget JSON Comparison

```javascript

function compareBudgets(before, after) {

return JSON.stringify(before) !== JSON.stringify(after);

}

```

  1. Participant Changes

```javascript

function detectParticipantChanges(before, after) {

const keysBefore = Object.keys(before);

const keysAfter = Object.keys(after);

// Check additions/removals

if (keysBefore.length !== keysAfter.length) return true;

// Check details for each participant

for (let key of keysBefore) {

if (!after[key]) return true; // Removed

if (before[key].participant_days !== after[key].participant_days) {

return true; // Days changed

}

}

return false;

}

```


Recommendations

Immediate Action Plan

  1. Keep Current Implementation

- Server-side detection is working

- No breaking changes needed

  1. Add Frontend Enhancement (Optional but Recommended)

- Show users what will change before submission

- Improve UX significantly

- About 4-6 hours of development

  1. Progressive Enhancement Approach

- Start with server-side (working now)

- Add frontend enhancement incrementally

- Best of both worlds

Code Structure

// change-request-tracker.js
class ChangeRequestTracker {
    constructor(originalData) {
        this.original = originalData;
        this.current = {};
    }
    
    detectChanges() {
        return {
            title: this.compareField('activity_title'),
            dates: this.compareDates(),
            participants: this.compareParticipants(),
            budget: this.compareBudget()
        };
    }
    
    compareField(fieldName) {
        return this.original[fieldName] !== this.current[fieldName];
    }
    
    compareDates() {
        // Quarter logic here
        const originalQuarter = this.getQuarter(this.original.date_to);
        const currentQuarter = this.getQuarter(this.current.date_to);
        
        return {
            changed: originalQuarter !== currentQuarter,
            stayedInQuarter: originalQuarter === currentQuarter
        };
    }
}

// Usage
const tracker = new ChangeRequestTracker({{ json_encode($parentMemo) }});

Conclusion

Recommendation: Keep server-side detection as primary, add frontend for UX.

Why?

  1. Security: Server-side can't be bypassed
  2. Reliability: Works even if JavaScript fails
  3. Performance: Current implementation is fast enough
  4. Maintenance: Single source of truth

If Adding Frontend:

  • Enhance UX with real-time feedback
  • No security impact (server validates)
  • Progressive enhancement approach

Final Answer:

Keep current server-side implementation

Add optional frontend enhancement ⭐ (Recommended for better UX)

Help Center Back to login