directus-extension-schedule
v1.1.0
Published
Schedule interface with start and end date fields, automatic draft creation, and cron-like monitoring
Downloads
18
Maintainers
Readme
Directus Schedule Extension
A comprehensive schedule interface for Directus with start and end date fields, time selection, and automatic draft creation for schedule mismatches.
Preview

Features
- Date Range Selection: Choose start and end dates with an intuitive calendar interface
- Time Selection: Optional time picker for precise scheduling
- Multiple Display Formats: Support for various date display formats (short, medium, long, numeric, European, ISO)
- Validation Rules: Configurable validation for date relationships and future dates
- Draft Mode: Automatic creation of draft entries when schedules don't match current time
- Cron-like Monitoring: Periodic checks for schedule mismatches (configurable interval)
- Automatic Status Management: Hooks system that automatically changes collection items to draft when schedules end
- Real-time Monitoring: Continuous monitoring of schedule end times with automatic status updates
Installation
Build the extension:
npm run buildLink it to your Directus instance:
npm run link
Configuration Options
Basic Options
- Start Date Field: Field name for the start date (default:
start_date) - End Date Field: Field name for the end date (default:
end_date) - Show Time: Enable time selection in addition to date selection
- Required: Make both start and end dates required fields
- Display Format: Choose how dates are displayed in the input field
- Validation: Set validation rules for date relationships
Draft Mode Options
- Collection for Drafts: Select from available collections where draft entries will be created
- Enable Draft Mode: Toggle automatic draft creation for schedule mismatches
- Cron Check Interval: Set the interval (in milliseconds) for checking schedule mismatches
- Auto Draft on End: Automatically change item status to draft when schedule ends
Draft Mode Functionality
When enabled, the schedule interface automatically monitors for cases where the current Directus time doesn't match the selected schedule range:
Mismatch Detection
- Before Start: Shows warning when current time is before scheduled start time
- After End: Shows error when current time is past scheduled end time
- Within Range: No mismatch detected when current time is within the schedule
Automatic Draft Creation
When a mismatch is detected, users can manually trigger the creation of a draft entry that includes:
- Original schedule information
- Current mismatch status
- Timestamp of creation
- Descriptive notes about the mismatch
Cron-like Monitoring
The interface runs periodic checks (default: every 5 minutes) to detect schedule mismatches automatically. This ensures that:
- Mismatches are detected even when the interface is not actively being used
- Users are notified of schedule issues in real-time
- Draft entries can be created proactively
Hooks System
The extension includes a powerful hooks system that automatically manages collection item statuses when schedules end:
Automatic Status Management
- Real-time Monitoring: Continuously monitors schedule end times
- Automatic Draft Conversion: Changes item status to draft when schedule ends
- Batch Processing: Handles multiple ended schedules efficiently
- Configurable: Customizable collection names, field names, and status values
Hook Events
items.create: Triggers when new schedules are createditems.update: Triggers when existing schedules are modifiedcron: Periodic checks for ended schedules (configurable interval)
Status Tracking
- Audit Trail: Records when and why items were auto-drafted
- Metadata: Adds
auto_drafted_atandauto_draft_reasonfields - Event Emission: Optional custom event emission for external integrations
For detailed information about the hooks system, see HOOKS.md.
Automatic Draft Status Changes
When enabled, the interface automatically changes the current item's status to "draft" when a schedule ends:
- Immediate Detection: Checks for ended schedules when the component mounts
- Automatic Updates: Changes status to draft without user intervention
- Status Tracking: Records when the schedule ended and adds explanatory notes
- Manual Override: Users can still manually trigger draft status changes
- Real-time Updates: Local interface updates to reflect the new status
Usage Examples
Basic Schedule Field
{
"interface": "schedule",
"options": {
"startDateField": "event_start",
"endDateField": "event_end",
"showTime": true,
"required": true
}
}With Draft Mode Enabled
{
"interface": "schedule",
"options": {
"startDateField": "meeting_start",
"endDateField": "meeting_end",
"showTime": true,
"collection": "meeting_drafts",
"enableDraftMode": true,
"cronInterval": 300000,
"autoDraftOnEnd": true
}
}Note: The collection field now uses a system collection list interface, allowing you to select from available collections in your Directus instance instead of typing the collection name manually.
Validation Rules
- None: No validation applied
- End date must be after start date: Ensures logical date ordering
- Start date must be in the future: Prevents scheduling in the past
- Both validations: Applies both validation rules
Display Formats
- Short: Jan 7, 2025
- Medium: January 7, 2025
- Long: Mon, January 7, 2025
- Numeric: 04/08/2025
- European: 07.01.2025
- ISO: 2025-01-07
Browser Compatibility
This extension uses modern JavaScript features and is compatible with:
- Chrome 88+
- Firefox 85+
- Safari 14+
- Edge 88+
Development
To run in development mode with hot reloading:
npm run devBuilding for Production
npm run buildContributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details.
