mirror of
https://github.com/vleeuwenmenno/supplements.git
synced 2025-12-08 06:02:34 +00:00
adds syncing
This commit is contained in:
178
lib/models/sync_enums.dart
Normal file
178
lib/models/sync_enums.dart
Normal file
@@ -0,0 +1,178 @@
|
||||
/// Enumeration for sync status of individual records
|
||||
enum SyncStatus {
|
||||
/// Record is newly created and needs to be synced
|
||||
pending,
|
||||
|
||||
/// Record is in sync with remote server
|
||||
synced,
|
||||
|
||||
/// Record has been modified locally and needs to be synced
|
||||
modified,
|
||||
|
||||
/// Record has a conflict that needs resolution
|
||||
conflict,
|
||||
|
||||
/// Record is being synced (temporary state)
|
||||
syncing,
|
||||
|
||||
/// Record sync failed and will be retried
|
||||
failed,
|
||||
}
|
||||
|
||||
/// Enumeration for overall sync operation status
|
||||
enum SyncOperationStatus {
|
||||
/// No sync operation in progress
|
||||
idle,
|
||||
|
||||
/// Currently syncing data
|
||||
syncing,
|
||||
|
||||
/// Last sync completed successfully
|
||||
success,
|
||||
|
||||
/// Last sync failed due to network issues
|
||||
networkError,
|
||||
|
||||
/// Last sync failed due to authentication issues
|
||||
authenticationError,
|
||||
|
||||
/// Last sync failed due to server issues
|
||||
serverError,
|
||||
|
||||
/// Last sync had conflicts that need resolution
|
||||
conflictsDetected,
|
||||
|
||||
/// Sync cancelled by user
|
||||
cancelled,
|
||||
}
|
||||
|
||||
/// Enumeration for conflict resolution strategies
|
||||
enum ConflictResolutionStrategy {
|
||||
/// Always prefer local changes
|
||||
preferLocal,
|
||||
|
||||
/// Always prefer remote changes
|
||||
preferRemote,
|
||||
|
||||
/// Prefer the most recently modified record
|
||||
preferNewer,
|
||||
|
||||
/// Ask user to resolve conflicts manually
|
||||
manual,
|
||||
}
|
||||
|
||||
/// Enumeration for sync frequency options
|
||||
enum SyncFrequency {
|
||||
/// Manual sync only
|
||||
manual,
|
||||
|
||||
/// Sync every 15 minutes
|
||||
every15Minutes,
|
||||
|
||||
/// Sync every hour
|
||||
hourly,
|
||||
|
||||
/// Sync every 6 hours
|
||||
every6Hours,
|
||||
|
||||
/// Sync once per day
|
||||
daily,
|
||||
}
|
||||
|
||||
/// Extension to get human-readable names for SyncStatus
|
||||
extension SyncStatusExtension on SyncStatus {
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case SyncStatus.pending:
|
||||
return 'Pending Sync';
|
||||
case SyncStatus.synced:
|
||||
return 'Synced';
|
||||
case SyncStatus.modified:
|
||||
return 'Modified';
|
||||
case SyncStatus.conflict:
|
||||
return 'Conflict';
|
||||
case SyncStatus.syncing:
|
||||
return 'Syncing...';
|
||||
case SyncStatus.failed:
|
||||
return 'Sync Failed';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension to get human-readable names for SyncOperationStatus
|
||||
extension SyncOperationStatusExtension on SyncOperationStatus {
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case SyncOperationStatus.idle:
|
||||
return 'Ready';
|
||||
case SyncOperationStatus.syncing:
|
||||
return 'Syncing...';
|
||||
case SyncOperationStatus.success:
|
||||
return 'Sync Complete';
|
||||
case SyncOperationStatus.networkError:
|
||||
return 'Network Error';
|
||||
case SyncOperationStatus.authenticationError:
|
||||
return 'Authentication Failed';
|
||||
case SyncOperationStatus.serverError:
|
||||
return 'Server Error';
|
||||
case SyncOperationStatus.conflictsDetected:
|
||||
return 'Conflicts Detected';
|
||||
case SyncOperationStatus.cancelled:
|
||||
return 'Sync Cancelled';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension to get duration for SyncFrequency
|
||||
extension SyncFrequencyExtension on SyncFrequency {
|
||||
Duration get duration {
|
||||
switch (this) {
|
||||
case SyncFrequency.manual:
|
||||
return Duration.zero; // Manual sync only
|
||||
case SyncFrequency.every15Minutes:
|
||||
return const Duration(minutes: 15);
|
||||
case SyncFrequency.hourly:
|
||||
return const Duration(hours: 1);
|
||||
case SyncFrequency.every6Hours:
|
||||
return const Duration(hours: 6);
|
||||
case SyncFrequency.daily:
|
||||
return const Duration(days: 1);
|
||||
}
|
||||
}
|
||||
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case SyncFrequency.manual:
|
||||
return 'Manual Only';
|
||||
case SyncFrequency.every15Minutes:
|
||||
return 'Every 15 Minutes';
|
||||
case SyncFrequency.hourly:
|
||||
return 'Hourly';
|
||||
case SyncFrequency.every6Hours:
|
||||
return 'Every 6 Hours';
|
||||
case SyncFrequency.daily:
|
||||
return 'Daily';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Constants for sync operations
|
||||
class SyncConstants {
|
||||
static const String syncFileName = 'supplements_sync.json';
|
||||
static const String syncFileBackupName = 'supplements_sync_backup.json';
|
||||
static const int currentSyncVersion = 1;
|
||||
static const int maxRetryAttempts = 3;
|
||||
static const Duration networkTimeout = Duration(seconds: 30);
|
||||
static const Duration conflictResolutionTimeout = Duration(minutes: 5);
|
||||
|
||||
/// Default WebDAV paths for different cloud providers
|
||||
static const String nextcloudWebdavPath = '/remote.php/dav/files/';
|
||||
static const String owncloudWebdavPath = '/remote.php/webdav/';
|
||||
|
||||
/// Supported cloud providers
|
||||
static const List<String> supportedProviders = [
|
||||
'Nextcloud',
|
||||
'ownCloud',
|
||||
'Generic WebDAV',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user