Skip to content

Commit

Permalink
Update Settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbarba19 committed Jun 5, 2024
1 parent 9bbd83f commit b76d0a3
Show file tree
Hide file tree
Showing 7 changed files with 7,770 additions and 43 deletions.
9 changes: 9 additions & 0 deletions app/femr/common/models/UserItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class UserItem {
private String PasswordCreatedDate;
private String DateCreated; //Sam Zanni
private Integer CreatedBy; //Sam Zanni
private String languageCode;

public UserItem() {
this.roles = new ArrayList<>();
Expand Down Expand Up @@ -150,4 +151,12 @@ public boolean equals(final Object obj) {

public void setCreatedBy (Integer CreatedBy) { this.CreatedBy = CreatedBy; } //Sam Zanni

public String getLanguageCode() {
return this.languageCode;
}

public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}

}
80 changes: 76 additions & 4 deletions app/femr/ui/controllers/SettingsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,95 @@
import com.google.inject.Inject;
import controllers.AssetsFinder;
import femr.business.services.core.ISessionService;
import femr.business.services.core.IUserService;
import femr.common.dtos.CurrentUser;
import femr.common.dtos.ServiceResponse;
import femr.common.models.UserItem;
import femr.ui.models.settings.EditViewModel;
import femr.ui.views.html.settings.index;

import femr.ui.views.html.sessions.create;
import femr.util.stringhelpers.StringUtils;
import play.data.FormFactory;
import play.mvc.Controller;
import play.mvc.Result;
import play.data.Form;

import java.util.ArrayList;

import java.util.ArrayList;

public class SettingsController extends Controller {
private final AssetsFinder assetsFinder;
private ISessionService sessionService;
private final FormFactory formFactory;
private final ISessionService sessionService;
private final IUserService userService;

@Inject
public SettingsController(AssetsFinder assetsFinder, ISessionService sessionService) {

public SettingsController(AssetsFinder assetsFinder,
FormFactory formFactory,
ISessionService sessionService,
IUserService userService) {
this.assetsFinder = assetsFinder;
this.formFactory = formFactory;
this.sessionService = sessionService;
this.userService = userService;
}

public Result index() {
CurrentUser currentUser = sessionService.retrieveCurrentUserSession();

return ok(femr.ui.views.html.settings.index.render(currentUser, assetsFinder));
}
}

public Result update() {
CurrentUser currentUser = sessionService.retrieveCurrentUserSession();
if (currentUser == null) {
return unauthorized();
}

Form<EditViewModel> editViewModelForm = formFactory.form(EditViewModel.class).bindFromRequest();
if (editViewModelForm.hasErrors()) {
return badRequest(index.render(currentUser, assetsFinder));
}

EditViewModel viewModel = editViewModelForm.get();
ServiceResponse<UserItem> userServiceResponse = userService.retrieveUser(currentUser.getId());
if (userServiceResponse.hasErrors()) {
return internalServerError();
}

UserItem userItem = userServiceResponse.getResponseObject();
userItem.setFirstName(viewModel.getFirstName());
userItem.setLastName(viewModel.getLastName());
userItem.setLanguageCode(viewModel.getLanguageCode());

if (StringUtils.isNotNullOrWhiteSpace(viewModel.getPasswordReset()) && viewModel.getPasswordReset().equals("on")) {
userItem.setPasswordReset(true);
} else {
userItem.setPasswordReset(false);
}


ServiceResponse<UserItem> updateResponse = userService.updateUser(userItem, null);
if (updateResponse.hasErrors()) {
return internalServerError();
}

return redirect("/settings");
}



private EditViewModel convertToEditViewModel(UserItem userItem) {
EditViewModel editViewModel = new EditViewModel();
editViewModel.setUserId(userItem.getId());
editViewModel.setFirstName(userItem.getFirstName());
editViewModel.setLastName(userItem.getLastName());
editViewModel.setEmail(userItem.getEmail());
editViewModel.setPasswordReset(Boolean.toString(userItem.isPasswordReset()));
editViewModel.setLanguageCode(userItem.getLanguageCode());
return editViewModel;
}

}
142 changes: 142 additions & 0 deletions app/femr/ui/models/settings/EditViewModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
fEMR - fast Electronic Medical Records
Copyright (C) 2014 Team fEMR
fEMR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fEMR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with fEMR. If not, see <http://www.gnu.org/licenses/>. If
you have any questions, contact <[email protected]>.
*/

package femr.ui.models.settings;

import femr.util.stringhelpers.StringUtils;
import play.data.validation.Constraints;
import play.data.validation.ValidationError;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

@Constraints.Validate
public class EditViewModel implements Constraints.Validatable<List<ValidationError>> {
private Integer userId;
private String firstName;
private String lastName;
private String email;
private String passwordReset;
private String newPassword;
private String newPasswordVerify;

private String languageCode;

@Override
public List<ValidationError> validate() {
Pattern hasLowercase = Pattern.compile("[a-z]");
Pattern hasUppercase = Pattern.compile("[A-Z]");
Pattern hasNumber = Pattern.compile("\\d");
List<ValidationError> errors = new ArrayList<>();

if (StringUtils.isNullOrWhiteSpace(firstName)) {
errors.add(new ValidationError("firstName", "First name is a required field"));
}
if (StringUtils.isNullOrWhiteSpace(email)) {
errors.add(new ValidationError("email", "Email is a required field"));
}
if (!newPassword.equals(newPasswordVerify)) {
errors.add(new ValidationError("newPassword", "Passwords do not match"));
}

if (newPassword.length() > 0) {
if (newPassword.length() < 8) {
errors.add(new ValidationError("newPassword", "Password must be at least 8 characters long"));
}
if (!hasUppercase.matcher(newPassword).find()) {
errors.add(new ValidationError("newPassword", "Password must have at least one uppercase character"));
}
if (!hasNumber.matcher(newPassword).find()) {
errors.add(new ValidationError("newPassword", "Password must have at least one number"));
}
if (!hasLowercase.matcher(newPassword).find()) {
errors.add(new ValidationError("newPassword", "Password must have at least one lowercase character"));
}
}

return errors.isEmpty() ? null : errors;
}

// Getters and setters

public Integer getUserId() {
return userId;
}

public void setUserId(Integer userId) {
this.userId = userId;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPasswordReset() {
return passwordReset;
}

public void setPasswordReset(String passwordReset) {
this.passwordReset = passwordReset;
}

public String getNewPassword() {
return newPassword;
}

public void setNewPassword(String newPassword) {
this.newPassword = newPassword;
}

public String getNewPasswordVerify() {
return newPasswordVerify;
}

public void setNewPasswordVerify(String newPasswordVerify) {
this.newPasswordVerify = newPasswordVerify;
}

public String getLanguageCode() {
return languageCode;
}

public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}
}
34 changes: 34 additions & 0 deletions app/femr/ui/models/settings/IndexViewModelGet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
fEMR - fast Electronic Medical Records
Copyright (C) 2014 Team fEMR
fEMR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
fEMR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with fEMR. If not, see <http://www.gnu.org/licenses/>. If
you have any questions, contact <[email protected]>.
*/

package femr.ui.models.settings;

import femr.data.models.core.IUser;

public class IndexViewModelGet {
private IUser user;

public IUser getUser() {
return user;
}

public void setUser(IUser user) {
this.user = user;
}
}
3 changes: 2 additions & 1 deletion app/femr/ui/views/layouts/settings.scala.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import femr.ui.controllers.admin.routes.UsersController
@(title: String,
currentUser: femr.common.dtos.CurrentUser,
styles: Html = Html(""),
Expand Down Expand Up @@ -71,7 +72,7 @@
@main(title, currentUser, adminStyles, assets = assets) {
<div id="admin-panels">
<div id="admin-left-panel">
<a id="settings_profile" href="@ConfigureController.manageGet()" class="fButton fOtherButton fAdminButton userBtns fAdminButtonLeftTextAlign"><span class="glyphicon glyphicon-cog"></span>
<a id="settings_profile" href="@UsersController.manageGet()" class="fButton fOtherButton fAdminButton userBtns fAdminButtonLeftTextAlign"><span class="glyphicon glyphicon-cog"></span>
Profile</a>
<a id="settings_language" href="@InventoryController.manageGet(0)" class="fButton fOtherButton fAdminButton userBtns fAdminButtonLeftTextAlign"><span class="glyphicon glyphicon-briefcase"></span>
Language</a>
Expand Down
37 changes: 0 additions & 37 deletions app/femr/ui/views/settings/index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,62 +42,25 @@ <h3 id="settings_welcome">Welcome, User. Please select a language.</h3>
<option value="fr">Français</option>
<option value="ar">العربية</option>
<option value="az">Azərbaycanca</option>
<option value="bg">български</option>
<option value="bn">বাংলা</option>
<option value="bs">Bosanski</option>
<option value="cs">Čeština</option>
<option value="da">Dansk</option>
<option value="de">Deutsch</option>
<option value="el">Ελληνικά</option>
<option value="et">Eesti</option>
<option value="fa">فارسی</option>
<option value="fi">Suomi</option>
<option value="fil">Filipino</option>
<option value="he">עברית</option>
<option value="hi">हिन्दी</option>
<option value="hr">Hrvatski</option>
<option value="hu">Magyar</option>
<option value="hy">Հայերեն</option>
<option value="id">Bahasa Indonesia</option>
<option value="it">Italiano</option>
<option value="ja">日本語</option>
<option value="ka">ქართული</option>
<option value="kk">Қазақ тілі</option>
<option value="km">ភាសាខ្មែរ</option>
<option value="ko">한국어</option>
<option value="ku">Kurdî</option>
<option value="ky">Кыргызча</option>
<option value="lo">ລາວ</option>
<option value="lt">Lietuvių</option>
<option value="lv">Latviešu</option>
<option value="mk">Македонски</option>
<option value="mn">Монгол</option>
<option value="ms">Bahasa Melayu</option>
<option value="my">ဗမာ</option>
<option value="ne">नेपाली</option>
<option value="nl">Nederlands</option>
<option value="no">Norsk</option>
<option value="pl">Polski</option>
<option value="ps">پښتو</option>
<option value="pt">Português</option>
<option value="ro">Română</option>
<option value="ru">Русский</option>
<option value="sd">سنڌي</option>
<option value="si">සිංහල</option>
<option value="sk">Slovenčina</option>
<option value="sl">Slovenščina</option>
<option value="sq">Shqip</option>
<option value="sr">Српски</option>
<option value="sv">Svenska</option>
<option value="sw">Kiswahili</option>
<option value="ta">தமிழ்</option>
<option value="tg">Тоҷикӣ</option>
<option value="th">ไทย</option>
<option value="tk">Türkmen</option>
<option value="tr">Türkçe</option>
<option value="uk">Українська</option>
<option value="ur">اردو</option>
<option value="uz">Oʻzbek</option>
<option value="vi">Tiếng Việt</option>
<option value="zh">中文</option>
</select>
Expand Down
Loading

0 comments on commit b76d0a3

Please sign in to comment.