2024-07-05 09:24:40 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:go_router/go_router.dart';
|
2024-08-30 12:52:32 +02:00
|
|
|
import 'package:oc_front/core/models/shared_workspace_local.dart';
|
|
|
|
import 'package:oc_front/core/models/workspace_local.dart';
|
2024-07-17 13:28:02 +02:00
|
|
|
import 'package:oc_front/core/sections/header/header.dart';
|
2024-08-08 08:42:32 +02:00
|
|
|
import 'package:oc_front/core/services/specialized_services/resource_service.dart';
|
2024-08-30 12:52:32 +02:00
|
|
|
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';
|
2024-07-05 09:24:40 +02:00
|
|
|
import 'package:oc_front/models/search.dart';
|
2024-08-30 12:52:32 +02:00
|
|
|
import 'package:oc_front/pages/shared.dart';
|
2024-07-05 09:24:40 +02:00
|
|
|
import 'package:oc_front/widgets/catalog.dart';
|
|
|
|
import 'package:oc_front/pages/abstract_page.dart';
|
|
|
|
import 'package:oc_front/core/sections/header/search.dart';
|
2024-08-30 12:52:32 +02:00
|
|
|
import 'package:oc_front/widgets/inputs/shallow_dropdown_input.dart';
|
|
|
|
import 'package:oc_front/widgets/inputs/shallow_text_input.dart';
|
2024-07-05 09:24:40 +02:00
|
|
|
|
|
|
|
class CatalogFactory implements AbstractFactory {
|
|
|
|
static List<AbstractItem> items = [];
|
|
|
|
static GlobalKey<CatalogPageWidgetState> key = GlobalKey<CatalogPageWidgetState>();
|
|
|
|
@override bool searchFill() { return CatalogFactory.items.isEmpty; }
|
|
|
|
@override Widget factory(GoRouterState state, List<String> args) { return CatalogPageWidget(); }
|
|
|
|
@override void search(BuildContext context) {
|
2024-08-08 08:42:32 +02:00
|
|
|
CatalogFactory.key.currentState?.widget.search.search(context, [ SearchConstants.get()! ], {}).then((value) {
|
2024-07-05 09:24:40 +02:00
|
|
|
if (value.data == null) { return; }
|
2024-08-08 08:42:32 +02:00
|
|
|
CatalogFactory.items = [ ...value.data!.workflows,
|
|
|
|
...value.data!.processings, ...value.data!.datas, ...value.data!.storages, ...value.data!.datacenters,];
|
2024-07-05 09:24:40 +02:00
|
|
|
searchWidgetKey.currentState?.setState(() {});
|
|
|
|
CatalogFactory.key.currentState?.setState(() {});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CatalogPageWidget extends StatefulWidget {
|
2024-08-30 12:52:32 +02:00
|
|
|
double? itemWidth;
|
2024-08-08 08:42:32 +02:00
|
|
|
final ResourceService search = ResourceService();
|
2024-08-30 12:52:32 +02:00
|
|
|
CatalogPageWidget ({
|
|
|
|
this.itemWidth,
|
|
|
|
}): super(key: CatalogFactory.key);
|
2024-07-05 09:24:40 +02:00
|
|
|
@override CatalogPageWidgetState createState() => CatalogPageWidgetState();
|
|
|
|
}
|
|
|
|
class CatalogPageWidgetState extends State<CatalogPageWidget> {
|
|
|
|
@override Widget build(BuildContext context) {
|
|
|
|
return Column( children : [
|
2024-08-30 12:52:32 +02:00
|
|
|
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<String?, dynamic> 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);
|
|
|
|
})
|
|
|
|
]),
|
2024-07-05 09:24:40 +02:00
|
|
|
SizedBox(
|
|
|
|
width: MediaQuery.of(context).size.width,
|
2024-08-08 08:42:32 +02:00
|
|
|
height: CatalogFactory.items.isEmpty ? 0 : MediaQuery.of(context).size.height - HeaderConstants.height - 50,
|
2024-08-30 12:52:32 +02:00
|
|
|
child: SingleChildScrollView( child: CatalogWidget(items: CatalogFactory.items, itemWidth: widget.itemWidth) )),
|
2024-07-05 09:24:40 +02:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|