From 1569a0797ec009c5ff7bd9be16a3e447e64afd75 Mon Sep 17 00:00:00 2001 From: igor Date: Tue, 7 Jul 2026 23:37:44 +0200 Subject: [PATCH] zmena generovania backend.js na JavaScript lebo Vue projekt nie je typescript, pridany deploy.bat skript pre nasadenie na produkciu, --- backend/config/Configuration.php | 6 +- backend/scripts/buildTypeScript.php | 18 +++-- backend/src/Init.php | 1 - deploy.bat | 9 +++ dev.bat | 2 + frontend/package.json | 2 +- frontend/src/backend.js | 113 ++++++++++++++++++++++++++-- frontend/src/views/Dashboard.vue | 2 +- 8 files changed, 134 insertions(+), 19 deletions(-) create mode 100644 deploy.bat create mode 100644 dev.bat diff --git a/backend/config/Configuration.php b/backend/config/Configuration.php index 6c96e15..eec67b4 100644 --- a/backend/config/Configuration.php +++ b/backend/config/Configuration.php @@ -29,10 +29,10 @@ if (!$loaded) { } $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https://" : "http://"; -$host = $_SERVER['HTTP_HOST']; -$uri = $_SERVER['REQUEST_URI']; // obsahuje aj query string +$host = $_SERVER['HTTP_HOST'] ?? ($_SERVER['SERVER_NAME'] ?? 'localhost'); +$script_name = $_SERVER['SCRIPT_NAME'] ?? ''; -define('URL_PREFIX', $protocol.$host.str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME'])); +define('URL_PREFIX', $protocol.$host.str_replace(basename($script_name), '', $script_name)); define('UPLOAD_DIR_ATTACHMENTS', __DIR__.'/../../data/attachments/'); if (!file_exists(UPLOAD_DIR_ATTACHMENTS)) { diff --git a/backend/scripts/buildTypeScript.php b/backend/scripts/buildTypeScript.php index 621f0d1..b07ef0c 100644 --- a/backend/scripts/buildTypeScript.php +++ b/backend/scripts/buildTypeScript.php @@ -1,19 +1,25 @@ { + var value = headers[key]; + if (typeof value === 'undefined' || value === null) return; + xhttp.setRequestHeader(key, value); + }); + } + + bearerSet(token) { + var storage = this.getStorage(); + if (storage == null) return; + token = this.normalizeBearerToken(token); + if (token == null) { + storage.removeItem(this.bearerStorageKey); + return; + } + storage.setItem(this.bearerStorageKey, token); + } + + addResponseHandler(handler) { + this.responseHandlers.push(handler); + return () => { + this.responseHandlers = this.responseHandlers.filter(registeredHandler => registeredHandler !== handler); + }; + } + + addErrorHandler(handler) { + this.errorHandlers.push(handler); + return () => { + this.errorHandlers = this.errorHandlers.filter(registeredHandler => registeredHandler !== handler); + }; + } + + emitResponseHandlers(response, context) { + this.responseHandlers.forEach(handler => { + try { + handler(response, context); + } catch (error) { + // Response handlers must not change the API request result. + } + }); + } + + emitErrorHandlers(response, context) { + this.errorHandlers.forEach(handler => { + try { + handler(response, context); + } catch (error) { + // Error handlers must not change the API request result. + } + }); + } + + emitHandlers(response, context) { + this.emitResponseHandlers(response, context); + if (response.status === 'ERROR') this.emitErrorHandlers(response, context); + } /* ---------------------------------------------------- * General API call */ call(method, data, callback) { var xhttp = new XMLHttpRequest(); + var headers = this.getRequestHeaders(); + var api = this; xhttp.withCredentials = true; xhttp.onreadystatechange = function() { - if (this.readyState == 4) { - if (this.status == 200) { - if (callback != null) callback(JSON.parse(this.responseText)); + if (this.readyState === 4) { + var response; + if (this.status === 200) { + response = JSON.parse(this.responseText); } else { - if (callback != null) callback({'status': 'ERROR', 'message': 'HTTP STATUS ' + this.status}); + response = {'status': 'ERROR', 'msg': 'HTTP STATUS ' + this.status}; } + var context = {method: method, data: data, httpStatus: this.status}; + api.emitHandlers(response, context); + if (callback != null) callback(response); } } var form_data = new FormData(); Object.keys(data).forEach(key => { let val = data[key]; + if (typeof val === 'undefined') return; if (typeof val == 'object') val = JSON.stringify(val); form_data.append(key, val); }); xhttp.open('POST', this.endpoint + '?action=' + method); + this.applyHeaders(xhttp, headers); xhttp.send(form_data); } callPromise(method, data) { return new Promise((resolve, reject) => { this.call(method, data, function(response) { - if (method == '__HELP__') { + if (method === '__HELP__') { resolve(response); return; } - if (response.status == 'OK') { + if (response.status === 'OK') { resolve(response.data); } else { reject(response.msg); diff --git a/frontend/src/views/Dashboard.vue b/frontend/src/views/Dashboard.vue index 7ebce81..0a1ed93 100644 --- a/frontend/src/views/Dashboard.vue +++ b/frontend/src/views/Dashboard.vue @@ -237,7 +237,7 @@ export default { for (let i = 0; i < for_reorder.length; i++) { new_ordnums[for_reorder[i].report_id] = i; } - backend.updateOrdnum(new_ordnums); + backend.updateOrdNum(new_ordnums); }, }, mounted() {