Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev v5.3 #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "gribouille/elm-table",
"summary": "Table component",
"license": "MPL-2.0",
"version": "5.2.1",
"version": "5.3.0",
"exposed-modules": [
"Table",
"Table.Column",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elm-table",
"version": "5.2.1",
"version": "5.3.0",
"description": "ELM Table component",
"repository": {
"type": "git",
Expand Down
52 changes: 26 additions & 26 deletions src/Internal/Column.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import Internal.Data exposing (..)
import Internal.State exposing (..)
import Internal.Util exposing (..)
import Monocle.Lens exposing (Lens)
import Table.Types exposing (Sort(..))
import Table.Types exposing (Action(..), Sort(..))


type alias Pipe msg =
(State -> State) -> msg


type alias ViewCell a msg =
a -> ( State, Pipe msg ) -> List (Html msg)
a -> (Action -> Pipe msg) -> State -> List (Html msg)


type alias ViewHeader a msg =
Column a msg -> ( State, Pipe msg ) -> List (Html msg)
Column a msg -> (Action -> Pipe msg) -> State -> List (Html msg)


type Column a msg
Expand Down Expand Up @@ -116,7 +116,7 @@ int get name abbrev =
, searchable = Just (String.fromInt << get)
, visible = True
, hiddable = True
, viewCell = \x _ -> [ text <| String.fromInt (get x) ]
, viewCell = \x _ _ -> [ text <| String.fromInt (get x) ]
, viewHeader = viewHeader
, default = True
}
Expand All @@ -133,7 +133,7 @@ string get name abbrev =
, searchable = Just get
, visible = True
, hiddable = True
, viewCell = \x _ -> [ text (get x) ]
, viewCell = \x _ _ -> [ text (get x) ]
, viewHeader = viewHeader
, default = True
}
Expand All @@ -150,7 +150,7 @@ bool get name abbrev =
, searchable = Nothing
, visible = True
, hiddable = True
, viewCell = \x _ -> [ text <| iff (get x) "☑" "☐" ]
, viewCell = \x _ _ -> [ text <| iff (get x) "☑" "☐" ]
, viewHeader = viewHeader
, default = True
}
Expand All @@ -167,7 +167,7 @@ float get name abbrev =
, searchable = Just (String.fromFloat << get)
, visible = True
, hiddable = True
, viewCell = \x _ -> [ text <| String.fromFloat (get x) ]
, viewCell = \x _ _ -> [ text <| String.fromFloat (get x) ]
, viewHeader = viewHeader
, default = True
}
Expand All @@ -184,14 +184,14 @@ clipboard get name abbrev =
, searchable = Just get
, visible = True
, hiddable = True
, viewCell = viewClipboard << get
, viewCell = viewClipboard
, viewHeader = viewHeader
, default = True
}


expand : Pipe msg -> Lens State StateTable -> (a -> String) -> Column a msg
expand pipe lens getID =
expand : Lens State StateTable -> (a -> String) -> Column a msg
expand lens getID =
Column
{ name = ""
, abbrev = ""
Expand All @@ -201,14 +201,14 @@ expand pipe lens getID =
, searchable = Nothing
, visible = True
, hiddable = False
, viewCell = \v ( s, _ ) -> viewExpand lens getID v ( s, pipe )
, viewCell = viewExpand lens getID
, viewHeader = viewHeader
, default = True
}


subtable : (a -> Bool) -> Pipe msg -> Lens State StateTable -> (a -> String) -> Column a msg
subtable isDisable pipe lens getID =
subtable : (a -> Bool) -> Lens State StateTable -> (a -> String) -> Column a msg
subtable isDisable lens getID =
Column
{ name = ""
, abbrev = ""
Expand All @@ -218,14 +218,14 @@ subtable isDisable pipe lens getID =
, searchable = Nothing
, visible = True
, hiddable = False
, viewCell = \v ( s, _ ) -> viewSubtable isDisable lens getID v ( s, pipe )
, viewCell = viewSubtable isDisable lens getID
, viewHeader = viewHeader
, default = True
}


viewExpand : Lens State StateTable -> (a -> String) -> a -> ( State, Pipe msg ) -> List (Html msg)
viewExpand lens getID v ( state, pipe ) =
viewExpand : Lens State StateTable -> (a -> String) -> ViewCell a msg
viewExpand lens getID v pipe state =
let
id =
getID v
Expand All @@ -241,14 +241,14 @@ viewExpand lens getID v ( state, pipe ) =
in
[ a
[ class "btn-expand"
, onClick <| pipe <| \s -> lens.set { conf | expanded = updatedExpand } s
, onClick <| pipe Expand <| \s -> lens.set { conf | expanded = updatedExpand } s
]
[ span [ class <| iff isExpanded "gg-collapse" "gg-expand" ] [] ]
]


viewSubtable : (a -> Bool) -> Lens State StateTable -> (a -> String) -> a -> ( State, Pipe msg ) -> List (Html msg)
viewSubtable isDisable lens getID v ( state, pipe ) =
viewSubtable : (a -> Bool) -> Lens State StateTable -> (a -> String) -> ViewCell a msg
viewSubtable isDisable lens getID v pipe state =
if isDisable v then
[ a [ class "btn-subtable is-disabled", disabled True ]
[ span [ class "gg-plus" ] [] ]
Expand All @@ -270,22 +270,22 @@ viewSubtable isDisable lens getID v ( state, pipe ) =
in
[ a
[ class "btn-subtable"
, onClick <| pipe <| \s -> lens.set { conf | subtable = updatedExpand } s
, onClick <| pipe ShowSubtable <| \s -> lens.set { conf | subtable = updatedExpand } s
]
[ span [ class <| iff isExpanded "gg-minus" "gg-plus" ] [] ]
]


viewHeader : Column a msg -> ( State, Pipe msg ) -> List (Html msg)
viewHeader (Column col) ( state, pipe ) =
viewHeader : ViewHeader a msg
viewHeader (Column col) pipe state =
[ iff (String.isEmpty col.abbrev)
(span [] [ text col.name ])
(abbr [ title col.name ] [ text col.abbrev ])
, iff (col.sortable /= Nothing)
(iff (state.orderBy == Just col.name)
(a
[ class "sort"
, onClick <| pipe <| \s -> { s | order = next s.order }
, onClick <| pipe SortColumn <| \s -> { s | order = next s.order }
]
[ text <|
case state.order of
Expand All @@ -301,7 +301,7 @@ viewHeader (Column col) ( state, pipe ) =
)
(a
[ class "sort"
, onClick <| pipe <| \s -> { s | order = Ascending, orderBy = Just col.name }
, onClick <| pipe SortColumn <| \s -> { s | order = Ascending, orderBy = Just col.name }
]
[ text "⇅" ]
)
Expand All @@ -310,7 +310,7 @@ viewHeader (Column col) ( state, pipe ) =
]


viewClipboard : String -> ( State, Pipe msg ) -> List (Html msg)
viewClipboard _ _ =
viewClipboard : a -> (Action -> Pipe msg) -> State -> List (Html msg)
viewClipboard _ _ _ =
-- TODO
[ div [] [ text "📋" ] ]
23 changes: 17 additions & 6 deletions src/Internal/Config.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Html.Attributes exposing (class)
import Internal.Column exposing (..)
import Internal.Data exposing (..)
import Internal.State exposing (..)
import Internal.Util exposing (iff)
import Table.Types exposing (..)


Expand Down Expand Up @@ -32,6 +33,7 @@ type alias ConfigInternal a b msg =
, subtable : Maybe (SubTable a b msg)
, errorView : String -> Html msg
, toolbar : List (Html msg)
, actions : List Action
}


Expand All @@ -54,6 +56,7 @@ config t s oe oi c =
, subtable = Nothing
, errorView = errorView
, toolbar = []
, actions = []
}


Expand All @@ -69,6 +72,7 @@ static onChange getID columns =
, subtable = Nothing
, errorView = errorView
, toolbar = []
, actions = []
}


Expand All @@ -84,6 +88,7 @@ dynamic onChangeExt onChangeInt getID columns =
, subtable = Nothing
, errorView = errorView
, toolbar = []
, actions = [ SearchEnter ]
}


Expand All @@ -96,6 +101,11 @@ withExpand col (Config c) =
Config { c | table = { t | expand = Just col } }


withActions : List Action -> Config a b msg -> Config a b msg
withActions actions (Config c) =
Config { c | actions = actions }


withSelection : Selection -> Config a b msg -> Config a b msg
withSelection s (Config c) =
Config { c | selection = s }
Expand Down Expand Up @@ -164,6 +174,7 @@ withSubtable getValues getID columns expand (Config c) =
, subtable = Just <| SubTable getValues { columns = columns, getID = getID, expand = expand }
, errorView = c.errorView
, toolbar = c.toolbar
, actions = c.actions
}


Expand All @@ -172,11 +183,11 @@ errorView msg =
div [ class "table-data-error" ] [ text msg ]


pipeInternal : Config a b msg -> Model a -> Pipe msg
pipeInternal (Config { onChangeInt }) (Model { rows, state }) fn =
onChangeInt <| Model { rows = rows, state = fn state }
pipeFn : Config a b msg -> Model a -> Action -> Pipe msg
pipeFn (Config { onChangeInt, onChangeExt, actions }) (Model { rows, state }) action fn =
iff (List.member action actions) onChangeExt onChangeInt <| Model { rows = rows, state = fn state }


pipeExternal : Config a b msg -> Model a -> Pipe msg
pipeExternal (Config { onChangeExt }) (Model { rows, state }) fn =
onChangeExt <| Model { rows = rows, state = fn state }
pipeInt : Config a b msg -> Model a -> Pipe msg
pipeInt (Config { onChangeInt }) (Model { rows, state }) fn =
onChangeInt <| Model { rows = rows, state = fn state }
5 changes: 5 additions & 0 deletions src/Internal/Data.elm
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ selected (Model { state }) =
subSelected : Model a -> List RowID
subSelected (Model { state }) =
Internal.State.subSelected state


setPagination : Model a -> Pagination -> Model a
setPagination (Model { state, rows }) p =
Model { state = Internal.State.setPagination state p, rows = rows }
22 changes: 11 additions & 11 deletions src/Internal/Pagination.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import Internal.Util exposing (..)
import Table.Types exposing (..)


tableFooterContent : Type -> Pipe msg -> Pipe msg -> Int -> Int -> Int -> Html msg
tableFooterContent type_ pipeInt pipeExt byPage page total =
tableFooterContent : (Action -> Pipe msg) -> Int -> Int -> Int -> Html msg
tableFooterContent pipe byPage page total =
let
nb =
ceiling (toFloat total / toFloat byPage)

( ia, ib, ic ) =
iff (nb == 1) ( 0, 0, 0 ) (pagIndex nb page)

pipe =
iff (type_ == Static) pipeInt pipeExt
p =
pipe ChangePageIndex
in
div [ class "table-footer" ]
[ nav
Expand All @@ -33,28 +33,28 @@ tableFooterContent type_ pipeInt pipeExt byPage page total =
[ ifh (nb > 1) <|
a
[ class <| "pagination-previous" ++ iff (page == 0) " is-disabled" ""
, onClick <| pipe <| \state -> { state | page = state.page - 1 }
, onClick <| p <| \state -> { state | page = state.page - 1 }
]
[ text "Previous" ]
, ifh (nb > 1) <|
a
[ class <| "pagination-next" ++ iff (page == nb - 1) " is-disabled" ""
, onClick <| pipe <| \state -> { state | page = page + 1 }
, onClick <| p <| \state -> { state | page = page + 1 }
]
[ text "Next page" ]
, ul [ class "pagination-list" ]
-- First page
[ ifh (nb > 3) <| paginationLink pipe page 0
[ ifh (nb > 3) <| paginationLink p page 0
, ifh (nb > 3) <| paginationEllipsis

-- Middle (m-1) m (m+1)
, ifh (nb > 1) <| paginationLink pipe page ia
, ifh (nb > 0) <| paginationLink pipe page ib
, ifh (nb > 2) <| paginationLink pipe page ic
, ifh (nb > 1) <| paginationLink p page ia
, ifh (nb > 0) <| paginationLink p page ib
, ifh (nb > 2) <| paginationLink p page ic

-- Last page
, ifh (nb > 4) <| paginationEllipsis
, ifh (nb > 4) <| paginationLink pipe page (nb - 1)
, ifh (nb > 4) <| paginationLink p page (nb - 1)
]
]
]
Expand Down
Loading