selfprivacy.org.app/lib/logic/cubit/app_config/app_config_state.dart

243 lines
7.2 KiB
Dart
Raw Normal View History

2021-01-06 19:35:57 +02:00
part of 'app_config_cubit.dart';
2021-10-12 00:10:04 +03:00
abstract class AppConfigState extends Equatable {
2021-01-06 19:35:57 +02:00
const AppConfigState({
2021-03-15 17:39:44 +02:00
required this.hetznerKey,
required this.cloudFlareKey,
required this.backblazeCredential,
required this.cloudFlareDomain,
required this.rootUser,
required this.hetznerServer,
required this.isServerStarted,
2021-03-31 14:37:39 +03:00
required this.isServerResetedFirstTime,
required this.isServerResetedSecondTime,
2021-01-06 19:35:57 +02:00
});
@override
2021-03-15 17:39:44 +02:00
List<Object?> get props => [
2021-01-06 19:35:57 +02:00
hetznerKey,
cloudFlareKey,
2021-02-03 22:26:38 +02:00
backblazeCredential,
2021-01-06 19:35:57 +02:00
cloudFlareDomain,
rootUser,
2021-01-21 09:35:38 +02:00
hetznerServer,
2021-02-16 20:48:15 +02:00
isServerStarted,
2021-03-31 14:37:39 +03:00
isServerResetedFirstTime,
2021-01-06 19:35:57 +02:00
];
2021-03-15 17:39:44 +02:00
final String? hetznerKey;
final String? cloudFlareKey;
final BackblazeCredential? backblazeCredential;
final CloudFlareDomain? cloudFlareDomain;
final User? rootUser;
final HetznerServerDetails? hetznerServer;
2021-03-23 21:50:11 +02:00
final bool isServerStarted;
2021-03-31 14:37:39 +03:00
final bool isServerResetedFirstTime;
final bool isServerResetedSecondTime;
2021-01-06 19:35:57 +02:00
bool get isHetznerFilled => hetznerKey != null;
bool get isCloudFlareFilled => cloudFlareKey != null;
2021-02-03 22:26:38 +02:00
bool get isBackblazeFilled => backblazeCredential != null;
2021-01-06 19:35:57 +02:00
bool get isDomainFilled => cloudFlareDomain != null;
bool get isUserFilled => rootUser != null;
2021-02-16 20:48:15 +02:00
bool get isServerCreated => hetznerServer != null;
2021-01-21 23:01:42 +02:00
2021-10-14 00:49:24 +03:00
bool get isFullyInitilized => _fulfilementList.every((el) => el!);
int get progress => _fulfilementList.where((el) => el!).length;
2021-06-21 00:08:52 +03:00
int get porgressBar {
if (progress < 6) {
return progress;
} else if (progress < 10) {
return 6;
} else {
return 7;
}
}
2021-01-06 19:35:57 +02:00
2021-03-25 10:32:00 +02:00
List<bool?> get _fulfilementList {
var res = [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
2021-03-31 14:37:39 +03:00
isServerResetedFirstTime,
isServerResetedSecondTime,
2021-03-25 10:32:00 +02:00
];
2021-03-30 20:38:40 +03:00
2021-03-25 10:32:00 +02:00
return res;
}
2021-01-06 19:35:57 +02:00
}
class TimerState extends AppConfigNotFinished {
2021-02-15 20:58:29 +02:00
TimerState({
2021-03-15 17:39:44 +02:00
required this.dataState,
2021-02-15 20:58:29 +02:00
this.timerStart,
this.duration,
2021-03-15 17:39:44 +02:00
required bool isLoading,
2021-02-16 20:48:15 +02:00
}) : super(
hetznerKey: dataState.hetznerKey,
cloudFlareKey: dataState.cloudFlareKey,
backblazeCredential: dataState.backblazeCredential,
cloudFlareDomain: dataState.cloudFlareDomain,
rootUser: dataState.rootUser,
hetznerServer: dataState.hetznerServer,
isServerStarted: dataState.isServerStarted,
2021-03-31 14:37:39 +03:00
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
2021-02-16 20:48:15 +02:00
isLoading: isLoading,
2022-02-08 08:59:19 +02:00
dnsMatches: dataState.dnsMatches,
2021-02-16 20:48:15 +02:00
);
2021-02-15 20:58:29 +02:00
final AppConfigNotFinished dataState;
2021-03-15 17:39:44 +02:00
final DateTime? timerStart;
final Duration? duration;
2021-02-15 20:58:29 +02:00
@override
2021-03-15 17:39:44 +02:00
List<Object?> get props => [
2021-02-15 20:58:29 +02:00
dataState,
timerStart,
duration,
];
}
class AppConfigNotFinished extends AppConfigState {
final bool isLoading;
2022-02-08 08:59:19 +02:00
final Map<String, bool>? dnsMatches;
AppConfigNotFinished({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
CloudFlareDomain? cloudFlareDomain,
User? rootUser,
HetznerServerDetails? hetznerServer,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
required this.isLoading,
2022-02-08 08:59:19 +02:00
required this.dnsMatches,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
cloudFlareDomain: cloudFlareDomain,
rootUser: rootUser,
hetznerServer: hetznerServer,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
cloudFlareDomain,
rootUser,
hetznerServer,
isServerStarted,
isServerResetedFirstTime,
2022-02-08 08:59:19 +02:00
isLoading,
dnsMatches,
];
AppConfigNotFinished copyWith({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
CloudFlareDomain? cloudFlareDomain,
User? rootUser,
HetznerServerDetails? hetznerServer,
bool? isServerStarted,
bool? isServerResetedFirstTime,
bool? isServerResetedSecondTime,
bool? isLoading,
2022-02-08 08:59:19 +02:00
Map<String, bool>? dnsMatches,
}) =>
AppConfigNotFinished(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
cloudFlareDomain: cloudFlareDomain ?? this.cloudFlareDomain,
rootUser: rootUser ?? this.rootUser,
hetznerServer: hetznerServer ?? this.hetznerServer,
isServerStarted: isServerStarted ?? this.isServerStarted,
isServerResetedFirstTime:
isServerResetedFirstTime ?? this.isServerResetedFirstTime,
isServerResetedSecondTime:
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
isLoading: isLoading ?? this.isLoading,
2022-02-08 08:59:19 +02:00
dnsMatches: dnsMatches ?? this.dnsMatches,
);
AppConfigFinished finish() => AppConfigFinished(
hetznerKey: hetznerKey!,
cloudFlareKey: cloudFlareKey!,
backblazeCredential: backblazeCredential!,
cloudFlareDomain: cloudFlareDomain!,
rootUser: rootUser!,
hetznerServer: hetznerServer!,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
}
class AppConfigEmpty extends AppConfigNotFinished {
AppConfigEmpty()
: super(
hetznerKey: null,
cloudFlareKey: null,
backblazeCredential: null,
cloudFlareDomain: null,
rootUser: null,
hetznerServer: null,
isServerStarted: false,
isServerResetedFirstTime: false,
isServerResetedSecondTime: false,
isLoading: false,
2022-02-08 08:59:19 +02:00
dnsMatches: null,
);
}
class AppConfigFinished extends AppConfigState {
const AppConfigFinished({
required String hetznerKey,
required String cloudFlareKey,
required BackblazeCredential backblazeCredential,
required CloudFlareDomain cloudFlareDomain,
required User rootUser,
required HetznerServerDetails hetznerServer,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
cloudFlareDomain: cloudFlareDomain,
rootUser: rootUser,
hetznerServer: hetznerServer,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
cloudFlareDomain,
rootUser,
hetznerServer,
isServerStarted,
isServerResetedFirstTime,
];
}