Entity class refactoring
This commit is contained in:
parent
2ea7d9440c
commit
78dd7df686
@ -211,12 +211,6 @@ class Entity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildHistoryWidget() {
|
|
||||||
return EntityHistoryWidget(
|
|
||||||
config: historyConfig,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget buildBadgeWidget(BuildContext context) {
|
Widget buildBadgeWidget(BuildContext context) {
|
||||||
return EntityModel(
|
return EntityModel(
|
||||||
entityWrapper: EntityWrapper(entity: this),
|
entityWrapper: EntityWrapper(entity: this),
|
||||||
|
@ -54,7 +54,7 @@ class EntityPageLayout extends StatelessWidget {
|
|||||||
Divider(),
|
Divider(),
|
||||||
this.entity._buildAdditionalControlsForPage(context),
|
this.entity._buildAdditionalControlsForPage(context),
|
||||||
Divider(),
|
Divider(),
|
||||||
this.entity.buildHistoryWidget(),
|
EntityHistoryWidget(),
|
||||||
EntityAttributesList()
|
EntityAttributesList()
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
@ -17,9 +17,7 @@ class EntityHistoryConfig {
|
|||||||
|
|
||||||
class EntityHistoryWidget extends StatefulWidget {
|
class EntityHistoryWidget extends StatefulWidget {
|
||||||
|
|
||||||
final EntityHistoryConfig config;
|
const EntityHistoryWidget({Key key}) : super(key: key);
|
||||||
|
|
||||||
const EntityHistoryWidget({Key key, @required this.config}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_EntityHistoryWidgetState createState() {
|
_EntityHistoryWidgetState createState() {
|
||||||
@ -33,6 +31,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
bool _needToUpdateHistory;
|
bool _needToUpdateHistory;
|
||||||
DateTime _historyLastUpdated;
|
DateTime _historyLastUpdated;
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
|
Entity entity;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -75,10 +74,10 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
} else {
|
} else {
|
||||||
_loadHistory(entity.entityId);
|
_loadHistory(entity.entityId);
|
||||||
}
|
}
|
||||||
return _buildChart();
|
return _buildChart(entity.historyConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildChart() {
|
Widget _buildChart(EntityHistoryConfig config) {
|
||||||
List<Widget> children = [];
|
List<Widget> children = [];
|
||||||
if (_history == null) {
|
if (_history == null) {
|
||||||
children.add(
|
children.add(
|
||||||
@ -90,7 +89,7 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
children.add(
|
children.add(
|
||||||
_selectChartWidget()
|
_selectChartWidget(config)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
children.add(Divider());
|
children.add(Divider());
|
||||||
@ -102,8 +101,8 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _selectChartWidget() {
|
Widget _selectChartWidget(EntityHistoryConfig config) {
|
||||||
switch (widget.config.chartType) {
|
switch (config.chartType) {
|
||||||
|
|
||||||
case EntityHistoryWidgetType.simple: {
|
case EntityHistoryWidgetType.simple: {
|
||||||
return SimpleStateHistoryChartWidget(
|
return SimpleStateHistoryChartWidget(
|
||||||
@ -114,14 +113,14 @@ class _EntityHistoryWidgetState extends State<EntityHistoryWidget> {
|
|||||||
case EntityHistoryWidgetType.numericState: {
|
case EntityHistoryWidgetType.numericState: {
|
||||||
return NumericStateHistoryChartWidget(
|
return NumericStateHistoryChartWidget(
|
||||||
rawHistory: _history,
|
rawHistory: _history,
|
||||||
config: widget.config,
|
config: config,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case EntityHistoryWidgetType.numericAttributes: {
|
case EntityHistoryWidgetType.numericAttributes: {
|
||||||
return CombinedHistoryChartWidget(
|
return CombinedHistoryChartWidget(
|
||||||
rawHistory: _history,
|
rawHistory: _history,
|
||||||
config: widget.config,
|
config: config,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user