Some updates to the frontent
This commit is contained in:
@ -2,24 +2,30 @@ import 'dart:html';
|
||||
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();
|
||||
String? serverLocation;
|
||||
String? serverType;
|
||||
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.
|
||||
@ -31,14 +37,13 @@ class _CreateEnvFormState extends State<CreateEnvForm> {
|
||||
EnvironmentLocalData(
|
||||
serverType: serverType!,
|
||||
serverLocation: serverLocation!,
|
||||
provider: "",
|
||||
provider: defaultProvider,
|
||||
name: name,
|
||||
description: description),
|
||||
SoftplayerCredsHelpers().fromLocalStorage())
|
||||
.then((rs) {
|
||||
Navigator.pop(context);
|
||||
}).catchError((e) {
|
||||
print(e);
|
||||
GrpcError error = e;
|
||||
String msg;
|
||||
if (error.message != null) {
|
||||
@ -56,65 +61,91 @@ class _CreateEnvFormState extends State<CreateEnvForm> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget createEnvForm() => SizedBox(
|
||||
width: 420,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Center(
|
||||
child: Column(children: [
|
||||
Divider(),
|
||||
Text("Provider the environment metadata"),
|
||||
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: true,
|
||||
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),
|
||||
),
|
||||
Divider(),
|
||||
DropdownButtonFormField(
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Enter the environment description",
|
||||
icon: Icon(Icons.computer),
|
||||
label: Text("Type of the server"),
|
||||
),
|
||||
value: null,
|
||||
isDense: true,
|
||||
items: [
|
||||
DropdownMenuItem(
|
||||
child: Text("lala1"),
|
||||
value: "test1",
|
||||
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),
|
||||
),
|
||||
DropdownMenuItem(child: Text("lala2"), value: "test2"),
|
||||
DropdownMenuItem(child: Text("lala3"), value: "test3"),
|
||||
DropdownMenuItem(child: Text("lala4"), value: "test4"),
|
||||
],
|
||||
onChanged: (value) => print(value),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => js.context.callMethod(
|
||||
'open', ['https://stackoverflow.com/questions/ask']),
|
||||
child: Text("Read more about environment types here"),
|
||||
)
|
||||
]))));
|
||||
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: 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,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:softplayer_web/api/grpc/environments.dart';
|
||||
import 'package:softplayer_web/helpers/providers/common.dart';
|
||||
|
||||
class EnvirnomentCard extends StatelessWidget {
|
||||
final EnvironmentLocalData env;
|
||||
@ -11,6 +12,17 @@ class EnvirnomentCard extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Provider provider = ProviderHelper().getProvider(env.provider);
|
||||
|
||||
String serverType;
|
||||
String serverLocation;
|
||||
try {
|
||||
serverType = ProviderHelper().getServerType(env.serverType);
|
||||
serverLocation = provider.getServerLocation(env.serverLocation);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
return Card(
|
||||
child: SelectionArea(
|
||||
child: Column(
|
||||
@ -25,21 +37,21 @@ class EnvirnomentCard extends StatelessWidget {
|
||||
top: BorderSide.none,
|
||||
),
|
||||
children: [
|
||||
TableRow(children: [
|
||||
Text("Provider"),
|
||||
Text(env.provider),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Description"),
|
||||
Text(env.description),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Provider"),
|
||||
Text(provider.getProviderName()),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Server Type"),
|
||||
Text(env.serverType),
|
||||
Text(serverType),
|
||||
]),
|
||||
TableRow(children: [
|
||||
Text("Location"),
|
||||
Text(env.serverLocation),
|
||||
Text(serverLocation),
|
||||
]),
|
||||
],
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:grpc/grpc_web.dart';
|
||||
import 'package:softplayer_web/api/grpc/creds.dart';
|
||||
import 'package:softplayer_web/api/grpc/environments.dart';
|
||||
@ -48,16 +49,25 @@ class _EnvirnomentListState extends State<EnvirnomentList> {
|
||||
if (snapshot.hasData) {
|
||||
var data = snapshot.requireData;
|
||||
if (data.isNotEmpty) {
|
||||
return GridView.count(
|
||||
crossAxisCount: 4,
|
||||
children: snapshot.data!
|
||||
.map((e) => EnvirnomentCard(
|
||||
env: e,
|
||||
))
|
||||
.toList(),
|
||||
);
|
||||
return Column(children: [
|
||||
Flexible(
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
icon: Icon(Icons.search),
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: GridView.count(
|
||||
crossAxisCount: 4,
|
||||
children: snapshot.data!
|
||||
.map((e) => EnvirnomentCard(
|
||||
env: e,
|
||||
))
|
||||
.toList(),
|
||||
))
|
||||
]);
|
||||
} else {
|
||||
print("npo data");
|
||||
return Center(
|
||||
child: Container(
|
||||
height: 300,
|
||||
|
Reference in New Issue
Block a user