Browse Source

CHG: config.ini changed parameter SLEEPTIME from seconds to milliseconds
CHG: BlinkOff() removed last paramter in FB API
ADD: FB_GENERIC to Notifications() classes
ADD: notify() -> if code == FB_GENERIC create new record instead to avoid save
CHG: getServerStatus() -> the count is made now on 'caption' field instead 'code'. Is more efficient
ADD: getServerStatus() -> new two methods StoreWebSession() and RestoreWebSession() usefull if in CLI calls need to read WEB session
CHG: omlink.js -> add fetchHeaders array, for fetch() call header default. Changed setInterval time to 3000 for refresh notification area
FIX: omlink.js -> used strict comparisons

Giancarlo Voci 8 years ago
parent
commit
222fab5529

+ 1 - 1
.gitignore

@@ -52,4 +52,4 @@ tmp
 /bundle.css
 /bundle.css
 *.min.js
 *.min.js
 *.min.css
 *.min.css
-/config.bin
+/cfg/*.bin

+ 1 - 1
cfg/config.ini

@@ -31,4 +31,4 @@ pass=ZrgzkvJrOKnNSCnPnGz3u{A6eHSNXVvs
 
 
 
 
 [FINDBOXSERVICE]
 [FINDBOXSERVICE]
-SLEEPTIME=1
+SLEEPTIME=500

+ 2 - 2
src/OpenMind/FindBox/FindBoxService.php

@@ -130,7 +130,7 @@ class FindBoxService
         // ----------
         // ----------
         // Restart blink if blink is ended
         // Restart blink if blink is ended
         $blinkEndTime = time() - $label->tsLastLongBlink;
         $blinkEndTime = time() - $label->tsLastLongBlink;
-        /** @var QueueCommand $label*/
+        /** @var QueueCommand $label */
         $calcDuration = $label->getBlinkDuration();
         $calcDuration = $label->getBlinkDuration();
         if ($blinkEndTime > $calcDuration) {
         if ($blinkEndTime > $calcDuration) {
           echo $this->getStrTime() . "Auto restart blinking for label $label->id\n";
           echo $this->getStrTime() . "Auto restart blinking for label $label->id\n";
@@ -147,7 +147,7 @@ class FindBoxService
       ob_flush();
       ob_flush();
       flush();
       flush();
       //echo $this->getStrTime() . memory_get_usage() . PHP_EOL;
       //echo $this->getStrTime() . memory_get_usage() . PHP_EOL;
-      sleep($f3->get('FINDBOXSERVICE.SLEEPTIME'));
+      usleep($f3->get('FINDBOXSERVICE.SLEEPTIME') * 1000);
     }
     }
 
 
     return;
     return;

+ 1 - 1
src/OpenMind/FindBox/SmartESL.php

@@ -117,7 +117,7 @@ class SmartESL
   public function BlinkOff()
   public function BlinkOff()
   {
   {
     $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
     $URI = "/1.0.0/index.php/smartesl.blink_special/2.0.0/";
-    $this->core->CallAPI($URI, "[[\"{$this->labels[0]}\"],0,0,0,0,0,1]", true);
+    $this->core->CallAPI($URI, "[[\"{$this->labels[0]}\"],0,0,0,0,0]", true);
   }
   }
 
 
   public function Display(string $templateId, string $barcode)
   public function Display(string $templateId, string $barcode)

+ 1 - 1
src/OpenMind/System/ErrorHandlers.php

@@ -41,9 +41,9 @@ class ErrorHandlers
       return;
       return;
     }
     }
 
 
+    // with return FALSE i leave to F3 the output of error code in AJAX
     //http_response_code(400);
     //http_response_code(400);
     //echo join(' - ', $arrayError);
     //echo join(' - ', $arrayError);
-    // with return FALSE i leave to F3 the output of error code in AJAX
     return FALSE;
     return FALSE;
   }
   }
 
 

+ 2 - 1
src/OpenMind/System/Notifications.php

@@ -12,6 +12,7 @@ use DB\SQL\Mapper;
 
 
 class Notifications extends Mapper
 class Notifications extends Mapper
 {
 {
+  const FB_GENERIC = 01;
   const FB_NOTALIVE = 11;
   const FB_NOTALIVE = 11;
 
 
   public function __construct()
   public function __construct()
@@ -48,7 +49,7 @@ class Notifications extends Mapper
 
 
   public function notify(int $code, string $caption, $link = '#')
   public function notify(int $code, string $caption, $link = '#')
   {
   {
-    if ($this->check($code)) {
+    if ($code == $this::FB_GENERIC || $this->check($code)) {
       $this->reset();
       $this->reset();
       $this->code = $code;
       $this->code = $code;
       $this->caption = $caption;
       $this->caption = $caption;

+ 31 - 2
src/OpenMind/System/System.php

@@ -84,10 +84,10 @@ class System extends PluginStrategy
 
 
     $ret = [];
     $ret = [];
     $notifications = new Notifications();
     $notifications = new Notifications();
-    $notifications->count = 'count(code)';
+    $notifications->count = 'count(caption)';
     $sqlGroupBy = array(
     $sqlGroupBy = array(
       'order' => 'timestamp DESC',
       'order' => 'timestamp DESC',
-      'group' => 'code'
+      'group' => 'caption'
     );
     );
     $ret['notify'] = array_map(array($notifications, 'cast'), $notifications->find(NULL, $sqlGroupBy));
     $ret['notify'] = array_map(array($notifications, 'cast'), $notifications->find(NULL, $sqlGroupBy));
 
 
@@ -101,6 +101,35 @@ class System extends PluginStrategy
     else
     else
       (new Notifications())->emptyAll();
       (new Notifications())->emptyAll();
   }
   }
+
+  /**
+   * Store in F3 cache the session id, usefull for CLI call
+   *
+   * @see System::RestoreWebSession()
+   * @param string $cacheName
+   */
+  public Function StoreWebSession(string $cacheName = 'WEBSESSIONID')
+  {
+    $this->cache->set($cacheName, session_id());
+  }
+
+  /**
+   * Restore the web session for CLI calls
+   *
+   * @see System::StoreWebSession()
+   * @param string $cacheName
+   */
+  public function RestoreWebSession(string $cacheName = 'WEBSESSIONID')
+  {
+    if ($this->cache->get($cacheName)) {
+      $id = $this->cache->get($cacheName);
+      if (isset($_SESSION)) {  // if there is already a session running
+        session_write_close(); // save and close it
+      }
+      session_id($id);
+      session_start();
+    }
+  }
 }
 }
 
 
 /** @var System $System * */
 /** @var System $System * */

+ 2 - 2
src/OpenMind/Web/Web.php

@@ -69,8 +69,8 @@ class Web extends PluginStrategy
         ]);*/
         ]);*/
 
 
     // Add to Global permission roles
     // Add to Global permission roles
-/*     $roles = new UserRoles();
-    $roles->add('importdata'); */
+/*    $roles = new UserRoles();
+    $roles->add('importdata');*/
   }
   }
 }
 }
 
 

+ 19 - 9
ui/js/omlink.js

@@ -6,10 +6,18 @@
  * @time 17:42
  * @time 17:42
  */
  */
 
 
+var fetchHeaders = {
+  'Accept': 'text/html',
+  'Content-Type': 'text/html',
+  'X-Requested-With': 'XMLHttpRequest',
+  'Cache-Control': 'no-cache',
+  'Pragma': 'no-cache',
+  'Expires': '0'
+};
 function NotificationBuilder(notifications) {
 function NotificationBuilder(notifications) {
   let tplNotify = '';
   let tplNotify = '';
   let htmlNotificationArea = '';
   let htmlNotificationArea = '';
-  if (notifications.length == 0) {
+  if (notifications.length === 0) {
     $('#notification_area_button').addClass('disabled');
     $('#notification_area_button').addClass('disabled');
     $('#sysmsgnum').empty();
     $('#sysmsgnum').empty();
   } else {
   } else {
@@ -30,9 +38,9 @@ ${tplNotify}
 }
 }
 
 
 function refreshNotificationArea() {
 function refreshNotificationArea() {
-  fetch(`${BASEURL}/api.system.getserverstatus`)
+  fetch(`${BASEURL}/api.system.getserverstatus`, {headers: fetchHeaders})
     .then(resp => {
     .then(resp => {
-      if (resp.status == 200)
+      if (resp.status === 200)
         return resp.json();
         return resp.json();
       else
       else
         return Promise.reject("getserverstatus: error");
         return Promise.reject("getserverstatus: error");
@@ -48,7 +56,7 @@ function refreshNotificationArea() {
 function NotificationDelete(link, code) {
 function NotificationDelete(link, code) {
   fetch(`${BASEURL}/api.system.removenotification/${code}`, {method: "POST"})
   fetch(`${BASEURL}/api.system.removenotification/${code}`, {method: "POST"})
     .then(() => {
     .then(() => {
-      if (link != '#')
+      if (link !== '#')
         window.location.href = `${BASEURL}${link}`;
         window.location.href = `${BASEURL}${link}`;
     })
     })
     .catch(() => {
     .catch(() => {
@@ -75,18 +83,20 @@ $(function () {
 
 
   refreshNotificationArea();
   refreshNotificationArea();
 
 
-  ForceFocus();
+  ForceFocus(); // INPUT AUTOFOCUS
 
 
-  $('form').on('submit', function () {
-    $('form input,select').prop('disabled', false);
+  $('#filters #filterIndex').val(currentFilterIdx);
+
+  $('body').on('submit', 'form', function () {
+    $('form input,form select').prop('disabled', false);
     setTimeout(function () {
     setTimeout(function () {
-      $('form input,select').prop('disabled', true);
+      $('form input,form select').prop('disabled', true);
     }, 500);
     }, 500);
   });
   });
 
 
   setInterval(() => {
   setInterval(() => {
     refreshNotificationArea();
     refreshNotificationArea();
-  }, 10000);
+  }, 3000);
 });
 });