Booking forms + Scheduler adaptation
This commit is contained in:
207
lib/widgets/dialog/new_box_shared.dart
Normal file
207
lib/widgets/dialog/new_box_shared.dart
Normal file
@@ -0,0 +1,207 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:oc_front/models/response.dart';
|
||||
import 'package:oc_front/core/services/router.dart';
|
||||
import 'package:oc_front/core/services/specialized_services/shared_service.dart';
|
||||
|
||||
class NewBoxSharedWidget extends StatefulWidget {
|
||||
String? _selected;
|
||||
SharedService service = SharedService();
|
||||
final TextEditingController _ctrl = TextEditingController();
|
||||
final TextEditingController _ctrlDescr = TextEditingController();
|
||||
NewBoxSharedWidget ({ super.key, });
|
||||
@override NewBoxSharedWidgetState createState() => NewBoxSharedWidgetState();
|
||||
}
|
||||
class NewBoxSharedWidgetState extends State<NewBoxSharedWidget> {
|
||||
GlobalKey<FormFieldState> key = GlobalKey<FormFieldState>();
|
||||
GlobalKey<FormFieldState> key2 = GlobalKey<FormFieldState>();
|
||||
@override Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
padding: const EdgeInsets.only( top: 0, bottom: 20, left: 20, right: 20),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment.centerRight,
|
||||
height: 50,
|
||||
child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [
|
||||
const Padding(padding: EdgeInsets.symmetric(horizontal: 10), child:
|
||||
Text("load or create a new shared workspace", style: TextStyle(color: Colors.grey, fontSize: 15)
|
||||
)),
|
||||
Padding ( padding: const EdgeInsets.symmetric(horizontal: 10), child:
|
||||
Tooltip( message: "back", child: InkWell(
|
||||
mouseCursor: SystemMouseCursors.click,
|
||||
onTap: () {
|
||||
AppRouter.catalog.go(context, {});
|
||||
},
|
||||
child: const Icon(Icons.arrow_back, color: Colors.black))),
|
||||
),
|
||||
Row ( mainAxisAlignment: MainAxisAlignment.end, children: [
|
||||
Tooltip( message: "close", child: InkWell(
|
||||
mouseCursor: SystemMouseCursors.click,
|
||||
onTap: () { Navigator.pop(context); },
|
||||
child: const Icon(Icons.close, color: Colors.black))),
|
||||
]),
|
||||
],),
|
||||
),
|
||||
FutureBuilder<APIResponse<RawData>>(
|
||||
future: widget.service.all(context),
|
||||
builder: (context, snapshot) {
|
||||
List<DropdownMenuItem> items = [];
|
||||
if (snapshot.data != null && snapshot.data!.data != null) {
|
||||
for (var item in snapshot.data!.data!.values) {
|
||||
items.add(DropdownMenuItem<String>(
|
||||
value: item["id"].toString(),
|
||||
child: Text(item["name"].toString()),
|
||||
));
|
||||
}
|
||||
}
|
||||
if (widget._selected != null
|
||||
&& !items.where((element) => element.value == widget._selected).isNotEmpty) {
|
||||
items.add(DropdownMenuItem<String>(
|
||||
value: widget._selected.toString(),
|
||||
child: Text(widget._selected.toString()),
|
||||
));
|
||||
}
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children : [
|
||||
SizedBox( width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 140 : 400, height: 50,
|
||||
child: DropdownButtonFormField(
|
||||
value: widget._selected,
|
||||
isExpanded: true,
|
||||
hint: const Text("load shared workspace...", style: TextStyle(color: Colors.grey, fontSize: 15)),
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
focusedBorder: const OutlineInputBorder( borderRadius: BorderRadius.zero,
|
||||
borderSide: BorderSide(color: Color.fromARGB(38, 166, 154, 1), width: 0),
|
||||
),
|
||||
fillColor: Colors.grey.shade300,
|
||||
contentPadding: const EdgeInsets.only(left: 30, right: 30, top: 10, bottom: 30),
|
||||
enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.zero,
|
||||
borderSide: BorderSide(color: Colors.grey.shade300, width: 0),
|
||||
),
|
||||
border: OutlineInputBorder( borderRadius: BorderRadius.zero,
|
||||
borderSide: BorderSide(color: Colors.grey.shade300, width: 0)),
|
||||
),
|
||||
items: items,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
widget._selected = value.toString();
|
||||
});
|
||||
})),
|
||||
Tooltip(
|
||||
message: 'empty selection',
|
||||
child: InkWell(
|
||||
mouseCursor: widget._selected == null || widget._selected!.isEmpty ? MouseCursor.defer : SystemMouseCursors.click,
|
||||
onTap: () {
|
||||
if (widget._selected == null || widget._selected!.isEmpty) { return; }
|
||||
setState(() { widget._selected = null; });
|
||||
},
|
||||
child: Container(
|
||||
width: 50, height: 50,
|
||||
decoration: const BoxDecoration( color: Colors.black,
|
||||
border: Border(right: BorderSide(color: Colors.white))),
|
||||
child: Icon(Icons.refresh, color: widget._selected == null || widget._selected!.isEmpty ? Colors.grey : Colors.white),
|
||||
)
|
||||
)
|
||||
),
|
||||
Tooltip(
|
||||
message: 'load shared workspace selected',
|
||||
child: InkWell(
|
||||
mouseCursor: widget._selected == null || widget._selected!.isEmpty
|
||||
? MouseCursor.defer : SystemMouseCursors.click,
|
||||
onTap: () async {
|
||||
},
|
||||
child: Container(
|
||||
width: 50, height: 50,
|
||||
color: Colors.black,
|
||||
child: Icon(Icons.open_in_browser_outlined,
|
||||
color: widget._selected == null || widget._selected!.isEmpty ? Colors.grey : Colors.white),
|
||||
)
|
||||
)
|
||||
)
|
||||
]);}),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 90 : 450,
|
||||
height: 50,
|
||||
child: TextFormField( key: key,
|
||||
expands: true,
|
||||
maxLines: null,
|
||||
minLines: null,
|
||||
cursorColor: const Color.fromARGB(38, 166, 154, 1),
|
||||
controller: widget._ctrl,
|
||||
onChanged: (value) { widget._ctrl.text = value; },
|
||||
validator: (value) => value == null || value.isEmpty ? "name is required" : null,
|
||||
decoration: InputDecoration(
|
||||
hintText: "name a new shared workspace...",
|
||||
fillColor: Colors.grey.shade300,
|
||||
filled: true,
|
||||
errorStyle: const TextStyle(fontSize: 0),
|
||||
contentPadding: const EdgeInsets.only(left: 30, right: 30, top: 15, bottom: 5),
|
||||
hintStyle: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300
|
||||
),
|
||||
border: InputBorder.none
|
||||
)
|
||||
)
|
||||
),
|
||||
Tooltip(
|
||||
message: 'add',
|
||||
child:InkWell(
|
||||
mouseCursor: widget._ctrl.value.text.isEmpty ? MouseCursor.defer : SystemMouseCursors.click,
|
||||
onTap: () async {
|
||||
if (key.currentState!.validate() && key2.currentState!.validate()) {
|
||||
await widget.service.post(context, {
|
||||
"name" :widget._ctrl.value.text,
|
||||
"description" : widget._ctrlDescr.value.text }, {});
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
width: 50,
|
||||
height: 50,
|
||||
color: Colors.black,
|
||||
child: Icon(Icons.add, color: widget._ctrl.value.text.isEmpty ? Colors.grey : Colors.white)
|
||||
)
|
||||
)
|
||||
)
|
||||
]),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 40 : 500,
|
||||
height: 50,
|
||||
child: TextFormField( key: key2,
|
||||
expands: true,
|
||||
maxLines: null,
|
||||
minLines: null,
|
||||
cursorColor: const Color.fromARGB(38, 166, 154, 1),
|
||||
controller: widget._ctrlDescr,
|
||||
onChanged: (value) { widget._ctrlDescr.text = value; },
|
||||
validator: (value) => value == null || value.isEmpty ? "name is required" : null,
|
||||
decoration: InputDecoration(
|
||||
hintText: "description of a new shared workspace...",
|
||||
fillColor: Colors.grey.shade300,
|
||||
filled: true,
|
||||
errorStyle: const TextStyle(fontSize: 0),
|
||||
contentPadding: const EdgeInsets.only(left: 30, right: 30, top: 15, bottom: 5),
|
||||
hintStyle: const TextStyle(
|
||||
color: Colors.black,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w300
|
||||
),
|
||||
border: InputBorder.none
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -330,6 +330,7 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
Tooltip( message: "check booking",
|
||||
child: InkWell( mouseCursor: SystemMouseCursors.click,
|
||||
onTap: () {
|
||||
if (dash.scheduleActive) { return; }
|
||||
if (dash.scheduler["start"] == null ) {
|
||||
DateTime now = DateTime.now().add(const Duration(minutes: 5));
|
||||
dash.scheduler["start"] = now.toUtc().toIso8601String();
|
||||
@@ -359,10 +360,11 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
);
|
||||
}, child: Container( margin: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5),
|
||||
border: Border.all(color: widget.booking == null ? Colors.black : (widget.booking == true ? Colors.green : Colors.red), width: 1)),
|
||||
border: Border.all(color: widget.booking == null && !dash.scheduleActive ? Colors.grey : (widget.booking == true || dash.scheduleActive ? Colors.green : Colors.red), width: 1)),
|
||||
width: 140, height: 30,
|
||||
child: Icon(
|
||||
Icons.verified_outlined, color:widget.booking == null ? Colors.black : (widget.booking == true? Colors.green : Colors.red)),
|
||||
Icons.verified_outlined,
|
||||
color: widget.booking == null && !dash.scheduleActive ? Colors.grey : (widget.booking == true || dash.scheduleActive ? Colors.green : Colors.red)),
|
||||
))
|
||||
),
|
||||
Tooltip( message: dash.scheduleActive ? "unbook" : "book",
|
||||
@@ -376,9 +378,12 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
|
||||
} else { k.currentState!.save();}
|
||||
}
|
||||
}
|
||||
if (dash.scheduler["start"] == null ) {
|
||||
DateTime now = DateTime.now().add(const Duration(minutes: 5));
|
||||
DateTime now = DateTime.now().add(const Duration(minutes: 5));
|
||||
if (dash.scheduler["start"] == null || DateTime.parse(dash.scheduler["start"]!).isBefore(now)) {
|
||||
dash.scheduler["start"] = now.toUtc().toIso8601String();
|
||||
if (dash.scheduler["end"] != null) {
|
||||
dash.scheduler["end"] = now.add(const Duration(minutes: 1)).toUtc().toIso8601String();
|
||||
}
|
||||
}
|
||||
widget.item.save!(widget.item.id);
|
||||
setState(() { });
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:oc_front/core/sections/header/menu.dart';
|
||||
import 'package:oc_front/core/services/router.dart';
|
||||
import 'package:oc_front/widgets/menu_clipper/arrow_clipper.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user