Browse Source

* Fixed watcher.js, build.js
* Added bell and number for notifications
* Test with WebSocket
* ajax polling for get omlink server status
* Refactor of webservice rest api call, moved to System class
* Added new rest api getserverstatus
* Fixed errors in Error Handler, Logger moved to OMUtils
* fb service now manage queuesystem messages
* Added SpawnServiceProcess() but maybe removed in future.

Giancarlo Voci 8 years ago
parent
commit
7c84de3267

+ 1 - 0
TODO.txt

@@ -4,6 +4,7 @@
 [✔] TODO workaround di letture errate dello scanner: se nella picking list viene passato un labelID invece che un barcode, ricava il barcode dalla labelID
 [✔] TODO creare la lista dell'etichetta del carrello tramite XLST+XML, aggiungere la colonna quantità nominale, aggiungere l'intestazione sulla tabella con riga orizzontale di separazione
 [✔] TODO aggiungere alla fine della picking list, sulla 7" l'elenco delle quantità prelevate e delle quantità mancanti (Anomalie) e trimmare la descrizione che in alcuni casi è molto lunga
+
 [✘] TODO Implementare GetJobStatus
 [✘] TODO aggiungere un timetrack dell'operatore che parte da quando da l'ok sulla etichetta da 7" fino all'ultima etichetta
 [✘] TODO Parametrizzare nel file LABEL.INI i parametri del BlinkSpecial

+ 3 - 3
build.js

@@ -37,15 +37,15 @@ compressor.minify({
 );
 
 compressor.minify({
-    compressor: 'uglifyjs',
+    compressor: 'uglify-es',
     input: jsList,
-    output: 'ui/bundle.min.js'
+    output: 'ui/js/omlink.min.js'
   }
 );
 
 compressor.minify({
     compressor: 'no-compress',
-    input: [].concat(libList, ["ui/bundle.min.js"]),
+    input: [].concat(libList, ["ui/js/omlink.min.js"]),
     output: 'bundle.js'
   }
 );

+ 0 - 1
index.php

@@ -11,7 +11,6 @@
 require_once 'lib/f3/base.php';
 $f3 = \Base::instance();
 
-
 // Initialize App Menu
 $f3->set('GLOBALMENU', array());
 

+ 33 - 19
package-lock.json

@@ -91,7 +91,7 @@
       "dependencies": {
         "chalk": {
           "version": "1.1.3",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "requires": {
             "ansi-styles": "^2.2.1",
@@ -567,7 +567,7 @@
       "dependencies": {
         "chalk": {
           "version": "1.1.3",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "requires": {
             "ansi-styles": "^2.2.1",
@@ -682,7 +682,7 @@
       "dependencies": {
         "chalk": {
           "version": "1.1.3",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "requires": {
             "ansi-styles": "^2.2.1",
@@ -791,17 +791,17 @@
       }
     },
     "color-convert": {
-      "version": "1.9.2",
-      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.2.tgz",
-      "integrity": "sha512-3NUJZdhMhcdPn8vJ9v2UQJoH0qqoGUkYTgFEPZaPjEtwmmKUfNV46zZmgB2M5M4DCEQHMaCfWHCxiBflLm04Tg==",
+      "version": "1.9.3",
+      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
+      "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
       "requires": {
-        "color-name": "1.1.1"
+        "color-name": "1.1.3"
       }
     },
     "color-name": {
-      "version": "1.1.1",
-      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.1.tgz",
-      "integrity": "sha1-SxQVMEz1ACjqgWQ2Q72C6gWANok="
+      "version": "1.1.3",
+      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
+      "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
     },
     "colors": {
       "version": "1.1.2",
@@ -1220,11 +1220,13 @@
         },
         "balanced-match": {
           "version": "1.0.0",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "brace-expansion": {
           "version": "1.1.11",
           "bundled": true,
+          "optional": true,
           "requires": {
             "balanced-match": "^1.0.0",
             "concat-map": "0.0.1"
@@ -1237,15 +1239,18 @@
         },
         "code-point-at": {
           "version": "1.1.0",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "concat-map": {
           "version": "0.0.1",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "console-control-strings": {
           "version": "1.1.0",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "core-util-is": {
           "version": "1.0.2",
@@ -1348,7 +1353,8 @@
         },
         "inherits": {
           "version": "2.0.3",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "ini": {
           "version": "1.3.5",
@@ -1358,6 +1364,7 @@
         "is-fullwidth-code-point": {
           "version": "1.0.0",
           "bundled": true,
+          "optional": true,
           "requires": {
             "number-is-nan": "^1.0.0"
           }
@@ -1370,17 +1377,20 @@
         "minimatch": {
           "version": "3.0.4",
           "bundled": true,
+          "optional": true,
           "requires": {
             "brace-expansion": "^1.1.7"
           }
         },
         "minimist": {
           "version": "0.0.8",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "minipass": {
           "version": "2.2.4",
           "bundled": true,
+          "optional": true,
           "requires": {
             "safe-buffer": "^5.1.1",
             "yallist": "^3.0.0"
@@ -1397,6 +1407,7 @@
         "mkdirp": {
           "version": "0.5.1",
           "bundled": true,
+          "optional": true,
           "requires": {
             "minimist": "0.0.8"
           }
@@ -1469,7 +1480,8 @@
         },
         "number-is-nan": {
           "version": "1.0.1",
-          "bundled": true
+          "bundled": true,
+          "optional": true
         },
         "object-assign": {
           "version": "4.1.1",
@@ -1479,6 +1491,7 @@
         "once": {
           "version": "1.4.0",
           "bundled": true,
+          "optional": true,
           "requires": {
             "wrappy": "1"
           }
@@ -1584,6 +1597,7 @@
         "string-width": {
           "version": "1.0.2",
           "bundled": true,
+          "optional": true,
           "requires": {
             "code-point-at": "^1.0.0",
             "is-fullwidth-code-point": "^1.0.0",
@@ -1717,7 +1731,7 @@
       "dependencies": {
         "chalk": {
           "version": "1.1.3",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
+          "resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
           "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
           "requires": {
             "ansi-styles": "^2.2.1",
@@ -2284,7 +2298,7 @@
     },
     "mkdirp": {
       "version": "0.5.1",
-      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
+      "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
       "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
       "requires": {
         "minimist": "0.0.8"

+ 6 - 12
src/OpenMind/FindBox/FindBox.php

@@ -15,30 +15,24 @@ class FindBox extends PluginStrategy
   public function __construct()
   {
     // CLI scripts
-    $this->AddRoute('GET /api.fb.service', __NAMESPACE__ . '\FindBoxService->Main');
+    $this->AddRoute('GET /cli.fb.service', __NAMESPACE__ . '\FindBoxService->Main');
   }
 
   /**
-   * Spawn and detach a new php process to call a webservice of OM-Link. With DEBUG>0 enable XDEBUG to stop to breakpoints
-   * This method make use of F3 Cache to pass object
-   *
-   * @param $data object to serialize
-   * @throws \Exception in case of no operative system is detected
+   * Check if is running, Spawn and detach the OM-Link background service.
+   * With DEBUG>0 enable XDEBUG to stop to breakpoints
    */
-  private function SpawnServiceProcess($data)
+  private function SpawnServiceProcess()
   {
     global $f3;
 
-    $objCacheId = 'obj' . rand(10, 200);
-    $this->cache->set($objCacheId, $data);
-
-    $cacheSeed = $f3->get('SEED');
     if ($f3->get('DEBUG') > 0)
       putenv('XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"');
 
-    $apiCall = "index.php /api.fb.service";
+    $apiCall = "index.php /cli.fb.service";
     switch (strtolower(PHP_OS_FAMILY)) {
       case 'linux':
+        // TODO: da TESTARE sotto Linux, specialmente putenv()
         $command = "nohup {$f3->get('PHP_PATH')} {$apiCall} &";
         break;
       case 'windows':

+ 16 - 3
src/OpenMind/FindBox/FindBoxService.php

@@ -24,6 +24,19 @@ class FindBoxService
     $this->labelToBlink = [];
   }
 
+  private function updateServiceStatus()
+  {
+    $qs = new QueueSystem('FindBoxService_isAlive');
+    if ($qs->check()) {
+      $qs->reset();
+      $qs->command = time();
+      $qs->servicename = 'FindBoxService_isAlive';
+      $qs->save();
+    } else
+      $qs->command = time();
+    $qs->update();
+  }
+
   private function getCurrentQueue()
   {
     echo "Checking QueueSystem               \n";
@@ -79,11 +92,10 @@ class FindBoxService
   {
     while (true) {
 
-      $this->getCurrentQueue();
+      $this->updateServiceStatus();
 
-      //$this->parseQueue();
+      $this->getCurrentQueue();
 
-      /** @var QueueCommand $label */
       echo 'Label in cache: ' . count($this->labelToBlink) . "     \n";
       foreach($this->labelToBlink as $labelId => $label) {
 
@@ -119,6 +131,7 @@ class FindBoxService
       sleep(1);
       echo "Restart loop                  \n";
       ob_flush();
+      flush();
 
     }
 

+ 2 - 3
src/OpenMind/System/ErrorHandlers.php

@@ -52,7 +52,6 @@ class ErrorHandlers
    */
   function WriteLog($logMessage, $traceNumber = 1)
   {
-    Global $System;
     $trace = debug_backtrace();
 
     if (count($trace) > 1) {
@@ -62,11 +61,11 @@ class ErrorHandlers
       $class = isset($trace['class']) ? $trace['class'] . ':' : '';
       $line = isset($trace['line']) ? $trace['line'] . ':' : '';
       //$userAgent = '(' . join(', ', $UA) . ')';
-      $System->getLogger()->write("{$line}{$class}{$method} " . str_replace(array("\r", "\n"), '', $logMessage));
+      OMUtils::getInstance()->getLogger()->write("{$line}{$class}{$method} " . str_replace(array("\r", "\n"), '', $logMessage));
       return;
     }
 
-    $System->getLogger()->write($logMessage);
+    OMUtils::getInstance()->getLogger()->write($logMessage);
   }
 
 }

+ 17 - 0
src/OpenMind/System/Notifications.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Giancarlo
+ * Date: 29/08/2018
+ * Time: 16:36
+ */
+
+namespace OpenMind\System;
+
+
+class Notifications
+{
+  public function __construct()
+  {
+  }
+}

+ 19 - 1
src/OpenMind/System/OMUtils.php

@@ -14,6 +14,24 @@ use RecursiveIteratorIterator;
 
 class OMUtils
 {
+
+  private $Logger;
+
+  public function __construct()
+  {
+    $this->Logger = new \Log('Site.log');
+  }
+
+  /**
+   * Get logger classe
+   *
+   * @return \Log
+   */
+  public function getLogger(): \Log
+  {
+    return $this->Logger;
+  }
+
   public static function getInstance()
   {
     static $instance = null;
@@ -74,7 +92,7 @@ class OMUtils
    */
   public function LoadEncryptedConfig(string $path)
   {
-    if(!file_exists($path))
+    if (!file_exists($path))
       throw new \Exception('Config file not found');
 
     $tmpFilepath = tempnam(sys_get_temp_dir(), 'om');

+ 6 - 1
src/OpenMind/System/QueueSystem.php

@@ -31,7 +31,7 @@ class QueueSystem extends Mapper
 
   /**
    * Send object to <$serviceName>.
-   * send() $obj will be serialized before send to queue
+   * send() serialize $obj before send to queue
    *
    * @param $obj
    */
@@ -44,6 +44,11 @@ class QueueSystem extends Mapper
     $this->save();
   }
 
+  /**
+   * Retrieve and unserialize current object
+   *
+   * @return mixed
+   */
   public function getCommandObject() {
     $decodedObj = base64_decode($this->command);
     $obj = unserialize($decodedObj);

+ 14 - 11
src/OpenMind/System/System.php

@@ -10,7 +10,6 @@ namespace OpenMind\System;
 
 class System extends PluginStrategy
 {
-  private $Logger;
   private $cache;
 
   public function __construct()
@@ -21,8 +20,6 @@ class System extends PluginStrategy
 
     $this->cache = \Cache::instance();
 
-    $this->Logger = new \Log('Site.log');
-
     // Set Database connection
     try {
       $f3->set('DB',
@@ -32,22 +29,20 @@ class System extends PluginStrategy
           $f3->get('dbpass'),
           array(
             \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
-            \PDO::ATTR_PERSISTENT => TRUE
+            \PDO::ATTR_PERSISTENT => FALSE
           )));
     } catch (PDOException $e) {
       die($e->getMessage());
     }
 
+    $this->setSystemRoutes();
+
   }
 
-  /**
-   * Get logger classe
-   *
-   * @return \Log
-   */
-  public function getLogger(): \Log
+  private function setSystemRoutes()
   {
-    return $this->Logger;
+    $this->AddRoute('GET /getserverstatus', __NAMESPACE__ . '\System->getServerStatus');
+    $this->AddRoute('PUT /api.system.kbd.insert', __NAMESPACE__ . '\System->insertKbdCode');
   }
 
   /**
@@ -59,6 +54,14 @@ class System extends PluginStrategy
   {
     return $this->cache;
   }
+
+  public function getServerStatus($f3)
+  {
+    // TODO da finire
+    echo json_encode([
+      'notify' => 9
+    ]);
+  }
 }
 
 /** @var System $System * */

+ 20 - 4
ui/css/omlink.css

@@ -116,18 +116,34 @@ input::-ms-input-placeholder {
 
 @keyframes blink {
   0% {
-    background-color: #afecbd;
+    -webkit-opacity: 0.1;
+    -moz-opacity: 0.1;
+    -ms-opacity: 0.1;
+    -o-opacity: 0.1;
+    opacity: 0.1;
   }
   100% {
-    background-color: #1e7e34;
+    -webkit-opacity: 1;
+    -moz-opacity: 1;
+    -ms-opacity: 1;
+    -o-opacity: 1;
+    opacity: 1;
   }
 }
 @-webkit-keyframes blink {
   0% {
-    background-color: #afecbd;
+    -webkit-opacity: 0.1;
+    -moz-opacity: 0.1;
+    -ms-opacity: 0.1;
+    -o-opacity: 0.1;
+    opacity: 0.1;
   }
   100% {
-    background-color: #1e7e34;
+    -webkit-opacity: 1;
+    -moz-opacity: 1;
+    -ms-opacity: 1;
+    -o-opacity: 1;
+    opacity: 1;
   }
 }
 .blink {

+ 8 - 8
ui/css/omlink.scss

@@ -137,23 +137,23 @@ input::-ms-input-placeholder {
 // Blink Effect
 @keyframes blink {
   0% {
-   // @include prefix(opacity, 0);
-    background-color: lighten(#28a745, 40%);
+   @include prefix(opacity, 0.1);
+    // background-color: lighten(#28a745, 40%);
   }
   100% {
-   // @include prefix(opacity, 1);
-    background-color: darken(#28a745, 10%);
+   @include prefix(opacity, 1);
+   // background-color: darken(#28a745, 10%);
   }
 }
 
 @-webkit-keyframes blink {
   0% {
-    // @include prefix(opacity, 0);
-    background-color: lighten(#28a745, 40%);
+    @include prefix(opacity, 0.1);
+    // background-color: lighten(#28a745, 40%);
   }
   100% {
-    // @include prefix(opacity, 1);
-    background-color: darken(#28a745, 10%);
+    @include prefix(opacity, 1);
+    // background-color: darken(#28a745, 10%);
   }
 }
 

BIN
ui/favicon_dimatec.ico


+ 7 - 3
ui/header.tpl

@@ -1,7 +1,11 @@
 <nav class="navbar sticky-top navbar-dark om-shadow navbar-expand">
 	<a href="{{@BASEURL}}/"><img class="img-fluid om-shadow navbar-brand customerlogo" src="{{@LOGO_CUSTOMER}}"/></a>
 	<div class="collapse navbar-collapse"></div>
-	<a class="navbar-brand" href="{{@BASEURL}}/logout">
-		<img src="{{@ICON_LOGOUT}}" class="img-fluid om-shadow"/>
-	</a>
+	<div class="navbar-brand">
+		<a href="javascript:void(0)" onclick="javascript:alert('Not implemented')" style="position: relative; margin-right: 20px">
+			<span>&#x1f514;</span>
+			<span id="sysmsgnum" class="blink badge badge-light" style="color: white; background-color: red; font-size: 40%; position: absolute; left: 15px; bottom: 0"></span>
+		</a>
+		<a href="{{@BASEURL}}/logout"><img src="{{@ICON_LOGOUT}}" class="img-fluid om-shadow"/></a>
+	</div>
 </nav>

+ 29 - 1
ui/js/omlink.js

@@ -6,11 +6,39 @@
  * @time 17:42
  */
 
-$(function(){
+$(function () {
+
+  var ws = new WebSocket('ws://localhost:80');
+  ws.onopen = function () {
+    console.log('websocket  connection stabilita...')
+    ws.send('hello')
+  }
+  ws.onmessage = function (message) {
+    console.log('Messaggio ricevuto :',message);
+  }
+
+
   $('form').on('submit', function () {
     $('form input,select').prop('disabled', false);
     setTimeout(function () {
       $('form input,select').prop('disabled', true);
     }, 500);
   });
+
+  setInterval(() => {
+    fetch('/omlink/getserverstatus')
+      .then(resp => {
+        if (resp.status == 200)
+          return resp.json();
+        else
+          return Promise.reject("getserverstatus: error");
+      })
+      .then(data => {
+        $('#sysmsgnum').html(data.notify);
+      })
+      .catch(err => {
+        console.log(err);
+      });
+  }, 5000);
 });
+

+ 16 - 10
watcher.js

@@ -1,41 +1,47 @@
 const fs = require('fs');
-const { exec } = require('child_process');
+const {exec} = require('child_process');
 
 // this is for fix because the event fire twice
 let twiceFix = false;
 
 function compileAll(event, fname) {
   console.log(`${fname} as changed`);
-  if(event == 'change' && twiceFix) {
+  if (event == 'change' && twiceFix) {
     twiceFix = false;
-    exec('sass ui/css/omlink.scss:ui/css/omlink.css', (error, out, err) => {
-      console.log('------------------------------ compileAll() ------------------------------');
-      if(error) {
+    exec('npx sass ui/css/omlink.scss:ui/css/omlink.css', (error, out, err) => {
+      console.log('------------------------------ CSS built ------------------------------');
+      if (error) {
         console.log(error);
         return;
       }
-      exec('npm run build dimatec');
+      exec('npm run build', (error, out, err) => {
+        console.log('------------------------------ Bundle JS/CSS ------------------------------');
+        if (error) {
+          console.log(error);
+          return;
+        }
+      });
     });
   }
   twiceFix = true;
 }
 
 console.log('Adding watcher for ui/css/omlink.scss');
-fs.watch('ui/css/omlink.scss', function(event, fname) {
+fs.watch('ui/css/omlink.scss', function (event, fname) {
   compileAll(event, fname);
 });
 
 console.log('Adding watcher for ui/customizations/dimatec.scss');
-fs.watch('ui/customizations/dimatec.scss', function(event, fname) {
+fs.watch('ui/customizations/dimatec.scss', function (event, fname) {
   compileAll(event, fname);
 });
 
 console.log('Adding watcher for ui/customizations/lamborghini.scss');
-fs.watch('ui/customizations/lamborghini.scss', function(event, fname) {
+fs.watch('ui/customizations/lamborghini.scss', function (event, fname) {
   compileAll(event, fname);
 });
 
 console.log('Adding watcher for ui/js/onlink.js');
-fs.watch('ui/js/omlink.js', function(event, fname) {
+fs.watch('ui/js/omlink.js', function (event, fname) {
   compileAll(event, fname);
 });