refs #3971 Version cookie fixes
gitea/hedera-web/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2022-11-11 20:31:17 +01:00
parent a59d062f95
commit 6f080b1275
7 changed files with 37 additions and 112 deletions

5
app.js
View File

@ -1,14 +1,15 @@
__webpack_public_path__ = _PUBLIC_PATH; __webpack_public_path__ = _PUBLIC_PATH;
require('hedera/hedera'); require('hedera/hedera');
const packageJson = require('./package.json');
window.onload = function() { window.onload = function() {
loadLocale(main); loadLocale(main);
} }
function main(req) { function main(req) {
if (req) if (req) onLocaleLoad(req);
onLocaleLoad(req); Vn.setVersion(packageJson.version);
hederaWeb = new Hedera.App(); hederaWeb = new Hedera.App();
hederaWeb.run(); hederaWeb.run();

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (22.44.8) stable; urgency=low hedera-web (22.44.9) stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -1,60 +0,0 @@
__webpack_public_path__ = _PUBLIC_PATH;
require('hedera/hedera');
window.onload = function() {
loadLocale(main);
}
function main(req) {
if (req)
onLocaleLoad(req);
hederaWeb = new Hedera.App();
hederaWeb.run();
}
function loadLocale(cb) {
Vn.Locale.init();
var lang = Vn.Locale.language;
var req = require.context('js', true, /locale\/en.yml$/);
onLocaleLoad(req);
switch (lang) {
case 'ca':
require([], function() {
cb(require.context('js', true, /locale\/ca.yml$/));
});
break;
case 'es':
require([], function() {
cb(require.context('js', true, /locale\/es.yml$/));
});
break;
case 'fr':
require([], function() {
cb(require.context('js', true, /locale\/fr.yml$/));
});
break;
case 'mn':
require([], function() {
cb(require.context('js', true, /locale\/mn.yml$/));
});
break;
case 'pt':
require([], function() {
cb(require.context('js', true, /locale\/pt.yml$/));
});
break;
default:
cb();
}
}
function onLocaleLoad(req) {
var keys = req.keys();
for (var i = 0; i < keys.length; i++)
Vn.Locale.add(req(keys[i]));
}

View File

@ -9,8 +9,7 @@ module.exports =
language: null language: null
,defaultLang: 'en' ,defaultLang: 'en'
,init: function () ,init: function() {
{
if (this.language) if (this.language)
return; return;
@ -25,8 +24,7 @@ module.exports =
this.language = language.substr(0, 2); this.language = language.substr(0, 2);
} }
,load: function (path, callback) ,load: function(path, callback) {
{
this.init(); this.init();
var data = { var data = {
@ -42,8 +40,7 @@ module.exports =
data.org = this.createRequest(data, false, this.language); data.org = this.createRequest(data, false, this.language);
} }
,createRequest: function (data, isDef, lang) ,createRequest: function(data, isDef, lang) {
{
var langFile = data.path +'/locale/'+ lang +'.yml'+ Vn.getVersion(); var langFile = data.path +'/locale/'+ lang +'.yml'+ Vn.getVersion();
var request = new XMLHttpRequest(); var request = new XMLHttpRequest();
@ -54,21 +51,17 @@ module.exports =
return request; return request;
} }
,onRequestReady: function (request, data, isDef) ,onRequestReady: function(request, data, isDef) {
{
if (request.readyState != 4) if (request.readyState != 4)
return; return;
if (isDef) if (isDef) {
{
this.loadFromRequest(request); this.loadFromRequest(request);
data.defOk = true; data.defOk = true;
} } else
else
data.orgOk = true; data.orgOk = true;
if (data.orgOk && data.defOk) if (data.orgOk && data.defOk) {
{
if (data.org != null) if (data.org != null)
this.loadFromRequest(data.org) this.loadFromRequest(data.org)
if (data.callback) if (data.callback)
@ -76,37 +69,32 @@ module.exports =
} }
} }
,loadFromRequest: function (request) ,loadFromRequest: function(request) {
{
if (request.status !== 200) if (request.status !== 200)
return false; return false;
try { try {
this.add(yaml.safeLoad(request.responseText)); this.add(yaml.safeLoad(request.responseText));
return true; return true;
} } catch (e) {
catch (e) {
console.error(e); console.error(e);
} }
return false return false
} }
,loadScript: function (path, callback) ,loadScript: function(path, callback) {
{
this.init(); this.init();
Vn.includeJs(path +'/locale/'+ this.language, callback); Vn.includeJs(path +'/locale/'+ this.language, callback);
} }
,add: function (translations) ,add: function(translations) {
{
for (var str in translations) for (var str in translations)
vnLocaleStrings[str] = translations[str]; vnLocaleStrings[str] = translations[str];
} }
} }
window._ = function (stringId) window._ = function(stringId) {
{
var string = vnLocaleStrings[stringId]; var string = vnLocaleStrings[stringId];
return string ? string : stringId; return string ? string : stringId;
} }

View File

@ -50,6 +50,10 @@ Vn = module.exports = {
return this._version; return this._version;
} }
,setVersion(version) {
document.cookie = `vnVersion=${version}; SameSite=Lax;`;
}
/** /**
* Includes a new CSS stylesheet in the current document, if the stylesheet * Includes a new CSS stylesheet in the current document, if the stylesheet
* is already included, does nothing. * is already included, does nothing.

View File

@ -1,6 +1,6 @@
{ {
"name": "hedera-web", "name": "hedera-web",
"version": "22.44.8", "version": "22.44.9",
"description": "Verdnatura web page", "description": "Verdnatura web page",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

View File

@ -64,14 +64,6 @@ class HtmlService extends Service {
header('Location: ?method=version-menu'); header('Location: ?method=version-menu');
} }
// Setting the version
$domain = explode(':', $_SERVER['HTTP_HOST'])[0];
setcookie('vnVersion', $this->getVersion()->toString(), [
'samesite' => 'Lax',
'domain' => $domain
]);
// Loading the requested page // Loading the requested page
$basePath = "pages/$page"; $basePath = "pages/$page";