2024-01-26 14:46:09 +00:00
|
|
|
part of 'server_jobs_bloc.dart';
|
2022-08-30 03:09:09 +00:00
|
|
|
|
2024-01-26 14:46:09 +00:00
|
|
|
sealed class ServerJobsState extends Equatable {
|
2022-09-18 20:12:09 +00:00
|
|
|
ServerJobsState({
|
2024-01-26 14:46:09 +00:00
|
|
|
final int? hashCode,
|
|
|
|
}) : _hashCode = hashCode ?? Object.hashAll([]);
|
|
|
|
|
|
|
|
final int? _hashCode;
|
|
|
|
|
|
|
|
final apiConnectionRepository = getIt<ApiConnectionRepository>();
|
2022-09-18 20:12:09 +00:00
|
|
|
|
2024-01-26 14:46:09 +00:00
|
|
|
List<ServerJob> get _serverJobList =>
|
|
|
|
apiConnectionRepository.apiData.serverJobs.data ?? [];
|
2022-08-30 03:09:09 +00:00
|
|
|
|
2022-09-19 00:21:08 +00:00
|
|
|
List<ServerJob> get serverJobList {
|
2022-09-20 09:42:20 +00:00
|
|
|
try {
|
|
|
|
final List<ServerJob> list = _serverJobList;
|
|
|
|
list.sort((final a, final b) => b.createdAt.compareTo(a.createdAt));
|
|
|
|
return list;
|
|
|
|
} on UnsupportedError {
|
|
|
|
return _serverJobList;
|
|
|
|
}
|
2022-09-19 00:21:08 +00:00
|
|
|
}
|
2022-09-18 20:12:09 +00:00
|
|
|
|
2023-07-02 11:41:54 +00:00
|
|
|
List<ServerJob> get backupJobList => serverJobList
|
|
|
|
.where(
|
2023-06-29 09:53:13 +00:00
|
|
|
// The backup jobs has the format of 'service.<service_id>.backup'
|
2023-07-02 15:23:12 +00:00
|
|
|
(final job) =>
|
|
|
|
job.typeId.contains('backup') || job.typeId.contains('restore'),
|
2023-07-02 11:41:54 +00:00
|
|
|
)
|
|
|
|
.toList();
|
2023-06-29 09:53:13 +00:00
|
|
|
|
2022-09-19 00:42:00 +00:00
|
|
|
bool get hasRemovableJobs => serverJobList.any(
|
|
|
|
(final job) =>
|
|
|
|
job.status == JobStatusEnum.finished ||
|
|
|
|
job.status == JobStatusEnum.error,
|
|
|
|
);
|
|
|
|
|
2022-08-30 03:09:09 +00:00
|
|
|
@override
|
2024-01-26 14:46:09 +00:00
|
|
|
List<Object?> get props => [_hashCode];
|
|
|
|
}
|
|
|
|
|
|
|
|
class ServerJobsInitialState extends ServerJobsState {
|
|
|
|
ServerJobsInitialState() : super(hashCode: Object.hashAll([]));
|
|
|
|
}
|
|
|
|
|
|
|
|
class ServerJobsListEmptyState extends ServerJobsState {
|
|
|
|
ServerJobsListEmptyState() : super(hashCode: Object.hashAll([]));
|
|
|
|
}
|
|
|
|
|
|
|
|
class ServerJobsListWithJobsState extends ServerJobsState {
|
|
|
|
ServerJobsListWithJobsState({
|
|
|
|
required final List<ServerJob> serverJobList,
|
|
|
|
}) : super(hashCode: Object.hashAll([...serverJobList]));
|
2022-08-30 03:09:09 +00:00
|
|
|
}
|