104 lines
4.4 KiB
Dart
104 lines
4.4 KiB
Dart
import 'package:oc_front/main.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:oc_front/widgets/catalog.dart';
|
|
import 'package:localstorage/localstorage.dart';
|
|
import 'package:oc_front/pages/abstract_page.dart';
|
|
import 'package:oc_front/models/resources/resources.dart';
|
|
import 'package:oc_front/core/sections/header/header.dart';
|
|
import 'package:oc_front/core/services/specialized_services/resource_service.dart';
|
|
|
|
|
|
class CatalogFactory implements AbstractFactory {
|
|
@override GlobalKey getKey() { return key; }
|
|
static GlobalKey<CatalogPageWidgetState> key = GlobalKey<CatalogPageWidgetState>();
|
|
@override void back(BuildContext context) {
|
|
var s = (localStorage.getItem("search") ?? "");
|
|
if (s != "") {
|
|
localStorage.setItem("search", s.split(",").sublist(1).join(","));
|
|
SearchConstants.set(s.split(",").sublist(1).join(","));
|
|
if ((localStorage.getItem("search") ?? "") == "") {
|
|
SearchConstants.remove();
|
|
key.currentState?.widget.isSearch = true;
|
|
key.currentState?.widget.items = [];
|
|
HeaderConstants.headerKey.currentState?.setState(() {});
|
|
HeaderConstants.headerWidget?.setState(() {});
|
|
CatalogFactory.key.currentState?.setState(() {});
|
|
} else {
|
|
CatalogFactory().search(context, false);
|
|
}
|
|
} else {
|
|
SearchConstants.remove();
|
|
key.currentState?.widget.isSearch = true;
|
|
key.currentState?.widget.items = [];
|
|
HeaderConstants.headerKey.currentState?.setState(() {});
|
|
HeaderConstants.headerWidget?.setState(() {});
|
|
CatalogFactory.key.currentState?.setState(() {});
|
|
}
|
|
}
|
|
@override bool searchFill() { return (key.currentState?.widget.items.isEmpty ?? true) && (key.currentState?.widget.isSearch ?? true); }
|
|
@override Widget factory(GoRouterState state, List<String> args) { return CatalogPageWidget(); }
|
|
@override String? getSearch() {
|
|
if ((localStorage.getItem("search") ?? "") == "") { return null; }
|
|
return localStorage.getItem("search")!.split(",")[0];
|
|
}
|
|
@override void search(BuildContext context, bool special) {
|
|
if (special) { return; } // T
|
|
key.currentState?.widget.isSearch = true;
|
|
var s = (localStorage.getItem("search") ?? "");
|
|
if (s != "") {
|
|
if (SearchConstants.get() == null) {
|
|
localStorage.setItem("search", s);
|
|
} else if (s.split(",")[0] != SearchConstants.get()) {
|
|
localStorage.setItem("search", "${SearchConstants.get()!},$s");
|
|
}
|
|
} else if ((SearchConstants.get() ?? "") == "") { return;
|
|
} else { localStorage.setItem("search", SearchConstants.get()!); }
|
|
CatalogFactory.key.currentState?.widget.search.search(context, [
|
|
localStorage.getItem("search")!.split(",")[0] ], {}).then((value) {
|
|
if (value.data == null) {
|
|
key.currentState?.widget.items = [];
|
|
} else {
|
|
key.currentState?.widget.isSearch = false;
|
|
key.currentState?.widget.items = [ ...value.data!.workflows,
|
|
...value.data!.processings, ...value.data!.datas, ...value.data!.storages, ...value.data!.computes,];
|
|
}
|
|
HeaderConstants.headerKey.currentState?.setState(() {});
|
|
HeaderConstants.headerWidget?.setState(() {});
|
|
CatalogFactory.key.currentState?.setState(() {}); // ignore: invalid_use_of_protected_member
|
|
});
|
|
}
|
|
}
|
|
|
|
// ignore: must_be_immutable
|
|
class CatalogPageWidget extends StatefulWidget {
|
|
double? itemWidth;
|
|
bool isSearch = true;
|
|
List<AbstractItem> items = [];
|
|
final ResourceService search = ResourceService();
|
|
CatalogPageWidget ({
|
|
this.itemWidth,
|
|
}): super(key: CatalogFactory.key);
|
|
@override CatalogPageWidgetState createState() => CatalogPageWidgetState();
|
|
}
|
|
class CatalogPageWidgetState extends State<CatalogPageWidget> {
|
|
@override Widget build(BuildContext context) {
|
|
if (widget.items.isEmpty) {
|
|
if (widget.isSearch) { return Container(); }
|
|
return Container(
|
|
width: getMainWidth(context),
|
|
height: getMainHeight(context) - 50,
|
|
color: Colors.grey.shade300,
|
|
child: const Center(child: Text("NO RESOURCES FOUND",
|
|
style: TextStyle(fontSize: 30, color: Colors.grey))
|
|
),
|
|
); }
|
|
return Column( children : [
|
|
SizedBox( width: getMainWidth(context),
|
|
height: getMainHeight(context) - 50,
|
|
child: SingleChildScrollView( child: CatalogWidget(items: CatalogFactory.key.currentState?.widget.items, itemWidth: widget.itemWidth) )),
|
|
]
|
|
);
|
|
}
|
|
}
|