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/perms_service.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/main.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 CollaborativeAreaType { global, collaborative_area, workspace, workflow, peer, resource } class SharedFactory implements AbstractFactory { @override GlobalKey getKey() { return key; } @override void clear() { } static GlobalKey key = GlobalKey(); @override bool searchFill() { return false; } @override Widget factory(GoRouterState state, List args) { return SharedPageWidget(); } @override void search(BuildContext context, bool special) { } } class SharedPageWidget extends StatefulWidget { CollaborativeAreaType type = CollaborativeAreaType.global; SharedPageWidget(): super(key: SharedFactory.key); @override SharedPageWidgetState createState() => SharedPageWidgetState(); static void search(BuildContext context) { } static Widget factory() { return SharedPageWidget(); } } class SharedPageWidgetState extends State { SharedService service = SharedService(); Widget getMenuItem(CollaborativeAreaType workspaceType, IconData icon) { var s = workspaceType == CollaborativeAreaType.global ? "dashboard" : workspaceType == CollaborativeAreaType.workspace ? "shared workspaces" : workspaceType == CollaborativeAreaType.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 ? darkColor : 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 key = GlobalKey(); if (CollaborativeAreaLocal.current == null) { Future.delayed( const Duration(microseconds: 100), () { HeaderConstants.setTitle("Choose a Collaborative Area"); 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: () => CollaborativeAreaLocal.current != null, context: context, load: (p0) async { CollaborativeAreaLocal.current = p0; HeaderConstants.setTitle("Collaborative Area <${CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.name ?? ""}>"); HeaderConstants.setDescription(CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.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: CollaborativeAreaType.collaborative_area, width: getMainWidth(context) <= 540 ? getMainWidth(context) - 140 : 400, attr: "description", color: Colors.black, hintColor: Colors.grey, hint: "enter collaborative area description...", filled: midColor, ) ], create: PermsService.getPerm(Perms.COLLABORATIVE_AREA_CREATE) ? (p0) async => await SharedService().post(context, p0, {}).then((value) { if (value.data != null) { CollaborativeAreaLocal.current = value.data!.id; } CollaborativeAreaLocal.init(context, true); HeaderConstants.setTitle("Collaborative Area <${CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.name ?? ""}>"); HeaderConstants.setDescription(CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.description ?? ""); Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {})); }) : null, type: CollaborativeAreaType.collaborative_area, all: () async => CollaborativeAreaLocal.workspaces.values.map( (e) => Shallow(id: e.id ?? "", name: e.name ?? "") ).toList(), ))); }); } else { Future.delayed( const Duration(milliseconds: 100), () { HeaderConstants.setTitle("Collaborative Area <${CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.name ?? ""}>"); HeaderConstants.setDescription(CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.description ?? ""); }); } Widget w = WorkspaceSharedPageWidget(type: widget.type); List addMenu = []; CollaborativeArea? current = CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current ?? ""]; if (widget.type == CollaborativeAreaType.workspace) { addMenu.add( Row( mainAxisAlignment: MainAxisAlignment.end, children : [ Container( padding: EdgeInsets.only(left: 20), decoration: BoxDecoration( border: Border(left: BorderSide(color: Colors.white)) ), child: ShallowDropdownInputWidget( tooltipLoad: "share", tooltipRemove: "unshare", iconLoad: Icons.share, type: widget.type, filled: lightColor, hintColor: midColor, color: Colors.white, prefixIcon: Icon(Icons.shopping_cart, color: Colors.white), current: WorkspaceLocal.current, all: () async => WorkspaceLocal.getWorkspacesShallow(), width: getMainWidth(context) / 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, CollaborativeAreaLocal.current ?? "", val); CollaborativeAreaLocal.init(context, false); }, remove: (String val) async { await service.removeWorkspace(context, CollaborativeAreaLocal.current ?? "", val); CollaborativeAreaLocal.init(context, false); })) ])); } if (widget.type == CollaborativeAreaType.workflow) { addMenu.add( Row( mainAxisAlignment: MainAxisAlignment.end, children : [ Container( padding: EdgeInsets.only(left: 20), decoration: BoxDecoration( border: Border(left: BorderSide(color: Colors.white)) ), child: ShallowDropdownInputWidget( tooltipLoad: "share", tooltipRemove: "unshare", iconLoad: Icons.share, filled: lightColor, hintColor: midColor, color: Colors.white, type: widget.type, all: () async { List 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: getMainWidth(context) / 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, CollaborativeAreaLocal.current ?? "", change); }, remove: (String change) async { await service.removeWorkflow(context, CollaborativeAreaLocal.current ?? "", change); })) ])); } if (widget.type == CollaborativeAreaType.peer) { addMenu.add( Row( mainAxisAlignment: MainAxisAlignment.end, children : [ Container( padding: EdgeInsets.only(left: 20), decoration: BoxDecoration( border: Border(left: BorderSide(color: Colors.white)) ), child: ShallowDropdownInputWidget( tooltipLoad: "add", iconLoad: Icons.add, filled: lightColor, hintColor: midColor, color: Colors.white, type: widget.type, all: () async { List 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: getMainWidth(context) / 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, CollaborativeAreaLocal.current ?? "", change); }, remove: (String change) async { await service.removePeer(context, CollaborativeAreaLocal.current ?? "", change); })) ])); } return Column( children: [ Container( height: 50, color: lightColor, width: getMainWidth(context), 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: () => CollaborativeAreaLocal.current != null, context: context, load: (p0) async { CollaborativeAreaLocal.current = p0; HeaderConstants.setTitle("Collaborative Area <${CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.name ?? ""}>"); HeaderConstants.setDescription(CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.description ?? ""); Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {})); }, form: [ ShallowTextInputWidget( change :(p0) => key.currentState?.setState(() {}), type: CollaborativeAreaType.collaborative_area, width: getMainWidth(context) <= 540 ? getMainWidth(context) - 140 : 400, attr: "description", color: Colors.black, hintColor: Colors.grey, filled: midColor, ) ], create: PermsService.getPerm(Perms.COLLABORATIVE_AREA_CREATE) ? (p0) async => await SharedService().post(context, p0, {}).then( (e) { if (e.data != null) { CollaborativeAreaLocal.current = e.data!.id; } CollaborativeAreaLocal.init(context, true); HeaderConstants.setTitle("Collaborative Area <${CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.name ?? ""}>"); HeaderConstants.setDescription(CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]?.description ?? ""); Future.delayed(const Duration(seconds: 1), () => SharedFactory.key.currentState?.setState(() {})); }) : null, type: CollaborativeAreaType.collaborative_area, all: () async => CollaborativeAreaLocal.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( decoration: BoxDecoration( color: Colors.black, border: Border(left: BorderSide(color: lightColor)) ), height: getMainHeight(context) - 50, width: 50, child: Column( children: [ getMenuItem(CollaborativeAreaType.global, Icons.dashboard), getMenuItem(CollaborativeAreaType.workspace, Icons.workspaces), getMenuItem(CollaborativeAreaType.workflow, Icons.rebase_edit), getMenuItem(CollaborativeAreaType.peer, Icons.group), ]) ), Container( height: getMainHeight(context) - 50, width: getMainWidth(context) -50, color: widget.type == CollaborativeAreaType.workflow || widget.type == CollaborativeAreaType.peer ? midColor : Colors.white, child: SingleChildScrollView( child: w )) ] ) ] ); } } class WorkspaceSharedPageWidget extends StatefulWidget { CollaborativeAreaType type = CollaborativeAreaType.global; WorkspaceSharedPageWidget({ required this.type }): super(key: null); @override WorkspaceSharedPageWidgetState createState() => WorkspaceSharedPageWidgetState(); } class WorkspaceSharedPageWidgetState extends State { @override Widget build(BuildContext context) { if (CollaborativeAreaLocal.current == null) { return Container(); } var space = CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current ?? ""]!; List items = []; List data = []; if (widget.type == CollaborativeAreaType.global) { } else if (widget.type == CollaborativeAreaType.workspace) { data = space.workspaces; } else if (widget.type == CollaborativeAreaType.workflow) { data = space.workflows; } else if (widget.type == CollaborativeAreaType.peer) { data = space.peers; } var current = CollaborativeAreaLocal.workspaces[CollaborativeAreaLocal.current]; for (var w in data) { if (widget.type == CollaborativeAreaType.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 == CollaborativeAreaType.workflow || widget.type == CollaborativeAreaType.peer) { List badges = []; if (widget.type == CollaborativeAreaType.peer && w.getID() == current?.creatorID) { badges.add(Icons.star); } items.add(ShallowItemRowWidget( item: w, badges: badges, edit: widget.type == CollaborativeAreaType.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 == CollaborativeAreaType.peer) { await SharedService().removePeer(context, CollaborativeAreaLocal.current ?? "", change); } else { await SharedService().removePeer(context, CollaborativeAreaLocal.current ?? "", change); } }, icon: widget.type == CollaborativeAreaType.workflow ? Icons.work_history_rounded : Icons.person, contextWidth: 200) ); } } if (items.isEmpty) { return Container( color: midColor, height: getMainHeight(context) - 50, width: getMainWidth(context) - 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 == CollaborativeAreaType.workflow || widget.type == CollaborativeAreaType.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 { @override Widget build(BuildContext context) { return Column( children: [ Container( width: getMainWidth(context) - 50, height: 50, padding: const EdgeInsets.symmetric(horizontal: 20), decoration: BoxDecoration(color: midColor), 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: getMainWidth(context) - 50, items: WorkspaceLocal.byWorkspace(widget.id)) : Container() ]); } }