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('' + status + ''); 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('Wyniki'); } jQuery('#last-raport-state').append(' '+statusInfo+' '); 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('
').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);