Add version control context processor and integrate map functionality with dedicated JavaScript

This commit is contained in:
pacnpal
2025-02-06 20:06:10 -05:00
parent f3d28817a5
commit ecf94bf84e
16 changed files with 1671 additions and 89 deletions

View File

@@ -0,0 +1,228 @@
# ThrillWiki Version Control System
## Overview
The ThrillWiki Version Control System (VCS) provides comprehensive version tracking, branching, and merging capabilities for all content in the system. It builds upon django-simple-history while adding powerful versioning features.
## Features
- Full version history tracking
- Branch-based development
- Version tagging
- Merge operations with conflict resolution
- Real-time collaborative editing
- Automatic change tracking
## Model Integration
### Making Models Version-Controlled
To add version control to any model, inherit from `HistoricalModel`:
```python
from history_tracking.models import HistoricalModel
class YourModel(HistoricalModel):
# Your model fields here
name = models.CharField(max_length=255)
class Meta:
# Your meta options
```
This automatically provides:
- Full version history
- Change tracking
- Branch support
- Merge capabilities
### Example Integration (from parks/models.py)
```python
from history_tracking.models import HistoricalModel
class Park(HistoricalModel):
name = models.CharField(max_length=255)
description = models.TextField()
def save(self, *args, **kwargs):
# Changes will be automatically tracked
super().save(*args, **kwargs)
```
## Usage Guide
### Basic Version Control Operations
1. Creating a Branch
```python
from history_tracking.managers import BranchManager
# Create a new feature branch
branch_manager = BranchManager()
feature_branch = branch_manager.create_branch(
name="feature/new-park-details",
user=request.user
)
```
2. Recording Changes
```python
from history_tracking.signals import ChangesetContextManager
# Making changes in a specific branch
with ChangesetContextManager(branch=feature_branch, user=request.user):
park = Park.objects.get(id=1)
park.description = "Updated description"
park.save() # Change is automatically tracked in the branch
```
3. Merging Changes
```python
# Merge feature branch back to main
success, conflicts = branch_manager.merge_branches(
source=feature_branch,
target=main_branch,
user=request.user
)
if not success:
# Handle merge conflicts
for conflict in conflicts:
# Resolve conflicts through UI or programmatically
pass
```
4. Working with Tags
```python
from history_tracking.models import VersionTag
# Tag a specific version
VersionTag.objects.create(
name="v1.0.0",
branch=main_branch,
content_type=ContentType.objects.get_for_model(park),
object_id=park.id,
created_by=user
)
```
## UI Integration
### HTMX Components
The system provides HTMX-powered components for real-time version control:
1. Version Control Panel
```html
{% include "history_tracking/version_control_panel.html" %}
```
2. Branch Selection
```html
<div hx-get="{% url 'history:branch-list' %}"
hx-trigger="load, branch-updated from:body">
</div>
```
3. Change History
```html
<div hx-get="{% url 'history:history-view' %}?branch={{ branch.name }}"
hx-trigger="load, branch-selected from:body">
</div>
```
## Best Practices
1. Branch Management
- Create feature branches for significant changes
- Use descriptive branch names (e.g., "feature/new-park-system")
- Clean up merged branches
- Regularly sync with main branch
2. Change Tracking
- Make atomic, related changes
- Provide clear change descriptions
- Group related changes in a single changeset
- Review changes before merging
3. Conflict Resolution
- Resolve conflicts promptly
- Communicate with team members about overlapping changes
- Test after resolving conflicts
- Document resolution decisions
4. Performance
- Use changesets for bulk operations
- Index frequently queried fields
- Clean up old branches and tags
- Monitor system performance
## Error Handling
1. Common Issues
```python
try:
branch_manager.merge_branches(source, target)
except ValidationError as e:
# Handle validation errors
except MergeConflict as e:
# Handle merge conflicts
```
2. Conflict Resolution
```python
from history_tracking.utils import resolve_conflicts
resolved = resolve_conflicts(
source_branch=source,
target_branch=target,
resolutions={
'conflict_id': 'resolution_type', # 'source', 'target', or 'manual'
},
manual_resolutions={
'conflict_id': 'manual resolution content'
},
user=request.user
)
```
## System Maintenance
1. Regular Tasks
- Clean up old branches
- Archive old versions
- Verify data integrity
- Monitor system health
2. Monitoring
```python
from history_tracking.utils import get_system_metrics
metrics = get_system_metrics()
# Check branch counts, merge success rates, etc.
```
## Security Considerations
1. Access Control
- All VCS operations require authentication
- Branch operations are logged
- Merge operations require proper permissions
- Changes are tracked with user attribution
2. Data Protection
- Historical data is preserved
- Audit logs are maintained
- Sensitive data is handled securely
- Backups include version history
## Support and Troubleshooting
For issues or questions:
1. Check the logs for detailed error messages
2. Review the conflict resolution documentation
3. Verify branch and change permissions
4. Contact the development team for assistance
## Contributing
When contributing to the VCS:
1. Follow the established branching pattern
2. Document significant changes
3. Add tests for new features
4. Update technical documentation

View File

@@ -0,0 +1,159 @@
# Version Control System Implementation Checklist
## Core Implementation ✓
- [x] Models
- [x] VersionBranch
- [x] VersionTag
- [x] ChangeSet
- [x] Generic relationships for flexibility
- [x] Managers
- [x] BranchManager
- [x] ChangeTracker
- [x] MergeStrategy
- [x] UI Components
- [x] Version Control Panel
- [x] Branch List
- [x] History View
- [x] Merge Panel
- [x] Branch Creation Form
## Asset Integration ✓
- [x] JavaScript
- [x] Version Control core functionality
- [x] HTMX integration
- [x] Event handling
- [x] CSS
- [x] Version control styles
- [x] Component styles
- [x] Responsive design
## Template Integration
- [x] Base Template Updates
- [x] Required JS/CSS includes
- [x] Version control status bar
- [x] HTMX setup
- [x] Park System
- [x] Park detail template
- [ ] Park list template
- [ ] Area detail template
- [ ] Rides System
- [ ] Ride detail template
- [ ] Ride list template
- [ ] Reviews System
- [ ] Review detail template
- [ ] Review list template
- [ ] Companies System
- [ ] Company detail template
- [ ] Company list template
## Model Integration
- [x] Park Model
- [x] VCS integration
- [x] Save method override
- [x] Version info methods
- [x] ParkArea Model
- [x] VCS integration
- [x] Save method override
- [x] Version info methods
- [ ] Ride Model
- [ ] VCS integration
- [ ] Save method override
- [ ] Version info methods
- [ ] Review Model
- [ ] VCS integration
- [ ] Save method override
- [ ] Version info methods
- [ ] Company Model
- [ ] VCS integration
- [ ] Save method override
- [ ] Version info methods
## Documentation
- [x] README creation
- [x] Implementation guide
- [x] Template integration guide
- [ ] API documentation
- [ ] User guide
## Testing Requirements
- [ ] Unit Tests
- [ ] Model tests
- [ ] Manager tests
- [ ] View tests
- [ ] Form tests
- [ ] Integration Tests
- [ ] Branch operations
- [ ] Merge operations
- [ ] Change tracking
- [ ] UI interactions
- [ ] UI Tests
- [ ] Component rendering
- [ ] User interactions
- [ ] Responsive design
- [ ] Browser compatibility
## Monitoring Setup
- [ ] Performance Metrics
- [ ] Branch operation timing
- [ ] Merge success rates
- [ ] Change tracking overhead
- [ ] UI responsiveness
- [ ] Error Tracking
- [ ] Operation failures
- [ ] Merge conflicts
- [ ] UI errors
- [ ] Performance issues
## Next Steps
1. Complete model integrations:
- Update Ride model
- Update Review model
- Update Company model
2. Template implementations:
- Create remaining detail templates
- Add version control to list views
- Implement version indicators
3. Testing:
- Write comprehensive test suite
- Set up CI/CD integration
- Perform load testing
4. Documentation:
- Complete API documentation
- Create user guide
- Add examples and tutorials
5. Monitoring:
- Set up performance monitoring
- Configure error tracking
- Create dashboards
## Known Issues
1. Need to implement proper error handling in JavaScript
2. Add loading states to UI components
3. Implement proper caching for version history
4. Add batch operations for multiple changes
5. Implement proper cleanup for old versions
## Future Enhancements
1. Add visual diff viewer
2. Implement branch locking
3. Add commenting on changes
4. Create change approval workflow
5. Add version comparison tool

View File

@@ -0,0 +1,86 @@
# Version Control UI Template Integration
## Templates Requiring VCS Integration
### Park System
- [x] parks/templates/parks/park_detail.html - Completed
- [ ] parks/templates/parks/park_list.html - Add version status indicators
- [ ] parks/templates/parks/park_area_detail.html - Add version control UI
### Rides System
- [ ] rides/templates/rides/ride_detail.html - Add version control UI
- [ ] rides/templates/rides/ride_list.html - Add version status indicators
### Reviews System
- [ ] reviews/templates/reviews/review_detail.html - Add version control UI
- [ ] reviews/templates/reviews/review_list.html - Add version status indicators
### Company System
- [ ] companies/templates/companies/company_detail.html - Add version control UI
- [ ] companies/templates/companies/company_list.html - Add version status indicators
## Integration Guidelines
### Detail Templates
For detail templates, add the version control UI below the main title:
```html
<!-- Title Section -->
<h1>{{ object.name }}</h1>
<!-- Version Control UI -->
{% include "history_tracking/includes/version_control_ui.html" %}
<!-- Rest of the content -->
```
### List Templates
For list templates, add version indicators in the list items:
```html
{% for item in object_list %}
<div class="item">
<h2>{{ item.name }}</h2>
{% if version_control.vcs_enabled %}
<div class="version-info text-sm text-gray-600">
Branch: {{ item.get_version_info.current_branch.name }}
</div>
{% endif %}
</div>
{% endfor %}
```
## Integration Steps
1. Update base template to include necessary JavaScript
```html
<!-- In base.html -->
<script src="{% static 'js/version-control.js' %}"></script>
```
2. Add version control UI to detail views
- Include the version control UI component
- Add branch switching functionality
- Display version history
3. Add version indicators to list views
- Show current branch
- Indicate if changes are pending
- Show version status
4. Update view classes
- Ensure models inherit from HistoricalModel
- Add version control context
- Handle branch switching
5. Test integration
- Verify UI appears correctly
- Test branch switching
- Verify history tracking
- Test merge functionality
## Next Steps
1. Create park area detail template with version control
2. Update ride detail template
3. Add version control to review system
4. Integrate with company templates

View File

@@ -0,0 +1,110 @@
# Version Control System UI Improvements
## Recent Improvements
### 1. Template Structure Enhancement
- Moved map initialization to dedicated JavaScript file
- Implemented data attribute pattern for passing data to JavaScript
- Improved template organization and maintainability
### 2. JavaScript Organization
- Created separate `map-init.js` for map functionality
- Established pattern for external JavaScript files
- Improved error handling and script loading
### 3. Asset Management
```javascript
// Static Asset Organization
/static/
/js/
version-control.js // Core VCS functionality
map-init.js // Map initialization logic
/css/
version-control.css // VCS styles
```
## Best Practices Established
### 1. Data Passing Pattern
```html
<!-- Using data attributes for JavaScript configuration -->
<div id="map"
data-lat="{{ coordinates.lat }}"
data-lng="{{ coordinates.lng }}"
data-name="{{ name }}">
</div>
```
### 2. JavaScript Separation
```javascript
// Modular JavaScript organization
document.addEventListener('DOMContentLoaded', function() {
// Initialize components
const mapContainer = document.getElementById('map');
if (mapContainer) {
// Component-specific logic
}
});
```
### 3. Template Structure
```html
{% block content %}
<!-- Main content -->
{% endblock %}
{% block extra_js %}
{{ block.super }}
<!-- Component-specific scripts -->
<script src="{% static 'js/component-script.js' %}"></script>
{% endblock %}
```
## Integration Guidelines
### 1. Adding New Components
1. Create dedicated JavaScript file in `/static/js/`
2. Use data attributes for configuration
3. Follow established loading pattern
4. Update base template if needed
### 2. Version Control UI
1. Include version control UI component
2. Add necessary data attributes
3. Ensure proper script loading
4. Follow established patterns
### 3. Static Asset Management
1. Keep JavaScript files modular
2. Use proper static file organization
3. Follow naming conventions
4. Maintain clear dependencies
## Next Steps
1. Apply this pattern to other templates:
- Ride detail template
- Review detail template
- Company detail template
2. Implement consistent error handling:
```javascript
function handleError(error) {
console.error('Component error:', error);
// Handle error appropriately
}
```
3. Add performance monitoring:
```javascript
// Add timing measurements
const startTime = performance.now();
// Component initialization
const endTime = performance.now();
console.debug(`Component initialized in ${endTime - startTime}ms`);
```
4. Documentation updates:
- Add JavaScript patterns to technical guide
- Update template integration guide
- Document asset organization