From 4483246c7b5b5470ee4e422a32f213b0fb5c3ccd Mon Sep 17 00:00:00 2001 From: jasonbarba Date: Mon, 10 Jun 2024 13:08:48 -0700 Subject: [PATCH] Working w/Settings tab - Local Storage --- .../ui/controllers/SettingsController.java | 15 ++----------- app/femr/ui/views/admin/index.scala.html | 4 ++-- app/femr/ui/views/home/index.scala.html | 7 ++++-- app/femr/ui/views/layouts/admin.scala.html | 4 ++-- app/femr/ui/views/layouts/settings.scala.html | 22 ++++++------------- app/femr/ui/views/manager/index.scala.html | 4 ++-- app/femr/ui/views/medical/index.scala.html | 4 ++-- .../views/partials/authenticated.scala.html | 3 ++- app/femr/ui/views/partials/footer.scala.html | 4 ++-- app/femr/ui/views/pharmacies/index.scala.html | 4 ++-- app/femr/ui/views/settings/index.scala.html | 17 ++++++-------- public/json/languages.json | 12 ++++++++-- 12 files changed, 45 insertions(+), 55 deletions(-) diff --git a/app/femr/ui/controllers/SettingsController.java b/app/femr/ui/controllers/SettingsController.java index 186bf20c0..25e0cac1f 100644 --- a/app/femr/ui/controllers/SettingsController.java +++ b/app/femr/ui/controllers/SettingsController.java @@ -44,18 +44,7 @@ public SettingsController(AssetsFinder assetsFinder, public Result index() { CurrentUser currentUser = sessionService.retrieveCurrentUserSession(); - System.out.println("Test"); - /*ServiceResponse userServiceResponse = userService.retrieveUser(currentUser.getId()); - if (userServiceResponse.hasErrors()){ - System.out.println("Test1333"); - throw new RuntimeException(); - }*/ - System.out.println("Test1"); - IndexViewModelGet viewModelGet = new IndexViewModelGet(); - System.out.println("Test2"); - Form editViewModelForm = formFactory.form(EditViewModel.class).bindFromRequest(); - System.out.println("Test3"); - return ok(femr.ui.views.html.settings.index.render(currentUser, viewModelGet, editViewModelForm, assetsFinder)); + return ok(femr.ui.views.html.settings.index.render(currentUser, assetsFinder)); } public Result update() { @@ -67,7 +56,7 @@ public Result update() { IndexViewModelGet viewModelGet = new IndexViewModelGet(); Form editViewModelForm = formFactory.form(EditViewModel.class).bindFromRequest(); if (editViewModelForm.hasErrors()) { - return badRequest(index.render(currentUser, viewModelGet, editViewModelForm, assetsFinder)); + return badRequest(index.render(currentUser, assetsFinder)); } EditViewModel viewModel = editViewModelForm.get(); diff --git a/app/femr/ui/views/admin/index.scala.html b/app/femr/ui/views/admin/index.scala.html index 1196f7492..b7580ad60 100644 --- a/app/femr/ui/views/admin/index.scala.html +++ b/app/femr/ui/views/admin/index.scala.html @@ -9,8 +9,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = @currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); diff --git a/app/femr/ui/views/home/index.scala.html b/app/femr/ui/views/home/index.scala.html index 33a1cb5ed..6d136d6f9 100644 --- a/app/femr/ui/views/home/index.scala.html +++ b/app/femr/ui/views/home/index.scala.html @@ -20,7 +20,10 @@ .then(response => response.json()) .then(data => { languageData = data; - updateLanguage(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = currentUser.getLanguageCode(); + updateLanguage(initialLanguage); + document.getElementById('languageSelect').value = initialLanguage; }); document.getElementById('languageSelect').addEventListener('change', function() { @@ -34,7 +37,7 @@ } } - function updateLanguage(languageCode = "en", currUser = " Admin!") { + function updateLanguage(languageCode, currUser = " Admin!") { const language = languageCode; updateTextContent("home_index_h2_Welcome", languageData[language].home_index_h2_Welcome + currUser); updateTextContent("home_index_div_Your", languageData[language].home_index_div_Your); diff --git a/app/femr/ui/views/layouts/admin.scala.html b/app/femr/ui/views/layouts/admin.scala.html index 2b88c3d15..9903db9d2 100644 --- a/app/femr/ui/views/layouts/admin.scala.html +++ b/app/femr/ui/views/layouts/admin.scala.html @@ -28,8 +28,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = @currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); diff --git a/app/femr/ui/views/layouts/settings.scala.html b/app/femr/ui/views/layouts/settings.scala.html index 37b25947d..845d50f33 100644 --- a/app/femr/ui/views/layouts/settings.scala.html +++ b/app/femr/ui/views/layouts/settings.scala.html @@ -24,8 +24,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); @@ -53,12 +53,6 @@ function updateLanguage(languageCode = "en") { localStorage.setItem('languageCode', languageCode); - updateChildTextContent("admin_configure", languageData[languageCode].admin_configure); - updateChildTextContent("admin_inventory", languageData[languageCode].admin_inventory); - updateChildTextContent("admin_trips", languageData[languageCode].admin_trips); - updateChildTextContent("admin_users", languageData[languageCode].admin_users); - updateChildTextContent("admin_updates", languageData[languageCode].admin_updates); - //updateTextContent("admin_title", languageData[languageCode].admin_title); } }); @@ -72,16 +66,14 @@ @main(title, currentUser, adminStyles, assets = assets) {
-
-

Settings Panel

+

Settings Panel

+
+
+

Language Preference.

+ @message
@content diff --git a/app/femr/ui/views/manager/index.scala.html b/app/femr/ui/views/manager/index.scala.html index 31c4747f9..99647a244 100644 --- a/app/femr/ui/views/manager/index.scala.html +++ b/app/femr/ui/views/manager/index.scala.html @@ -16,8 +16,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = @currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); diff --git a/app/femr/ui/views/medical/index.scala.html b/app/femr/ui/views/medical/index.scala.html index 02d45f637..16c693a83 100644 --- a/app/femr/ui/views/medical/index.scala.html +++ b/app/femr/ui/views/medical/index.scala.html @@ -13,8 +13,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = @currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); diff --git a/app/femr/ui/views/partials/authenticated.scala.html b/app/femr/ui/views/partials/authenticated.scala.html index dc68275d1..f471d8935 100644 --- a/app/femr/ui/views/partials/authenticated.scala.html +++ b/app/femr/ui/views/partials/authenticated.scala.html @@ -21,7 +21,7 @@ .then(data => { languageData = data; const initialLanguage = localStorage.getItem('languageCode') || 'en'; - //const initialLanguage = @currentUser.getLanguageCode(); + //const initialLanguage = currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); @@ -47,6 +47,7 @@ updateTextContent("langCode_admin", languageData[languageCode].langCode_admin); updateTextContent("langCode_superUser", languageData[languageCode].langCode_superUser); updateTextContent("langCode_reference", languageData[languageCode].langCode_reference); + updateTextContent("langCode_settings", languageData[languageCode].langCode_settings); } }); diff --git a/app/femr/ui/views/partials/footer.scala.html b/app/femr/ui/views/partials/footer.scala.html index 5fab4554f..ae3edef15 100644 --- a/app/femr/ui/views/partials/footer.scala.html +++ b/app/femr/ui/views/partials/footer.scala.html @@ -6,8 +6,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); diff --git a/app/femr/ui/views/pharmacies/index.scala.html b/app/femr/ui/views/pharmacies/index.scala.html index 6da3574ef..f12b1ba61 100644 --- a/app/femr/ui/views/pharmacies/index.scala.html +++ b/app/femr/ui/views/pharmacies/index.scala.html @@ -13,8 +13,8 @@ .then(response => response.json()) .then(data => { languageData = data; - //const initialLanguage = localStorage.getItem('languageCode') || 'en'; - const initialLanguage = @currentUser.getLanguageCode(); + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = @currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); diff --git a/app/femr/ui/views/settings/index.scala.html b/app/femr/ui/views/settings/index.scala.html index 530b3faad..aa85c1ae2 100644 --- a/app/femr/ui/views/settings/index.scala.html +++ b/app/femr/ui/views/settings/index.scala.html @@ -1,6 +1,6 @@ @(currentUser: femr.common.dtos.CurrentUser, - viewModelGet: femr.ui.models.settings.IndexViewModelGet, - form: play.data.Form[femr.ui.models.settings.EditViewModel], + //viewModelGet: femr.ui.models.settings.IndexViewModelGet, + //form: play.data.Form[femr.ui.models.settings.EditViewModel], assets: AssetsFinder) @import femr.ui.views.html.layouts.settings @@ -17,10 +17,8 @@ .then(response => response.json()) .then(data => { languageData = data; - let initialLanguage = @currentUser.getLanguageCode(); - if (initialLanguage == null) { - initialLanguage = "en"; - } + const initialLanguage = localStorage.getItem('languageCode') || 'en'; + //const initialLanguage = currentUser.getLanguageCode(); updateLanguage(initialLanguage); document.getElementById('languageSelect').value = initialLanguage; }); @@ -36,16 +34,15 @@ } } - function updateLanguage(languageCode = "en") { + function updateLanguage(languageCode) { localStorage.setItem('languageCode', languageCode); - //updateTextContent("admin_welcome", languageData[languageCode].admin_welcome); + updateTextContent("settings_title", languageData[languageCode].settings_title); + updateTextContent("settings_language", languageData[languageCode].settings_language); } }); @settings("Settings Panel", currentUser, assets = assets) { -

Welcome, User. Please select a language.

-