diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/download-data.vue b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/download-data.vue index e7b9aa6cf5172226aed726b7443590fee9eb52de..b8eb99763e7392eca5b84eda67755e9834b30d30 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/download-data.vue +++ b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/download-data.vue @@ -181,6 +181,7 @@ import {getIVServiceURL, getSiteMetaDataServiceURL} from 'ui/web-services/instan import {getStatisticsServiceURL} from 'ui/web-services/statistics-data'; import {getGroundwaterServiceURL} from 'ui/web-services/groundwater-levels'; import {getPrimaryParameter} from 'ml/components/hydrograph/selectors/time-series-data'; +import {getIVParameter} from 'ml/selectors/hydrograph-data-selector'; import {isCalculatedTemperature} from 'ml/parameter-code-utils'; import { @@ -189,6 +190,7 @@ import { hasVisibleMedianStatisticsData } from '../selectors/time-series-data'; + export default { name: 'DownloadData', components: { @@ -208,7 +210,8 @@ export default { hasVisibleCompareIVData: hasVisibleIVData('compare'), hasVisibleMedianData: hasVisibleMedianStatisticsData, hasVisibleGroundwaterLevels: hasVisibleGroundwaterLevels, - primaryParameter: getPrimaryParameter + primaryParameter: getPrimaryParameter, + secondaryParameter: getIVParameter('secondary') }); const reduxStore = inject('store'); @@ -226,13 +229,19 @@ export default { return DateTime.fromMillis(inMillis, {zone: config.locationTimeZone}).toISO(); }; - const getIVDataURL = function(reduxStore, siteno, timeRangeKind) { + const getIVDataURL = function(reduxStore, siteno, dataKind) { + const timeRangePrefix = { + primary: 'current', + secondary: 'current', + prioryear: 'compare' + }; + const currentState = reduxStore.getState(); - const timeRange = getTimeRange(timeRangeKind)(currentState); + const timeRange = getTimeRange(timeRangePrefix[dataKind])(currentState); return getIVServiceURL({ siteno, - parameterCode: getPrimaryParameter(currentState).parameterCode, + parameterCode: dataKind === 'secondary' ? state.secondaryParameter.value.parameterCode : state.primaryParameter.value.parameterCode, startTime: toISO(timeRange.start), endTime: toISO(timeRange.end), format: 'rdb' @@ -267,7 +276,10 @@ export default { showErrorMessage.value = false; switch (buttonSelected) { case 'primary': - downloadUrl.value = getIVDataURL(reduxStore, siteno, 'current'); + downloadUrl.value = getIVDataURL(reduxStore, siteno, 'primary'); + break; + case 'secondary': + downloadUrl.value = getIVDataURL(reduxStore, siteno, 'secondary'); break; case 'compare': downloadUrl.value = getIVDataURL(reduxStore, siteno, 'prioryear');