From a8dd918370f956830f9c5980d2f791cbff0f1993 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jan 2024 12:15:31 +0100 Subject: [PATCH 1/6] feat #6235 Updated readme and minor changes --- README.md | 32 +++++++++++++++++++++++--------- js/main.js | 2 +- proxy.js | 15 +++++++++++---- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7f1f153..4427c44 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,29 @@ Worker Time Control is a project developed by Verdnatura Levante SL, designed to manage time-related functionalities. This application helps in efficient time tracking and management for workers. +## Prerequisites + +Required applications. + +* Node.js +* Docker + ## Installation -1. Clone the repository: +1. Clone the repository. +```text +$ git clone https://gitea.verdnatura.es/verdnatura/worker-time-control +``` +2. Install dependencies using npm. +```text +$ npm i +``` +3. Duplicate the `.env.example` file and rename it to `.env`. Then, configure it. +``` +$ cp .env.example .env +``` - git clone https://gitea.verdnatura.es/verdnatura/worker-time-control -3. Install dependencies using npm: - - npm install - -## Usage - - npm start +## Launch +``` +$ npm start +``` \ No newline at end of file diff --git a/js/main.js b/js/main.js index 2919bc6..38c19d7 100644 --- a/js/main.js +++ b/js/main.js @@ -70,7 +70,7 @@ $.ajaxPrefilter(function(xhr) { headers: { Authorization : token }, - timeout: 1000, + timeout: 2000, contentType: 'application/json; charset=utf-8', dataType: 'json', processData: false, diff --git a/proxy.js b/proxy.js index 30f546f..e6bbf25 100644 --- a/proxy.js +++ b/proxy.js @@ -3,16 +3,23 @@ const dotenv = require('dotenv'); const { createProxyMiddleware } = require('http-proxy-middleware'); const app = express(); +const env = process.env; dotenv.config(); + +if (!env.TARGET || !env.PORT) { + console.error(`[ERROR] The '.env' file is not configured`); + process.exit(); +} + const apiProxy = createProxyMiddleware('/api', { - target: process.env.TARGET, - changeOrigin: true, + target: env.TARGET, + changeOrigin: true, }); app.use('/api', apiProxy); app.use('/', express.static(__dirname)); -const port = process.env.PORT; +const port = env.PORT; app.listen(port, () => { - console.log(`Server running on port: ${port}`); + console.log(`[SERVER] Running on port: ${port}`); }); -- 2.40.1 From 125d9e97fb080e5214e5a18dd82f134b112c512b Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 30 Jan 2024 14:44:44 +0100 Subject: [PATCH 2/6] feat #6235 Added device label --- css/style.css | 9 +++++++++ index.html | 3 +++ js/index.js | 25 ++++++++++++++++++------- js/main.js | 4 ++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/css/style.css b/css/style.css index 3586062..b9b664c 100644 --- a/css/style.css +++ b/css/style.css @@ -26,6 +26,15 @@ h1 { span { color: #ED4947; } +.device { + position: fixed; + bottom: 20px; + left: 20px; + float: left; + font-size: 1em; + font-weight: 400; + color: white; +} .total { float: right; font-weight: bold; diff --git a/index.html b/index.html index c29bfe9..7ce1b37 100644 --- a/index.html +++ b/index.html @@ -82,6 +82,9 @@ and open the template in the editor.

developed with by Verdnatura

+ +

+
diff --git a/js/index.js b/js/index.js index b6dbdc8..929e86d 100644 --- a/js/index.js +++ b/js/index.js @@ -7,12 +7,14 @@ $(document).ready(function () { function setEvents() { const heartEl = document.querySelector('body > h1 > span'); - + refreshDeviceLabel() + heartEl.addEventListener('click', function() { Swal.fire({ title: 'Iniciar sesión', html: - ` + ` + `, confirmButtonText: 'Login', showCloseButton: true, @@ -21,7 +23,8 @@ function setEvents() { if(result.isConfirmed) { const user = $('#user').val(); const pass = $('#pass').val(); - signIn(user,pass); + const device = $('#device').val(); + signIn(user, pass, device); } }); }); @@ -36,8 +39,11 @@ function setEvents() { $("#txtPin").text("ID USUARIO"); }); - $(".btnOk").on("click", login); - + $(".btnOk").on("click", function () { + if (pin) { + login(); + }; + }); } function login() { @@ -56,7 +62,7 @@ function login() { }); } -function signIn(user, password) { +function signIn(user, password, device) { $.post({ urlPath: 'vnUsers/sign-in', jsonData: {user, password}, @@ -65,9 +71,14 @@ function signIn(user, password) { localStorage.setItem("token", data.token); localStorage.setItem("ttl", data.ttl); localStorage.setItem("user", user); - localStorage.setItem("password", password); + localStorage.setItem("device", device); localStorage.setItem("created", Date.now()); getTokenConfig(); + refreshDeviceLabel(); }, }) +} + +function refreshDeviceLabel() { + $("#deviceLabel").text(localStorage.getItem('device') ?? '') } \ No newline at end of file diff --git a/js/main.js b/js/main.js index 38c19d7..6abda0e 100644 --- a/js/main.js +++ b/js/main.js @@ -66,11 +66,11 @@ $.ajaxPrefilter(function(xhr) { const token = localStorage.getItem('token') Object.assign(xhr, { - url: `api/${xhr.urlPath}`, + url: `/api/${xhr.urlPath}`, headers: { Authorization : token }, - timeout: 2000, + timeout: 1000, contentType: 'application/json; charset=utf-8', dataType: 'json', processData: false, -- 2.40.1 From 2e310bc06c6905dee4f7a4c7b87dfe19207b3786 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 31 Jan 2024 07:49:25 +0100 Subject: [PATCH 3/6] feat #6235 Added device param --- js/clockIn.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/clockIn.js b/js/clockIn.js index 748f61f..50bb19d 100644 --- a/js/clockIn.js +++ b/js/clockIn.js @@ -45,7 +45,8 @@ function setView() { function fichar(direction) { const data = { workerFk: userData['userFk'], - direction + direction, + device: localStorage.getItem("device") } $.post({ -- 2.40.1 From b16ca6b83fb62f0670cf01dc7cc9ed5ca902cf5d Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 31 Jan 2024 09:04:49 +0100 Subject: [PATCH 4/6] feat #6235 Added device param --- js/main.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 6abda0e..60a2c1f 100644 --- a/js/main.js +++ b/js/main.js @@ -97,13 +97,20 @@ $.ajaxPrefilter(function(xhr) { mensaje = 'Ajax request aborted'; break; case 'error': + if (xhr?.responseJSON?.error?.name == 'UserError') { + mensaje = xhr.responseJSON.error.message; + break; + } switch (xhr.status){ case 0: mensaje = 'Not connect: Verify Network'; break; + case 504: + mensaje = 'No se ha podido conectar con Salix, consulta con informática'; + break; case 555: mensaje = JSON.parse(xhr.statusText).Message; - break; + break; default: if (xhr.status >= 400 && xhr.status < 500) mensaje = xhr.statusText; -- 2.40.1 From 886205f4a246b0b8ee9ac70b1345d81516cf03eb Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 31 Jan 2024 09:11:10 +0100 Subject: [PATCH 5/6] feat #6235 Modified timeout --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 60a2c1f..23944d3 100644 --- a/js/main.js +++ b/js/main.js @@ -70,7 +70,7 @@ $.ajaxPrefilter(function(xhr) { headers: { Authorization : token }, - timeout: 1000, + timeout: 2000, contentType: 'application/json; charset=utf-8', dataType: 'json', processData: false, -- 2.40.1 From 9d34a220334dbbfeeb0b7171663d65a549ac9835 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 12:56:52 +0100 Subject: [PATCH 6/6] fix: #6656 Concatene strings --- js/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/main.js b/js/main.js index 23944d3..1d4f89b 100644 --- a/js/main.js +++ b/js/main.js @@ -45,7 +45,7 @@ function getTokenConfig() { } function checkValidity() { - const created = localStorage.getItem('created'); + const created = +localStorage.getItem('created'); const ttl = localStorage.getItem('ttl'); if (isCheckingToken || !created) return; -- 2.40.1