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;
require('hedera/hedera');
const packageJson = require('./package.json');
window.onload = function() {
loadLocale(main);
}
function main(req) {
if (req)
onLocaleLoad(req);
if (req) onLocaleLoad(req);
Vn.setVersion(packageJson.version);
hederaWeb = new Hedera.App();
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.

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
,defaultLang: 'en'
,init: function ()
{
,init: function() {
if (this.language)
return;
@ -22,12 +21,11 @@ module.exports =
else if (navigator.language)
language = navigator.language;
this.language = language.substr (0, 2);
this.language = language.substr(0, 2);
}
,load: function (path, callback)
{
this.init ();
,load: function(path, callback) {
this.init();
var data = {
path: path,
@ -36,77 +34,67 @@ module.exports =
orgOk: this.defaultLang === this.language
};
data.def = this.createRequest (data, true, this.defaultLang);
data.def = this.createRequest(data, true, this.defaultLang);
if (!data.orgOk)
data.org = this.createRequest (data, false, this.language);
data.org = this.createRequest(data, false, this.language);
}
,createRequest: function (data, isDef, lang)
{
var langFile = data.path +'/locale/'+ lang +'.yml'+ Vn.getVersion ();
,createRequest: function(data, isDef, lang) {
var langFile = data.path +'/locale/'+ lang +'.yml'+ Vn.getVersion();
var request = new XMLHttpRequest ();
request.open ('get', langFile, true);
var request = new XMLHttpRequest();
request.open('get', langFile, true);
request.onreadystatechange =
this.onRequestReady.bind (this, request, data, isDef);
request.send ();
this.onRequestReady.bind(this, request, data, isDef);
request.send();
return request;
}
,onRequestReady: function (request, data, isDef)
{
,onRequestReady: function(request, data, isDef) {
if (request.readyState != 4)
return;
if (isDef)
{
this.loadFromRequest (request);
if (isDef) {
this.loadFromRequest(request);
data.defOk = true;
}
else
} else
data.orgOk = true;
if (data.orgOk && data.defOk)
{
if (data.orgOk && data.defOk) {
if (data.org != null)
this.loadFromRequest (data.org)
this.loadFromRequest(data.org)
if (data.callback)
data.callback ();
data.callback();
}
}
,loadFromRequest: function (request)
{
,loadFromRequest: function(request) {
if (request.status !== 200)
return false;
try {
this.add (yaml.safeLoad (request.responseText));
this.add(yaml.safeLoad(request.responseText));
return true;
}
catch (e) {
console.error (e);
} catch (e) {
console.error(e);
}
return false
}
,loadScript: function (path, callback)
{
this.init ();
Vn.includeJs (path +'/locale/'+ this.language, callback);
,loadScript: function(path, callback) {
this.init();
Vn.includeJs(path +'/locale/'+ this.language, callback);
}
,add: function (translations)
{
,add: function(translations) {
for (var str in translations)
vnLocaleStrings[str] = translations[str];
}
}
window._ = function (stringId)
{
window._ = function(stringId) {
var string = vnLocaleStrings[stringId];
return string ? string : stringId;
}

View File

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

View File

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

View File

@ -64,14 +64,6 @@ class HtmlService extends Service {
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
$basePath = "pages/$page";