From 68df4be547b8d7f7cd79c000f89c2afc84fa3cc3 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Wed, 21 May 2025 14:00:50 +0200 Subject: [PATCH] Widget actions: Add aggregation type parameter for analyzer action (#3195) Closes #3088. Signed-off-by: Florian Hotze --- .../src/assets/definitions/widgets/actions.js | 5 ++++ .../assets/definitions/widgets/chart/index.js | 25 +++---------------- .../definitions/widgets/chart/options.js | 19 ++++++++++++++ .../src/components/widgets/widget-actions.js | 3 ++- .../web/src/pages/analyzer/analyzer.vue | 5 ++++ 5 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/options.js diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/actions.js b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/actions.js index cfc26f061..10fdadb10 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/actions.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/actions.js @@ -1,5 +1,6 @@ // parameter group & parameters definitions for actions import { po, pt, pi, pb } from './helpers.js' +import { aggregationTypeOptions } from './chart/options.js' export const actionGroup = (label, description, groupPrefix) => { groupPrefix = (groupPrefix) ? groupPrefix += '_' : '' @@ -131,6 +132,10 @@ export const actionParams = (groupName, paramPrefix) => { ]).v((value, configuration, configDescription, parameters) => { return ['analyzer'].indexOf(configuration[paramPrefix + 'action']) >= 0 }), + po(paramPrefix + 'actionAnalyzerAggregation', 'Initial Aggregation', 'The initial aggregation of the analyzer - ', aggregationTypeOptions) + .v((value, configuration, configDescription, parameters) => { + return ['analyzer'].indexOf(configuration[paramPrefix + 'action']) >= 0 && configuration[paramPrefix + 'actionAnalyzerCoordSystem'] === 'aggregate' + }), pt(paramPrefix + 'actionConfirmation', 'Action Confirmation', 'Shows a dialog or sheet to ask for confirmation before the action is executed. Can either be a text to show in the dialog or a JSON object { type: "dialog", title: "Confirm", text: "Are you sure?" } or { type: "sheet", text: "Confirm", color: "green" }').a(), pt(paramPrefix + 'actionFeedback', 'Action Feedback', 'Shows a toast popup when the action has been executed. Can either be a text to show or a JSON object including some of the supported parameters').a() .v((value, configuration, configDescription, parameters) => { diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/index.js b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/index.js index a4169890e..1f7df3b2b 100644 --- a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/index.js +++ b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/index.js @@ -3,6 +3,7 @@ import { actionGroup, actionParams } from '../actions.js' import { pg, pb, pt, pn, pi } from '../helpers.js' +import { aggregationTypeOptions, dimensionTypeOptions } from './options.js' const positionGroup = pg('position', 'Position', 'Each parameter accepts pixel values or percentages. Additionally, top accepts "top", "middle" and "bottom" to align the component vertically, and left accepts "left", "center" and "right" to align the component horizontally') @@ -123,25 +124,7 @@ const seriesTypeParameter = (...types) => { } const aggregationFunctionParameter = pt('aggregationFunction', 'Aggregation Function', 'How to reduce the data points in a same aggregation cluster to a single value. If not specified, the average function will be used.') - .o([ - { value: 'average', label: 'Average' }, - { value: 'sum', label: 'Sum' }, - { value: 'min', label: 'Minimum' }, - { value: 'max', label: 'Maximum' }, - { value: 'first', label: 'First (earliest)' }, - { value: 'last', label: 'Last (latest)' }, - { value: 'diff_first', label: 'Difference of firsts' }, - { value: 'diff_last', label: 'Difference of lasts' } - ], true) - -const dimensionTypesOptions = [ - { value: 'minute', label: 'Minute of Hour' }, - { value: 'hour', label: 'Hour of Day' }, - { value: 'isoWeekday', label: 'Day of Week (starting on Monday)' }, - { value: 'weekday', label: 'Day of Week (starting on Sunday)' }, - { value: 'date', label: 'Day of Month' }, - { value: 'month', label: 'Month of Year' } -] + .o(aggregationTypeOptions, true) export default { 'oh-chart-grid': { @@ -357,7 +340,7 @@ export default { type: 'TEXT', description: 'The largest data point cluster size.
It should be consistent with the chart type, and match the type of a category axis where this series will appear.', limitToOptions: true, - options: dimensionTypesOptions + options: dimensionTypeOptions }, { name: 'dimension2', @@ -365,7 +348,7 @@ export default { type: 'TEXT', description: 'The smallest data point cluster size.
Set only when you have 2 category axes (for instance day of the week and hour of the day), and make sure to match the type of the 2nd axis.', limitToOptions: true, - options: dimensionTypesOptions + options: dimensionTypeOptions }, { name: 'transpose', diff --git a/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/options.js b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/options.js new file mode 100644 index 000000000..86b47de37 --- /dev/null +++ b/bundles/org.openhab.ui/web/src/assets/definitions/widgets/chart/options.js @@ -0,0 +1,19 @@ +export const dimensionTypeOptions = [ + { value: 'minute', label: 'Minute of Hour' }, + { value: 'hour', label: 'Hour of Day' }, + { value: 'isoWeekday', label: 'Day of Week (starting on Monday)' }, + { value: 'weekday', label: 'Day of Week (starting on Sunday)' }, + { value: 'date', label: 'Day of Month' }, + { value: 'month', label: 'Month of Year' } +] + +export const aggregationTypeOptions = [ + { value: 'average', label: 'Average' }, + { value: 'sum', label: 'Sum' }, + { value: 'min', label: 'Minimum' }, + { value: 'max', label: 'Maximum' }, + { value: 'first', label: 'First (earliest)' }, + { value: 'last', label: 'Last (latest)' }, + { value: 'diff_first', label: 'Difference of firsts' }, + { value: 'diff_last', label: 'Difference of lasts' } +] diff --git a/bundles/org.openhab.ui/web/src/components/widgets/widget-actions.js b/bundles/org.openhab.ui/web/src/components/widgets/widget-actions.js index 5fbe7cf5b..adcb5472b 100644 --- a/bundles/org.openhab.ui/web/src/components/widgets/widget-actions.js +++ b/bundles/org.openhab.ui/web/src/components/widgets/widget-actions.js @@ -285,10 +285,11 @@ export const actionsMixin = { let actionAnalyzerItems = actionConfig[prefix + 'actionAnalyzerItems'] const actionAnalyzerChartType = actionConfig[prefix + 'actionAnalyzerChartType'] const actionAnalyzerCoordSystem = actionConfig[prefix + 'actionAnalyzerCoordSystem'] + const actionAnalyzerAggregation = actionConfig[prefix + 'actionAnalyzerAggregation'] if (Array.isArray(actionAnalyzerItems)) { actionAnalyzerItems = actionAnalyzerItems.join(',') } - this.$f7.views.main.router.navigate(`/analyzer/?items=${actionAnalyzerItems || ''}&chartType=${actionAnalyzerChartType || ''}&coordSystem=${actionAnalyzerCoordSystem || ''}`) + this.$f7.views.main.router.navigate(`/analyzer/?items=${actionAnalyzerItems || ''}&chartType=${actionAnalyzerChartType || ''}&coordSystem=${actionAnalyzerCoordSystem || ''}&aggregation=${actionAnalyzerAggregation || ''}`) console.log('Opening the analyzer') break case 'url': diff --git a/bundles/org.openhab.ui/web/src/pages/analyzer/analyzer.vue b/bundles/org.openhab.ui/web/src/pages/analyzer/analyzer.vue index 618125fb5..ddb683ab8 100644 --- a/bundles/org.openhab.ui/web/src/pages/analyzer/analyzer.vue +++ b/bundles/org.openhab.ui/web/src/pages/analyzer/analyzer.vue @@ -330,6 +330,11 @@ export default { this.updateItems(this.$f7route.query.items.split(',')).then(() => { if (this.$f7route.query.chartType) this.changeChartType(this.$f7route.query.chartType) if (this.$f7route.query.coordSystem) this.changeCoordSystem(this.$f7route.query.coordSystem) + if (this.$f7route.query.aggregation) { + for (const options in this.seriesOptions) { + this.$set(this.seriesOptions[options], 'aggregation', this.$f7route.query.aggregation) + } + } }) }, updateItems (itemNames) {