Skip to content

Commit

Permalink
Fixes #16611: Change model in user management and text from buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaadF committed Jan 24, 2020
1 parent 257a966 commit 3ad8e36
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 47 deletions.
17 changes: 5 additions & 12 deletions user-management/src/main/elm/sources/DataTypes.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module DataTypes exposing (..)

import Dict exposing (Dict)
import Http exposing (Error)
import String exposing (toUpper)
import Toasty
import Toasty.Defaults

Expand Down Expand Up @@ -42,17 +41,15 @@ type alias UserInfos =
, authz: Authorization
}

-- the full list of digest + list of users


type alias UsersConf =
{ digest : String
, users : List User
}

type EditMod
= On
| Off
type PanelMode
= AddMode
| EditMode User
| Closed

type alias Model =
{ contextPath : String
Expand All @@ -62,13 +59,10 @@ type alias Model =
, rolesConf : RoleConf -- from API
, authorizations : Authorization
, toasties : Toasty.Stack Toasty.Defaults.Toast
, editMod : EditMod
, addMod : EditMod
, userFocusOn : User
, panelMode : PanelMode
, password : String
, login : String
, hashedPasswd : Bool
, clearPasswd : Bool
}


Expand All @@ -85,7 +79,6 @@ type Msg
| ActivePanelSettings User
| ActivePanelAddUser
| DeactivatePanel
| ChangeFocusOn User
| Password String
| Login String
| AddRole User String
Expand Down
4 changes: 2 additions & 2 deletions user-management/src/main/elm/sources/Init.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Init exposing (..)
------------------------------

import ApiCalls exposing (getUsersConf)
import DataTypes exposing (Authorization, EditMod(..), Model, Msg(..))
import DataTypes exposing (Authorization, Model, Msg(..), PanelMode(..))
import Dict exposing (fromList)
import Html.Attributes exposing (style)
import Http
Expand All @@ -27,7 +27,7 @@ authorizations =
init : { contextPath : String } -> ( Model, Cmd Msg )
init flags =
let
initModel = Model flags.contextPath "" (fromList []) (fromList []) [] authorizations Toasty.initialState Off Off {login = "", role = [], authz = []} "" "" True False
initModel = Model flags.contextPath "" (fromList []) (fromList []) [] authorizations Toasty.initialState Closed "" "" True
in
( initModel
, getUsersConf initModel
Expand Down
41 changes: 19 additions & 22 deletions user-management/src/main/elm/sources/UserManagement.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ port module UserManagement exposing (processApiError, update)

import ApiCalls exposing (addUser, computeRoleCoverage, getRoleConf, getUsersConf, postReloadConf, updateUser)
import Browser
import DataTypes exposing (Authorization, EditMod(..), Model, Msg(..), User, Username, Users)
import DataTypes exposing (Authorization, Model, Msg(..), PanelMode(..), User, Username, Users)
import Dict exposing (fromList)
import Http exposing (..)
import Init exposing (createErrorNotification, defaultConfig, init, subscriptions)
Expand Down Expand Up @@ -64,7 +64,7 @@ update msg model =
PostReloadUserInfo result ->
case result of
Ok _ ->
( { model | editMod = Off}
( { model | panelMode = Closed}
, getUsersConf model
)

Expand All @@ -80,16 +80,22 @@ update msg model =
Toasty.update defaultConfig ToastyMsg subMsg model

ActivePanelAddUser ->
if model.addMod == On then
({model | addMod = Off}, Cmd.none)
if model.panelMode == AddMode then
({model | panelMode = Closed}, Cmd.none)
else
({model | addMod = On, editMod = Off}, Cmd.none)
ActivePanelSettings username ->
({model | addMod = Off, editMod = On, userFocusOn = username}, Cmd.none)
({model | panelMode = AddMode}, Cmd.none)
ActivePanelSettings user ->
case model.panelMode of
EditMode u ->
if u.login == user.login then
({model | panelMode = Closed}, Cmd.none)
else
({model | panelMode = EditMode user}, Cmd.none)
_ ->
({model | panelMode = EditMode user}, Cmd.none)

DeactivatePanel ->
({model | addMod = Off, editMod = Off, userFocusOn = { login = "", authz = [], role = []}}, Cmd.none)

({model | panelMode = Closed}, Cmd.none)

ComputeRoleCoverage result ->
case result of
Expand Down Expand Up @@ -129,27 +135,18 @@ update msg model =
Notification subMsg ->
Toasty.update defaultConfig Notification subMsg model

ChangeFocusOn userToFocus ->
({model | userFocusOn = userToFocus}, Cmd.none)
Password newPassword ->
({model | password = newPassword}, Cmd.none)
Login newLogin ->
({model | login = newLogin}, Cmd.none)
SubmitUpdatedInfos u ->
let
newLogin =
if isEmpty u.login then
model.userFocusOn.login
else
u.login
in
({model | password = "", login = "", userFocusOn = {login = newLogin, authz =[], role = []}}, updateUser model u.login model.password { u | login = model.login })
({model | password = "", login = ""}, updateUser model u.login model.password { u | login = model.login })
SubmitNewUser u password ->
({model | addMod = Off}, addUser model u)
({model | panelMode = Closed}, addUser model u)
PreHashedPasswd ->
({model | hashedPasswd = True, clearPasswd = False}, Cmd.none)
({model | hashedPasswd = True}, Cmd.none)
ClearPasswd ->
({model | clearPasswd = True, hashedPasswd = False}, Cmd.none)
({model | hashedPasswd = False}, Cmd.none)


processApiError : Error -> Model -> ( Model, Cmd Msg )
Expand Down
27 changes: 16 additions & 11 deletions user-management/src/main/elm/sources/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module View exposing (..)


import ApiCalls exposing (deleteUser)
import DataTypes exposing (EditMod(..), Model, Msg(..), RoleConf, User, Username, Users, UsersConf)
import DataTypes exposing (Model, Msg(..), PanelMode(..), RoleConf, User, Username, Users, UsersConf)
import Dict exposing (keys)
import Html exposing (Html, a, br, button, div, h3, h4, h6, i, input, option, p, select, span, text)
import Html.Attributes exposing (attribute, class, disabled, hidden, id, placeholder, required, type_, value)
Expand Down Expand Up @@ -35,15 +35,15 @@ hashPasswordMenu : Model -> Html Msg
hashPasswordMenu model =
let
hashPasswdIsActivate =
if (model.clearPasswd == False) && (model.hashedPasswd == True) then
if (model.hashedPasswd == True) then
"active"
else
""
clearPasswdIsActivate =
if (model.clearPasswd == True) && (model.hashedPasswd == False) then
"active"
else
""
if (model.hashedPasswd == False) then
"active"
else
""
in
div [class "btn-group", attribute "role" "group"]
[
Expand Down Expand Up @@ -73,20 +73,25 @@ displayRightPanelAddUser model =

displayRightPanel : Model -> Html Msg
displayRightPanel model =
let
user = case model.panelMode of
EditMode u -> u
_ -> User "" [] []
in
div [class "panel-wrap"]
[
div [class "panel"]
[
a [class "close close-panel", onClick DeactivatePanel][]
, h4 [] [text model.userFocusOn.login]
, h4 [] [text user.login]
,
input [class "form-control", type_ "text", placeholder "New Username", onInput Login] []
, br [] []
, hashPasswordMenu model
, input [class "form-control", type_ "password", placeholder "New Password", onInput Password, attribute "autocomplete" "new-password" ] []
, br [] []
, button [class "btn btn-sm btn-danger",onClick (CallApi ( deleteUser model.userFocusOn.login))] [text "Delete "]
, button [class "btn btn-sm btn-primary", onClick (SubmitUpdatedInfos model.userFocusOn)] [text "Submit"]
, button [class "btn btn-sm btn-danger",onClick (CallApi ( deleteUser user.login))] [text "Delete "]
, button [class "btn btn-sm btn-primary", onClick (SubmitUpdatedInfos user)] [text "Submit"]

]
]
Expand All @@ -97,7 +102,7 @@ displayUsersConf model u =
users =
(map (\(name, rights) -> (User name rights.custom rights.roles)) (Dict.toList u)) |> List.map (\user -> displayUser model user)
newUserMenu =
if model.addMod == On then
if model.panelMode == AddMode then
displayRightPanelAddUser model
else
div [] []
Expand Down Expand Up @@ -134,7 +139,7 @@ displayUsersConf model u =
displayUser : Model -> User -> Html Msg
displayUser model user =
let
panel = if model.editMod == Off then div [][] else displayRightPanel model
panel = if model.panelMode /= EditMode user then div [][] else displayRightPanel model
in
div [ class "col-xs-12 col-sm-6 col-md-3" ]
[ div [ class "user", id "fast-transition"]
Expand Down

0 comments on commit 3ad8e36

Please sign in to comment.