oc-front/lib/core/sections/header/header.dart
2025-02-04 17:02:49 +01:00

141 lines
5.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:localstorage/localstorage.dart';
import 'package:oc_front/core/models/workspace_local.dart';
import 'package:oc_front/core/sections/header/default.dart';
import 'package:oc_front/core/sections/header/menu.dart';
import 'package:oc_front/core/services/perms_service.dart';
import 'package:oc_front/core/services/router.dart';
import 'package:oc_front/main.dart';
import 'package:oc_front/pages/shared.dart';
import 'package:oc_front/widgets/inputs/shallow_dropdown_input.dart';
import 'package:oc_front/widgets/inputs/shallow_text_input.dart';
class SearchConstants {
static final Map<String, String?> _searchHost = {};
static String? get() { return _searchHost[AppRouter.currentRoute.route]; }
static void set(String? search) { _searchHost[AppRouter.currentRoute.route] = search; }
static void remove() { _searchHost.remove(AppRouter.currentRoute.route); }
static void clear() {
localStorage.setItem("search", "");
_searchHost.clear();
}
}
class HeaderConstants {
static GlobalKey<HeaderMenuWidgetState> headerKey = GlobalKey<HeaderMenuWidgetState>();
static final List<RouterItem> noHeader = [
AppRouter.scheduler,
AppRouter.compute,
AppRouter.shared,
AppRouter.workflowItem,
AppRouter.workflowIDItem,
];
static HeaderWidgetState? headerWidget;
static double height = 200;
static String? title;
static String? description;
static getKey() {
headerKey = GlobalKey<HeaderMenuWidgetState>();
return headerKey;
}
static setTitle(String? v) {
title = v;
Future.delayed(Duration(milliseconds: 100), () {
HeaderConstants.headerWidget?.setState(() {});
});
}
static setDescription(String? v) {
description = v;
Future.delayed(Duration(milliseconds: 100), () {
HeaderConstants.headerWidget?.setState(() {});
});
}
static bool isNoHeader(String route) {
return noHeader.where((element) => element.route == route).isNotEmpty;
}
}
class HeaderWidget extends StatefulWidget {
const HeaderWidget () : super(key: null);
@override HeaderWidgetState createState() => HeaderWidgetState();
}
class HeaderWidgetState extends State<HeaderWidget> {
@override Widget build(BuildContext context) {
HeaderConstants.headerWidget = this;
if (HeaderConstants.isNoHeader(AppRouter.currentRoute.route)) {
return Container();
}
if (AppRouter.currentRoute.factory.searchFill()) {
return DefaultWidget();
}
HeaderConstants.height = HeaderConstants.isNoHeader(AppRouter.currentRoute.route) || !AppRouter.currentRoute.factory.searchFill() ? 50 : 100;
return Column( children: [
AppRouter.currentRoute.factory.searchFill() ? Container() : Container(
height: 50, width: getMainWidth(context),
decoration: BoxDecoration(
color: midColor,
border: Border(bottom: BorderSide(color: Colors.white, width: 1),)
),
child: Row(crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.end,
children: [
InkWell( onTap: () {
AppRouter.currentRoute.factory.back(context);
},
child:
Container(width: 50, height: 50,
color: Colors.black,
child: Center(child: Icon(Icons.keyboard_backspace, color: Colors.white))
),
),
ShallowTextInputWidget(
filled: midColor,
current: AppRouter.currentRoute.factory.getSearch(),
width: getMainWidth(context) - 501,
type: CollaborativeAreaType.workspace,
hint: "search in resources...",
iconLoad: PermsService.getPerm(Perms.SEARCH_INTERNAL) ? Icons.search : null,
iconRemove: PermsService.getPerm(Perms.SEARCH_EXTERNAL) ? Icons.screen_search_desktop_outlined : null,
tooltipLoad: PermsService.getPerm(Perms.SEARCH_INTERNAL) ? "search" : null,
tooltipRemove: PermsService.getPerm(Perms.SEARCH_EXTERNAL) ? "distributed search" : null,
canLoad: PermsService.getPerm(Perms.SEARCH_INTERNAL) ? (String? str) => str != null && str.isNotEmpty : null,
canRemove: PermsService.getPerm(Perms.SEARCH_EXTERNAL) ? (String? str) => str != null && str.isNotEmpty : null,
change: (value) => SearchConstants.set(value),
loadStr: PermsService.getPerm(Perms.SEARCH_INTERNAL) ? (String val) async {
AppRouter.currentRoute.factory.search(context, false);
} : null,
remove: PermsService.getPerm(Perms.SEARCH_EXTERNAL) ? (String val) async {
AppRouter.currentRoute.factory.search(context, true);
} : null,
),
Container( padding: EdgeInsets.only(left: 50),
decoration: BoxDecoration( border: Border( left: BorderSide( color: Colors.white ))),
child: ShallowDropdownInputWidget(
prefixIcon: Padding( padding: EdgeInsets.only(right: 10), child: Icon(Icons.shopping_cart, color: Colors.grey)),
current: WorkspaceLocal.current,
width: 350,
all: () async => WorkspaceLocal.getWorkspacesShallow(),
type: CollaborativeAreaType.workspace,
change: (String? change) {
WorkspaceLocal.changeWorkspace(change.toString());
},
canLoad: (p0) => true,
load: (p0) async {
scaffoldKey.currentState?.openEndDrawer();
},
tooltipLoad: "open workspace manager",
iconLoad: Icons.remove_red_eye,
color: Colors.black,
filled: midColor,
hintColor: Colors.grey,
))
])
),
],);
}
}