oc-front/lib/pages/workflow.dart

83 lines
4.2 KiB
Dart
Raw Normal View History

2024-07-17 13:28:02 +02:00
import 'dart:convert';
import 'package:flutter/material.dart';
2024-07-17 13:28:02 +02:00
import 'package:flutter_flow_chart/flutter_flow_chart.dart';
import 'package:go_router/go_router.dart';
2024-07-17 13:28:02 +02:00
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/workflow_service.dart';
import 'package:oc_front/models/response.dart';
2024-07-17 13:28:02 +02:00
import 'package:oc_front/models/search.dart';
import 'package:oc_front/pages/abstract_page.dart';
2024-07-17 13:28:02 +02:00
import 'package:oc_front/widgets/dialog/new_box.dart';
import 'package:oc_front/widgets/items/item_row.dart';
class WorkflowFactory implements AbstractFactory {
static GlobalKey<WorkflowPageWidgetState> key = GlobalKey<WorkflowPageWidgetState>();
@override bool searchFill() { return false; }
@override Widget factory(GoRouterState state, List<String> args) { return WorkflowPageWidget(); }
@override void search(BuildContext context) { }
}
class WorkflowPageWidget extends StatefulWidget {
WorkflowPageWidget () : super(key: WorkflowFactory.key);
@override WorkflowPageWidgetState createState() => WorkflowPageWidgetState();
static void search(BuildContext context) { }
static Widget factory() { return WorkflowPageWidget(); }
}
class WorkflowPageWidgetState extends State<WorkflowPageWidget> {
2024-07-17 13:28:02 +02:00
final WorflowService _service = WorflowService();
Widget itemBuild(Object item) {
var e = item as AbstractItem;
return e.logo != null ? Image.memory(base64Decode(e.logo ?? ""), fit: BoxFit.fill)
: Image.network('https://get-picto.com/wp-content/uploads/2024/01/logo-instagram-png.webp', fit: BoxFit.fill);
}
Widget itemTooltipBuild(Object item) {
var e = item as AbstractItem;
return Container(color: Colors.white, child: ItemRowWidget(low: true, contextWidth: 300, item: e));
}
List<DropdownMenuItem> getItems(Object? data) {
data = data as APIResponse<RawData>?;
if (data != null && data.data != null && data.data!.values.isNotEmpty) {
return (data.data!.values as List<dynamic>).map((dynamic value) {
return DropdownMenuItem<String>(
value: value.toString(),
child: Text(value.toString()),
);
}).toList();
2024-07-17 13:28:02 +02:00
}
return [];
}
Widget onDashboardAlertOpened(BuildContext context, Dashboard dash) {
return NewBoxWidget<RawData>(service: _service, dash: dash,
getItems: getItems);
}
@override Widget build(BuildContext context) {
var quart = MediaQuery.of(context).size.width / 6;
return FlowChart<AbstractItem>(
onDashboardAlertOpened: onDashboardAlertOpened,
dashboard: Dashboard(
name: "workflow_${DateTime.now().toString().replaceAll(" ", "_").substring(0, DateTime.now().toString().length - 7)}"),
itemWidget: itemBuild,
categories: const ["computing", "data", "datacenter", "storage"],
draggableItemBuilder: (cat) => WorkspaceLocal.byTopic(cat).toList(),
itemWidgetTooltip: itemTooltipBuild,
innerMenuWidth: quart > 80 ? quart : 80,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height - HeaderConstants.height,
onNewConnection: (p1, p2) { },
onDashboardTapped: (context, position) { },
onScaleUpdate: (newScale) { },
onDashboardSecondaryTapped: (context, position) { },
onDashboardLongTapped: (context, position) { },
onDashboardSecondaryLongTapped: (context, position) { },
onElementLongPressed: (context, position, element) { },
onElementSecondaryLongTapped: (context, position, element) { },
onElementPressed: (context, position, element) { },
onElementSecondaryTapped: (context, position, element) { },
onHandlerPressed: (context, position, handler, element) { },
onHandlerLongPressed: (context, position, handler, element) { },
onPivotSecondaryPressed: (context, pivot) { },
);
}
}