Resolves #116 Add Iframe panel support
This commit is contained in:
parent
92d0b5c055
commit
74572168ae
@ -262,7 +262,6 @@ class HomeAssistant {
|
||||
await _sendInitialMessage("get_panels").then((data) {
|
||||
if (data["success"]) {
|
||||
data["result"].forEach((k,v) {
|
||||
if (k != "lovelace" && !v["component_name"].startsWith("dev-") && v["component_name"]!="profile" && v["component_name"]!="states" && v["component_name"]!="kiosk") {
|
||||
String title = v['title'] == null ? "${k[0].toUpperCase()}${k.substring(1)}" : "${v['title'][0].toUpperCase()}${v['title'].substring(1)}";
|
||||
panels.add(Panel(
|
||||
id: k,
|
||||
@ -273,7 +272,6 @@ class HomeAssistant {
|
||||
icon: v["icon"]
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -305,15 +305,6 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
);
|
||||
}
|
||||
|
||||
void _showPanelPage(Panel panel) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PanelPage(title: "${panel.title}", panel: panel),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
List<Tab> buildUIViewTabs() {
|
||||
List<Tab> result = [];
|
||||
|
||||
@ -362,15 +353,24 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
||||
} else {
|
||||
if (_homeAssistant != null && _homeAssistant.panels.isNotEmpty) {
|
||||
_homeAssistant.panels.forEach((Panel panel) {
|
||||
if (!panel.isHidden) {
|
||||
menuItems.add(
|
||||
new ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(panel.icon)),
|
||||
title: Text("${panel.title}(${panel.urlPath})"),
|
||||
onTap: () =>_showPanelPage(panel)
|
||||
title: Text("${panel.title}"),
|
||||
onTap: () => panel.handleOpen(context)
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
menuItems.add(Divider());
|
||||
menuItems.addAll([
|
||||
new ListTile(
|
||||
leading: Icon(MaterialDesignIcons.getIconDataFromIconName("mdi:home-assistant")),
|
||||
title: Text("Open Web UI"),
|
||||
onTap: null,
|
||||
),
|
||||
Divider()
|
||||
]);
|
||||
}
|
||||
menuItems.addAll([
|
||||
new ListTile(
|
||||
|
@ -16,11 +16,30 @@ class Panel {
|
||||
final String urlPath;
|
||||
final Map config;
|
||||
String icon;
|
||||
bool isHidden = true;
|
||||
|
||||
Panel({this.id, this.type, this.title, this.urlPath, this.icon, this.config}) {
|
||||
if (icon == null || !icon.startsWith("mdi:")) {
|
||||
icon = Panel.iconsByComponent[type];
|
||||
}
|
||||
isHidden = (type != "iframe");
|
||||
}
|
||||
|
||||
void handleOpen(BuildContext context) {
|
||||
if (type == "iframe") {
|
||||
Logger.d("Launching custom tab with ${config["url"]}");
|
||||
HAUtils.launchURLInCustomTab(context, config["url"]);
|
||||
} else if (type == "config") {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PanelPage(title: "$title", panel: this),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
String url = "$homeAssistantWebHost/$urlPath";
|
||||
Logger.d("Launching custom tab with $url");
|
||||
HAUtils.launchURLInCustomTab(context, url);
|
||||
}
|
||||
}
|
||||
|
||||
Widget getWidget() {
|
||||
|
Reference in New Issue
Block a user