Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaadF committed Oct 25, 2022
1 parent 6b82f4c commit 69299f2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 26 deletions.
Expand Up @@ -31,21 +31,22 @@ import AgentValueParser exposing (..)
--
-- Port for interacting with external JS
--
port copy : String -> Cmd msg
port storeDraft : Value -> Cmd msg
port clearDraft : String -> Cmd msg
port getDrafts : () -> Cmd msg
port draftsResponse : (Value -> msg) -> Sub msg
port openManager : String -> Cmd msg
port updateResources : (() -> msg) -> Sub msg
port successNotification : String -> Cmd msg
port errorNotification : String -> Cmd msg
port infoNotification : String -> Cmd msg
port pushUrl : String -> Cmd msg
port getUrl : () -> Cmd msg
port readUrl : (String -> msg) -> Sub msg
port clearTooltips : String -> Cmd msg
port scrollMethod : (Bool , String) -> Cmd msg
port copy : String -> Cmd msg
port storeDraft : Value -> Cmd msg
port clearDraft : String -> Cmd msg
port getDrafts : () -> Cmd msg
port draftsResponse : (Value -> msg) -> Sub msg
port openManager : String -> Cmd msg
port updateResources : (() -> msg) -> Sub msg
port successNotification : String -> Cmd msg
port errorNotification : String -> Cmd msg
port infoNotification : String -> Cmd msg
port pushUrl : String -> Cmd msg
port getUrl : () -> Cmd msg
port readUrl : (String -> msg) -> Sub msg
port clearTooltips : String -> Cmd msg
port scrollMethod : (Bool , String) -> Cmd msg
port preventReloadingBehavior : () -> Cmd msg

-- utility to write a understandable debug message from a get response
debugHttpErr : Detailed.Error String -> String
Expand Down Expand Up @@ -167,7 +168,7 @@ selectTechnique model technique =
in
({ model | mode = TechniqueDetails effectiveTechnique state ui } )
|> update OpenMethods
|> Tuple.mapSecond ( always ( Cmd.batch [ getRessources state model, action ] ))
|> Tuple.mapSecond ( always ( Cmd.batch [ getRessources state model, action, preventReloadingBehavior () ] ))

generator : Random.Generator String
generator = Random.map (UUID.toString) UUID.generator
Expand Down Expand Up @@ -206,7 +207,7 @@ update msg model =
( model , Cmd.none )

GetTechniques (Ok (metadata, techniques)) ->
({ model | techniques = techniques, loadingTechniques = False}, getUrl () )
({ model | techniques = techniques, loadingTechniques = False}, Cmd.batch[getUrl (), preventReloadingBehavior()])
GetTechniques (Err err) ->
({ model | loadingTechniques = False} , errorNotification ("Error when getting techniques: " ++ debugHttpErr err ) )

Expand Down Expand Up @@ -314,7 +315,7 @@ update msg model =
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] )
({ model | techniques = techniques, mode = newMode, drafts = drafts}, Cmd.batch [ clearDraft idToClean.value, successNotification "Technique saved!", pushUrl technique.id.value, preventReloadingBehavior ()] )

SaveTechnique (Err err) ->
( model , errorNotification ("Error when saving technique: " ++ debugHttpErr err ) )
Expand Down
Expand Up @@ -16,12 +16,13 @@ import Random
import UUID

-- PORTS / SUBSCRIPTIONS
port successNotification : String -> Cmd msg
port errorNotification : String -> Cmd msg
port pushUrl : (String,String) -> Cmd msg
port initTooltips : String -> Cmd msg
port readUrl : ((String, String) -> msg) -> Sub msg
port copy : String -> Cmd msg
port successNotification : String -> Cmd msg
port errorNotification : String -> Cmd msg
port pushUrl : (String,String) -> Cmd msg
port initTooltips : String -> Cmd msg
port readUrl : ((String, String) -> msg) -> Sub msg
port copy : String -> Cmd msg
port preventReloadingBehavior : () -> Cmd msg

subscriptions : Model -> Sub Msg
subscriptions _ =
Expand Down Expand Up @@ -139,7 +140,7 @@ update msg model =
let
modelUI = model.ui
in
(model, Cmd.batch [getRuleDetails model rId, pushUrl ("rule", rId.value)])
(model, Cmd.batch [getRuleDetails model rId, pushUrl ("rule", rId.value), preventReloadingBehavior ()])

OpenRuleDetails rId False ->
(model, getRuleDetails model rId)
Expand Down Expand Up @@ -298,9 +299,10 @@ update msg model =
, getRulesTree newModel
, getRulesComplianceDetails ruleDetails.id newModel
, getRuleNodesDirectives ruleDetails.id newModel
, preventReloadingBehavior()
]
)
_ -> (model, Cmd.none)
_ -> (model, preventReloadingBehavior())


SaveRuleDetails (Err err) ->
Expand Down
Expand Up @@ -73,6 +73,12 @@
});
}, 950);

app.ports.preventReloadingBehavior.subscribe(function() {
$('.jstree-anchor').click(function (event) {
event.preventDefault();
});
});

});
</script>

Expand Down
Expand Up @@ -142,6 +142,12 @@
});
}, 950);

app.ports.preventReloadingBehavior.subscribe(function() {
$('.jstree-anchor').click(function (event) {
event.preventDefault();
});
});

});

function scrollToMethod(target){
Expand Down

0 comments on commit 69299f2

Please sign in to comment.