From 6412514cae30a0bb99519df04983db17f5dfc992 Mon Sep 17 00:00:00 2001 From: Wampie Driessen Date: Thu, 3 Aug 2023 16:30:40 +0200 Subject: [PATCH 1/8] Allow a 'default locale' and locale switcher on status pages --- db/patch-status-page-locale-selector.sql | 5 +++ server/database.js | 1 + server/model/status_page.js | 4 +++ .../status-page-socket-handler.js | 2 ++ src/lang/en.json | 2 ++ src/mixins/lang.js | 7 +++++ src/pages/StatusPage.vue | 31 +++++++++++++++++-- 7 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 db/patch-status-page-locale-selector.sql diff --git a/db/patch-status-page-locale-selector.sql b/db/patch-status-page-locale-selector.sql new file mode 100644 index 00000000..3335e3ba --- /dev/null +++ b/db/patch-status-page-locale-selector.sql @@ -0,0 +1,5 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; +ALTER TABLE status_page ADD show_locale_selector BOOLEAN NOT NULL DEFAULT 0; +ALTER TABLE status_page ADD default_locale TEXT DEFAULT ""; +COMMIT; diff --git a/server/database.js b/server/database.js index 42d64279..2ca9bda8 100644 --- a/server/database.js +++ b/server/database.js @@ -77,6 +77,7 @@ class Database { "patch-added-kafka-producer.sql": true, "patch-add-certificate-expiry-status-page.sql": true, "patch-monitor-oauth-cc.sql": true, + "patch-status-page-locale-selector.sql": true, }; /** diff --git a/server/model/status_page.js b/server/model/status_page.js index e168acf2..efb261a6 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -231,6 +231,8 @@ class StatusPage extends BeanModel { theme: this.theme, published: !!this.published, showTags: !!this.show_tags, + showLocaleSelector: !!this.show_locale_selector, + defaultLocale: this.default_locale, domainNameList: this.getDomainNameList(), customCSS: this.custom_css, footerText: this.footer_text, @@ -254,6 +256,8 @@ class StatusPage extends BeanModel { theme: this.theme, published: !!this.published, showTags: !!this.show_tags, + showLocaleSelector: !!this.show_locale_selector, + defaultLocale: this.default_locale, customCSS: this.custom_css, footerText: this.footer_text, showPoweredBy: !!this.show_powered_by, diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index eba40dae..1e487082 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -158,6 +158,8 @@ module.exports.statusPageSocketHandler = (socket) => { //statusPage.published = ; //statusPage.search_engine_index = ; statusPage.show_tags = config.showTags; + statusPage.show_locale_selector = config.showLocaleSelector; + statusPage.default_locale = config.defaultLocale; //statusPage.password = null; statusPage.footer_text = config.footerText; statusPage.custom_css = config.customCSS; diff --git a/src/lang/en.json b/src/lang/en.json index 8a894e5c..1c0cc3f6 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -260,6 +260,8 @@ "Switch to Light Theme": "Switch to Light Theme", "Switch to Dark Theme": "Switch to Dark Theme", "Show Tags": "Show Tags", + "Show Locale Selector": "Show Locale Selector", + "Default Locale": "Default Locale", "Hide Tags": "Hide Tags", "Description": "Description", "No monitors available.": "No monitors available.", diff --git a/src/mixins/lang.js b/src/mixins/lang.js index 7e36d158..8f1b0fe5 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -29,6 +29,13 @@ export default { this.$i18n.locale = lang; localStorage.locale = lang; setPageLocale(); + }, + /** Change the language for the current page (no localstore set) */ + async changeCurrentPageLang(lang) { + let message = (await langModules["../lang/" + lang + ".json"]()).default; + this.$i18n.setLocaleMessage(lang, message); + this.$i18n.locale = lang; + setPageLocale(); } } }; diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 606d9657..48d0f210 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -48,6 +48,18 @@ +
+ + +
+ +
+ + +
+
@@ -116,7 +128,7 @@
- +

@@ -139,7 +151,14 @@ /> - + + + + + +

@@ -697,6 +716,10 @@ export default { this.incident = res.data.incident; this.maintenanceList = res.data.maintenanceList; this.$root.publicGroupList = res.data.publicGroupList; + + if (!localStorage.locale && this.config.defaultLocale) { + this.$root.changeCurrentPageLang(this.config.defaultLocale) + } }).catch( function (error) { if (error.response.status === 404) { location.href = "/page-not-found"; @@ -1075,6 +1098,10 @@ footer { display: flex; align-items: center; gap: 10px; + + .title { + flex-grow: 1; + } } .logo-wrapper { From deaec80cb030e6baf321b31edbe64abe837d24c9 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:32:52 +0200 Subject: [PATCH 2/8] Allow a 'default locale' and locale switcher on status pages --- db/patch-status-page-locale-selector.sql | 5 +++ server/database.js | 1 + server/model/status_page.js | 4 +++ .../status-page-socket-handler.js | 2 ++ src/lang/en.json | 2 ++ src/mixins/lang.js | 7 +++++ src/pages/StatusPage.vue | 31 +++++++++++++++++-- 7 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 db/patch-status-page-locale-selector.sql diff --git a/db/patch-status-page-locale-selector.sql b/db/patch-status-page-locale-selector.sql new file mode 100644 index 00000000..3335e3ba --- /dev/null +++ b/db/patch-status-page-locale-selector.sql @@ -0,0 +1,5 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; +ALTER TABLE status_page ADD show_locale_selector BOOLEAN NOT NULL DEFAULT 0; +ALTER TABLE status_page ADD default_locale TEXT DEFAULT ""; +COMMIT; diff --git a/server/database.js b/server/database.js index 42d64279..2ca9bda8 100644 --- a/server/database.js +++ b/server/database.js @@ -77,6 +77,7 @@ class Database { "patch-added-kafka-producer.sql": true, "patch-add-certificate-expiry-status-page.sql": true, "patch-monitor-oauth-cc.sql": true, + "patch-status-page-locale-selector.sql": true, }; /** diff --git a/server/model/status_page.js b/server/model/status_page.js index e168acf2..efb261a6 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -231,6 +231,8 @@ class StatusPage extends BeanModel { theme: this.theme, published: !!this.published, showTags: !!this.show_tags, + showLocaleSelector: !!this.show_locale_selector, + defaultLocale: this.default_locale, domainNameList: this.getDomainNameList(), customCSS: this.custom_css, footerText: this.footer_text, @@ -254,6 +256,8 @@ class StatusPage extends BeanModel { theme: this.theme, published: !!this.published, showTags: !!this.show_tags, + showLocaleSelector: !!this.show_locale_selector, + defaultLocale: this.default_locale, customCSS: this.custom_css, footerText: this.footer_text, showPoweredBy: !!this.show_powered_by, diff --git a/server/socket-handlers/status-page-socket-handler.js b/server/socket-handlers/status-page-socket-handler.js index eba40dae..1e487082 100644 --- a/server/socket-handlers/status-page-socket-handler.js +++ b/server/socket-handlers/status-page-socket-handler.js @@ -158,6 +158,8 @@ module.exports.statusPageSocketHandler = (socket) => { //statusPage.published = ; //statusPage.search_engine_index = ; statusPage.show_tags = config.showTags; + statusPage.show_locale_selector = config.showLocaleSelector; + statusPage.default_locale = config.defaultLocale; //statusPage.password = null; statusPage.footer_text = config.footerText; statusPage.custom_css = config.customCSS; diff --git a/src/lang/en.json b/src/lang/en.json index 8a894e5c..1c0cc3f6 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -260,6 +260,8 @@ "Switch to Light Theme": "Switch to Light Theme", "Switch to Dark Theme": "Switch to Dark Theme", "Show Tags": "Show Tags", + "Show Locale Selector": "Show Locale Selector", + "Default Locale": "Default Locale", "Hide Tags": "Hide Tags", "Description": "Description", "No monitors available.": "No monitors available.", diff --git a/src/mixins/lang.js b/src/mixins/lang.js index 7e36d158..8f1b0fe5 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -29,6 +29,13 @@ export default { this.$i18n.locale = lang; localStorage.locale = lang; setPageLocale(); + }, + /** Change the language for the current page (no localstore set) */ + async changeCurrentPageLang(lang) { + let message = (await langModules["../lang/" + lang + ".json"]()).default; + this.$i18n.setLocaleMessage(lang, message); + this.$i18n.locale = lang; + setPageLocale(); } } }; diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 606d9657..48d0f210 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -48,6 +48,18 @@
+
+ + +
+ +
+ + +
+
@@ -116,7 +128,7 @@
- +

@@ -139,7 +151,14 @@ /> - + + + + + +

@@ -697,6 +716,10 @@ export default { this.incident = res.data.incident; this.maintenanceList = res.data.maintenanceList; this.$root.publicGroupList = res.data.publicGroupList; + + if (!localStorage.locale && this.config.defaultLocale) { + this.$root.changeCurrentPageLang(this.config.defaultLocale) + } }).catch( function (error) { if (error.response.status === 404) { location.href = "/page-not-found"; @@ -1075,6 +1098,10 @@ footer { display: flex; align-items: center; gap: 10px; + + .title { + flex-grow: 1; + } } .logo-wrapper { From be461a0efd41a7c9db5531bdaba4b3d573954053 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:43:59 +0200 Subject: [PATCH 3/8] Fix linter issues --- src/pages/StatusPage.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 48d0f210..10275ac1 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -55,8 +55,8 @@
- +
@@ -156,7 +156,7 @@ @@ -718,7 +718,7 @@ export default { this.$root.publicGroupList = res.data.publicGroupList; if (!localStorage.locale && this.config.defaultLocale) { - this.$root.changeCurrentPageLang(this.config.defaultLocale) + this.$root.changeCurrentPageLang(this.config.defaultLocale); } }).catch( function (error) { if (error.response.status === 404) { From a50209b6c8e792dbace09f5b18a745fe3b7dbaa2 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Sat, 5 Aug 2023 17:55:27 +0200 Subject: [PATCH 4/8] Update src/mixins/lang.js Co-authored-by: Matthew Nickson --- src/mixins/lang.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mixins/lang.js b/src/mixins/lang.js index 8f1b0fe5..1e2d048a 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -30,7 +30,10 @@ export default { localStorage.locale = lang; setPageLocale(); }, - /** Change the language for the current page (no localstore set) */ + /** + * Change the language for the current page (no localstore set) + * @param {string} lang Code of language to switch to. + */ async changeCurrentPageLang(lang) { let message = (await langModules["../lang/" + lang + ".json"]()).default; this.$i18n.setLocaleMessage(lang, message); From 8fa40d02aabdc05a8fb016985a93740eaa69b715 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Sat, 5 Aug 2023 18:47:52 +0200 Subject: [PATCH 5/8] Update src/mixins/lang.js --- src/mixins/lang.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixins/lang.js b/src/mixins/lang.js index 1e2d048a..9e5cafe7 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -31,7 +31,7 @@ export default { setPageLocale(); }, /** - * Change the language for the current page (no localstore set) + * Change the language for the current page (no localstore set) * @param {string} lang Code of language to switch to. */ async changeCurrentPageLang(lang) { From af45fa844e5639fdadc12c74d61cb16c490934e9 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Sat, 5 Aug 2023 18:47:57 +0200 Subject: [PATCH 6/8] Update src/mixins/lang.js --- src/mixins/lang.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mixins/lang.js b/src/mixins/lang.js index 9e5cafe7..f2d20606 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -30,7 +30,7 @@ export default { localStorage.locale = lang; setPageLocale(); }, - /** + /** * Change the language for the current page (no localstore set) * @param {string} lang Code of language to switch to. */ From 60271ffa0b577c3f9643ea96f91e0102d64d493f Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:32:55 +0200 Subject: [PATCH 7/8] Convert migration to knex migration --- .../2023-09-13-1047-locale-on-statuspage.js | 15 +++++++++++++++ db/patch-status-page-locale-selector.sql | 5 ----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js delete mode 100644 db/patch-status-page-locale-selector.sql diff --git a/db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js b/db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js new file mode 100644 index 00000000..1f7a1393 --- /dev/null +++ b/db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js @@ -0,0 +1,15 @@ +exports.up = function (knex) { + return knex.schema + .alterTable("status_page", function (table) { + table.boolean("show_locale_selector").notNullable().defaultTo(false); + table.string("default_locale").nullable().defaultTo(""); + }); +}; + +exports.down = function (knex) { + return knex.schema + .alterTable("status_page", function (table) { + table.dropColumn("default_locale"); + table.dropColumn("show_locale_selector"); + }); +}; diff --git a/db/patch-status-page-locale-selector.sql b/db/patch-status-page-locale-selector.sql deleted file mode 100644 index 3335e3ba..00000000 --- a/db/patch-status-page-locale-selector.sql +++ /dev/null @@ -1,5 +0,0 @@ --- You should not modify if this have pushed to Github, unless it does serious wrong with the db. -BEGIN TRANSACTION; -ALTER TABLE status_page ADD show_locale_selector BOOLEAN NOT NULL DEFAULT 0; -ALTER TABLE status_page ADD default_locale TEXT DEFAULT ""; -COMMIT; From 144794b770dfa07d989dece58e7ba60c73f46401 Mon Sep 17 00:00:00 2001 From: Wampie Driessen <1059058+wampiedriessen@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:35:52 +0200 Subject: [PATCH 8/8] Fix linter warning --- src/mixins/lang.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mixins/lang.js b/src/mixins/lang.js index b7eb6f3d..32d23e9f 100644 --- a/src/mixins/lang.js +++ b/src/mixins/lang.js @@ -37,6 +37,7 @@ export default { /** * Change the language for the current page (no localstore set) * @param {string} lang Code of language to switch to. + * @returns {Promise} */ async changeCurrentPageLang(lang) { let message = (await langModules["../lang/" + lang + ".json"]()).default;