Resolves #70 Build default_view automatically

This commit is contained in:
estevez
2018-09-28 13:33:15 +03:00
parent b935a0e372
commit af3a5bc611
4 changed files with 68 additions and 14 deletions

View File

@ -10,6 +10,8 @@ class EntityCollection {
viewList = [];
}
bool get hasDefaultView => _entities["group.default_view"] != null;
void parse(List rawData) {
_entities.clear();
viewList.clear();
@ -55,4 +57,31 @@ class EntityCollection {
return _entities[entityId] != null;
}
Map<String,List<String>> getDefaultViewTopLevelEntities() {
Map<String,List<String>> result = {"userGroups": [], "notGroupedEntities": []};
List<String> entities = [];
_entities.forEach((id, entity){
if ((id.indexOf("group.") == 0) && (id.indexOf(".all_") == -1) && (!entity.isView)) {
result["userGroups"].add(id);
}
if (!entity.isGroup) {
entities.add(id);
}
});
entities.forEach((entiyId) {
bool foundInGroup = false;
result["userGroups"].forEach((userGroupId) {
if (_entities[userGroupId].childEntities.contains(entiyId)) {
foundInGroup = true;
}
});
if (!foundInGroup) {
result["notGroupedEntities"].add(entiyId);
}
});
return result;
}
}