Browse Source

added last raport status

Piotr Labudda 7 years ago
parent
commit
46765b95c9
4 changed files with 102 additions and 0 deletions
  1. 86 0
      theme/assets/js/updateLastRaportProgress.js
  2. 8 0
      theme/bocian.php
  3. 2 0
      theme/view/top.php
  4. 6 0
      tools/Bocian.php

+ 86 - 0
theme/assets/js/updateLastRaportProgress.js

@@ -0,0 +1,86 @@
+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);

+ 8 - 0
theme/bocian.php

@@ -43,6 +43,14 @@ class Theme_bocian extends ThemeDefault {
 				'URL_FETCH_BI_AUDIT_PROGRESS' => Router::getRoute('UrlAction_Bocian')->getLink('fetchProgressAjax')
 			]);
 		}
+
+		UI::inlineJS(dirname(__FILE__) . '/assets/js/updateLastRaportProgress.js', [
+			'DBG' => (V::get('DBG', '', $_GET)),
+			'DBG_FAKE_ANIM' => (V::get('DBG_FAKE_ANIM', '', $_GET)),
+			'URL_FETCH_BI_AUDIT_PROGRESS' => Router::getRoute('UrlAction_Bocian')->getLink('fetchProgressAjax'),
+			'URL_BI_AUDIT_RESULT' => Router::getRoute('UrlAction_BiAuditGenerate')->getLink(''),
+			'ID_ARG_BI_AUDIT_RESULT' => 'ID_BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA'
+		]);
 	}
 
 	function login($data) {

+ 2 - 0
theme/view/top.php

@@ -210,6 +210,8 @@
 	                            <li><a href="<?php echo Request::getPathUri(); ?>index.php?_route=Menu" title="Menu silnika procesy5" class="btn btn-success">Menu</a></li>
                             </ul>
                         </div>
+                        <div class="smad-heder-title menu-item" style="vertical-align:top"><span class="smad-line-red">|</span> OSTATNI RAPORT:</div>
+                        <div class="menu-item" id="last-raport-state"></div>
                     </div>
                 </div>
                 <div class="col-md-6 padding-lr-0">

+ 6 - 0
tools/Bocian.php

@@ -3154,6 +3154,12 @@ public function showPowiazaniaEnergaRumKontrahenciPowiazania($items) {
 		if (empty($args['ids'])) return [ 'msg' => "empty ids", 'type' => "success" ];
 		$ids = $args['ids'];
 
+		if ('last' === $ids) {
+			$ids = [
+				DB::getPDO()->fetchValue(" select ID from BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA order by ID DESC limit 1 ")
+			];
+		}
+
 		// private static function getDirectory($table, $id) {
 		$firstId = reset($ids);
 		{