Style Dashboard by rules

This commit is contained in:
mr 2024-11-22 09:39:04 +01:00
parent 7fea931b63
commit e73ca6b532
4 changed files with 56 additions and 15 deletions

View File

@ -87,15 +87,15 @@ final WorflowService _service = WorflowService();
if (objAbs.topic == "compute" ) {
var compute = objAbs as ComputeItem;
if (compute.technology == 0) {
return Icon(FontAwesomeIcons.docker, size: 18);
return Icon(FontAwesomeIcons.docker, size: 16);
} else if (compute.technology == 1) {
return Icon(FontAwesomeIcons.lifeRing, size: 18);
return Icon(FontAwesomeIcons.lifeRing, size: 16);
} else if (compute.technology == 2) {
return Icon(FontAwesomeIcons.cubes, size: 18);
return Icon(FontAwesomeIcons.cubes, size: 16);
} else if (compute.technology == 3) {
return Icon(FontAwesomeIcons.hardDrive, size: 18);
return Icon(FontAwesomeIcons.hardDrive, size: 16);
} else if (compute.technology == 4) {
return Icon(FontAwesomeIcons.v, size: 18);
return Icon(FontAwesomeIcons.v, size: 16);
}
}
return null;
@ -105,15 +105,15 @@ final WorflowService _service = WorflowService();
var objAbs = obj as AbstractItem?;
if (objAbs == null) { return null; }
if (objAbs.topic == "processing" ) {
return Icon(FontAwesomeIcons.gear) ;
return Icon(FontAwesomeIcons.gear, size: 16);
} else if (objAbs.topic == "data" ) {
return Icon(FontAwesomeIcons.file);
return Icon(FontAwesomeIcons.file, size: 16);
} else if (objAbs.topic == "storage" ) {
return Icon(FontAwesomeIcons.database);
return Icon(FontAwesomeIcons.database, size: 16);
} else if (objAbs.topic == "compute" ) {
return Icon(FontAwesomeIcons.microchip);
return Icon(FontAwesomeIcons.microchip, size: 16);
} else if (objAbs.topic == "workflows" ) {
return Icon(FontAwesomeIcons.diagramProject);
return Icon(FontAwesomeIcons.diagramProject, size: 16);
}
return null;
}
@ -290,6 +290,32 @@ final WorflowService _service = WorflowService();
dash.infoItemWidget = getForms;
dash.infoWidget = getDashInfoForms;
dash.widthOffset = 50;
dash.arrowStyleRules = [
(dash) {
for (var arrow in dash.arrows) {
var from = dash.elements.firstWhere((element) => arrow.fromID.contains(element.id)).element;
var to = dash.elements.firstWhere((element) => arrow.toID.contains(element.id)).element;
if ((from is ProcessingItem && to is ComputeItem) || (to is ProcessingItem && from is ComputeItem)) {
arrow.params.color = Colors.orange;
arrow.params.dashSpace = 2;
arrow.params.dashWidth = 2;
} else if ((from is ProcessingItem && to is StorageItem) || (to is ProcessingItem && from is StorageItem)) {
arrow.params.color = redColor;
arrow.params.dashSpace = 2;
arrow.params.dashWidth = 2;
} else if ((from is ProcessingItem && to is DataItem) || (to is ProcessingItem && from is DataItem)) {
arrow.params.color = Colors.blue;
arrow.params.dashSpace = 2;
arrow.params.dashWidth = 2;
} else {
arrow.params.color = Colors.black;
arrow.params.dashSpace = 0;
arrow.params.dashWidth = 0;
}
}
return dash.arrows;
}
];
dash.saveRules = [
(dash) {
dash.error = null;

View File

@ -115,11 +115,11 @@ class SchedulerFormsWidgetState extends State<SchedulerFormsWidget> {
if (end.isBefore(DateTime.now())) {
// get difference between now and start
delayed = end.difference(DateTime.now());
}
Future.delayed(delayed, () {
WorkflowFactory.key.currentState?.setState(() { });
});
}
}
List<GlobalKey<FormFieldState>> formKeys = [GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>(), GlobalKey<FormFieldState>()];
var shallow = ShallowTextInputWidget(
width: 200 - 1, readOnly: readOnly,

View File

@ -61,6 +61,7 @@ class Dashboard extends ChangeNotifier {
double widthOffset = 0;
double heightOffset = 0;
List<bool Function(Dashboard)> saveRules = [];
List<List<ArrowPainter> Function(Dashboard)> arrowStyleRules = [];
String? error;
@ -152,7 +153,9 @@ class Dashboard extends ChangeNotifier {
map['dashboardSizeWidth'] as double? ?? 0,
map['dashboardSizeHeight'] as double? ?? 0,
);
for (var f in d.arrowStyleRules) {
d.arrows = f(d);
}
if (map['gridBackgroundParams'] != null) {
d.gridBackgroundParams = GridBackgroundParams.fromMap(
map['gridBackgroundParams'] as Map<String, dynamic>,
@ -179,6 +182,9 @@ class Dashboard extends ChangeNotifier {
(x) => ArrowPainter.fromMap(x as Map<String, dynamic>),
),
);
for (var f in arrowStyleRules) {
arrows = f(this);
}
elements = List<FlowElement>.from(
(map['elements'] as List<dynamic>).map<FlowElement>(
(x) => FlowElement.fromMap(this, x as Map<String, dynamic>),
@ -244,6 +250,9 @@ class Dashboard extends ChangeNotifier {
for(var el in elements) {
graph['elements'][el.id] = el.serialize();
}
for (var f in arrowStyleRules) {
arrows = f(this);
}
graph['arrows'] = arrows.map((e) => e.serialize()).toList();
d["id"]=id;
d["name"]=name;
@ -322,12 +331,18 @@ class Dashboard extends ChangeNotifier {
void addArrows(ArrowPainter f) {
arrows.add(f);
for (var f in arrowStyleRules) {
arrows = f(this);
}
addChange = true;
saveDash(id);
}
void removeArrows(bool Function(ArrowPainter) f) {
arrows.removeWhere((element) => f(element));
for (var f in arrowStyleRules) {
arrows = f(this);
}
saveDash(id);
}

View File

@ -352,7 +352,7 @@ class DrawArrowState extends State<DrawArrow> {
if ( widget.flow.widget.dashboard.arrows.where(
(element) => element.fromID == "${widget.srcElement.id}_${widget.index}").isEmpty) {
widget.flow.widget.dashboard.addArrows(painter);
widget.flow.widget.dashboard.save!(widget.flow.widget.dashboard.id);
widget.flow.widget.dashboard.saveDash(widget.flow.widget.dashboard.id);
} else {
var i = widget.flow.widget.dashboard.arrows.indexWhere(
(element) => element.fromID == "${widget.srcElement.id}_${widget.index}");