376 lines
20 KiB
Dart
376 lines
20 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:oc_front/core/models/shared_workspace_local.dart';
|
|
import 'package:oc_front/core/models/workspace_local.dart';
|
|
import 'package:oc_front/core/sections/header/header.dart';
|
|
import 'package:oc_front/core/services/router.dart';
|
|
import 'package:oc_front/core/services/specialized_services/peer_service.dart';
|
|
import 'package:oc_front/core/services/specialized_services/shared_service.dart';
|
|
import 'package:oc_front/core/services/specialized_services/workflow_service.dart';
|
|
import 'package:oc_front/models/response.dart';
|
|
import 'package:oc_front/models/shared.dart';
|
|
import 'package:oc_front/pages/abstract_page.dart';
|
|
import 'package:oc_front/widgets/catalog.dart';
|
|
import 'package:oc_front/widgets/dialog/shallow_creation.dart';
|
|
import 'package:oc_front/widgets/inputs/shallow_text_input.dart';
|
|
import 'package:oc_front/widgets/items/shallow_item_row.dart';
|
|
import 'package:oc_front/widgets/inputs/shallow_dropdown_input.dart';
|
|
|
|
enum SharedWorkspaceType { global, shared_workspace, workspace, workflow, peer, resource }
|
|
|
|
class SharedFactory implements AbstractFactory {
|
|
static GlobalKey<SharedPageWidgetState> key = GlobalKey<SharedPageWidgetState>();
|
|
@override bool searchFill() { return false; }
|
|
@override Widget factory(GoRouterState state, List<String> args) { return SharedPageWidget(); }
|
|
@override void search(BuildContext context) { }
|
|
}
|
|
|
|
class SharedPageWidget extends StatefulWidget {
|
|
SharedWorkspaceType type = SharedWorkspaceType.global;
|
|
SharedPageWidget(): super(key: SharedFactory.key);
|
|
@override SharedPageWidgetState createState() => SharedPageWidgetState();
|
|
static void search(BuildContext context) { }
|
|
static Widget factory() { return SharedPageWidget(); }
|
|
}
|
|
class SharedPageWidgetState extends State<SharedPageWidget> {
|
|
SharedService service = SharedService();
|
|
Widget getMenuItem(SharedWorkspaceType workspaceType, IconData icon) {
|
|
var s = workspaceType == SharedWorkspaceType.global ? "dashboard" : workspaceType == SharedWorkspaceType.workspace ? "shared workspaces" : workspaceType == SharedWorkspaceType.workflow ? "shared workflows" : "peers engaged";
|
|
return Tooltip( message: s,
|
|
child: InkWell( mouseCursor: SystemMouseCursors.click,
|
|
onTap: () => setState(() {
|
|
widget.type = workspaceType;
|
|
}),
|
|
child: Container( width: 50, height: 50,
|
|
color: widget.type == workspaceType ? Color.fromRGBO(38, 166, 154, 1) : Colors.transparent,
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
child : Icon(icon,
|
|
color: widget.type == workspaceType ? Colors.white : Colors.white, size: 20))));
|
|
}
|
|
|
|
@override Widget build(BuildContext context) {
|
|
GlobalKey<ShallowTextInputWidgetState> key = GlobalKey<ShallowTextInputWidgetState>();
|
|
if (SharedWorkspaceLocal.current == null) {
|
|
Future.delayed( const Duration(microseconds: 100), () {
|
|
HeaderConstants.setTitle("Choose a Shared Workspace");
|
|
HeaderConstants.setDescription("select a shared workspace to continue");
|
|
});
|
|
Future.delayed( const Duration(milliseconds: 100), () {
|
|
showDialog(
|
|
barrierDismissible: false,
|
|
context: context, builder: (BuildContext ctx) => AlertDialog(
|
|
titlePadding: EdgeInsets.zero,
|
|
insetPadding: EdgeInsets.zero,
|
|
backgroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
|
|
title: ShallowCreationDialogWidget(
|
|
formKey: key,
|
|
canClose: () => SharedWorkspaceLocal.current != null,
|
|
context: context,
|
|
load: (p0) async {
|
|
SharedWorkspaceLocal.current = p0;
|
|
HeaderConstants.setTitle("Shared Workspace <${SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.name ?? ""}>");
|
|
HeaderConstants.setDescription(SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.description ?? "");
|
|
Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {}));
|
|
},
|
|
form: [
|
|
ShallowTextInputWidget(
|
|
change :(p0) => key.currentState?.setState(() {}),
|
|
canLoad: (po) => po != null && po.isNotEmpty,
|
|
type: SharedWorkspaceType.shared_workspace,
|
|
width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 140 : 400,
|
|
attr: "description",
|
|
color: Colors.black,
|
|
hintColor: Colors.grey,
|
|
filled: Colors.grey.shade300,
|
|
)
|
|
],
|
|
create: (p0) async => await SharedService().post(context, p0, {}).then((value) {
|
|
if (value.data != null) {
|
|
SharedWorkspaceLocal.current = value.data!.id;
|
|
}
|
|
SharedWorkspaceLocal.init(context, true);
|
|
|
|
HeaderConstants.setTitle("Shared Workspace <${SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.name ?? ""}>");
|
|
HeaderConstants.setDescription(SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.description ?? "");
|
|
Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {}));
|
|
}),
|
|
type: SharedWorkspaceType.shared_workspace,
|
|
all: () async => SharedWorkspaceLocal.workspaces.values.map(
|
|
(e) => Shallow(id: e.id ?? "", name: e.name ?? "") ).toList(),
|
|
)));
|
|
});
|
|
} else {
|
|
Future.delayed( const Duration(milliseconds: 100), () {
|
|
HeaderConstants.setTitle("Shared Workspace <${SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.name ?? ""}>");
|
|
HeaderConstants.setDescription(SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.description ?? "");
|
|
});
|
|
}
|
|
Widget w = WorkspaceSharedPageWidget(type: widget.type);
|
|
List<Widget> addMenu = [];
|
|
SharedWorkspace? current = SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current ?? ""];
|
|
if (widget.type == SharedWorkspaceType.workspace) {
|
|
addMenu.add( Row( mainAxisAlignment: MainAxisAlignment.end,
|
|
children : [ ShallowDropdownInputWidget(
|
|
tooltipLoad: "share",
|
|
tooltipRemove: "unshare",
|
|
iconLoad: Icons.share,
|
|
type: widget.type,
|
|
current: WorkspaceLocal.current,
|
|
all: () async => WorkspaceLocal.getWorkspacesShallow(),
|
|
width: MediaQuery.of(context).size.width / 3,
|
|
canLoad: (String? change) => current == null || !current.workspaces.map( (e) => e.id ).contains(change),
|
|
canRemove: (String? change) => current == null || current.workspaces.map( (e) => e.id ).contains(change),
|
|
load: (String val) async {
|
|
await service.addWorkspace(context, SharedWorkspaceLocal.current ?? "", val);
|
|
SharedWorkspaceLocal.init(context, false);
|
|
},
|
|
remove: (String val) async {
|
|
await service.removeWorkspace(context, SharedWorkspaceLocal.current ?? "", val);
|
|
SharedWorkspaceLocal.init(context, false);
|
|
})
|
|
]));
|
|
}
|
|
if (widget.type == SharedWorkspaceType.workflow) {
|
|
addMenu.add( Row( mainAxisAlignment: MainAxisAlignment.end,
|
|
children : [ ShallowDropdownInputWidget(
|
|
tooltipLoad: "share",
|
|
tooltipRemove: "unshare",
|
|
iconLoad: Icons.share,
|
|
type: widget.type, all: () async {
|
|
List<Shallow> shals = [];
|
|
await WorflowService().all(context).then((value) {
|
|
if (value.data != null) {
|
|
shals = value.data!.values.map((e) => Shallow(id: e["id"], name: e["name"])).toList();
|
|
}
|
|
});
|
|
return shals;
|
|
},
|
|
width: MediaQuery.of(context).size.width / 3,
|
|
canLoad: (String? change) => current == null || !current.workflows.map( (e) => e.id ).contains(change),
|
|
canRemove: (String? change) => current == null || current.workflows.map( (e) => e.id ).contains(change),
|
|
load: (String change) async {
|
|
await service.addWorkflow(context, SharedWorkspaceLocal.current ?? "", change);
|
|
},
|
|
remove: (String change) async {
|
|
await service.removeWorkflow(context, SharedWorkspaceLocal.current ?? "", change);
|
|
})
|
|
]));
|
|
}
|
|
if (widget.type == SharedWorkspaceType.peer) {
|
|
addMenu.add( Row( mainAxisAlignment: MainAxisAlignment.end,
|
|
children : [ ShallowDropdownInputWidget(
|
|
tooltipLoad: "add",
|
|
iconLoad: Icons.add,
|
|
type: widget.type, all: () async {
|
|
List<Shallow> shals = [];
|
|
await PeerService().all(context).then((value) {
|
|
if (value.data != null) {
|
|
shals = value.data!.values.map((e) => Shallow(id: e["id"], name: e["name"])).toList();
|
|
}
|
|
});
|
|
return shals;
|
|
},
|
|
width: MediaQuery.of(context).size.width / 3,
|
|
canLoad: (String? change) => current == null || !current.peers.map( (e) => e.id ).contains(change),
|
|
canRemove: (String? change) => current == null || current.peers.map( (e) => e.id ).contains(change),
|
|
load: (String change) async {
|
|
await service.addPeer(context, SharedWorkspaceLocal.current ?? "", change);
|
|
},
|
|
remove: (String change) async {
|
|
await service.removePeer(context, SharedWorkspaceLocal.current ?? "", change);
|
|
})
|
|
]));
|
|
}
|
|
return Column( children: [
|
|
Container(
|
|
height: 50,
|
|
color: const Color.fromRGBO(38, 166, 154, 1),
|
|
width: MediaQuery.of(context).size.width,
|
|
padding: const EdgeInsets.only(left: 50),
|
|
child: Stack( alignment: Alignment.centerLeft, children: [
|
|
Tooltip( message: "open file", child: Padding( padding: const EdgeInsets.only(right: 15),
|
|
child: InkWell( mouseCursor: SystemMouseCursors.click,
|
|
onTap: () {
|
|
showDialog(
|
|
barrierDismissible: false,
|
|
context: context, builder: (context) {
|
|
return AlertDialog(
|
|
titlePadding: EdgeInsets.zero,
|
|
insetPadding: EdgeInsets.zero,
|
|
backgroundColor: Colors.white,
|
|
shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(0)),
|
|
title: ShallowCreationDialogWidget(
|
|
formKey: key,
|
|
canClose: () => SharedWorkspaceLocal.current != null,
|
|
context: context,
|
|
load: (p0) async {
|
|
SharedWorkspaceLocal.current = p0;
|
|
HeaderConstants.setTitle("Shared Workspace <${SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.name ?? ""}>");
|
|
HeaderConstants.setDescription(SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.description ?? "");
|
|
Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {}));
|
|
},
|
|
form: [
|
|
ShallowTextInputWidget(
|
|
change :(p0) => key.currentState?.setState(() {}),
|
|
type: SharedWorkspaceType.shared_workspace,
|
|
width: MediaQuery.of(context).size.width <= 540 ? MediaQuery.of(context).size.width - 140 : 400,
|
|
attr: "description",
|
|
color: Colors.black,
|
|
hintColor: Colors.grey,
|
|
filled: Colors.grey.shade300,
|
|
)
|
|
],
|
|
create: (p0) async => await SharedService().post(context, p0, {}).then( (e) {
|
|
if (e.data != null) {
|
|
SharedWorkspaceLocal.current = e.data!.id;
|
|
}
|
|
SharedWorkspaceLocal.init(context, true);
|
|
|
|
HeaderConstants.setTitle("Shared Workspace <${SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.name ?? ""}>");
|
|
HeaderConstants.setDescription(SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current]?.description ?? "");
|
|
Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {}));
|
|
}),
|
|
type: SharedWorkspaceType.shared_workspace,
|
|
all: () async => SharedWorkspaceLocal.workspaces.values.map(
|
|
(e) => Shallow(id: e.id ?? "", name: e.name ?? "") ).toList(),
|
|
));
|
|
});
|
|
},
|
|
child: const Icon(Icons.folder_open, color: Colors.white)))),
|
|
Positioned( right: 0, child: Row( children: addMenu))
|
|
])),
|
|
Row(
|
|
children: [
|
|
Container(
|
|
color: Colors.black,
|
|
height: MediaQuery.of(context).size.height - HeaderConstants.height - 50,
|
|
width: 50,
|
|
child: Column(
|
|
children: [
|
|
getMenuItem(SharedWorkspaceType.global, Icons.dashboard),
|
|
getMenuItem(SharedWorkspaceType.workspace, Icons.workspaces),
|
|
getMenuItem(SharedWorkspaceType.workflow, Icons.rebase_edit),
|
|
getMenuItem(SharedWorkspaceType.peer, Icons.group),
|
|
])
|
|
),
|
|
Container(
|
|
height: MediaQuery.of(context).size.height - HeaderConstants.height - 50,
|
|
width: MediaQuery.of(context).size.width -50,
|
|
color: widget.type == SharedWorkspaceType.workflow || widget.type == SharedWorkspaceType.peer ? Colors.grey.shade300 : Colors.white,
|
|
child: SingleChildScrollView( child: w ))
|
|
]
|
|
) ]
|
|
);
|
|
}
|
|
}
|
|
|
|
class WorkspaceSharedPageWidget extends StatefulWidget {
|
|
SharedWorkspaceType type = SharedWorkspaceType.global;
|
|
WorkspaceSharedPageWidget({ required this.type }): super(key: null);
|
|
@override WorkspaceSharedPageWidgetState createState() => WorkspaceSharedPageWidgetState();
|
|
}
|
|
class WorkspaceSharedPageWidgetState extends State<WorkspaceSharedPageWidget> {
|
|
|
|
@override Widget build(BuildContext context) {
|
|
if (SharedWorkspaceLocal.current == null) {
|
|
return Container();
|
|
}
|
|
var space = SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current ?? ""]!;
|
|
List<Widget> items = [];
|
|
List<ShallowData> data = [];
|
|
if (widget.type == SharedWorkspaceType.global) {
|
|
} else if (widget.type == SharedWorkspaceType.workspace) {
|
|
data = space.workspaces;
|
|
} else if (widget.type == SharedWorkspaceType.workflow) {
|
|
data = space.workflows;
|
|
} else if (widget.type == SharedWorkspaceType.peer) {
|
|
data = space.peers;
|
|
}
|
|
var current = SharedWorkspaceLocal.workspaces[SharedWorkspaceLocal.current];
|
|
for (var w in data) {
|
|
if (widget.type == SharedWorkspaceType.workspace) {
|
|
if (WorkspaceLocal.workspaces[w.getID()] == null) { continue; }
|
|
items.add(WorkspaceSharedItemPageWidget(name: "Workspace <${WorkspaceLocal.workspaces[w.getID()]!.name}>", id: w.getID()));
|
|
} else if (widget.type == SharedWorkspaceType.workflow || widget.type == SharedWorkspaceType.peer) {
|
|
List<IconData> badges = [];
|
|
if (widget.type == SharedWorkspaceType.peer && w.getID() == current?.creatorID) {
|
|
badges.add(Icons.star);
|
|
}
|
|
items.add(ShallowItemRowWidget(
|
|
item: w, badges: badges,
|
|
edit: widget.type == SharedWorkspaceType.workflow ? (String? change) {
|
|
if (change != null) {
|
|
WorkspaceLocal.changeWorkspaceByName(change.split("~")[1]);
|
|
}
|
|
Future.delayed(const Duration(seconds: 1), () => AppRouter.workflowIDItem.go(context, { "id": change ?? "" }));
|
|
} : null,
|
|
delete: (String? change) async {
|
|
if (change == null) { return; }
|
|
if (widget.type == SharedWorkspaceType.peer) {
|
|
await SharedService().removePeer(context, SharedWorkspaceLocal.current ?? "", change);
|
|
} else {
|
|
await SharedService().removePeer(context, SharedWorkspaceLocal.current ?? "", change);
|
|
}
|
|
},
|
|
icon: widget.type == SharedWorkspaceType.workflow ? Icons.work_history_rounded : Icons.person,
|
|
contextWidth: 200)
|
|
);
|
|
}
|
|
}
|
|
if (items.isEmpty) {
|
|
return Container(
|
|
color: Colors.grey.shade300,
|
|
height: MediaQuery.of(context).size.height - HeaderConstants.height - 50,
|
|
width: MediaQuery.of(context).size.width - 50,
|
|
alignment: Alignment.center,
|
|
padding: const EdgeInsets.all(50),
|
|
child: Text("NO ITEMS SHARED", style: const TextStyle(fontSize: 25, fontWeight: FontWeight.w600, color: Colors.white)));
|
|
}
|
|
if (widget.type == SharedWorkspaceType.workflow || widget.type == SharedWorkspaceType.peer) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(50),
|
|
child: Stack( alignment: Alignment.topLeft, children : items));
|
|
}
|
|
return Column( mainAxisAlignment: MainAxisAlignment.start, children : items);
|
|
}
|
|
}
|
|
|
|
class WorkspaceSharedItemPageWidget extends StatefulWidget {
|
|
bool open = true;
|
|
String id = "";
|
|
String name = "";
|
|
WorkspaceSharedItemPageWidget({ this.name = "", this.id = "" }): super(key: null);
|
|
@override WorkspaceSharedItemPageWidgetState createState() => WorkspaceSharedItemPageWidgetState();
|
|
}
|
|
class WorkspaceSharedItemPageWidgetState extends State<WorkspaceSharedItemPageWidget> {
|
|
@override Widget build(BuildContext context) {
|
|
return Column( children: [
|
|
Container(
|
|
width: MediaQuery.of(context).size.width - 50,
|
|
height: 50,
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
decoration: BoxDecoration(color: Colors.grey.shade300),
|
|
child: Stack(
|
|
alignment: Alignment.centerLeft,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
const Padding(padding: EdgeInsets.only(right: 20), child: Icon(Icons.shopping_cart_outlined, size: 18, color: Colors.white)),
|
|
Text(widget.name,
|
|
style: const TextStyle(fontSize: 15, color: Colors.white, fontWeight: FontWeight.w600)),
|
|
]
|
|
),
|
|
Positioned( right: 0, top: 5, child: IconButton( icon: Icon(widget.open ? Icons.arrow_drop_up : Icons.arrow_drop_down, color: Colors.white),
|
|
onPressed: () => setState(() {
|
|
widget.open = !widget.open;
|
|
})))
|
|
])
|
|
),
|
|
widget.open ? CatalogWidget(itemWidth: MediaQuery.of(context).size.width - 50,
|
|
items: WorkspaceLocal.byWorkspace(widget.id)) : Container()
|
|
]);
|
|
}
|
|
} |