module ArrayBased.GetTableData exposing (fetchDataFromServer) import Dict import Http import Json.Decode as Decode import Json.Decode.Pipeline exposing (required, optional, decode, hardcoded) import ArrayBased.Messages as Messages import ArrayBased.Model as Model import InputTable.Model fetchDataFromServer : String -> Cmd Messages.Msg fetchDataFromServer path = let request = Http.get path apiGetDecoder in Http.send Messages.UpdateDataFromServer request apiGetDecoder : Decode.Decoder Model.DataFromServer apiGetDecoder = decode Model.DataFromServer |> required "headers" (Decode.list headerDecoder) |> optional "accordionHeaders" (Decode.maybe (Decode.list headerDecoder)) Nothing |> required "rows" (Decode.list rowDecoder) |> optional "incompleteColumn" (Decode.maybe Decode.int) Nothing |> optional "incompleteText" Decode.string "No" |> optional "headerIdsToRemoteIds" (Decode.dict Decode.string) Dict.empty |> optional "sideBarHeaders" (Decode.maybe (Decode.list sideBarHeaderDecoder)) Nothing |> optional "tableAction" (Decode.maybe Decode.string) Nothing |> optional "showVisibleColumnsUi" Decode.bool False |> optional "hasSideTable" Decode.bool False |> optional "sideRows" (Decode.list sideRowDecoder) [] |> optional "sideTableAction" Decode.string "Assign" |> optional "sideTablePreposition" Decode.string "to" |> optional "rowIdsToTitles" (Decode.dict Decode.string) Dict.empty headerDecoder : Decode.Decoder Model.HeaderData headerDecoder = decode Model.HeaderData |> required "id" Decode.string |> required "value" Decode.string |> required "type" Decode.string |> required "visible" Decode.bool |> optional "options" (Decode.list Decode.string) [] |> optional "displayedTextOptions" (Decode.list Decode.string) [] |> optional "hasNumericalValues" Decode.bool False |> optional "description" (Decode.maybe Decode.string) Nothing sideBarHeaderDecoder : Decode.Decoder Model.SideBarHeaderData sideBarHeaderDecoder = decode Model.SideBarHeaderData |> required "id" Decode.string |> required "value" Decode.string |> required "type" Decode.string |> optional "options" (Decode.list Decode.string) [] |> optional "displayedTextOptions" (Decode.list Decode.string) [] |> optional "hasNumericalValues" Decode.bool False |> optional "description" (Decode.maybe Decode.string) Nothing rowDecoder : Decode.Decoder Model.ApiRowData rowDecoder = decode Model.ApiRowData |> required "id" Decode.string |> optional "checkboxDisabledMsg" (Decode.maybe Decode.string) Nothing |> required "cells" (Decode.array cellDecoder) |> optional "accordionRows" (Decode.maybe accordionRowsDecoder) Nothing |> optional "rowFocusUrl" (Decode.maybe Decode.string) Nothing accordionRowsDecoder : Decode.Decoder (List (InputTable.Model.AccordionRow Model.RowData)) accordionRowsDecoder = Decode.list accordionRowDecoder accordionRowDecoder : Decode.Decoder (InputTable.Model.AccordionRow Model.RowData) accordionRowDecoder = decode InputTable.Model.AccordionRow |> required "id" Decode.string |> required "cells" (Decode.array cellDecoder) cellDecoder : Decode.Decoder Model.Cell cellDecoder = decode Model.Cell |> required "value" Decode.string |> optional "link" (Decode.maybe Decode.string) Nothing sideRowDecoder : Decode.Decoder (InputTable.Model.SideRow Model.Person) sideRowDecoder = decode InputTable.Model.SideRow |> required "id" Decode.string |> hardcoded False |> required "data" personDecoder personDecoder : Decode.Decoder Model.Person personDecoder = Decode.map2 Model.Person (Decode.field "name" Decode.string) (Decode.field "email" Decode.string)