Remove a lot and start from scratch

Signed-off-by: Nikolai Rodionov <nrodionov@eos-uptrade.de>
This commit is contained in:
Nikolai Rodionov
2026-04-27 12:53:52 +02:00
parent a5e0b659b7
commit 7b6b568950
21 changed files with 468 additions and 1325 deletions

View File

@@ -1,5 +1,6 @@
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_dart_proto/main.dart';
import 'package:softplayer_dart_proto/src/accounts/v1/accounts_v1.pb.dart';
import 'package:softplayer_dart_proto/src/accounts/v1/accounts_v1.pbgrpc.dart';
class AccountLocalData {
AccountLocalData({
@@ -12,36 +13,18 @@ class AccountLocalData {
class AccountsGrpc {
final GrpcWebClientChannel channel;
late AccountsClient accountsStub;
late AccountsServiceClient accountsStub;
AccountsGrpc({
required this.channel,
});
void init() {
accountsStub = AccountsClient(channel);
}
Future<AccountLocalData> signIn(
String username, String email, String password) async {
final request = AccountWithPassword(
data: AccountData(
name: username,
email: email,
),
password: AccountPassword(
password: password,
));
try {
final response = await accountsStub.signIn(request);
return AccountLocalData(uuid: response.id.id, token: response.token);
} catch (e) {
rethrow;
}
accountsStub = AccountsServiceClient(channel);
}
Future<AccountLocalData> signUp(
String username, String email, String password) async {
final request = AccountWithPassword(
final request = SignUpRequest(
data: AccountData(
name: username,
email: email,
@@ -51,36 +34,7 @@ class AccountsGrpc {
));
try {
final response = await accountsStub.signUp(request);
return AccountLocalData(uuid: response.id.id, token: response.token);
} catch (e) {
rethrow;
}
}
Future<Empty> resetPassword(String username, String email) async {
final request = AccountData(
name: username,
email: email,
);
try {
final response = await accountsStub.resetPassword(request);
return response;
} catch (e) {
rethrow;
}
}
Future<Empty> newPassword(
String username, String code, String newPassword) async {
final request = AccountWithPasswordAndCode(
data: AccountData(
name: username,
),
code: code,
password: AccountPassword(password: newPassword));
try {
final response = await accountsStub.newPassword(request);
return response;
return AccountLocalData(uuid: "test", token: "test");
} catch (e) {
rethrow;
}

View File

@@ -1,106 +0,0 @@
import 'package:softplayer_dart_proto/main.dart';
import 'package:softplayer_web/api/grpc/creds.dart';
class EnvironmentLocalData {
EnvironmentLocalData(
{required this.serverType,
required this.serverLocation,
required this.provider,
required this.name,
required this.description,
this.uuid});
final String name;
final String description;
final String provider;
final String serverType;
final String serverLocation;
String? uuid;
}
class EnvironmentsGrpc {
// final GrpcWebClientChannel channel;
final EnvironmentsClient envStub;
// Init the grpc channel for environments
EnvironmentsGrpc(channel) : envStub = EnvironmentsClient(channel);
// Get environments from the API
Future<EnvironmentLocalData> get(String uuid, SoftplayerCreds creds) async {
final request = GetOptions(
id: EnvironmentId(uuid: uuid),
ownerId: OwnerId(uuid: creds.uuid),
token: Token(token: creds.token),
);
try {
final response = await envStub.get(request);
return EnvironmentLocalData(
uuid: uuid,
serverType: response.spec.serverType.toString(),
serverLocation: response.spec.serverLocation.toString(),
provider: response.spec.provider.toString(),
name: response.metadata.name,
description: response.metadata.description);
} catch (e) {
rethrow;
}
}
Future<EnvironmentLocalData> create(
EnvironmentLocalData data, SoftplayerCreds creds) async {
print(data);
final request = CreateOptions(
metadata:
EnvironmentMetadata(description: data.description, name: data.name),
spec: EnvironmentSpec(
// Currently we do not support other kinds
kubernetes: Kubernetes.KUBERNETES_K3S,
// Currently we do not support other providers
provider: Provider.PROVIDER_HETZNER,
serverLocation: Location.values
.firstWhere((e) => e.toString() == data.serverLocation),
serverType: ServerType.values
.firstWhere((e) => e.toString() == data.serverType),
),
ownerId: OwnerId(uuid: creds.uuid),
token: Token(token: creds.token),
);
try {
final response = await envStub.create(request);
return EnvironmentLocalData(
uuid: response.id.uuid,
serverType: response.spec.serverType.toString(),
serverLocation: response.spec.serverLocation.toString(),
provider: response.spec.provider.toString(),
name: response.metadata.name,
description: response.metadata.description);
} catch (e) {
rethrow;
}
}
Stream<List<EnvironmentLocalData>> list(SoftplayerCreds creds) async* {
List<EnvironmentLocalData> envs = [];
try {
await for (var feature in envStub.list(
ListOptions(
ownerId: OwnerId(uuid: creds.uuid),
token: Token(token: creds.token),
),
)) {
envs.add(EnvironmentLocalData(
uuid: feature.id.uuid,
serverType: feature.spec.serverType.toString(),
serverLocation: feature.spec.serverLocation.toString(),
provider: feature.spec.provider.toString(),
name: feature.metadata.name,
description: feature.metadata.description,
));
}
} catch (e) {
rethrow;
}
yield envs;
}
}

View File

@@ -1,161 +0,0 @@
import 'dart:js' as js;
import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_dart_proto/main.dart';
import 'package:softplayer_web/api/grpc/creds.dart';
import 'package:softplayer_web/api/grpc/environments.dart';
import 'package:softplayer_web/helpers/providers/common.dart' as helper;
class CreateEnvForm extends StatefulWidget {
CreateEnvForm(GrpcWebClientChannel channel, {super.key})
: environmentsGrpc = EnvironmentsGrpc(channel);
final EnvironmentsGrpc environmentsGrpc;
@override
State<StatefulWidget> createState() => _CreateEnvFormState();
}
class _CreateEnvFormState extends State<CreateEnvForm> {
final _formKey = GlobalKey<FormState>();
final String defaultProvider = Provider.PROVIDER_HETZNER.toString();
late helper.Provider provider =
helper.ProviderHelper().getProvider(defaultProvider);
late String defaultLocation = provider.defaultLocation();
final nameCtl = TextEditingController();
final descriptionCtl = TextEditingController();
late String? serverLocation = defaultLocation;
late String? serverType = ServerType.SERVER_TYPE_REGULAR.toString();
void createEnvironment() {
// Validate returns true if the form is valid, or false otherwise.
if (_formKey.currentState!.validate()) {
final name = nameCtl.text;
final description = descriptionCtl.text;
widget.environmentsGrpc
.create(
EnvironmentLocalData(
serverType: serverType!,
serverLocation: serverLocation!,
provider: defaultProvider,
name: name,
description: description),
SoftplayerCredsHelpers().fromLocalStorage())
.then((rs) {
Navigator.pop(context);
}).catchError((e) {
GrpcError error = e;
String msg;
if (error.message != null) {
msg = error.message!;
} else {
msg = error.toString();
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(msg),
backgroundColor: Colors.red,
showCloseIcon: true,
behavior: SnackBarBehavior.floating,
));
});
}
}
String defaultServerType = "Regular";
Widget createEnvForm() => SingleChildScrollView(
child: SizedBox(
width: 420,
child: Form(
key: _formKey,
child: Center(
child: Column(children: [
TextFormField(
autofocus: true,
controller: nameCtl,
decoration: const InputDecoration(
hintText: "Enter the environment name",
icon: Icon(Icons.computer),
label: Text("Name"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextFormField(
autofocus: false,
controller: descriptionCtl,
decoration: const InputDecoration(
hintText: "Enter the environment description",
icon: Icon(Icons.description),
label: Text("Description"),
),
maxLength: 360,
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
DropdownButtonFormField(
decoration: const InputDecoration(
hintText: "Enter the environment description",
icon: Icon(Icons.computer),
label: Text("Type of the server"),
),
value: ServerType.SERVER_TYPE_REGULAR.toString(),
isDense: true,
items: ServerType.values
.where((element) =>
element != ServerType.SERVER_TYPE_CUSTOM &&
element != ServerType.SERVER_TYPE_UNSPECIFIED)
.map((serverType) {
return DropdownMenuItem(
value: serverType.toString(),
child: Text(helper.ProviderHelper()
.getServerType(serverType.toString())),
);
}).toList(),
onChanged: (value) => setState(() {
serverType = value;
}),
),
TextButton(
onPressed: () => js.context.callMethod(
'open', ['https://stackoverflow.com/questions/ask']),
child: const Text("Read more about environment types here"),
),
DropdownButtonFormField(
decoration: const InputDecoration(
hintText: "Enter the environment location",
icon: Icon(Icons.location_on),
label: Text("Location of the server"),
),
value: defaultLocation,
isDense: true,
items: Location.values
.where((element) => element
.toString()
.contains(provider.getProviderName().toUpperCase()))
.map((serverType) {
return DropdownMenuItem(
value: serverType.toString(),
child: Text(
provider.getServerLocation(serverType.toString())),
);
}).toList(),
onChanged: (value) => setState(() {
serverLocation = value;
}),
),
])))));
List<Widget> createEnvActions() => [
TextButton(
onPressed: createEnvironment,
child: const Text('OK'),
),
];
@override
Widget build(BuildContext context) => AlertDialog(
title: const Text("Create a new environment"),
content: createEnvForm(),
actions: createEnvActions(),
);
}

View File

@@ -1,102 +0,0 @@
import 'package:flutter/material.dart';
import 'package:softplayer_web/api/grpc/environments.dart';
import 'package:softplayer_web/components/environment_preview.dart';
import 'package:softplayer_web/helpers/providers/common.dart';
class EnvirnomentCard extends StatefulWidget {
final EnvironmentLocalData env;
const EnvirnomentCard({
super.key,
required this.env,
});
@override
State<EnvirnomentCard> createState() => _EnvirnomentCardState();
}
class _EnvirnomentCardState extends State<EnvirnomentCard> {
late double elevation = 1.0;
@override
Widget build(BuildContext context) {
Provider provider = ProviderHelper().getProvider(widget.env.provider);
String serverType;
String serverLocation;
try {
serverType = ProviderHelper().getServerType(widget.env.serverType);
serverLocation = provider.getServerLocation(widget.env.serverLocation);
} catch (e) {
rethrow;
}
return Container(
margin: const EdgeInsets.all(8.0),
height: 10,
child: MouseRegion(
onExit: (event) {
setState(() {
elevation = 1.0;
});
},
onEnter: (event) {
setState(() {
elevation = 5.0;
});
},
child: Card(
elevation: elevation,
child: SelectionArea(
child: InkWell(
onLongPress: () => showMenu(
position: RelativeRect.fromSize(Rect.largest, Size.infinite),
context: context,
items: [
const PopupMenuItem(child: Text("test")),
const PopupMenuItem(child: Text("text")),
],
),
onTap: () => showDialog(
context: context,
builder: (context) => EnvirnomentPreiview(env: widget.env),
),
child: Column(
children: [
Text(widget.env.name),
const Divider(),
Table(
border: const TableBorder(
bottom: BorderSide.none,
left: BorderSide.none,
right: BorderSide.none,
top: BorderSide.none,
),
children: [
TableRow(children: [
const Text("Description"),
Text(widget.env.description),
]),
TableRow(children: [
const Text("Provider"),
Text(provider.getProviderName()),
]),
TableRow(children: [
const Text("Server Type"),
Text(serverType),
]),
TableRow(children: [
const Text("Location"),
Text(serverLocation),
]),
],
)
],
),
),
),
),
),
);
}
}

View File

@@ -1,90 +0,0 @@
import 'package:flutter/material.dart';
import 'package:softplayer_web/api/grpc/environments.dart';
import 'package:softplayer_web/helpers/providers/common.dart';
class EnvirnomentPreiview extends StatefulWidget {
@override
State<StatefulWidget> createState() => _EnvirnomentPreviewState();
final EnvironmentLocalData env;
const EnvirnomentPreiview({
super.key,
required this.env,
});
}
class _EnvirnomentPreviewState extends State<EnvirnomentPreiview> {
@override
Widget build(BuildContext context) {
Provider provider = ProviderHelper().getProvider(widget.env.provider);
String serverType;
String serverLocation;
try {
serverType = ProviderHelper().getServerType(widget.env.serverType);
serverLocation = provider.getServerLocation(widget.env.serverLocation);
} catch (e) {
rethrow;
}
return AlertDialog(
title: Text(widget.env.name),
content: SizedBox(
height: 420,
width: 420,
child: Column(
children: [
Table(
border: const TableBorder(
bottom: BorderSide.none,
left: BorderSide.none,
right: BorderSide.none,
top: BorderSide.none,
),
children: [
TableRow(children: [
const Text("Description"),
Text(widget.env.description),
]),
TableRow(children: [
const Text("Provider"),
Text(provider.getProviderName()),
]),
TableRow(children: [
const Text("Server Type"),
Text(serverType),
]),
TableRow(children: [
const Text("Location"),
Text(serverLocation),
]),
],
),
const Divider(),
Table(
border: const TableBorder(
bottom: BorderSide.none,
left: BorderSide.none,
right: BorderSide.none,
top: BorderSide.none,
),
children: const [
TableRow(children: [
Text("Price per hour"),
Text("0.52"),
]),
TableRow(children: [
Text("Current usage"),
Text("10.5"),
]),
],
),
],
),
),
actions: [
TextButton(onPressed: () => print("lala"), child: const Text("test")),
TextButton(onPressed: () => print("lala"), child: const Text("test")),
]);
}
}

View File

@@ -1,105 +0,0 @@
import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/grpc/creds.dart';
import 'package:softplayer_web/api/grpc/environments.dart';
import 'package:softplayer_web/components/environment_card.dart';
class EnvirnomentList extends StatefulWidget {
const EnvirnomentList({
super.key,
required this.channel,
});
final GrpcWebClientChannel channel;
@override
State<StatefulWidget> createState() => _EnvirnomentListState();
}
class _EnvirnomentListState extends State<EnvirnomentList> {
late EnvironmentsGrpc envGrpc;
List<String> envs = [];
@override
void initState() {
super.initState();
envGrpc = EnvironmentsGrpc(widget.channel);
}
final GlobalKey<ScaffoldState> _key = GlobalKey(); // Create a key
@override
Widget build(BuildContext context) {
return Scaffold(
key: _key,
endDrawer: const Drawer(child: Text("Env")),
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
gradient: LinearGradient(colors: [
Colors.blueGrey,
Colors.cyan,
Colors.yellow,
])),
child: StreamBuilder(
stream:
envGrpc.list(SoftplayerCredsHelpers().fromLocalStorage()),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const CircularProgressIndicator();
} else if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return const Text('Error!');
} else {
if (snapshot.hasData) {
var data = snapshot.requireData;
if (data.isNotEmpty) {
return Container(
margin: const EdgeInsetsDirectional.fromSTEB(
50.0, 20.0, 50.0, 10.0),
child: Column(children: [
Flexible(
child: Container(
child: const TextField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
labelText: "Search",
prefixIcon: Icon(Icons.search)),
),
),
),
Container(
child: Flexible(
child: GridView.count(
childAspectRatio: (30 / 13),
crossAxisCount: 4,
children: snapshot.data!
.map((e) => EnvirnomentCard(
env: e,
))
.toList(),
)),
)
]),
);
} else {
return Center(
child: Container(
height: 300,
decoration: BoxDecoration(
border: Border.all(),
shape: BoxShape.rectangle,
borderRadius:
const BorderRadius.all(Radius.circular(10)),
color: const Color.fromRGBO(100, 150, 80, 20),
),
child: const Text(
"To get strated, use the button in the corner"),
));
}
}
}
}
return const Text("err");
})));
}
}

View File

@@ -62,142 +62,6 @@ class _LoginFormState extends State<LoginForm> {
}
}
void submitSignIn() {
// Validate returns true if the form is valid, or false otherwise.
if (_formKey.currentState!.validate()) {
final username = usernameCtrl.text;
final password = passwordCtrl.text;
accountsGrpc.signIn(username, "", password).then((rs) {
window.localStorage["token"] = rs.token;
window.localStorage["uuid"] = rs.uuid;
widget.notifyParent();
// Navigator.of(context, rootNavigator: true).pop();
}).catchError((e) {
GrpcError error = e;
String msg;
if (error.message != null) {
msg = error.message!;
} else {
msg = error.toString();
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(msg),
backgroundColor: Colors.red,
showCloseIcon: true,
behavior: SnackBarBehavior.floating,
));
passwordCtrl.clear();
});
}
}
void subminResetPassword() {
// Validate returns true if the form is valid, or false otherwise.
if (_formKey.currentState!.validate()) {
final username = usernameCtrl.text;
final password = passwordCtrl.text;
final code = codeCtrl.text;
accountsGrpc.newPassword(username, code, password).then((rs) {
action = Action.singIn;
// Navigator.of(context, rootNavigator: true).pop();
}).catchError((e) {
GrpcError error = e;
String msg;
if (error.message != null) {
msg = error.message!;
} else {
msg = error.toString();
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(msg),
backgroundColor: Colors.red,
showCloseIcon: true,
behavior: SnackBarBehavior.floating,
));
passwordCtrl.clear();
});
}
}
void sendCode() {
if (_formKey.currentState!.validate()) {
final username = usernameCtrl.text;
final email = emailCtrl.text;
accountsGrpc
.resetPassword(username, email)
.then((_) => setState(() {
codeEnabled = true;
}))
.catchError((e) {
GrpcError error = e;
String msg;
if (error.message != null) {
msg = error.message!;
} else {
msg = error.toString();
}
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(msg),
backgroundColor: Colors.red,
showCloseIcon: true,
behavior: SnackBarBehavior.floating,
));
});
}
}
Widget signInForm() => SizedBox(
width: 420,
height: 280,
child: Form(
key: _formKey,
child: Center(
child: Column(children: [
TextFormField(
onFieldSubmitted: (value) => submitSignIn(),
autofocus: true,
controller: usernameCtrl,
decoration: const InputDecoration(
hintText: "Enter your username",
icon: Icon(Icons.account_circle),
label: Text("Username"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextFormField(
onFieldSubmitted: (value) => submitSignIn(),
controller: passwordCtrl,
obscureText: true,
decoration: const InputDecoration(
hintText: "Enter your password",
icon: Icon(Icons.password),
label: Text("Password")),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextButton(
onPressed: () => setState(() {
action = Action.resetPassword;
}),
child: const Text("reset yomakeur password")),
]))));
List<Widget> signInActions() => [
TextButton(
onPressed: () => setState(() {
action = Action.signUp;
}),
child: const Text('Sing Up'),
),
TextButton(
onPressed: submitSignIn,
child: const Text('OK'),
),
];
List<Widget> signUpActions() => [
TextButton(
onPressed: () => setState(() {
@@ -224,10 +88,6 @@ class _LoginFormState extends State<LoginForm> {
}),
child: const Text('Sing Up'),
),
TextButton(
onPressed: subminResetPassword,
child: const Text('OK'),
),
];
Widget signUpForm() => SizedBox(
@@ -288,88 +148,6 @@ class _LoginFormState extends State<LoginForm> {
cursorRadius: const Radius.circular(10),
),
]))));
Widget resetPasswordForm() => SizedBox(
width: 420,
height: 420,
child: Form(
key: _formKey,
child: Center(
child: Column(children: [
TextFormField(
// onFieldSubmitted: (value) => submitSignUp(),
autofocus: true,
controller: usernameCtrl,
decoration: const InputDecoration(
hintText: "Enter your username",
icon: Icon(Icons.account_circle),
label: Text("Username"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextFormField(
// onFieldSubmitted: (value) => submitSignUp(),
controller: emailCtrl,
autofocus: true,
decoration: const InputDecoration(
hintText: "Enter your email",
icon: Icon(Icons.email),
label: Text("Email"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextButton(
onPressed: () => sendCode(),
child: const Text("send code to email")),
TextFormField(
// onFieldSubmitted: (value) => submitSignUp(),
controller: codeCtrl,
autofocus: false,
enabled: codeEnabled,
decoration: const InputDecoration(
hintText: "Enter code that you've received via the email",
icon: Icon(Icons.numbers),
label: Text("Code"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextFormField(
// onFieldSubmitted: (value) => submitSignUp(),
controller: passwordCtrl,
autofocus: false,
enabled: codeEnabled,
obscureText: true,
decoration: const InputDecoration(
hintText: "Enter a new password",
icon: Icon(Icons.password),
label: Text("Password"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
TextFormField(
// onFieldSubmitted: (value) => submitSignUp(),
controller: passwordVerifyCtrl,
autofocus: false,
enabled: codeEnabled,
obscureText: true,
decoration: const InputDecoration(
hintText: "Enter a new password",
icon: Icon(Icons.password),
label: Text("Password"),
),
cursorWidth: 1,
cursorHeight: 18,
cursorRadius: const Radius.circular(10),
),
]))));
@override
void initState() {
super.initState();
@@ -383,22 +161,14 @@ class _LoginFormState extends State<LoginForm> {
// content: action == Action.singIn ? signInForm() : signUpForm(),
content: () {
switch (action) {
case Action.signUp:
return signUpForm();
case Action.resetPassword:
return resetPasswordForm();
default:
return signInForm();
return signUpForm();
}
}(),
actions: () {
switch (action) {
case Action.signUp:
return signUpActions();
case Action.resetPassword:
return resetPasswordActions();
default:
return signInActions();
return signUpActions();
}
}());
}

View File

@@ -1,28 +0,0 @@
import 'dart:html';
import 'package:flutter/material.dart';
import 'package:softplayer_web/api/grpc/accounts.dart';
import 'package:softplayer_web/components/menubar.dart';
class PageWrapper extends StatelessWidget {
final Widget child;
final MenuPanel appBar;
const PageWrapper(
{super.key,
required this.child,
required this.appBar,
required this.accountsGrpc});
final AccountsGrpc accountsGrpc;
bool isSignedIn() {
return window.localStorage.containsKey("token");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: appBar,
body: child,
);
}
}

View File

@@ -1,52 +0,0 @@
import 'package:softplayer_dart_proto/environments/environments_v1.pbenum.dart';
import 'package:softplayer_web/helpers/providers/hetzner.dart';
abstract class Provider {
String getServerLocation(String serverLocation);
String rawServerLocation(String serverLocation);
String defaultLocation();
String getProviderName();
String rawProviderName();
}
class ProviderHelper {
String getServerType(String serverType) {
if (serverType == ServerType.SERVER_TYPE_STARTER.toString()) {
return "Starter";
} else if (serverType == ServerType.SERVER_TYPE_REGULAR.toString()) {
return "Regular";
} else if (serverType == ServerType.SERVER_TYPE_PLUS.toString()) {
return "Plus";
} else if (serverType == ServerType.SERVER_TYPE_PRO.toString()) {
return "Pro";
} else if (serverType == ServerType.SERVER_TYPE_CUSTOM.toString()) {
throw 'Custom server type is not yet supported';
} else {
throw 'Unknown server type';
}
}
String rawServerType(String serverType) {
if (serverType == "Starter") {
return ServerType.SERVER_TYPE_STARTER.toString();
} else if (serverType == "Regular") {
return ServerType.SERVER_TYPE_REGULAR.toString();
} else if (serverType == "Plus") {
return ServerType.SERVER_TYPE_PLUS.toString();
} else if (serverType == "Pro") {
return ServerType.SERVER_TYPE_PRO.toString();
} else {
throw 'Unknown server type';
}
}
Hetzner getProvider(String provider) {
switch (provider) {
case "hetzner" || "PROVIDER_HETZNER":
return Hetzner();
default:
throw "unknown prodiver";
}
}
}

View File

@@ -1,53 +0,0 @@
import 'package:softplayer_dart_proto/environments/environments_v1.pbgrpc.dart';
import 'package:softplayer_web/helpers/providers/common.dart' as helper;
class Hetzner implements helper.Provider {
@override
String getProviderName() {
return "Hetzner";
}
@override
String rawProviderName() {
return Provider.PROVIDER_HETZNER.toString();
}
@override
String getServerLocation(String serverType) {
if (serverType == Location.LOCATION_HETZNER_ASHBURN.toString()) {
return "Ashburn, USA";
} else if (serverType == Location.LOCATION_HETZNER_FALKENSTEIN.toString()) {
return "Falkenstein, Germany";
} else if (serverType == Location.LOCATION_HETZNER_HELSINKI.toString()) {
return "Helsinki, Finland";
} else if (serverType == Location.LOCATION_HETZNER_HILLSBORO.toString()) {
return "Hillsboro, USA";
} else if (serverType == Location.LOCATION_HETZNER_NUREMBERG.toString()) {
return "Nuremberg, Germany";
} else {
throw 'Unknown server type';
}
}
@override
String rawServerLocation(String serverLocation) {
if (serverLocation == "Ashburn, USA") {
return Location.LOCATION_HETZNER_ASHBURN.toString();
} else if (serverLocation == "Falkenstein, Germany") {
return Location.LOCATION_HETZNER_FALKENSTEIN.toString();
} else if (serverLocation == "Helsinki, Finland") {
return Location.LOCATION_HETZNER_HELSINKI.toString();
} else if (serverLocation == "Hillsboro, USA") {
return Location.LOCATION_HETZNER_HILLSBORO.toString();
} else if (serverLocation == "Nuremberg, Germany") {
return Location.LOCATION_HETZNER_NUREMBERG.toString();
} else {
throw 'Unknown server type';
}
}
@override
String defaultLocation() {
return Location.LOCATION_HETZNER_NUREMBERG.toString();
}
}

View File

@@ -4,9 +4,6 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'package:grpc/grpc_web.dart';
import 'package:softplayer_web/api/grpc/accounts.dart';
import 'package:softplayer_web/api/grpc/creds.dart';
import 'package:softplayer_web/components/create_env_form.dart';
import 'package:softplayer_web/components/environments.dart';
import 'package:softplayer_web/components/login_form.dart';
void main() async {
@@ -58,90 +55,22 @@ class _StateRootWidget extends State<RootWidget> {
}
final GlobalKey<ScaffoldState> _key = GlobalKey(); // Create a key
@override
Widget build(BuildContext context) {
if (!isSignedIn()) {
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/login_background.jpg"),
fit: BoxFit.cover,
),
),
child: LoginForm(
grpcChannel: widget.channel,
notifyParent: refresh,
),
));
} else {
EnvirnomentList envList = EnvirnomentList(channel: widget.channel);
return DefaultTabController(
length: 3,
initialIndex: 0,
child: Scaffold(
key: _key,
endDrawer: const Drawer(child: Text("text")),
body: TabBarView(children: [envList, envList]),
appBar: AppBar(
backgroundColor: Colors.grey,
centerTitle: false,
title: const Text("Softplayer"),
bottom: const TabBar(
tabs: <Widget>[
Tab(
icon: Icon(Icons.computer),
text: "Environments",
),
Tab(
icon: Icon(Icons.install_desktop),
text: "Your applications",
),
Tab(
icon: Icon(Icons.list),
text: "Application Catalog",
),
],
return Scaffold(
body: Container(
width: double.infinity,
height: double.infinity,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/login_background.jpg"),
fit: BoxFit.cover,
),
),
actions: [
PopupMenuButton(
child: const Row(children: [
Icon(Icons.account_circle),
Text("account"),
]),
itemBuilder: (context) => [
const PopupMenuItem(
child: Row(
children: [Icon(Icons.settings), Text("Settings")],
),
),
const PopupMenuItem(
child: Row(children: [
Icon(Icons.monetization_on),
Text("Invoices"),
])),
PopupMenuItem(
child: const Row(
children: [Icon(Icons.logout), Text("Sign out")]),
onTap: () {
SoftplayerCredsHelpers().cleanupLocalStorate();
refresh();
},
),
])
],
),
floatingActionButton: FloatingActionButton(
child: const Icon(Icons.add),
onPressed: () => showDialog(
context: context,
builder: (context) => CreateEnvForm(widget.channel),
),
),
),
);
}
child: LoginForm(
grpcChannel: widget.channel,
notifyParent: refresh,
)));
}
}

View File

@@ -1,10 +0,0 @@
class CatalogEntry {
CatalogEntry({
required this.name,
required this.description,
required this.logoUrl,
});
final String name;
final String description;
final String logoUrl;
}

View File

@@ -1,10 +0,0 @@
class Environment {
final String name;
final List<String> apps;
final String provider;
Environment({
required this.name,
required this.apps,
required this.provider,
});
}

View File

@@ -1,29 +0,0 @@
import 'package:flutter/material.dart';
class AboutPage extends StatefulWidget {
const AboutPage({super.key});
final String title = "about";
@override
State<AboutPage> createState() => _AboutPage();
}
class _AboutPage extends State<AboutPage> {
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'test',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
);
}
}

View File

@@ -1,77 +0,0 @@
import 'package:flutter/material.dart';
import 'package:softplayer_web/api/third_party/chartmuseum.dart';
import 'package:softplayer_web/components/catalog_card.dart';
import 'package:softplayer_web/models/catalog_entry.dart';
class CatalogPage extends StatefulWidget {
const CatalogPage({
super.key,
});
final String title = "catalog";
@override
State<CatalogPage> createState() => _CatalogPage();
}
class _CatalogPage extends State<CatalogPage> {
late Future<List<HelmChart>> helmChart;
@override
void initState() {
super.initState();
helmChart = fetchCharts();
}
final List<CatalogEntry> catalog = [
CatalogEntry(
name: "openvpn",
description: "you know what I mean",
logoUrl:
"https://upload.wikimedia.org/wikipedia/commons/f/f5/OpenVPN_logo.svg"),
CatalogEntry(
name: "openvpn",
description: "you know what I mean",
logoUrl:
"https://upload.wikimedia.org/wikipedia/commons/f/f5/OpenVPN_logo.svg"),
];
@override
Widget build(BuildContext context) {
print(helmChart);
return Container(
margin: const EdgeInsets.all(14),
child: Container(
child: Row(children: <Widget>[
const SizedBox(
width: 200,
child: Card(
child: Column(
children: <Widget>[Text("Filter")],
))),
Flexible(
child: Column(
children: <Widget>[
const TextField(
decoration: InputDecoration(
icon: Icon(Icons.search),
labelText: "Search",
),
autofocus: true,
),
CatalogCard(data: catalog),
FutureBuilder(
future: helmChart,
builder: (context, snapshot) {
print(snapshot);
if (snapshot.hasData) {
return Text(snapshot.data!.first.name);
} else if (snapshot.hasError) {
return SelectableText('${snapshot.error}');
}
return const CircularProgressIndicator();
}),
],
),
)
])),
);
}
}

View File

@@ -1,24 +0,0 @@
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
static String title = "home";
@override
State<HomePage> createState() => _HomePage();
}
class _HomePage extends State<HomePage> {
@override
Widget build(BuildContext context) {
return const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
],
));
}
}