mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-04 23:24:20 +00:00
refactor: Getters for backup-related jobs
This commit is contained in:
parent
290c4166c5
commit
2b8d3ee6d0
|
@ -35,7 +35,7 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
|||
state.copyWith(
|
||||
backblazeBucket: bucket,
|
||||
isInitialized: backupConfig?.isInitialized,
|
||||
autobackupPeriod: backupConfig?.autobackupPeriod,
|
||||
autobackupPeriod: backupConfig?.autobackupPeriod ?? Duration.zero,
|
||||
backups: backups,
|
||||
preventActions: false,
|
||||
refreshing: false,
|
||||
|
@ -164,8 +164,8 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
|||
|
||||
Future<void> forceUpdateBackups() async {
|
||||
emit(state.copyWith(preventActions: true));
|
||||
await api.forceBackupListReload();
|
||||
getIt<NavigationService>().showSnackBar('backup.refetching_list'.tr());
|
||||
await api.forceBackupListReload();
|
||||
emit(state.copyWith(preventActions: false));
|
||||
}
|
||||
|
||||
|
@ -187,12 +187,30 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
|||
|
||||
Future<void> restoreBackup(final String backupId) async {
|
||||
emit(state.copyWith(preventActions: true));
|
||||
|
||||
/// TOOD: ???
|
||||
//await api.restoreBackup(backupId);
|
||||
await api.restoreBackup(backupId);
|
||||
emit(state.copyWith(preventActions: false));
|
||||
}
|
||||
|
||||
Future<void> setAutobackupPeriod(final Duration? period) async {
|
||||
emit(state.copyWith(preventActions: true));
|
||||
final result = await api.setAutobackupPeriod(period: period?.inMinutes);
|
||||
if (result.success == false) {
|
||||
getIt<NavigationService>()
|
||||
.showSnackBar(result.message ?? 'Unknown error');
|
||||
emit(state.copyWith(preventActions: false));
|
||||
} else {
|
||||
getIt<NavigationService>()
|
||||
.showSnackBar('backup.autobackup_period_set'.tr());
|
||||
emit(
|
||||
state.copyWith(
|
||||
preventActions: false,
|
||||
autobackupPeriod: period ?? Duration.zero,
|
||||
),
|
||||
);
|
||||
}
|
||||
await updateBackups();
|
||||
}
|
||||
|
||||
@override
|
||||
void clear() async {
|
||||
emit(const BackupsState());
|
||||
|
|
|
@ -19,6 +19,10 @@ class BackupsState extends ServerInstallationDependendState {
|
|||
final Duration? autobackupPeriod;
|
||||
final BackblazeBucket? backblazeBucket;
|
||||
|
||||
List<Backup> serviceBackups(final String serviceId) => backups
|
||||
.where((final backup) => backup.serviceId == serviceId)
|
||||
.toList(growable: false);
|
||||
|
||||
@override
|
||||
List<Object> get props => [
|
||||
isInitialized,
|
||||
|
@ -43,7 +47,11 @@ class BackupsState extends ServerInstallationDependendState {
|
|||
preventActions: preventActions ?? this.preventActions,
|
||||
refreshTimer: refreshTimer ?? this.refreshTimer,
|
||||
refreshing: refreshing ?? this.refreshing,
|
||||
autobackupPeriod: autobackupPeriod ?? this.autobackupPeriod,
|
||||
// The autobackupPeriod might be null, so if the duration is set to 0, we
|
||||
// set it to null.
|
||||
autobackupPeriod: autobackupPeriod?.inSeconds == 0
|
||||
? null
|
||||
: autobackupPeriod ?? this.autobackupPeriod,
|
||||
backblazeBucket: backblazeBucket ?? this.backblazeBucket,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ class ServerJobsState extends ServerInstallationDependendState {
|
|||
List<ServerJob> get backupJobList => serverJobList
|
||||
.where(
|
||||
// The backup jobs has the format of 'service.<service_id>.backup'
|
||||
(final job) => job.typeId.contains('backup'),
|
||||
(final job) =>
|
||||
job.typeId.contains('backup') || job.typeId.contains('restore'),
|
||||
)
|
||||
.toList();
|
||||
|
||||
|
|
Loading…
Reference in a new issue