Shared WS

This commit is contained in:
mr
2024-08-27 15:38:21 +02:00
parent 36a70db69f
commit 6ba32a7dfa
19 changed files with 479 additions and 87 deletions

View File

@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:oc_front/models/search.dart';
import 'package:oc_front/pages/workflow.dart';
@@ -6,7 +8,8 @@ Map<String, Map<String, AbstractItem>> proxyWfItem = {};
class ProxyFormsWidget extends StatefulWidget {
AbstractItem item;
ProxyFormsWidget ({ super.key, required this.item });
Dashboard dash;
ProxyFormsWidget ({ super.key, required this.item, required this.dash });
@override ProxyFormsWidgetState createState() => ProxyFormsWidgetState();
}
class ProxyFormsWidgetState extends State<ProxyFormsWidget> {
@@ -18,7 +21,7 @@ class ProxyFormsWidgetState extends State<ProxyFormsWidget> {
children.add(
Tooltip( message: child,
child: Container( margin: EdgeInsets.only(top: children.isEmpty ? 0 : 15),
width: 160, height: 30,
width: 200, height: 30,
child: TextFormField( textAlign: TextAlign.start,
initialValue: widget.item.model?.model?[child]?.value,
onChanged: (value) {
@@ -48,8 +51,80 @@ class ProxyFormsWidgetState extends State<ProxyFormsWidget> {
)))
);
}
if (widget.dash.scheduler["mode"] != null && widget.dash.scheduler["mode"] == 1) {
children.add(
Tooltip( message: "hostname",
child: Container( margin: EdgeInsets.only(top: children.isEmpty ? 0 : 15),
width: 200, height: 30,
child: TextFormField( textAlign: TextAlign.start,
onChanged: (value) {
widget.item.model ?? Model();
Future.delayed(const Duration(seconds: 2), () {
if (widget.item.model!.model?["hostname"]?.value == value) {
dash.save!(dash.id);
}
});
widget.item.model?.model?["hostname"]?.value = value;
},
style: const TextStyle(fontSize: 12),
decoration: const InputDecoration(
hintText: "enter hostname...",
fillColor: Colors.white,
filled: true,
labelText: "hostname",
alignLabelWithHint: false,
errorStyle: TextStyle(fontSize: 0),
hintStyle: TextStyle(fontSize: 10),
labelStyle: TextStyle(fontSize: 10),
floatingLabelBehavior: FloatingLabelBehavior.always,
enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Colors.grey)),
border: OutlineInputBorder(borderSide: BorderSide(color: Colors.grey)),
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
),
)))
);
children.add(
Tooltip( message: "port",
child: Container( margin: EdgeInsets.only(top: children.isEmpty ? 0 : 15),
width: 200, height: 50,
child: TextFormField( textAlign: TextAlign.start,
onChanged: (value) {
widget.item.model ?? Model();
Future.delayed(const Duration(seconds: 2), () {
if (widget.item.model!.model?["port"]?.value == value) {
dash.save!(dash.id);
}
});
try {
widget.item.model?.model?["port"]?.value = int.parse(value);
} catch (e) { /**/ }
},
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
], // Only numbers can be entered
maxLength: 4,
style: const TextStyle(fontSize: 12),
decoration: const InputDecoration(
hintText: "enter port...",
fillColor: Colors.white,
filled: true,
labelText: "port",
alignLabelWithHint: false,
errorStyle: TextStyle(fontSize: 0),
hintStyle: TextStyle(fontSize: 10),
labelStyle: TextStyle(fontSize: 10),
floatingLabelBehavior: FloatingLabelBehavior.always,
enabledBorder: OutlineInputBorder(borderSide: BorderSide(color: Colors.grey)),
border: OutlineInputBorder(borderSide: BorderSide(color: Colors.grey)),
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
),
)))
);
}
return Column( children: [
Container( padding: const EdgeInsets.all(10), width: 200, height: 60, margin: const EdgeInsets.only(bottom: 15),
Container( padding: const EdgeInsets.all(10), width: 250, height: 60, margin: const EdgeInsets.only(bottom: 15),
decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Colors.grey, width: 1))),
child: const Column( mainAxisAlignment: MainAxisAlignment.center, children: [
Text("ELEMENT INFO", style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold), textAlign: TextAlign.center),

View File

@@ -1,10 +1,12 @@
import 'package:alert_banner/exports.dart';
import 'package:cron/cron.dart';
import 'package:flutter/widgets.dart';
import 'package:intl/intl.dart' as intl;
import 'package:flutter/material.dart';
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:flutter_advanced_switch/flutter_advanced_switch.dart';
import 'package:datetime_picker_formfield/datetime_picker_formfield.dart';
import 'package:oc_front/core/models/shared_workspace_local.dart';
import 'package:oc_front/core/services/specialized_services/check_service.dart';
import 'package:oc_front/pages/workflow.dart';
import 'package:oc_front/widgets/dialog/alert.dart';
@@ -44,13 +46,15 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
List<GlobalKey<FormFieldState>> formKeys = [GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>(),
GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>()];
return Column( children: [
Container( padding: const EdgeInsets.all(10), width: 200, height: 60,
Container( padding: const EdgeInsets.all(10), width: 250, height: 60,
decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Colors.grey, width: 1))),
child: const Column( mainAxisAlignment: MainAxisAlignment.center, children: [
Text("WORKFLOW INFO", style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold), textAlign: TextAlign.center),
Text("<general>", style: TextStyle(fontSize: 12), textAlign: TextAlign.center),
])),
Container(height: 20),
Container(height: 20,
width: 250,
),
AdvancedSwitch(
width: 140,
initialValue: widget.item.scheduler["mode"] == 1,
@@ -131,11 +135,10 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
lastDate: DateTime(2100)
);
if (date != null) {
var n = TimeOfDay.now();
TimeOfDay? time = n;
TimeOfDay? time;
var count = 0;
while(((time?.hour ?? 0) + ((time?.minute ?? 0) / 100)) <= (n.hour + ((n.minute + 1) / 100)) ) {
if (count > 0 && time != null) {
while(date!.microsecondsSinceEpoch <= (DateTime.now().microsecondsSinceEpoch) || time == null) {
if (count > 0) {
showAlertBanner( context, () {},
const AlertAlertBannerChild(
text: "must be at least 1 minute from now to let system check info"),// <-- Put any widget here you want!
@@ -161,9 +164,9 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
);
if (time == null) { return DateTime.now().add( const Duration(minutes: 1)); }
count++;
date = DateTime(date.year, date.month, date.day, time.hour, time.minute);
widget.item.scheduler["start"] = date.toUtc().toIso8601String();
}
date = date.add(Duration(hours: time?.hour ?? 0, minutes: time?.minute ?? 0));
widget.item.scheduler["start"] = date.toUtc().toIso8601String();
widget.item.save!(widget.item.id);
}
return date;
@@ -228,13 +231,15 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
);
if (date != null) {
// ignore: use_build_context_synchronously
var n = TimeOfDay.now();
TimeOfDay? time = TimeOfDay(hour: date.hour, minute: date.minute);
date = DateTime(date.year, date.month, date.day, date.hour, date.minute);
TimeOfDay? time;
var count = 0;
while(((time?.hour ?? 0) + (time?.minute ?? 0 / 100)) <= (n.hour + ((n.minute + 1) / 100)) ) {
if (count > 0 && time != null) {
while(date!.microsecondsSinceEpoch <= (DateTime.now().microsecondsSinceEpoch)
|| time == null
|| (date.microsecondsSinceEpoch) <= (DateTime.parse(widget.item.scheduler["start"] ?? DateTime.now().toIso8601String()).microsecondsSinceEpoch)) {
if (count > 0) {
showAlertBanner( context, () {},
const AlertAlertBannerChild(text: "must be at least 1 minute from now to let system check info"),// <-- Put any widget here you want!
const AlertAlertBannerChild(text: "must be at least 1 minute from now to let system check info && upper starting date"),// <-- Put any widget here you want!
alertBannerLocation: AlertBannerLocation.bottom,);
}
time = await showTimePicker(context: context,
@@ -257,9 +262,9 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
);
if (time == null) { return null; }
count++;
date = DateTime(date.year, date.month, date.day, time.hour, time.minute);
widget.item.scheduler["end"] = date.toUtc().toIso8601String();
}
date = date.add(Duration(hours: time?.hour ?? 0, minutes: time?.minute ?? 0));
widget.item.scheduler["end"] = date.toUtc().toIso8601String();
widget.item.save!(widget.item.id);
}
return date;
@@ -326,7 +331,11 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
),
))),
const Divider(color: Colors.grey),
Container(
width: 250,
height: 20,
decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Colors.black, width: 1))),
),
Tooltip( message: "check booking",
child: InkWell( mouseCursor: SystemMouseCursors.click,
onTap: () {
@@ -361,7 +370,7 @@ 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 && !dash.scheduleActive ? Colors.grey : (widget.booking == true || dash.scheduleActive ? Colors.green : Colors.red), width: 1)),
width: 140, height: 30,
width: 200, height: 30,
child: Icon(
Icons.verified_outlined,
color: widget.booking == null && !dash.scheduleActive ? Colors.grey : (widget.booking == true || dash.scheduleActive ? Colors.green : Colors.red)),
@@ -389,12 +398,31 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
setState(() { });
}, child: Container( margin: const EdgeInsets.all(10),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(5),
border: Border.all(color: dash.scheduleActive ? Colors.green : Colors.black, width: 1)),
width: 140, height: 30,
border: Border.all(color: dash.scheduleActive ? Colors.green : Colors.black)),
width: 200, height: 30,
child: Icon(
dash.scheduleActive ? Icons.cancel_schedule_send : Icons.schedule_send, color: dash.scheduleActive ? Colors.green : Colors.black),
))
),
widget.item.info["shared"] != null && (widget.item.info["shared"] as List<dynamic>).isNotEmpty ? Column( children: [
Container(
height: 20,
width: 250,
decoration: const BoxDecoration(border: Border(top: BorderSide(color: Colors.black))),
),
Container( alignment: Alignment.center, padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text( textAlign: TextAlign.center,
style: const TextStyle(fontSize: 14, color: Colors.black, fontWeight: FontWeight.bold),
"Workflow is shared in ${(widget.item.info["shared"] as List<dynamic>).length} workspace(s)")),
...(widget.item.info["shared"] as List<dynamic>).where( (e) => SharedWorkspaceLocal.getSharedWorkspace(e) != null
).map((e) {
return Container( alignment: Alignment.center, padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
child: Row( children: [
const Padding(padding: EdgeInsets.only(right: 10), child: Icon(Icons.work, color: Colors.grey, size: 15)),
Text(style: const TextStyle(fontSize: 12, color: Colors.grey),
"Workspace: ${SharedWorkspaceLocal.getSharedWorkspace(e)!.name}") ]));
},)
]) : Container()
]);
}
}

View File

@@ -0,0 +1,142 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/models/shared_workspace_local.dart';
import 'package:oc_front/core/services/specialized_services/shared_service.dart';
import 'package:oc_front/models/shared.dart';
import 'package:oc_front/pages/catalog.dart';
import 'package:oc_front/pages/catalog_item.dart';
import 'package:oc_front/pages/workflow.dart';
enum SharedMenuWorkspaceType { workspace, workflow, peer }
class SharedMenuWorkspaceWidget extends StatefulWidget {
List<dynamic> excluded = [];
SharedMenuWorkspaceType type = SharedMenuWorkspaceType.workspace;
double? width;
String contextID;
SharedService service = SharedService();
String? selected;
bool inner = false;
bool reverse = false;
double? topMargin;
String? before;
TextEditingController ctrl = TextEditingController();
SharedMenuWorkspaceWidget ({ Key? key, this.width, required this.contextID, this.selected,
this.type = SharedMenuWorkspaceType.workspace, this.topMargin, this.excluded = const [],
this.inner = false, this.reverse = false, this.before}): super(key: key);
@override SharedMenuWorkspaceWidgetState createState() => SharedMenuWorkspaceWidgetState();
}
class SharedMenuWorkspaceWidgetState extends State<SharedMenuWorkspaceWidget> {
@override Widget build(BuildContext context) {
return Row( children: [
Tooltip( message: "current workspace", child:
Theme(
data: Theme.of(context).copyWith(
canvasColor: Colors.grey,
),
child: Container(
margin: EdgeInsets.only(top: widget.topMargin ?? (widget.inner ? 0 : 10)),
height: 50, width: (widget.width ?? MediaQuery.of(context).size.width) - 100,
decoration: BoxDecoration(
color: widget.reverse ? Colors.white : ( widget.inner ? Color.fromRGBO(38, 166, 154, 1) : Colors.grey.shade300 ),
border: const Border(bottom: BorderSide(color: Colors.transparent, width: 1))
),
padding: EdgeInsets.only(left: (widget.width ?? 400) < 400 ? 20 : 50, right: (widget.width ?? 400) < 400 ? 20 : 0),
child: DropdownButtonFormField(
value: widget.selected,
isExpanded: true,
style: const TextStyle(color:Colors.black, fontSize: 15),
hint: Text("choose shared workspace...", style: TextStyle(color: widget.inner ? Colors.grey.shade300 : Colors.grey, fontSize: 15)),
icon: Icon( // Add this
Icons.arrow_drop_down, // Add this
color: widget.inner ? Colors.white : Colors.grey, // Add this
),
decoration: InputDecoration(
filled: true,
suffixIconColor: widget.inner ? Colors.grey.shade300 : Colors.grey,
focusedBorder: const OutlineInputBorder( borderRadius: BorderRadius.zero,
borderSide: BorderSide(color: Colors.transparent, width: 0),
),
fillColor: widget.reverse ? Colors.white : (widget.inner ? const Color.fromRGBO(38, 166, 154, 1) : Colors.grey.shade300),
contentPadding: EdgeInsets.only(left: 0 , right: (widget.width ?? 400) < 400 ? 0 : 30, top: 10, bottom: 30),
enabledBorder: const OutlineInputBorder( borderRadius: BorderRadius.zero,
borderSide: BorderSide(color: Colors.transparent, width: 0),
),
border: const OutlineInputBorder( borderRadius: BorderRadius.zero,
borderSide: BorderSide(color: Colors.transparent, width: 0)),
),
items: SharedWorkspaceLocal.workspaces.values.where((element) => !widget.excluded.contains(element.id)
).map((e) => DropdownMenuItem(
value: e.id ,child: Text(e.name ?? ""),)).toList(),
onChanged: (value) {
setState(() {
widget.before = widget.selected;
widget.selected = value.toString();
});
})))),
Tooltip(
message: 'share',
child:InkWell(
mouseCursor: widget.selected == null || widget.selected == widget.before ? MouseCursor.defer : SystemMouseCursors.click,
onTap: () async {
if (widget.selected != null && widget.contextID != "" && widget.selected != widget.before) {
if (widget.type == SharedMenuWorkspaceType.peer) {
await widget.service.addPeer(context, widget.selected!, widget.contextID);
} else if (widget.type == SharedMenuWorkspaceType.workflow) {
await widget.service.addWorkflow(context, widget.selected!, widget.contextID);
} else {
await widget.service.addWorkspace(context, widget.selected!, widget.contextID);
}
SharedWorkspaceLocal.init(context, false);
setState(() {});
dash.selectedLeftMenuKey.currentState?.setState(() { });
CatalogFactory.key.currentState?.setState(() {});
CatalogItemFactory.key.currentState?.setState(() {});
WorkflowFactory.key.currentState?.setState(() {});
}
},
child: Container(
margin: EdgeInsets.only(top: widget.topMargin ?? (widget.inner ? 0 : 10)),
width: 50,
height: 50,
color: Colors.black,
child: Icon(Icons.share_rounded,
color: widget.selected == null || widget.selected == widget.before ? Colors.grey : Colors.white)
)
)
),
Tooltip(
message: 'unshare',
child:InkWell(
mouseCursor: widget.selected == null || widget.selected == widget.before ? MouseCursor.defer : SystemMouseCursors.click,
onTap: () async {
if (widget.selected != null && widget.contextID != "" && widget.selected != widget.before) {
if (widget.type == SharedMenuWorkspaceType.peer) {
await widget.service.removePeer(context, widget.selected!, widget.contextID);
} else if (widget.type == SharedMenuWorkspaceType.workflow) {
await widget.service.removeWorkflow(context, widget.selected!, widget.contextID);
} else {
await widget.service.removeWorkspace(context, widget.selected!, widget.contextID);
}
SharedWorkspaceLocal.init(context, false);
setState(() {});
dash.selectedLeftMenuKey.currentState?.setState(() { });
CatalogFactory.key.currentState?.setState(() {});
CatalogItemFactory.key.currentState?.setState(() {});
WorkflowFactory.key.currentState?.setState(() {});
}
},
child: Container(
decoration: const BoxDecoration(
color: Colors.black,
border: Border(left: BorderSide(color: Colors.white, width: 1))
),
margin: EdgeInsets.only( top: widget.topMargin ?? (widget.inner ? 0 : 10 )),
width: 50,
height: 50,
child: Icon(Icons.delete, color: widget.selected == null || widget.selected == widget.before ? Colors.grey : Colors.white)
)
)
)
]);
}
}

View File

@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:oc_front/core/models/shared_workspace_local.dart';
import 'package:oc_front/core/models/workspace_local.dart';
import 'package:oc_front/widgets/menu_clipper/shared_workspace_menu.dart';
class MenuWorkspaceWidget extends StatefulWidget {
bool simpliest = false;
double? width;
@@ -17,7 +19,7 @@ class MenuWorkspaceWidgetState extends State<MenuWorkspaceWidget> {
data: Theme.of(context).copyWith(
canvasColor: widget.simpliest ? Colors.grey.shade300 : Colors.grey,
),
child: Container( height: 50, width: widget.width ?? MediaQuery.of(context).size.width / ( widget.simpliest ? 1 : 2),
child: Container( height: 50, width: widget.width ?? MediaQuery.of(context).size.width / ( widget.simpliest ? 1 : 3),
decoration: BoxDecoration(
color: widget.simpliest ? Colors.white : const Color.fromRGBO(38, 166, 154, 1),
border: Border(bottom: BorderSide(color: widget.simpliest ? Colors.grey.shade300 : Colors.transparent, width: 1))
@@ -58,12 +60,13 @@ class MenuWorkspaceWidgetState extends State<MenuWorkspaceWidget> {
}
});
})))),
widget.simpliest ? Container() : Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: (MediaQuery.of(context).size.width / 2) - 50,
width: (MediaQuery.of(context).size.width / 3) - 50,
height: 50,
decoration: const BoxDecoration(border: Border(left: BorderSide(color: Colors.white))),
child: TextFormField(
@@ -106,7 +109,12 @@ class MenuWorkspaceWidgetState extends State<MenuWorkspaceWidget> {
)
)
)
])
]),
widget.simpliest ? Container() : SharedMenuWorkspaceWidget( inner: true,
excluded: const[],
before: WorkspaceLocal.workspaces[WorkspaceLocal.current]!.shared,
selected: WorkspaceLocal.workspaces[WorkspaceLocal.current]!.shared,
contextID: WorkspaceLocal.current ?? "", width: (MediaQuery.of(context).size.width / 3))
]);
}
}