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;
|
2020-03-20 00:59:53 +02:00
|
|
|
final String componentName;
|
2019-03-13 16:39:23 +02:00
|
|
|
final String title;
|
|
|
|
final String urlPath;
|
|
|
|
final Map config;
|
|
|
|
String icon;
|
2019-03-13 17:23:23 +02:00
|
|
|
bool isHidden = true;
|
2019-09-02 21:08:20 +03:00
|
|
|
bool isWebView = false;
|
2019-03-13 16:39:23 +02:00
|
|
|
|
2020-03-20 00:59:53 +02:00
|
|
|
Panel({this.id, this.componentName, this.title, this.urlPath, this.icon, this.config}) {
|
2019-03-13 16:39:23 +02:00
|
|
|
if (icon == null || !icon.startsWith("mdi:")) {
|
2020-03-20 00:59:53 +02:00
|
|
|
icon = Panel.iconsByComponent[componentName];
|
2019-03-13 16:39:23 +02:00
|
|
|
}
|
2020-03-20 00:59:53 +02:00
|
|
|
isHidden = (componentName == 'kiosk' || componentName == 'states' || componentName == 'profile' || componentName == 'developer-tools');
|
2020-05-01 16:47:41 +03:00
|
|
|
isWebView = (componentName != 'lovelace' && !componentName.startsWith('haclient'));
|
2019-03-13 17:23:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleOpen(BuildContext context) {
|
2020-05-03 13:00:32 +03:00
|
|
|
if (componentName.startsWith('haclient')) {
|
2020-04-01 20:04:32 +03:00
|
|
|
Navigator.of(context).pushNamed(urlPath);
|
2020-03-20 00:59:53 +02:00
|
|
|
} else if (componentName == 'lovelace') {
|
2020-05-14 19:44:50 +03:00
|
|
|
HomeAssistant().currentDashboardPath = this.urlPath;
|
|
|
|
Logger.d('Switching to dashboard: ${this.urlPath}');
|
2020-03-20 12:14:14 +02:00
|
|
|
HomeAssistant().autoUi = false;
|
2020-03-20 00:59:53 +02:00
|
|
|
SharedPreferences.getInstance().then((prefs) {
|
|
|
|
prefs.setString('lovelace_dashboard_url', this.urlPath);
|
|
|
|
eventBus.fire(ReloadUIEvent());
|
|
|
|
});
|
2019-03-13 17:23:23 +02:00
|
|
|
} else {
|
2020-07-20 15:21:31 +03:00
|
|
|
Launcher.launchAuthenticatedWebView(context: context, url: "${AppSettings().httpWebHost}/$urlPath", title: "Back to app");
|
2019-03-13 17:23:23 +02:00
|
|
|
}
|
2019-03-13 16:39:23 +02:00
|
|
|
}
|
|
|
|
|
2020-03-20 00:59:53 +02:00
|
|
|
Widget getMenuItemWidget(BuildContext context) {
|
|
|
|
return ListTile(
|
|
|
|
leading: Icon(MaterialDesignIcons.getIconDataFromIconName(this.icon)),
|
|
|
|
title: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Text("${this.title}"),
|
|
|
|
Container(width: 4.0,),
|
2020-04-04 18:13:55 +03:00
|
|
|
isWebView ? Text("webview", style: Theme.of(context).textTheme.overline) : Container(width: 1.0,)
|
2020-03-20 00:59:53 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
this.handleOpen(context);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-13 16:39:23 +02:00
|
|
|
Widget getWidget() {
|
2020-03-20 00:59:53 +02:00
|
|
|
switch (componentName) {
|
2019-03-13 16:39:23 +02:00
|
|
|
default: {
|
2020-03-20 00:59:53 +02:00
|
|
|
return Text("Unsupported panel component: $componentName");
|
2019-03-13 16:39:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|