2018-09-28 10:15:25 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
|
|
|
class View {
|
|
|
|
String _entityId;
|
|
|
|
int _count;
|
|
|
|
Map<String, HACard> cards;
|
|
|
|
Map<String, Badge> badges;
|
|
|
|
|
|
|
|
bool get isThereBadges => (badges != null) && (badges.isNotEmpty);
|
|
|
|
|
|
|
|
View(String groupId, int viewCount) {
|
|
|
|
_entityId = groupId;
|
|
|
|
_count = viewCount;
|
|
|
|
cards = {};
|
|
|
|
badges = {};
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:18:37 +03:00
|
|
|
void add(Entity entity) {
|
|
|
|
if (!entity.isGroup) {
|
|
|
|
_addEntityWithoutGroup(entity);
|
|
|
|
} else {
|
|
|
|
_addCardWithEntities(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _addBadge(String entityId) {
|
2018-09-28 10:15:25 +03:00
|
|
|
badges.addAll({entityId: Badge(entityId)});
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:18:37 +03:00
|
|
|
void _addEntityWithoutGroup(Entity entity) {
|
|
|
|
if (UIBuilder.isBadge(entity.domain)) {
|
|
|
|
//This is badge
|
|
|
|
_addBadge(entity.entityId);
|
|
|
|
} else {
|
|
|
|
//This is a standalone entity
|
|
|
|
String groupIdToAdd = "${entity.domain}.${entity.domain}$_count";
|
|
|
|
if (cards[groupIdToAdd] == null) {
|
|
|
|
_addCard(groupIdToAdd, entity.domain);
|
|
|
|
}
|
|
|
|
cards[groupIdToAdd].addEntity(entity.entityId);
|
2018-09-28 10:15:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:18:37 +03:00
|
|
|
void _addCard(String entityId, String friendlyName) {
|
2018-09-28 10:15:25 +03:00
|
|
|
cards.addAll({"$entityId": HACard(entityId, friendlyName)});
|
|
|
|
}
|
|
|
|
|
2018-09-28 11:18:37 +03:00
|
|
|
void _addCardWithEntities(Entity entity) {
|
|
|
|
cards.addAll({"${entity.entityId}": HACard(entity.entityId, entity.displayName)});
|
|
|
|
cards[entity.entityId].addEntities(entity.childEntities);
|
2018-09-28 10:15:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|