2018-09-28 10:15:25 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
|
|
|
class UIBuilder {
|
|
|
|
EntityCollection _entities;
|
|
|
|
Map<String, View> _views;
|
2018-09-28 11:18:37 +03:00
|
|
|
static List badgeDomains = ["alarm_control_panel", "binary_sensor", "device_tracker", "updater", "sun", "timer", "sensor"];
|
2018-09-28 10:15:25 +03:00
|
|
|
|
|
|
|
bool get isEmpty => _views.length == 0;
|
|
|
|
Map<String, View> get views => _views ?? {};
|
|
|
|
|
|
|
|
UIBuilder() {
|
|
|
|
_views = {};
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:18:37 +03:00
|
|
|
static bool isBadge(String domain) {
|
|
|
|
return badgeDomains.contains(domain);
|
|
|
|
}
|
|
|
|
|
2018-09-28 10:15:25 +03:00
|
|
|
void build(EntityCollection entitiesCollection) {
|
|
|
|
_entities = entitiesCollection;
|
|
|
|
_views.clear();
|
2018-09-28 13:33:15 +03:00
|
|
|
if (!_entities.hasDefaultView) {
|
|
|
|
_createDefaultView();
|
|
|
|
}
|
2018-09-28 11:23:48 +03:00
|
|
|
_createViews(entitiesCollection.viewList);
|
2018-09-28 10:15:25 +03:00
|
|
|
}
|
|
|
|
|
2018-09-28 13:33:15 +03:00
|
|
|
void _createDefaultView() {
|
|
|
|
Map<String, List<String>> userGroupsList = _entities.getDefaultViewTopLevelEntities();
|
|
|
|
TheLogger.log("RESULT", "${userGroupsList["userGroups"]}");
|
|
|
|
TheLogger.log("RESULT", "${userGroupsList["notGroupedEntities"]}");
|
|
|
|
View view = View("group.default_view", 0);
|
|
|
|
userGroupsList["userGroups"].forEach((groupId){
|
|
|
|
view.add(_entities.get(groupId));
|
|
|
|
});
|
|
|
|
userGroupsList["notGroupedEntities"].forEach((entityId){
|
|
|
|
view.add(_entities.get(entityId));
|
|
|
|
});
|
|
|
|
_views["group.default_view"] = view;
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:23:48 +03:00
|
|
|
void _createViews(List<String> viewsList) {
|
2018-09-28 10:15:25 +03:00
|
|
|
int counter = 0;
|
|
|
|
viewsList.forEach((viewId) {
|
|
|
|
counter += 1;
|
2018-09-28 11:23:48 +03:00
|
|
|
View view = View(viewId, counter);
|
2018-09-28 10:15:25 +03:00
|
|
|
|
|
|
|
try {
|
|
|
|
Entity viewGroupEntity = _entities.get(viewId);
|
|
|
|
viewGroupEntity.childEntities.forEach((
|
2018-09-28 11:23:48 +03:00
|
|
|
entityId) { //Each entity or group in view
|
2018-09-28 10:15:25 +03:00
|
|
|
if (_entities.isExist(entityId)) {
|
2018-09-28 11:18:37 +03:00
|
|
|
view.add(_entities.get(entityId));
|
2018-09-28 10:15:25 +03:00
|
|
|
} else {
|
|
|
|
TheLogger.log("Warning", "Unknown entity inside view: $entityId");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
TheLogger.log("Error","Error parsing view: $viewId");
|
|
|
|
}
|
2018-09-28 11:23:48 +03:00
|
|
|
|
|
|
|
_views[viewId] = view;
|
2018-09-28 10:15:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|