module ArrayBased.View exposing (view) import Array import Html exposing (..) import Html.Attributes exposing (class, href) import ArrayBased.Messages exposing (..) import InputTable.View import InputTable.Model import ArrayBased.Model as Model type alias Config = { rowLink : Maybe String , rowsAreSelectable : Bool , currentPage : Int } view : Config -> Model.Model -> Html Msg view config model = let tableState = model.tableState currentPage = if model.tableState.currentPage == 0 then config.currentPage else model.tableState.currentPage childConfig = { getRowAttributes = Just (getRowAttributes model.incompleteColumnAndText) , rowLink = config.rowLink , currentPage = currentPage } tableState2 = { tableState | currentPage = currentPage } in div [] (if model.isLoadingInitialRows then [ div [ class "table__loading-message" ] [ text "Loading table data" ] , div [ class "loader" ] [] ] else [ Html.map ArrayBased.Messages.Table (InputTable.View.view childConfig ({ tableState2 | rowsAreSelectable = config.rowsAreSelectable }) ) ] ) getRowAttributes : Maybe ( Int, String ) -> InputTable.Model.Row Model.RowData -> List (Attribute msg) getRowAttributes incompleteColumnAndText row = (("table__row" :: (getCompleteClass incompleteColumnAndText row)) ++ (getExpandedClass row)) |> makeClass makeClass : List String -> List (Attribute msg) makeClass stringList = [ class (String.join " " stringList) ] getExpandedClass : InputTable.Model.Row Model.RowData -> List String getExpandedClass row = case row.accordionExpanded of True -> [ "table__row--expanded" ] False -> [] getCompleteClass : Maybe ( Int, String ) -> InputTable.Model.Row Model.RowData -> List String getCompleteClass incompleteColumnAndText row = case incompleteColumnAndText of Nothing -> [] Just ( incompleteColumnIndex, incompleteText ) -> let cell = Array.get incompleteColumnIndex row.data in case cell of Just cell -> if cell.value == incompleteText then [ "table__row--incomplete-submission" ] else [] _ -> []