Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Oct 13, 2021
1 parent 845cc91 commit 8649d90
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ saveDisableAction ruleDetails model =
in
send SaveDisableAction req

saveCategoryDetails : (Category Rule) -> Bool -> Model -> Cmd Msg
saveCategoryDetails category creation model =
saveCategoryDetails : (Category Rule) -> String -> Bool -> Model -> Cmd Msg
saveCategoryDetails category parentId creation model =
let
(method, url) = if creation then ("PUT","/rules/categories") else ("POST", ("/rules/categories/"++category.id))
req =
request
{ method = method
, headers = []
, url = getUrl model url
, body = encodeCategoryDetails category |> jsonBody
, body = encodeCategoryDetails parentId category |> jsonBody
, expect = expectJson decodeGetCategoryDetails
, timeout = Nothing
, withCredentials = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ type alias RuleDetailsUI = { editDirectives: Bool, editGroups : Bool, newTag : T

type alias RuleDetails = { originRule : Maybe Rule, rule : Rule, tab : TabMenu, ui : RuleDetailsUI }

type alias CategoryDetails = { originCategory : Maybe (Category Rule), category : Category Rule, tab : TabMenu}
type alias CategoryDetails = { originCategory : Maybe (Category Rule), category : Category Rule, parentId : String, tab : TabMenu}

type Mode
= Loading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,29 @@ import DataTypes exposing (..)
import Json.Encode exposing (..)


encodeRuleCategory: (String, Category Rule) -> Value
encodeRuleCategory (parent, category) =
object [
("parents" , string parent )
, ("name" , string category.name )
]

encodeRuleDetails: Rule -> Value
encodeRuleDetails ruleDetails =
let
listTags = object(List.map (\t -> (t.key, string t.value)) ruleDetails.tags)
in
object [
("id" , string ruleDetails.id.value )
, ("displayName" , string ruleDetails.name )
, ("category" , string ruleDetails.categoryId )
, ("shortDescription" , string ruleDetails.shortDescription )
, ("longDescription" , string ruleDetails.longDescription )
, ("enabled" , bool ruleDetails.enabled )
, ("system" , bool ruleDetails.isSystem )
, ("directives" , list string (List.map .value ruleDetails.directives) )
, ("targets" , list encodeTargets ruleDetails.targets )
, ("tags" , list encodeTags ruleDetails.tags )
("id" , string ruleDetails.id.value )
, ("displayName" , string ruleDetails.name )
, ("category" , string ruleDetails.categoryId )
, ("shortDescription" , string ruleDetails.shortDescription )
, ("longDescription" , string ruleDetails.longDescription )
, ("enabled" , bool ruleDetails.enabled )
, ("system" , bool ruleDetails.isSystem )
, ("directives" , list string (List.map .value ruleDetails.directives) )
, ("targets" , list encodeTargets ruleDetails.targets )
, ("tags" , list encodeTags ruleDetails.tags )
]

encodeCategoryDetails: (Category Rule) -> Value
encodeCategoryDetails category =
object [
("name" , string category.name )
encodeCategoryDetails: String -> (Category Rule) -> Value
encodeCategoryDetails parentId category =
object
[ ("parent" , string parentId )
, ("name" , string category.name )
, ("description" , string category.description )
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Init exposing (init)
import View exposing (view)
import Result
import ApiCalls exposing (getRuleDetails, getRulesCategoryDetails, getRulesTree, saveDisableAction)
import ViewUtils exposing (getListCategories, getParentCategoryId)
import List.Extra exposing (remove)
import Random
import UUID
Expand Down Expand Up @@ -107,17 +108,19 @@ update msg model =
GetCategoryDetailsResult res ->
case res of
Ok c ->
({model | mode = CategoryForm (CategoryDetails (Just c) c Information )}, Cmd.none)
({model | mode = CategoryForm (CategoryDetails (Just c) c (getParentCategoryId (getListCategories model.rulesTree) c.id) Information)}, Cmd.none)
Err err ->
(model, Cmd.none)

OpenRuleDetails rId True ->
(model, Cmd.batch [getRuleDetails model rId, pushUrl ("rule", rId.value)])

OpenRuleDetails rId False ->
(model, getRuleDetails model rId)

OpenCategoryDetails category True ->
(model, Cmd.batch [getRulesCategoryDetails model category, pushUrl ("ruleCategory" , category)])

OpenCategoryDetails category False ->
(model, getRulesCategoryDetails model category)

Expand Down Expand Up @@ -190,7 +193,7 @@ update msg model =
NewCategory id ->
let
category = Category id "" "" (SubCategories []) []
categoryDetails = CategoryDetails Nothing category Information
categoryDetails = CategoryDetails Nothing category "rootRuleCategory" Information
in
({model | mode = CategoryForm categoryDetails}, Cmd.none )

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,25 @@ view model =

childsList = ul[class "jstree-children"] (List.concat [ categories, rules] )

treeItem =
if item.id /= "rootRuleCategory" then
if (String.isEmpty model.ui.ruleFilters.treeFilters.filter) || ((List.length rules > 0) || (List.length categories > 0)) then
Just (
li[class "jstree-node jstree-open"]
[ i[class "jstree-icon jstree-ocl"][]
, a[href "#", class "jstree-anchor", onClick (OpenCategoryDetails item.id True)]
[ i [class "jstree-icon jstree-themeicon fa fa-folder jstree-themeicon-custom"][]
, span [class "treeGroupCategoryName tooltipable"][text item.name]
]
, childsList
]
)
else
Nothing
else
Just childsList
in
if (String.isEmpty model.ui.ruleFilters.treeFilters.filter) || ((List.length rules > 0) || (List.length categories > 0)) then
Just (
li[class "jstree-node jstree-open"]
[ i[class "jstree-icon jstree-ocl"][]
, a[href "#", class "jstree-anchor", onClick (OpenCategoryDetails item.id True)]
[ i [class "jstree-icon jstree-themeicon fa fa-folder jstree-themeicon-custom"][]
, span [class "treeGroupCategoryName tooltipable"][text item.name]
]
, childsList
]
)
else
Nothing
treeItem

templateMain = case model.mode of
Loading -> text "loading"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ editionTemplateCat model details =
, div [class "form-group"]
[ label[for "category-parent"][text "Parent"]
, div[]
[ select[ id "category-parent", class "form-control" ] --, onInput (\s -> UpdateCategory {category | parent = s} ) ]
(buildListCategories "" model.rulesTree)
[ select[ id "category-parent", class "form-control", onInput (\s -> UpdateCategoryForm {details | parentId = s}) ]
(buildListCategories "" category.id details.parentId model.rulesTree)
]
]
, div [class "form-group"]
Expand Down Expand Up @@ -80,7 +80,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 (Maybe.Extra.isNothing details.originCategory)))]
, 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"][]]
]
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ import ViewUtils exposing (thClass, sortTable, getDirectivesSortFunction, filter
--
-- This file contains all methods to display the details of the selected rule.
--
buildListCategories : String -> (Category Rule) -> List(Html Msg)
buildListCategories sep c =
let
newList =
let
currentOption = [option [value c.id][text (sep ++ c.name)]]
separator = sep ++ "└─ "
listCategories = List.concatMap (buildListCategories separator) (getSubElems c)
in
List.append currentOption listCategories
in
newList
buildListCategories : String -> String -> String -> (Category Rule) -> List(Html Msg)
buildListCategories sep categoryId parentId c =
if categoryId == c.id then
[]
else
let
newList =
let
currentOption = [option [value c.id, selected (parentId == c.id)][text (sep ++ c.name)]]
separator = sep ++ "└─ "
listCategories = List.concatMap (buildListCategories separator categoryId parentId) (getSubElems c)
in
List.append currentOption listCategories
in
newList

buildTagsContainer : Rule -> Bool -> RuleDetails -> Html Msg
buildTagsContainer rule editMode details =
Expand Down Expand Up @@ -111,7 +114,7 @@ tabContent model details =
[ label[for "rule-category"][text "Category"]
, div[]
[ select[ id "rule-category", class "form-control", onInput (\s -> UpdateRuleForm {details | rule = {rule | categoryId = s}} ) ]
(buildListCategories "" model.rulesTree)
(buildListCategories "" "" rule.categoryId model.rulesTree)
]
]
, div [class "tags-container"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ getCategoryName model id =
Just c -> c.name
Nothing -> id

getParentCategoryId : List (Category a) -> String -> String
getParentCategoryId categories categoryId =
let
findSubCategory : String -> Category a -> Bool
findSubCategory catId cat =
case List.Extra.find (\c -> c.id == catId) (getSubElems cat) of
Just _ -> True
Nothing -> False
in
case List.Extra.find (\c -> (findSubCategory categoryId c)) categories of
Just ct -> ct.id
Nothing -> "rootRuleCategory"
--
-- DATATABLES & TREES
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
.content-wrapper .rudder-template .jstree .jstree-node{
overflow: hidden;
}
.content-wrapper .rudder-template .jstree > .jstree-container-ul:first-child > ul.jstree-children > .jstree-node{
margin-left: 0px;
}

.content-wrapper .rudder-template .jstree .fa.jstree-icon,
.content-wrapper .rudder-template .jstree .rudder-label.label-sm{
margin-right: 2px;
Expand Down

0 comments on commit 8649d90

Please sign in to comment.