1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- var DBG = DBG || false
- var DBG_FAKE_ANIM = DBG_FAKE_ANIM || false
- if (!URL_FETCH_BI_AUDIT_PROGRESS) throw "Missing URL_FETCH_BI_AUDIT_PROGRESS"
- if (!jQuery('#last-raport-state').length) return;
- // 'URL_BI_AUDIT_RESULT' => Router::getRoute('UrlAction_BiAuditGenerate')->getLink(''),
- // 'ID_ARG_BI_AUDIT_RESULT' => 'ID_BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA'
- // index.php?_route=UrlAction_BiAuditGenerate&ID_BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA=102
- var IS_STARTED = false
- var DBG_COUNTER = 0;
- function updateLastRaportView(respJson) {
- if (!respJson.body || !respJson.body.ids || !respJson.body.progress) return;
- if (!jQuery('#last-raport-state').length) return;
- if(DBG)console.log('DBG:updateLastRaportView', {respJson: respJson, tblStruct: tblStruct});
- var idx = 0;
- var respId = respJson.body.ids[idx]
- var progress = respJson.body.progress[idx]
- var percent = Math.round(100 * progress)
- if (DBG_FAKE_ANIM && percent > 0 && percent < 100) percent += (DBG_COUNTER * 10)
- var status = (respJson.body.statuses[idx]) ? respJson.body.statuses[idx] : ''
- if (DBG_FAKE_ANIM) status = (percent < 100) ? 'IN_PROGRES' : 'DONE'
- var statusInfo = (respJson.body.statusesInfo[idx]) ? respJson.body.statusesInfo[idx] : ''
- jQuery('#last-raport-state').get(0).innerHTML = '';
- var el = jQuery('<span style="display:inline-block; width:140px; text-align:center">' + status + '</span>');
- jQuery('#last-raport-state').append(el);
- if ('GENERATED' === status) {
- var resultLink = URL_BI_AUDIT_RESULT + '&' + ID_ARG_BI_AUDIT_RESULT + '=' + respId;
- jQuery('#last-raport-state').append('<a style="margin-left:8px; padding:6px 12px; vertical-align:top" class="btn btn-default btn-link" href="'+resultLink+'">Wyniki</a>');
- }
- jQuery('#last-raport-state').append('<span style="display:block; font-size:12px; color:#c0c0c0; line-height:16px"> '+statusInfo+' </span>');
- if(DBG)console.log('DBG:updateLastRaportView loop ('+idx+', el)', {el: el, progress: progress, pr: percent });
- updatePercentView(el, {
- percent: percent,
- status: status,
- })
- }
- function updatePercentView(el, props) {
- var hrNode = jQuery(el).find('hr')
- if (!hrNode.length) hrNode = jQuery('<hr>').appendTo(el)
- if (props.percent > 100) props.percent = 100
- hrNode.attr('style', "margin:0; padding:0; border-bottom:3px solid #f00; width:" + props.percent + "%")
- if (props.status) jQuery(el).find('span').text(props.status)
- }
- function updateLastRaportProgress() {
- DBG_COUNTER += 1
- if(DBG)console.log('updateLastRaportProgress ('+DBG_COUNTER+')');
- global.fetch(URL_FETCH_BI_AUDIT_PROGRESS, {
- method: 'POST',
- credentials: 'same-origin',
- body: JSON.stringify({
- ids: 'last'
- })
- }).then(function (response) {
- return response.json()
- }).then(function (respJson) {
- updateLastRaportView(respJson)
- IS_STARTED = false;
- startUpdateLastRaportProgress()
- }).catch(function (e) {
- if(DBG)console.warn('e:', e)
- IS_STARTED = false
- })
- IS_STARTED = false
- }
- function startUpdateLastRaportProgress() {
- if (IS_STARTED) return;
- IS_STARTED = true
- if(DBG)console.log('START updateLastRaportProgress ...');
- global.setTimeout(updateLastRaportProgress, 1000)
- }
- setTimeout(startUpdateLastRaportProgress, 100);
|