This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/ui_class/panel_class.dart

57 lines
1.4 KiB
Dart
Raw Normal View History

2019-03-13 16:39:23 +02:00
part of '../main.dart';
class Panel {
static const iconsByComponent = {
"config": "mdi:settings",
"history": "mdi:poll-box",
"map": "mdi:tooltip-account",
"logbook": "mdi:format-list-bulleted-type",
"custom": "mdi:home-assistant"
};
final String id;
final String type;
final String title;
final String urlPath;
final Map config;
String icon;
2019-03-13 17:23:23 +02:00
bool isHidden = true;
2019-03-13 16:39:23 +02:00
Panel({this.id, this.type, this.title, this.urlPath, this.icon, this.config}) {
if (icon == null || !icon.startsWith("mdi:")) {
icon = Panel.iconsByComponent[type];
}
2019-03-13 17:25:08 +02:00
isHidden = (type != "iframe" && type != "config");
2019-03-13 17:23:23 +02:00
}
void handleOpen(BuildContext context) {
if (type == "iframe") {
Logger.d("Launching custom tab with ${config["url"]}");
HAUtils.launchURLInCustomTab(context: context, url: config["url"]);
2019-03-13 17:23:23 +02:00
} else if (type == "config") {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => PanelPage(title: "$title", panel: this),
)
);
} else {
String url = "${ConnectionManager().httpWebHost}/$urlPath";
2019-03-13 17:23:23 +02:00
Logger.d("Launching custom tab with $url");
HAUtils.launchURLInCustomTab(context: context, url: url);
2019-03-13 17:23:23 +02:00
}
2019-03-13 16:39:23 +02:00
}
Widget getWidget() {
switch (type) {
case "config": {
return ConfigPanelWidget();
}
default: {
return Text("Unsupported panel component: $type");
}
}
}
}