diff --git a/framework/public/devUI/assets/js/uc_balancing.js b/framework/public/devUI/assets/js/uc_balancing.js index 0d25413..9691e87 100644 --- a/framework/public/devUI/assets/js/uc_balancing.js +++ b/framework/public/devUI/assets/js/uc_balancing.js @@ -1,265 +1,150 @@ $(document).ready(function() { let customLabels = {}; - const balanceRetrieve = (assetId,epoch) => { - window.assetId = assetId; - window.highlightEpoch = 1 * epoch; - - $('.assetLabel').html(window.assetId); - - let epochQuery = ""; - if(epoch) { - epochQuery = "&epoch="+epoch; - } - $.getJSON("/api/balancing/balance?assetId="+assetId+epochQuery,balanceRender); - $.getJSON("/api/asset/get?assetId="+assetId+"&type=balance", function(data) { - if(typeof data.balancerule !== 'undefined') { - if(typeof data.balancerule.from !== 'undefined') { - $('#allocation').val(data.balancerule.from); - $('#direction-from').attr('checked','checked'); - } - if(typeof data.balancerule.to !== 'undefined') { - $('#allocation').val(data.balancerule.to); - $('#direction-to').attr('checked','checked'); - } - } - }); + if($.urlParam('meterId')) { + window.assetId = $.urlParam('meterId'); } + if($.urlParam('assetId')) { + window.assetId = $.urlParam('assetId'); + } + + $.getJSON("/api/tariff/customLabels", function(data) { + customLabels = data; + retrieveBalances(window.assetId); + }) - const showLedger = function() { - const updateTXs = function(assetId,epoch,label) { - $.getJSON("/api/balancing/statements?assetId="+assetId+"&epoch="+epoch+"&label="+label,function(data) { - let openSaldo = 0; - let closeSaldo = 0; - let html = ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - - let hasUpstream = false; - let opening_rows = ''; - let closing_rows = ''; - - for(let i=0;i' + data[i].from + ''; - - btnclass = 'btn-light'; - - html_row += ''; - html_row += ''; - html_row += ''; - - if(data[i].label == '.clearing') { - closing_rows += html_row; - } else { - opening_rows += html_row; - } - } - html += ''; - html += ''; - html += ''; - html += ''; - html += closing_rows; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += opening_rows; - html += ''; - - html += '
 VonAnEnergie
' + (data[i].energy/1000).toFixed(3).replace('.',',') + 'kWh
Abschlussbuchungen
 
Verlauf
'; - - $('#txTable').html(html); - $('#activeFilter').off(); - $('#activeFilter').click(function() { - updateTXs(null,epoch, label); - $('#activeFilter').hide(); - $('#deactivatedFilter').show(); - }); - if(assetId !== null) { - $('.notFiltered').removeClass('text-decoration-line-through'); - $('#activeFilter').show(); - $('#deactivatedFilter').hide(); - } else { - $('.notFiltered').addClass('text-decoration-line-through'); - $('#activeFilter').hide(); - $('#deactivatedFilter').show(); - } - - $('#deactivatedFilter').click(function() { - updateTXs(window.assetId,epoch, label); - $('#activeFilter').show(); - $('#deactivatedFilter').hide(); - }); - $('.btnAsset').off(); - $('.btnAsset').click(function() { - balanceRetrieve($(this).attr('data-assetId'),epoch); - $('#modalStatement').modal('hide'); - }); - }); + const renderTransactions = function(data) { + let html = ''; + html += ''; + html += ''; + html += ''; + html += ''; + html += ''; + for(let i=0;i'; + + html += ''; + html += ''; + html += ''; } - - $('.filterAsset').html(window.assetId); - $('#txTable').html('...'); - $('#balanceModal').html('...'); - if( ($(this).data('sealed')) && ($(this).data('sealed').length > 0)) { + html += ''; + html += '
VonNachEnergie
'+(data.transactions[i].energy/1000).toFixed(3).replace('.',',')+'kWh
'; + $('#txTable').html(html); + $('#balanceHeader').html("Bilanzierung: "+window.assetId+" - Produkt: "+data.epoch); + if(typeof data.seal !=='undefined') { + $('#sealBtn').removeClass('btn-warning'); $('#sealBtn').html(''); - $('#sealBtn').addClass('btn-light'); - $('#sealBtn').removeClass('btn-warning') $('#sealBtn').attr('disabled','disabled'); - $.getJSON("/api/balancing/decodeSeal?seal="+$(this).data('sealed'),function(data) { - if(data.from == window.assetId) { - $('#fromorto').html('Marktpartner'); - $('#marketpartner').html(''); - } else { - $('#fromorto').html('Marktpartner'); - $('#marketpartner').html(''); - } - $('.btnAsset').off(); - $('.btnAsset').click(function() { - balanceRetrieve($(this).attr('data-assetId'),epoch); - $('#modalStatement').modal('hide'); - }); - }) } else { - $('#sealBtn').html(''); $('#sealBtn').addClass('btn-warning'); - $('#sealBtn').removeClass('btn-light'); + $('#sealBtn').html(''); $('#sealBtn').removeAttr('disabled'); } - let html = ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += ''; - html += '
AllokationStromproduktBezugLieferungVerlauf
'+window.assetId+''+new Date($(this).attr('data-time')* 1).toLocaleString()+''+($(this).attr('data-in')/1000).toFixed(3).replace('.',',')+'kWh'+($(this).attr('data-out')/1000).toFixed(3).replace('.',',')+'kWh'+(($(this).attr('data-out') - $(this).attr('data-in'))/1000).toFixed(3).replace('.',',')+'kWh
'; - $('#sealBtn').attr('data-epoch',$(this).attr('data-epoch')); - $('#balanceModal').html(html); - $('#modalStatement').modal('show'); - updateTXs(window.assetId,$(this).attr('data-epoch'), $(this).attr('data-label')); + $('#sealBtn').off(); + $('#sealBtn').click(function() { + $.getJSON("/api/balancing/seal?assetId="+window.assetId+"&epoch="+data.epoch, function(data) { + retrieveBalances(window.assetId); + $('#modalTransactions').modal('hide'); + }); + }); + $('.openBalance').off(); + $('.openBalance').click(function() { + window.assetId = $(this).attr('data-assetId'); + retrieveBalances(window.assetId,$(this).attr('data-epoch')); + $('#modalTransactions').modal('hide'); + }) } - - const balanceRender = (data) => { - if(data.length == 0) { - $('#epochbalance').html(""); - return; - } - let html = ''; + const renderBalances = function(data,highlight) { + let html =''; + html += '
'; html += ''; html += ''; html += ''; html += ''; - html += ''; - html += ''; - html += ''; - html += ''; + html += ''; + html += ''; html += ''; html += ''; html += ''; + let lastEpoch = 0; + for(let i=0;i'; - } - html += ''; - html += '' + customLabels[data[i].label] + ''; - html += '' + (data[i].in/1000).toFixed(3).replace('.',',') + 'kWh'; - html += '' + (data[i].out/1000).toFixed(3).replace('.',',') + 'kWh'; - html += '' + ((data[i].out - data[i].in)/1000).toFixed(3).replace('.',',') + 'kWh'; - html += ''; + data[i].energy *= -1; // clearerer to interpret. + html += ''; + let bgclass = ''; + if(data[i].epoch == highlight) { + bgclass = 'bg-success'; + } + if(typeof data[i].seal == 'undefined') { + html += ''; + } else { + html += ''; } + html += ''; + html += ''; + let color = 'text-danger'; + if(data[i].energy > 0) { + color = 'text-success'; + } + html += ''; + html += ''; + lastEpoch = data[i].epoch; } html += ''; - html += '
 StromproduktSegmentBezugEinspeisungSaldoZeitfensterSaldo
 '+new Date(data[i].time).toLocaleString()+''+(data[i].energy/1000).toFixed(3).replace('.',',')+'kWh
'; - $('#backBtn').attr('data-epoch',data[data.length-1].epoch); - $('#fwdBtn').attr('data-epoch',data[0].epoch + 24); - $('#epochbalance').html(html); - $('.btnLedger').off(); - $('.btnLedger').click(showLedger); - } - $.getJSON("/api/tariff/customLabels", function(data) { - customLabels = data; - - if($.urlParam('assetId')) { - $('#searchMeter').val($.urlParam('assetId')); - balanceRetrieve($.urlParam('assetId'),$.urlParam('epoch')); - } else { - balanceRetrieve('eaf_general'); - } + html += ''; + $('#balances').html(html); + $('.btnClear').off(); + $('.btnClear').click(function() { + $.getJSON("/api/balancing/seal?assetId="+window.assetId+"&epoch="+$(this).data('epoch'), function(data) { + retrieveBalances(window.assetId); + }); + }); + $('.btnProduct').off(); + $('.btnProduct').click(function() { + $.getJSON("/api/balancing/balance?assetId="+window.assetId+"&epoch="+$(this).data('epoch'), function(data) { + renderTransactions(data); + $('#modalTransactions').modal('show'); + }); + }); + $('#backBtn').off(); $('#backBtn').click(function() { - balanceRetrieve(window.assetId,$(this).attr('data-epoch')); + retrieveBalances(window.assetId,highlight,lastEpoch); }); $('#fwdBtn').click(function() { - balanceRetrieve(window.assetId,$(this).attr('data-epoch')); + retrieveBalances(window.assetId,highlight,data[0].epoch + 10); }); + } - - }); - - $('#sealBtn').click(function(e) { - $.getJSON("/api/balancing/sealBalance?assetId="+window.assetId+"&epoch="+$(this).attr('data-epoch'), function(data) { - $('#modalStatement').modal('hide'); - balanceRetrieve(window.assetId,$(this).attr('data-epoch')); + /** + * Retrieves balances for the given asset ID. + * + * @param {string} assetId - The ID of the asset. + */ + const retrieveBalances = function(assetId,highlight,before) { + $('.assetLabel').html(assetId); + $('#balances').html(''); + $.getJSON("/api/balancing/latestBalances?assetId="+assetId+"&n=10&before="+before,function(data) { + renderBalances(data,highlight); }); - }); + $.getJSON("/api/asset/get?assetId="+assetId+"&type=balance", function(data) { + if(typeof data.balancerule !== 'undefined') { + if(typeof data.balancerule.from !== 'undefined') { + $('#allocation').val(data.balancerule.from); + $('#direction-from').attr('checked','checked'); + } + if(typeof data.balancerule.to !== 'undefined') { + $('#allocation').val(data.balancerule.to); + $('#direction-to').attr('checked','checked'); + } + } + }); + } + $('#balancerule').submit(function(e) { e.preventDefault(); $('#btnRule').attr('disabled','disabled'); diff --git a/framework/public/devUI/index.html b/framework/public/devUI/index.html index 67a7b15..143d66b 100644 --- a/framework/public/devUI/index.html +++ b/framework/public/devUI/index.html @@ -20,7 +20,6 @@ -