Skip to content

Commit

Permalink
Merge branch 'enh_21929/missing_a_loading_info_when_a_technique_it_is…
Browse files Browse the repository at this point in the history
…_being_saved_pr' into branches/rudder/7.2
  • Loading branch information
VinceMacBuche committed Feb 17, 2023
2 parents e0db0e6 + b0e670c commit cd57f40
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,30 +307,38 @@ update msg model =
(newMode, idToClean) =
case model.mode of
TechniqueDetails _ (Edit _) ui ->
(TechniqueDetails technique (Edit technique) ui, technique.id)
(TechniqueDetails technique (Edit technique) {ui | saving = False}, technique.id)
TechniqueDetails _ (Creation id) ui ->
(TechniqueDetails technique (Edit technique) ui, id)
(TechniqueDetails technique (Edit technique) {ui | saving = False}, id)
TechniqueDetails _ (Clone _ id) ui ->
(TechniqueDetails technique (Edit technique) ui, id)
(TechniqueDetails technique (Edit technique) {ui | saving = False}, id)
m -> (m, technique.id)
drafts = Dict.remove idToClean.value model.drafts
in
({ model | techniques = techniques, mode = newMode, drafts = drafts}, Cmd.batch [ clearDraft idToClean.value, successNotification "Technique saved!", pushUrl technique.id.value] )

SaveTechnique (Err err) ->
( model , errorNotification ("Error when saving technique: " ++ debugHttpErr err ) )
let
newModel = case model.mode of
TechniqueDetails t s ui -> {model | mode = TechniqueDetails t s {ui | saving = False}}
_ -> model
in
( newModel , errorNotification ("Error when saving technique: " ++ debugHttpErr err ) )

StartSaving ->
case model.mode of
TechniqueDetails t o ui ->
case model.mode of
TechniqueDetails t o ui ->
let
newUi = {ui | saving = True}
in
case o of
Edit _ ->
update (CallApi (saveTechnique t False Nothing)) { model | mode = TechniqueDetails t o ui }
update (CallApi (saveTechnique t False Nothing)) { model | mode = TechniqueDetails t o newUi }
Creation internalId ->
update (CallApi (saveTechnique t True (Just internalId))) { model | mode = TechniqueDetails t o ui }
update (CallApi (saveTechnique t True (Just internalId))) { model | mode = TechniqueDetails t o newUi }
Clone _ internalId ->
update (CallApi (saveTechnique t True (Just internalId))) { model | mode = TechniqueDetails t o ui }
_ -> (model, Cmd.none)
update (CallApi (saveTechnique t True (Just internalId))) { model | mode = TechniqueDetails t o newUi }
_ -> (model, Cmd.none)

DeleteTechnique (Ok (metadata, techniqueId)) ->
case model.mode of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,13 @@ showTechnique model technique origin ui =
elem :: base
) technique.elems
)

btnSave : Bool -> Bool -> Msg -> Html Msg
btnSave saving disable action =
let
icon = if saving then i [ class "fa fa-spinner fa-pulse"] [] else i [ class "fa fa-download"] []
in
button [class ("btn btn-success btn-save" ++ (if saving then " saving" else "")), type_ "button", disabled (saving || disable), onClick action]
[ icon ]
in
div [ class "main-container" ] [
div [ class "main-header" ] [
Expand All @@ -280,10 +286,7 @@ showTechnique model technique origin ui =
text "Reset "
, i [ class "fa fa-undo"] []
]
, button [ class "btn btn-success btn-save", disabled (isUnchanged || not (isValid ui) || ui.saving || String.isEmpty technique.name|| not areErrorOnMethodParameters || not areErrorOnMethodCondition || not areBlockOnError), onClick StartSaving] [
text "Save "
, i [ class ("fa fa-download " ++ (if ui.saving then "glyphicon glyphicon-cog fa-spin" else "")) ] []
]
, btnSave ui.saving (isUnchanged || not (isValid ui) || String.isEmpty technique.name|| not areErrorOnMethodParameters || not areErrorOnMethodCondition || not areBlockOnError) StartSaving
]
]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ type alias UI =
, hasWriteRights : Bool
, loadingRules : Bool
, isAllCatFold : Bool
, saving : Bool
}

type alias Changes =
Expand Down Expand Up @@ -310,7 +311,7 @@ type Msg
| NewRule RuleId
| NewCategory String
| GetRepairedReport RuleId Int
| CallApi (Model -> Cmd Msg)
| CallApi Bool (Model -> Cmd Msg)
| GetRuleDetailsResult (Result Error Rule)
| GetPolicyModeResult (Result Error String)
| GetCategoryDetailsResult (Result Error (Category Rule))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ init flags =

initCategory = Category "" "" "" (SubCategories []) []
initFilters = Filters (TableFilters Name Asc "" []) (TreeFilters "" [] (Tag "" "") [])
initUI = UI initFilters initFilters initFilters NoModal flags.hasWriteRights True False
initUI = UI initFilters initFilters initFilters NoModal flags.hasWriteRights True False False
initModel = Model flags.contextPath Loading "" initCategory initCategory initCategory Dict.empty Dict.empty Dict.empty Dict.empty initUI

listInitActions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ update msg model =
GenerateId nextMsg ->
(model, Random.generate nextMsg generator)
-- Do an API call
CallApi call ->
(model, call model)
CallApi saving call ->
let
ui = model.ui
newModel = {model | ui = {ui | saving = saving}}
in
(newModel, call model)
-- neutral element
Ignore ->
( model , Cmd.none)
Expand Down Expand Up @@ -291,7 +295,8 @@ update msg model =
Just _ -> "saved"
Nothing -> "created"
ui = details.ui
newModel = {model | mode = RuleForm {details | originRule = Just ruleDetails, rule = ruleDetails, ui = {ui | editDirectives = False, editGroups = False }}}
modelUi = model.ui
newModel = {model | mode = RuleForm {details | originRule = Just ruleDetails, rule = ruleDetails, ui = {ui | editDirectives = False, editGroups = False}}, ui = {modelUi | saving = False} }
in
(newModel, Cmd.batch
[ successNotification ("Rule '"++ ruleDetails.name ++"' successfully " ++ action)
Expand Down Expand Up @@ -515,7 +520,7 @@ processApiError apiName err model =
errorMessage

in
({model | mode = if model.mode == Loading then RuleTable else model.mode, ui = { modelUi | loadingRules = False}}, errorNotification ("Error when "++apiName ++",details: \n" ++ message ) )
({model | mode = if model.mode == Loading then RuleTable else model.mode, ui = { modelUi | loadingRules = False, saving = False}}, errorNotification ("Error when "++apiName ++",details: \n" ++ message ) )

getUrl : Model -> String
getUrl model = model.contextPath ++ "/secure/configurationManager/ruleManagement"
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ view model =
, div [ class "modal-footer" ] [
button [ class "btn btn-default", onClick (ClosePopup Ignore) ]
[ text "Cancel " ]
, button [ class "btn btn-danger", onClick (ClosePopup (CallApi (deleteRule rule))) ]
, button [ class "btn btn-danger", onClick (ClosePopup (CallApi False (deleteRule rule))) ]
[ text "Delete "
, i [ class "fa fa-times-circle" ] []
]
Expand Down Expand Up @@ -206,7 +206,7 @@ view model =
, div [ class "modal-footer" ] [
button [ class "btn btn-default", onClick (ClosePopup Ignore) ]
[ text "Cancel " ]
, button [ class "btn btn-danger", onClick (ClosePopup (CallApi (deleteCategory category))) ]
, button [ class "btn btn-danger", onClick (ClosePopup (CallApi False (deleteCategory category))) ]
[ text "Delete "
, i [ class "fa fa-times-circle" ] []
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import String exposing ( fromFloat)
import NaturalOrdering exposing (compareOn)
import ApiCalls exposing (..)
import ViewTabContent exposing (buildListCategories)
import ViewUtils exposing (btnSave)


--
-- This file contains all methods to display the details of the selected category.
Expand Down Expand Up @@ -83,8 +85,7 @@ editionTemplateCat model details =
[ button [ class "btn btn-danger" , onClick (OpenDeletionPopupCat category)]
[ text "Delete", i [ class "fa fa-times-circle"][]]
]
, button [class "btn btn-success", type_ "button", onClick (CallApi (saveCategoryDetails category details.parentId (Maybe.Extra.isNothing details.originCategory)))]
[ text "Save", i [ class "fa fa-download"][]]
, btnSave model.ui.saving False (CallApi True (saveCategoryDetails category details.parentId (Maybe.Extra.isNothing details.originCategory)))
]
else
[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import String
import ApiCalls exposing (..)
import ViewTabContent exposing (tabContent)
import Maybe.Extra
import ViewUtils exposing (badgePolicyMode, countRecentChanges, getRuleNbGroups, getRuleNbNodes, getNbResourcesBadge, getGroupsNbResourcesBadge)
import ViewUtils exposing (badgePolicyMode, countRecentChanges, getRuleNbGroups, getRuleNbNodes, getNbResourcesBadge, getGroupsNbResourcesBadge, btnSave)

--
-- This file contains all methods to display the details of the selected rule.
Expand Down Expand Up @@ -148,7 +148,8 @@ editionTemplate model details =
if String.isEmpty (String.trim rule.name) then
Ignore
else
(CallApi (saveRuleDetails rule (Maybe.Extra.isNothing details.originRule)))
(CallApi True (saveRuleDetails rule (Maybe.Extra.isNothing details.originRule)))

in
div [class "main-container"]
[ div [class "main-header "]
Expand All @@ -163,7 +164,7 @@ editionTemplate model details =
:: (
if model.ui.hasWriteRights then
[ div [ class "btn-group" ] topButtons
, button [class "btn btn-success", type_ "button", disabled (String.isEmpty (String.trim rule.name)), onClick saveAction][text "Save", i [ class "fa fa-download"] []]
, btnSave model.ui.saving (String.isEmpty (String.trim rule.name)) saveAction
]
else
[]
Expand Down Expand Up @@ -227,4 +228,4 @@ editionTemplate model details =
]
, div [class "main-details"]
[ tabContent model details ]
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ getNodeLink contextPath id =
getNodeHostname : Model -> String -> String
getNodeHostname model id = (Maybe.withDefault (NodeInfo id id "" "" ) (Dict.get id model.nodes)).hostname


goToBtn : String -> Html Msg
goToBtn link =
a [ class "btn-goto", href link , onCustomClick (GoTo link)] [ i[class "fa fa-pen"][] ]
Expand Down Expand Up @@ -704,4 +703,12 @@ getGroupsNbResourcesBadge nbTargets nbInclude msg =
span [class ("nb-resources" ++ warningClass), title warningTitle]
[ text (String.fromInt nbTargets)
, warningIcon
]
]

btnSave : Bool -> Bool -> Msg -> Html Msg
btnSave saving disable action =
let
icon = if saving then i [ class "fa fa-spinner fa-pulse"] [] else i [ class "fa fa-download"] []
in
button [class ("btn btn-success btn-save" ++ (if saving then " saving" else "")), type_ "button", disabled (saving || disable), onClick action]
[ icon ]
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,20 @@ ul.applied-list > .add-target > .fa{
font-weight: bold;
}

/* === BTN SAVE === */
.btn.btn-save{
min-width: 86px;
}
.btn.btn-save:before{
content: "Save";
}
.btn.btn-save.saving:before{
content: "Saving";
}
.btn.btn-save > .fa.fa-spin{
position: static;
font-size: inherit;
}
/* === KEYFRAMES === */
@keyframes fadein {
0% {opacity: 0; transform:translateX(-100px);}
Expand All @@ -1586,4 +1600,4 @@ ul.applied-list > .add-target > .fa{
@keyframes load {
0% {left: -180px;}
100% {left: 100%;}
}
}

0 comments on commit cd57f40

Please sign in to comment.