selfprivacy.org.app/lib/logic/cubit/server_installation/server_installation_state.dart

340 lines
9.8 KiB
Dart
Raw Normal View History

part of '../server_installation/server_installation_cubit.dart';
2021-01-06 17:35:57 +00:00
abstract class ServerInstallationState extends Equatable {
const ServerInstallationState({
2021-03-15 15:39:44 +00:00
required this.hetznerKey,
required this.cloudFlareKey,
required this.backblazeCredential,
required this.serverDomain,
2021-03-15 15:39:44 +00:00
required this.rootUser,
required this.serverDetails,
2021-03-15 15:39:44 +00:00
required this.isServerStarted,
2021-03-31 11:37:39 +00:00
required this.isServerResetedFirstTime,
required this.isServerResetedSecondTime,
2021-01-06 17:35:57 +00:00
});
@override
2021-03-15 15:39:44 +00:00
List<Object?> get props => [
2021-01-06 17:35:57 +00:00
hetznerKey,
cloudFlareKey,
2021-02-03 20:26:38 +00:00
backblazeCredential,
serverDomain,
2021-01-06 17:35:57 +00:00
rootUser,
serverDetails,
2021-02-16 18:48:15 +00:00
isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime,
2021-01-06 17:35:57 +00:00
];
2021-03-15 15:39:44 +00:00
final String? hetznerKey;
final String? cloudFlareKey;
final BackblazeCredential? backblazeCredential;
final ServerDomain? serverDomain;
2021-03-15 15:39:44 +00:00
final User? rootUser;
final ServerHostingDetails? serverDetails;
2021-03-23 19:50:11 +00:00
final bool isServerStarted;
2021-03-31 11:37:39 +00:00
final bool isServerResetedFirstTime;
final bool isServerResetedSecondTime;
2021-01-06 17:35:57 +00:00
bool get isHetznerFilled => hetznerKey != null;
bool get isCloudFlareFilled => cloudFlareKey != null;
2021-02-03 20:26:38 +00:00
bool get isBackblazeFilled => backblazeCredential != null;
bool get isDomainFilled => serverDomain != null;
2021-01-06 17:35:57 +00:00
bool get isUserFilled => rootUser != null;
bool get isServerCreated => serverDetails != null;
2021-01-21 21:01:42 +00:00
2021-10-13 21:49:24 +00:00
bool get isFullyInitilized => _fulfilementList.every((el) => el!);
ServerSetupProgress get progress =>
ServerSetupProgress.values[_fulfilementList.where((el) => el!).length];
2021-06-20 21:08:52 +00:00
int get porgressBar {
if (progress.index < 6) {
return progress.index;
} else if (progress.index < 10) {
2021-06-20 21:08:52 +00:00
return 6;
} else {
return 7;
}
}
2021-01-06 17:35:57 +00:00
2021-03-25 08:32:00 +00:00
List<bool?> get _fulfilementList {
var res = [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime,
isServerResetedSecondTime,
2021-03-25 08:32:00 +00:00
];
2021-03-30 17:38:40 +00:00
2021-03-25 08:32:00 +00:00
return res;
}
2021-01-06 17:35:57 +00:00
}
class TimerState extends ServerInstallationNotFinished {
2021-02-15 18:58:29 +00:00
TimerState({
2021-03-15 15:39:44 +00:00
required this.dataState,
2021-02-15 18:58:29 +00:00
this.timerStart,
this.duration,
2021-03-15 15:39:44 +00:00
required bool isLoading,
2021-02-16 18:48:15 +00:00
}) : super(
hetznerKey: dataState.hetznerKey,
cloudFlareKey: dataState.cloudFlareKey,
backblazeCredential: dataState.backblazeCredential,
serverDomain: dataState.serverDomain,
2021-02-16 18:48:15 +00:00
rootUser: dataState.rootUser,
serverDetails: dataState.serverDetails,
2021-02-16 18:48:15 +00:00
isServerStarted: dataState.isServerStarted,
2021-03-31 11:37:39 +00:00
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
2021-02-16 18:48:15 +00:00
isLoading: isLoading,
2022-02-08 06:59:19 +00:00
dnsMatches: dataState.dnsMatches,
2021-02-16 18:48:15 +00:00
);
2021-02-15 18:58:29 +00:00
final ServerInstallationNotFinished dataState;
2021-03-15 15:39:44 +00:00
final DateTime? timerStart;
final Duration? duration;
2021-02-15 18:58:29 +00:00
@override
2021-03-15 15:39:44 +00:00
List<Object?> get props => [
2021-02-15 18:58:29 +00:00
dataState,
timerStart,
duration,
];
}
enum ServerSetupProgress {
nothingYet,
hetznerFilled,
cloudFlareFilled,
backblazeFilled,
domainFilled,
userFilled,
serverCreated,
serverStarted,
serverResetedFirstTime,
serverResetedSecondTime,
}
class ServerInstallationNotFinished extends ServerInstallationState {
final bool isLoading;
2022-02-08 06:59:19 +00:00
final Map<String, bool>? dnsMatches;
ServerInstallationNotFinished({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
required this.isLoading,
2022-02-08 06:59:19 +00:00
required this.dnsMatches,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
serverDomain: serverDomain,
rootUser: rootUser,
serverDetails: serverDetails,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
serverDomain,
rootUser,
serverDetails,
isServerStarted,
isServerResetedFirstTime,
2022-02-08 06:59:19 +00:00
isLoading,
dnsMatches,
];
ServerInstallationNotFinished copyWith({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
bool? isServerStarted,
bool? isServerResetedFirstTime,
bool? isServerResetedSecondTime,
bool? isLoading,
2022-02-08 06:59:19 +00:00
Map<String, bool>? dnsMatches,
}) =>
ServerInstallationNotFinished(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
serverDomain: serverDomain ?? this.serverDomain,
rootUser: rootUser ?? this.rootUser,
serverDetails: serverDetails ?? this.serverDetails,
isServerStarted: isServerStarted ?? this.isServerStarted,
isServerResetedFirstTime:
isServerResetedFirstTime ?? this.isServerResetedFirstTime,
isServerResetedSecondTime:
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
isLoading: isLoading ?? this.isLoading,
2022-02-08 06:59:19 +00:00
dnsMatches: dnsMatches ?? this.dnsMatches,
);
ServerInstallationFinished finish() => ServerInstallationFinished(
hetznerKey: hetznerKey!,
cloudFlareKey: cloudFlareKey!,
backblazeCredential: backblazeCredential!,
serverDomain: serverDomain!,
rootUser: rootUser!,
serverDetails: serverDetails!,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
}
class ServerInstallationEmpty extends ServerInstallationNotFinished {
ServerInstallationEmpty()
: super(
hetznerKey: null,
cloudFlareKey: null,
backblazeCredential: null,
serverDomain: null,
rootUser: null,
serverDetails: null,
isServerStarted: false,
isServerResetedFirstTime: false,
isServerResetedSecondTime: false,
isLoading: false,
2022-02-08 06:59:19 +00:00
dnsMatches: null,
);
}
class ServerInstallationFinished extends ServerInstallationState {
const ServerInstallationFinished({
required String hetznerKey,
required String cloudFlareKey,
required BackblazeCredential backblazeCredential,
required ServerDomain serverDomain,
required User rootUser,
required ServerHostingDetails serverDetails,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
serverDomain: serverDomain,
rootUser: rootUser,
serverDetails: serverDetails,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
serverDomain,
rootUser,
serverDetails,
isServerStarted,
isServerResetedFirstTime,
];
}
enum RecoveryStep {
Selecting,
RecoveryKey,
NewDeviceKey,
OldToken,
HetznerToken,
ServerSelection,
CloudflareToken,
BackblazeToken,
}
enum ServerRecoveryCapabilities {
none,
legacy,
loginTokens,
}
enum ServerRecoveryMethods {
newDeviceKey,
recoveryKey,
oldToken,
}
class ServerInstallationRecovery extends ServerInstallationState {
final RecoveryStep currentStep;
final ServerRecoveryCapabilities recoveryCapabilities;
const ServerInstallationRecovery({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
required RecoveryStep this.currentStep,
required ServerRecoveryCapabilities this.recoveryCapabilities,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
serverDomain: serverDomain,
rootUser: rootUser,
serverDetails: serverDetails,
isServerStarted: true,
isServerResetedFirstTime: true,
isServerResetedSecondTime: true,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
serverDomain,
rootUser,
serverDetails,
isServerStarted,
isServerResetedFirstTime,
currentStep
];
ServerInstallationRecovery copyWith({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
RecoveryStep? currentStep,
ServerRecoveryCapabilities? recoveryCapabilities,
}) =>
ServerInstallationRecovery(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
serverDomain: serverDomain ?? this.serverDomain,
rootUser: rootUser ?? this.rootUser,
serverDetails: serverDetails ?? this.serverDetails,
currentStep: currentStep ?? this.currentStep,
recoveryCapabilities: recoveryCapabilities ?? this.recoveryCapabilities,
);
}