Skip to content
Snippets Groups Projects
Commit 7cf68f67 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

feat: Working version of place/weather data source combination

parent 2fd19a86
No related branches found
No related tags found
1 merge request!191Add map module and Open-Meteo support
...@@ -1082,3 +1082,4 @@ downloadedTime=Time of download ...@@ -1082,3 +1082,4 @@ downloadedTime=Time of download
observationCount=Observation count observationCount=Observation count
weatherDatasource=Weather datasource weatherDatasource=Weather datasource
useWeatherStation=Use weather station
...@@ -1057,7 +1057,7 @@ privacyStatement=Personvernerkl\u00e6ring ...@@ -1057,7 +1057,7 @@ privacyStatement=Personvernerkl\u00e6ring
privacyStatementFileName=Personvernerklaering_NIBIO-VIPS.pdf privacyStatementFileName=Personvernerklaering_NIBIO-VIPS.pdf
thresholdDSVMax=DSV-terskel for h\u00f8y infeksjonsrisiko thresholdDSVMax=DSV-terskel for h\u00f8y infeksjonsrisiko
thresholdDSVTempMin=Minimumstemperatur for beregning av DSV thresholdDSVTempMin=Minimumstemperatur for beregning av DSV
useGridWeatherData=Bruk v\u00e6rdata fra rutenett useGridWeatherData=Bruk v\u00e6rdata for mitt steds posisjon
doNotUse=Ikke bruk doNotUse=Ikke bruk
defaultGridWeatherStationDataSource=GRID-basert v\u00e6rdatakilde defaultGridWeatherStationDataSource=GRID-basert v\u00e6rdatakilde
weatherStationDataSources=V\u00e6r(stasjons)datakilder weatherStationDataSources=V\u00e6r(stasjons)datakilder
...@@ -1081,3 +1081,4 @@ downloadedTime=Tidspunkt for nedlasting ...@@ -1081,3 +1081,4 @@ downloadedTime=Tidspunkt for nedlasting
observationCount=Antall observasjoner observationCount=Antall observasjoner
weatherDatasource=V\u00e6rdatakilde weatherDatasource=V\u00e6rdatakilde
useWeatherStation=Bruk v\u00e6rstasjon
...@@ -1070,3 +1070,4 @@ isGridWeatherDataSource=This is a grid based weather data source ...@@ -1070,3 +1070,4 @@ isGridWeatherDataSource=This is a grid based weather data source
weatherStationDataSourceStored=Weather (station) data source was successfully stored weatherStationDataSourceStored=Weather (station) data source was successfully stored
weatherStationDataSourceDeleted=The weather (station) data source was successfully deleted weatherStationDataSourceDeleted=The weather (station) data source was successfully deleted
weatherDatasource=Weather datasource weatherDatasource=Weather datasource
useWeatherStation=Use weather station
...@@ -70,8 +70,9 @@ ...@@ -70,8 +70,9 @@
renderPoiSelect(selectLocationElement, locationList, selectedPoiId); renderPoiSelect(selectLocationElement, locationList, selectedPoiId);
// Setting weather station select list state correct on page load // Setting weather station select list state correct on page load
<#if isGridForecastSupported> <#if isGridForecastSupported && forecastConfiguration.forecastConfigurationId??>
handleUseGridWeatherDataClicked(document.getElementById("useGridWeatherData")<#if forecastConfiguration.weatherStationPointOfInterestId?has_content && forecastConfiguration.weatherStationPointOfInterestId.pointOfInterestId?has_content>,${forecastConfiguration.weatherStationPointOfInterestId.pointOfInterestId}</#if>); setUseGridWeatherData(<#if forecastConfiguration.useGridWeatherData>"true"<#else>"false"</#if>)
handleWeatherDatasourceSelected(<#if forecastConfiguration.weatherStationPointOfInterestId?has_content && forecastConfiguration.weatherStationPointOfInterestId.pointOfInterestId?has_content>${forecastConfiguration.weatherStationPointOfInterestId.pointOfInterestId}</#if>);
</#if> </#if>
/** /**
...@@ -397,22 +398,36 @@ ...@@ -397,22 +398,36 @@
} }
}; };
window.handleUseGridWeatherDataClicked = function(theCheckBox, weatherStationPointOfInterestId) { window.handleWeatherDatasourceSelected = function(weatherStationPointOfInterestId) {
weatherStationList = document.getElementById("weatherStationPointOfInterestId"); let weatherStationList = document.getElementById("weatherStationPointOfInterestId");
let listContainer = document.getElementById("weatherstationListContainer");
weatherStationPointOfInterestIdHiddenField = document.getElementById("weatherStationPointOfInterestIdHidden"); weatherStationPointOfInterestIdHiddenField = document.getElementById("weatherStationPointOfInterestIdHidden");
if(theCheckBox.checked) // Which data source is selected?
let useGridWeatherData;
const radios = document.getElementsByName("useGridWeatherData");
for(const radio of radios)
{
if(radio.checked)
{
useGridWeatherData = radio.value;
break;
}
}
//console.info("useGridWeatherData=" + useGridWeatherData)
if(useGridWeatherData == "true")
{ {
// Select weatherStationId -2 // Select weatherStationId -2
weatherStationList.selectedIndex = 0; weatherStationList.selectedIndex = 0;
// Disable the weatherstation select list // Disable the weatherstation select list
weatherStationList.disabled=true; weatherStationList.disabled=true;
listContainer.style.display="none";
weatherStationList.name="weatherStationPointOfInterestIdDisabled"; weatherStationList.name="weatherStationPointOfInterestIdDisabled";
// Enable the hidden field // Enable the hidden field
weatherStationPointOfInterestIdHiddenField.disabled=false weatherStationPointOfInterestIdHiddenField.disabled=false
weatherStationPointOfInterestIdHiddenField.name="weatherStationPointOfInterestId"; weatherStationPointOfInterestIdHiddenField.name="weatherStationPointOfInterestId";
} }
else else if(useGridWeatherData == "false")
{ {
// Select weatherStationId -1 OR the optionally provided weatherStationPointOfInterestId // Select weatherStationId -1 OR the optionally provided weatherStationPointOfInterestId
if(weatherStationPointOfInterestId == undefined || weatherStationPointOfInterestId == null) if(weatherStationPointOfInterestId == undefined || weatherStationPointOfInterestId == null)
...@@ -428,6 +443,8 @@ ...@@ -428,6 +443,8 @@
} }
// Enable the weather station select list // Enable the weather station select list
weatherStationList.disabled=false; weatherStationList.disabled=false;
listContainer.style.display="block";
weatherStationList.name="weatherStationPointOfInterestId"; weatherStationList.name="weatherStationPointOfInterestId";
// Disable the hidden field // Disable the hidden field
weatherStationPointOfInterestIdHiddenField.disabled=true weatherStationPointOfInterestIdHiddenField.disabled=true
...@@ -435,20 +452,32 @@ ...@@ -435,20 +452,32 @@
} }
}; };
window.setUseGridWeatherData = function(useGridWeatherData)
{
//console.info("setuseGridWeatherData, input value=" + useGridWeatherData);
const radios = document.getElementsByName("useGridWeatherData");
for(const radio of radios)
{
//console.info("radio value=" + radio.value + ", so the radio should " + (radio.value == useGridWeatherData ? "": "NOT") + " be checked" );
radio.checked = radio.value == useGridWeatherData;
}
}
let handleLocationChanged = function(){
window.handleLocationChanged = function(){
let weatherstationSelect = document.getElementById("weatherStationPointOfInterestId"); let weatherstationSelect = document.getElementById("weatherStationPointOfInterestId");
let weatherDatasourceFieldset = document.getElementById("weatherDatasourceFieldset");
// Which location has been selected? // Which location has been selected?
let selectedPoiId = document.getElementById("locationPointOfInterestId").options[document.getElementById("locationPointOfInterestId").selectedIndex].value; let selectedPoiId = document.getElementById("locationPointOfInterestId").options[document.getElementById("locationPointOfInterestId").selectedIndex].value;
if(selectedPoiId <= 0) if(selectedPoiId <= 0)
{ {
document.getElementById("weatherDatasourceFieldset").disabled = true; if(weatherDatasourceFieldset != null) weatherDatasourceFieldset.disabled = true;
weatherstationSelect.selectedIndex = 0; weatherstationSelect.selectedIndex = 0;
return; return;
} }
// Enable the weather datasource fieldset // Enable the weather datasource fieldset
document.getElementById("weatherDatasourceFieldset").disabled=false; if(weatherDatasourceFieldset != null) weatherDatasourceFieldset.disabled = false;
let selectedLocation = undefined; let selectedLocation = undefined;
for(let i=0; i<locationList.length;i++) for(let i=0; i<locationList.length;i++)
...@@ -471,9 +500,8 @@ ...@@ -471,9 +500,8 @@
<#if isGridForecastSupported> <#if isGridForecastSupported>
let gridCheckBox = document.getElementById("useGridWeatherData"); setUseGridWeatherData(selectedLocation.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION ? "false" : "true");
gridCheckBox.checked = (selectedLocation.pointOfInterestTypeId != POI_TYPE_WEATHERSTATION); handleWeatherDatasourceSelected(selectedLocation.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION ? selectedLocation.pointOfInterestId: undefined);
handleUseGridWeatherDataClicked(gridCheckBox, (selectedLocation.pointOfInterestTypeId == POI_TYPE_WEATHERSTATION ? selectedLocation.pointOfInterestId: undefined));
</#if> </#if>
} }
...@@ -562,8 +590,9 @@ ...@@ -562,8 +590,9 @@
<label for="locationPointOfInterestId">${i18nBundle.locationPointOfInterestId}</label> <label for="locationPointOfInterestId">${i18nBundle.locationPointOfInterestId}</label>
<div class="select-container" style="flex: 1; display: flex; align-items: center;"> <div class="select-container" style="flex: 1; display: flex; align-items: center;">
<select class="form-control" id="locationPointOfInterestId" name="locationPointOfInterestId" onchange="handleLocationChanged();" onblur="validateField(this);" style="width: calc(100% - 30px);"> <select class="form-control" id="locationPointOfInterestId" name="locationPointOfInterestId" onchange="handleLocationChanged();" onblur="validateField(this);" style="width: calc(100% - 30px);">
</select> </select>&nbsp;
<i id="open-map-modal-icon" class="fa fa-map-marker" onclick="openLocationMap()"></i> <button type="button" class="btn btn-primary" onclick="openLocationMap()"><i class="fa fa-map-marker fa-lg"></i>&nbsp;&nbsp;Velg i kart</button>
<div id="location-map" class="map-modal"></div> <div id="location-map" class="map-modal"></div>
</div> </div>
<span class="help-block" id="${formId}_locationPointOfInterestId_validation"></span> <span class="help-block" id="${formId}_locationPointOfInterestId_validation"></span>
...@@ -575,27 +604,36 @@ ...@@ -575,27 +604,36 @@
<#else> <#else>
<div class="alert alert-info" role="alert">Velg sted ovenfor først, og velg deretter værstasjon. Hvis stedet du har valgt ikke er en værstasjon, vil værstasjonslista sorteres etter avstand til ditt sted.</div> <div class="alert alert-info" role="alert">Velg sted ovenfor først, og velg deretter værstasjon. Hvis stedet du har valgt ikke er en værstasjon, vil værstasjonslista sorteres etter avstand til ditt sted.</div>
</#if> </#if>
<#if isGridForecastSupported>
<fieldset id="weatherDatasourceFieldset" <#if !forecastConfiguration.weatherStationPointOfInterestId?has_content>disabled</#if>> <fieldset id="weatherDatasourceFieldset" <#if !forecastConfiguration.weatherStationPointOfInterestId?has_content>disabled</#if>>
<legend style="margin-bottom: 0px;">${i18nBundle.weatherDatasource}</legend> <legend style="margin-bottom: 0px;">${i18nBundle.weatherDatasource}</legend>
<div class="form-group">
<label for="weatherStationPointOfInterestId">${i18nBundle.weatherStationPointOfInterestId}</label>
<select class="form-control" id="weatherStationPointOfInterestId" name="weatherStationPointOfInterestId" onblur="if(!document.getElementById('useGridWeatherData').checked) {validateField(this);}">
</select>
<span class="help-block" id="${formId}_weatherStationPointOfInterestId_validation"></span>
</div>
<#if isGridForecastSupported>
<input type="hidden" id="weatherStationPointOfInterestIdHidden" name="weatherStationPointOfInterestIdDisabled" value="-2" disabled="disabled"/> <input type="hidden" id="weatherStationPointOfInterestIdHidden" name="weatherStationPointOfInterestIdDisabled" value="-2" disabled="disabled"/>
<div class="form-group"> <div class="form-group">
<div class="checkbox"> <div class="radio">
<label> <label>
<input type="checkbox" id="useGridWeatherData" name="useGridWeatherData"<#if forecastConfiguration.useGridWeatherData?has_content && forecastConfiguration.useGridWeatherData == true> checked="checked"</#if> onclick="handleUseGridWeatherDataClicked(this);"/> <input type="radio" id="useGridWeatherData" value="true" name="useGridWeatherData"<#if forecastConfiguration.useGridWeatherData?has_content && forecastConfiguration.useGridWeatherData == true> checked="checked"</#if> onclick="handleWeatherDatasourceSelected();"/>
</label> </label>
${i18nBundle.useGridWeatherData} ${i18nBundle.useGridWeatherData}
<span class="help-block" id="${formId}_useGridWeatherData_validation"></span>
</div> </div>
</#if> </#if>
<#if isGridForecastSupported><div class="radio">
<label>
<input type="radio" name="useGridWeatherData" id="useWeatherstationRadio" value="false" onclick="handleWeatherDatasourceSelected();">
${i18nBundle.useWeatherStation}
</label>
</#if>
<div class="form-group" id="weatherstationListContainer" style="display: <#if isGridForecastSupported>none<#else>block</#if>;">
<#if !isGridForecastSupported><label for="weatherStationPointOfInterestId">${i18nBundle.weatherStationPointOfInterestId}</label></#if>
<select class="form-control" id="weatherStationPointOfInterestId" name="weatherStationPointOfInterestId" onblur="if(document.getElementById('useWeatherstationRadio') == null || document.getElementById('useWeatherstationRadio').checked) {validateField(this);}">
</select>
<span class="help-block" id="${formId}_weatherStationPointOfInterestId_validation"></span>
</div>
<#if isGridForecastSupported>
</div>
</fieldset> </fieldset>
</#if>
<#else> <#else>
<input type="hidden" name="multipleNew" value="true"/> <input type="hidden" name="multipleNew" value="true"/>
<div class="form-group"> <div class="form-group">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment