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