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/specialized_services/resource_service.dart'; import 'package:oc_front/core/services/specialized_services/shared_service.dart'; import 'package:oc_front/core/services/specialized_services/workspace_service.dart'; import 'package:oc_front/models/response.dart'; import 'package:oc_front/models/search.dart'; import 'package:oc_front/pages/shared.dart'; import 'package:oc_front/widgets/catalog.dart'; import 'package:oc_front/pages/abstract_page.dart'; import 'package:oc_front/core/sections/header/search.dart'; import 'package:oc_front/widgets/inputs/shallow_dropdown_input.dart'; import 'package:oc_front/widgets/inputs/shallow_text_input.dart'; class CatalogFactory implements AbstractFactory { static List items = []; static GlobalKey key = GlobalKey(); @override bool searchFill() { return CatalogFactory.items.isEmpty; } @override Widget factory(GoRouterState state, List args) { return CatalogPageWidget(); } @override void search(BuildContext context) { CatalogFactory.key.currentState?.widget.search.search(context, [ SearchConstants.get()! ], {}).then((value) { if (value.data == null) { return; } CatalogFactory.items = [ ...value.data!.workflows, ...value.data!.processings, ...value.data!.datas, ...value.data!.storages, ...value.data!.datacenters,]; searchWidgetKey.currentState?.setState(() {}); CatalogFactory.key.currentState?.setState(() {}); }); } } class CatalogPageWidget extends StatefulWidget { double? itemWidth; final ResourceService search = ResourceService(); CatalogPageWidget ({ this.itemWidth, }): super(key: CatalogFactory.key); @override CatalogPageWidgetState createState() => CatalogPageWidgetState(); } class CatalogPageWidgetState extends State { @override Widget build(BuildContext context) { return Column( children : [ CatalogFactory.items.isEmpty ? Container() : Row( children: [ ShallowDropdownInputWidget( current: WorkspaceLocal.current, width: MediaQuery.of(context).size.width / 3, all: () async => WorkspaceLocal.getWorkspacesShallow(), type: SharedWorkspaceType.workspace, change: (String? change) { WorkspaceLocal.changeWorkspace(change.toString()); }, color: Colors.white, filled: const Color.fromRGBO(38, 166, 154, 1), hintColor: Colors.grey.shade300, canRemove: (String? remove) => remove != null, remove: (String? remove) async { if (remove == null) { return; } WorkspaceLocal.deleteWorkspace(remove); }, ), ShallowTextInputWidget( width: MediaQuery.of(context).size.width / 3, type: SharedWorkspaceType.workspace, color: Colors.white, filled: const Color.fromRGBO(38, 166, 154, 1), hintColor: Colors.grey.shade300, canRemove: (p0) => p0 != null, remove: (p0) async { await WorkspaceService().delete(context, p0, {}).then( (e) => WorkspaceLocal.deleteWorkspace(p0)); }, canLoad: (String? remove) => remove != null, load: (Map add) async { if (add["name"] == null) { return; } WorkspaceLocal.createWorkspace(add["name"], context); }, ), ShallowDropdownInputWidget( iconLoad: Icons.share_rounded, tooltipLoad: 'share', tooltipRemove: 'unshare', color: Colors.white, filled: const Color.fromRGBO(38, 166, 154, 1), hintColor: Colors.grey.shade300, type: SharedWorkspaceType.workspace, all: () async => SharedWorkspaceLocal.workspaces.values.map( (e) => Shallow(id: e.id ?? "", name: e.name ?? "") ).toList(), current: WorkspaceLocal.workspaces[WorkspaceLocal.current]?.shared, width: (MediaQuery.of(context).size.width / 3), canLoad: (String? change) => SharedWorkspaceLocal.workspaces[change] == null || !SharedWorkspaceLocal.workspaces[change]!.workspaces.map( (e) => e.id ).contains(WorkspaceLocal.current), canRemove: (String? change) => SharedWorkspaceLocal.workspaces[change] == null || SharedWorkspaceLocal.workspaces[change]!.workspaces.map( (e) => e.id ).contains(WorkspaceLocal.current), load: (String val) async { await SharedService().addWorkspace(context, val, WorkspaceLocal.current ?? ""); // ignore: use_build_context_synchronously SharedWorkspaceLocal.init(context, false); }, remove: (String val) async { await SharedService().removeWorkspace(context, val, WorkspaceLocal.current ?? ""); // ignore: use_build_context_synchronously SharedWorkspaceLocal.init(context, false); }) ]), SizedBox( width: MediaQuery.of(context).size.width, height: CatalogFactory.items.isEmpty ? 0 : MediaQuery.of(context).size.height - HeaderConstants.height - 50, child: SingleChildScrollView( child: CatalogWidget(items: CatalogFactory.items, itemWidth: widget.itemWidth) )), ] ); } }