refactor: Getters for backup-related jobs

pull/228/head
Inex Code 2023-07-02 18:23:12 +03:00
parent 290c4166c5
commit 2b8d3ee6d0
3 changed files with 34 additions and 7 deletions

View File

@ -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());

View File

@ -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,
);
}

View File

@ -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();