Das teste ich gerade bei mir. Es erfordert Eingriffe in
js/belchertown.js.tmpl und index.html.tmpl.
Zunächst brauchen Sie eine zusätzliche Datei, siehe Anhang. Dann muß in
belchertown.js.tmpl zweimal (!) die folgende Zeile eingefügt werden:
ajaxdwdalert().then(show_dwd_forecast_alert);
und zwar am Ende der Funktionen update_weewx_data und in update_current_wx
am Ende des Abschnittes "interval_minute". Ganz ans Ende der Datei kommt
noch:
#include "js/woellsdorf.inc.txt"
In index.html.tmpl muß das #if-Statement auskommentiert werden, das die
Variable forecast_enabled abfragt, also sowohl die Zeile mit #if als auch
die zugehörige mit #end if.
Aber ich kann keine Gewähr geben, daß es schon reibungsfrei funktioniert.
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/5055da1f-5849-48d4-9c95-76e45a7613abn%40googlegroups.com.
async function ajaxdwd()
{
reply = await fetch(get_relative_url() + "/json/dwd.json");
if (reply.ok)
{
return await reply.json();
}
else
{
throw new Error("HTTP error! Unable to load dwd.json");
}
}
function update_dwd_data(dwd_data)
{
}
async function ajaxdwdalert()
{
reply = await fetch(get_relative_url() + "/dwd/warn-DL.json");
if (reply.ok)
{
return await reply.json();
}
else
{
throw new Error("HTTP error! Unable to load warn-DL.json");
}
}
function show_dwd_forecast_alert(data)
{
var forecast_alert_modal, forecast_alerts;
forecast_alert_modal = "";
forecast_alerts = [];
//console.log('data',data);
// Empty anything that's been appended to the modal from the previous run
//jQuery(".wx-stn-alert-text").empty();
let modals = jQuery(".wx-stn-alert-text").find('.modal');
let modal_ids = [];
jQuery.each(modals,
function(i,el) {
let id = jQuery(this).attr('id')
//console.log('each',i,id,typeof el,el);
jQuery('#'+id).modal('hide');
jQuery('#'+id).on("hidden.bs.modal",
function() {
modal_ids.push('#'+id);
});
});
//console.log('modal_ids',modal_ids,modals.length,modal_ids.length);
setTimeout(1000,function(){console.log('modal_ids
timeout',modal_ids,modals.length,modal_ids.length);});
// make sure alert is in effect
now = new Date();
now_ts = now.valueOf();
for (let i = 0; i < data.length; i++)
{
//console.log('i',i,data[i]['start'],now_ts);
let forecast_alert_title = data[i]["headline"];
let forecast_alert_starts =
tzAdjustedMoment(parseFloat(data[i]['start'])/1000).format('$obs.label.time_forecast_alert_expires');
let forecast_alert_expires =
tzAdjustedMoment(parseFloat(data[i]['end'])/1000).format('$obs.label.time_forecast_alert_expires');
let forecast_alert_body = '<p
style="line-height=1'+(parseInt(data[i]['level'])>2?';font-size:110%':'')+'">'+
data[i]['headline']+
'</p><p
style="font-size:80%;line-height:1">gültig vom '+
forecast_alert_starts+
' bis '+
forecast_alert_expires+
'</p><p>'+
data[i]["description"]+
'</p><p>'+
data[i]["instruction"]+
'</p><p style="font-size:80%">Quelle:
Deutscher Wetterdienst (DWD)'+
'</p><p style="font-size:40%">'+
data[i]['type']+' – '+data[i]['event']+
'  –  '+
data[i]['level']+' –
'+data[i]['level_text']+
'</p>';
if (parseFloat(data[i]['start'])<=now_ts)
forecast_alert_expires = 'gültig bis '+forecast_alert_expires;
else
forecast_alert_expires = 'ab '+forecast_alert_starts;
let forecast_alert_link = "";
let forecast_alert_icon = data[i]["icon"];
if (forecast_alert_icon.substring(0,3)=='../')
forecast_alert_icon = forecast_alert_icon.substring(3);
forecast_alert_icon = get_relative_url()+'/'+forecast_alert_icon;
forecast_alerts.push({"title": forecast_alert_title, "body":
forecast_alert_body, "link": forecast_alert_link, "expires":
forecast_alert_expires, "icon":forecast_alert_icon,
"region":data[i]['regionName']});
}
//console.log('forecast_alerts',forecast_alerts);
if (forecast_alerts.length > 0)
{
let alert = '<div class="row">';
let alert_modal = "";
let col = 'lg-3';
if (forecast_alerts.length<3) col = 'sm-6';
if (forecast_alerts.length==3) col = 'lg-4';
for (let i = 0; i < forecast_alerts.length; i++)
{
alert += '<div class="col-'+col+' col-xs-12"
style="line-height:1">';
alert += '<img src="'+forecast_alerts[i]["icon"]+'"
style="float:left;width:35px;height:35px;margin-right:0.5em" />';
alert += '<a href="#forecast-alert-'+i+'" data-toggle="modal"
data-target="#forecast-alert-'+i+
'">'+
forecast_alerts[i]["title"].replace('Amtliche ','')+
'<span style="font-size:70%"><br />'+
forecast_alerts[i]["expires"]+
'</span></a>';
alert += '</div>';
alert_modal += "<!-- Forecast Alert Modal " + i + " -->";
alert_modal += "<div class='modal fade' id='forecast-alert-" + i +
"' tabindex='-1' role='dialog' aria-labelledby='forecast-alert'>";
alert_modal += "<div class='modal-dialog' role='document'>";
alert_modal += "<div class='modal-content'>";
alert_modal += "<div class='modal-header'>";
alert_modal += "<button type='button' class='close'
data-dismiss='modal' aria-label='Close'><span
aria-hidden='true'>×</span></button>";
alert_modal += "<h4 class='modal-title' id='forecast-alert'>" +
forecast_alerts[i]["region"] + "</h4>";
alert_modal += "</div>";
alert_modal += "<div class='modal-body' style='min-height:80px'>";
alert_modal += "<img src='"+forecast_alerts[i]["icon"]+"'
alt='"+forecast_alerts[i]["title"]+"' style='float:left;margin-right:1em'/>"
alert_modal += forecast_alerts[i]["body"];
alert_modal += "</div>";
alert_modal += "<div class='modal-footer'>";
alert_modal += "<button type='button' class='btn btn-primary'
data-dismiss='modal'>$obs.label.close</button>";
alert_modal += "</div>";
alert_modal += "</div>";
alert_modal += "</div>";
alert_modal += "</div>";
}
alert += '</div>';
jQuery.each(jQuery(".wx-stn-alert-text").find('.modal'),
function(i,el) {
let id = jQuery(this).attr('id')
//console.log('each',i,id,typeof el,el);
jQuery('#'+id).modal('hide');
});
jQuery(".wx-stn-alert").hide();
jQuery(".wx-stn-alert-text").html(alert+alert_modal);
jQuery(".wx-stn-alert").show();
}
else
{
jQuery.each(jQuery(".wx-stn-alert-text").find('.modal'),
function(i,el) {
let id = jQuery(this).attr('id')
console.log('each',i,id,typeof el,el);
jQuery('#'+id).modal('hide');
});
jQuery(".wx-stn-alert").hide();
jQuery(".wx-stn-alert-text").empty();
}
}