module SideTable.View exposing (view) {-| Displays the SideBar @docs view -} import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (onClick, onInput, on) import InputTable.Messages exposing (..) import InputTable.Model exposing (..) import InputTable.RowFilter exposing (containsCi) import Set view : TableState rowData sideRowData -> Html (TableMsg rowData focussedData) view tableState = let visibleRows = List.filter (rowPassesSearch tableState.sideSearchText tableState.sideColumns) tableState.sideRows visibleRowIds = visibleRows |> List.map .id |> Set.fromList getCount = List.filter .checked >> List.length >> toString selectedCount = getCount tableState.sideRows selectedMainTableCount = getCount tableState.rows in div [ class "sidebar__section" ] [ div [ class "sidebar__header" ] [ span [ class "sidebar__title" ] [ text "Reviewers" ] , button [ class "sidebar__close-button" , onClick ToggleSideTable ] [] , (checkbox (ToggleVisibleSideRowsCheckboxes visibleRowIds) <| List.all .checked visibleRows) , input [ placeholder "Search" , class "table__search" , value tableState.sideSearchText , onInput UpdateSideSearchText ] [] , div [ class "hint hint--important" ] [ text <| (toString <| List.length visibleRows) ++ " visible of " ++ (toString <| List.length tableState.sideRows) ++ ". " ++ selectedCount ++ " selected." ] ] , div [ class "side-table-container" ] [ table [ class "side-table" ] [ tbody [] (if List.isEmpty tableState.sideRows then [ div [ class "table__all-columns-message" ] [ span [] [ text "You have not yet invited any reviewers to this event. " ] , a [ href "../../manage-users#reviewers" ] [ text "Click here to invite reviewers." ] ] ] else if List.isEmpty visibleRows then [ div [ class "table__all-columns-message" ] [ text "There are no reviewers that include the search input" ] ] else (List.map (viewRow tableState.sideColumns) visibleRows ) ) ] ] , div [] [ div [ class "hint hint--important" ] [ text <| tableState.sideTableAction ++ " " ++ selectedMainTableCount ++ (if selectedMainTableCount == "1" then " submission " else " submissions " ) ++ tableState.sideTablePreposition ++ " " ++ selectedCount ++ (if selectedCount == "1" then " reviewer." else " reviewers." ) ] , case tableState.cannotAssignSideRowsReason of Nothing -> text "" Just reason -> div [ class "hint hint--important hint--warning" ] [ text reason ] , (if tableState.sideTableIsAssigning then div [] [ div [ class "table__loading-message" ] [ text <| tableState.sideTableAction ++ "ing..." ] , div [ class "loader" ] [] ] else button [ class "button button--primary button--cta" , onClick PostSideRows ] [ text tableState.sideTableAction ] ) ] ] viewHeader : SideColumn sideRowData -> Html (TableMsg rowData focussedData) viewHeader column = td [] [ text column.header ] viewRow : List (SideColumn sideRowData) -> SideRow sideRowData -> Html (TableMsg rowData focussedData) viewRow columns row = tr [ class "side-table__row", onClick (ToggleSideRowCheckbox row.id) ] <| (td [ class "" ] [ (checkboxNoMsg row.checked) ]) :: (List.map (viewCell row) columns) viewCell : SideRow sideRowData -> SideColumn sideRowData -> Html (TableMsg rowData focussedData) viewCell row column = td [] [ text (column.get row.data) ] rowPassesSearch : String -> List (SideColumn sideRowData) -> SideRow sideRowData -> Bool rowPassesSearch searchTerm columns row = (searchTerm == "") || List.any (\c -> containsCi (c.get row.data) searchTerm) columns checkboxNoMsg : Bool -> Html (TableMsg rowData focussedData) checkboxNoMsg bool = input [ type_ "checkbox" , checked bool ] [] checkbox : TableMsg rowData focussedData -> Bool -> Html (TableMsg rowData focussedData) checkbox msg checked_ = input [ type_ "checkbox" , checked checked_ , onClick msg ] []