@@ -1,69 +1,255 @@
1module Index exposing (main)
1module Index exposing (main)
3−import Html exposing (Html)
4−import Json.Decode as Decode
6−import Index.Dashboard as Dashboard
4+import Browser
6+import Html exposing (..)
7+import Html.Attributes exposing (class, href, src, style, title)
8+import Json.Decode as D
10+import Elm.License as License
11+import Elm.Package as Package
7−import Index.Project as Project exposing (Project)
12+import Elm.Project as Project
13+import Elm.Version as Version
15+import Index.Icon as Icon
16+import Index.Navigator as Navigator
17+import Index.Skeleton as Skeleton
24+main : Program D.Value Model Never
15− Html.programWithFlags
26+ Browser.fullscreen
16− { init = init
27+ { init = \env -> (D.decodeValue decoder env.flags, Cmd.none)
28+ , update = \_ model -> (model, Cmd.none)
29+ , subscriptions = \_ -> Sub.none
17 , view = view
30 , view = view
18− , update = update
31+ , onNavigation = Nothing
19− , subscriptions = subscriptions
44+ , readme : Maybe String
45+ , project : Project.Project
46+ , exactDeps : Dict.Dict String Version.Version
60+decoder : D.Decoder Flags
63+ (D.field "root" D.string)
64+ (D.field "pwd" (D.list D.string))
65+ (D.field "dirs" (D.list D.string))
66+ (D.field "files" (D.list fileDecoder))
67+ (D.field "readme" (D.nullable D.string))
68+ (D.field "project" Project.decoder)
69+ (D.field "exactDeps" (D.dict Version.decoder))
72+fileDecoder : D.Decoder File
75+ (D.field "name" D.string)
76+ (D.field "runnable" D.bool)
27type alias Model =
83type alias Model =
28− Project
84+ Result D.Error Flags
35−init : Decode.Value -> (Model, Cmd msg)
91+view : Model -> Browser.View msg
36−init flags =
92+view model =
37− case Project.decode flags of
93+ case model of
39− Debug.crash "TODO"
95+ { title = "???"
97+ [ text "Something went wrong!"
41− Ok project ->
101+ Ok { root, pwd, dirs, files, readme, project, exactDeps } ->
42− (project, Cmd.none)
102+ { title = String.join "/" ("~" :: pwd)
104+ [ header [ class "header" ] []
105+ , div [ class "content" ]
106+ [ Navigator.view root pwd
107+ , section [ class "left-column" ]
108+ [ viewFiles dirs files
111+ , section [ class "right-column" ]
112+ [ viewProjectSummary project
113+ , viewDeps exactDeps project
114+ , viewTestDeps exactDeps project
116+ , div [ style "clear" "both" ] []
46−-- UPDATE
123+-- VIEW README
49−update : msg -> Model -> (Model, Cmd msg)
126+viewReadme : Maybe String -> Html msg
50−update _ model =
127+viewReadme readme =
51− (model, Cmd.none)
128+ case readme of
133+ Skeleton.readmeBox markdown
58−subscriptions : Model -> Sub msg
140+viewFiles : List String -> List File -> Html msg
141+viewFiles dirs files =
143+ { title = "File Navigation"
144+ , items = List.map viewDir dirs ++ List.map viewFile files
149+viewDir : String -> List (Html msg)
151+ [ a [ href dir ] [ Icon.folder, text dir ]
155+viewFile : File -> List (Html msg)
157+ [ a [ href name ] [ Icon.lookup name, text name ]
64−-- VIEW
162+-- VIEW PAGE SUMMARY
165+viewProjectSummary : Project.Project -> Html msg
166+viewProjectSummary project =
168+ Project.Application info ->
170+ { title = "Source Directories"
171+ , items = List.map (\dir -> [text dir]) info.dirs
174+ -- TODO show estimated bundle size here
176+ Project.Package info ->
178+ { title = "Package Info"
180+ [ [ text ("Name: " ++ Package.toString info.name) ]
181+ , [ text ("Version: " ++ Version.toString info.version) ]
182+ , [ text ("License: " ++ License.toString info.license) ]
192+type alias ExactDeps =
193+ Dict.Dict String Version.Version
196+viewDeps : ExactDeps -> Project.Project -> Html msg
197+viewDeps exactDeps project =
201+ Project.Application info ->
202+ List.map (viewDependency exactDeps) info.deps
204+ Project.Package info ->
205+ List.map (viewDependency exactDeps) info.deps
208+ { title = "Dependencies"
209+ , items = dependencies
210+ , footer = Nothing -- TODO Just ("/_elm/dependencies", "Add more dependencies?")
214+viewTestDeps : ExactDeps -> Project.Project -> Html msg
215+viewTestDeps exactDeps project =
219+ Project.Application info ->
220+ List.map (viewDependency exactDeps) info.testDeps
222+ Project.Package info ->
223+ List.map (viewDependency exactDeps) info.testDeps
226+ { title = "Test Dependencies"
227+ , items = dependencies
228+ , footer = Nothing -- TODO Just ("/_elm/test-dependencies", "Add more test dependencies?")
67−view : Model -> Html msg
232+viewDependency : ExactDeps -> (Package.Name, vsn) -> List (Html msg)
68−view =
233+viewDependency exactDeps (pkg, _) =
69− Dashboard.view
234+ case Dict.get (Package.toString pkg) exactDeps of
236+ [ div [ style "float" "left" ]
238+ , text (Package.toString pkg)
240+ , div [ style "float" "right" ] [ text "???" ]
244+ [ div [ style "float" "left" ]
246+ , a [ href (toPackageUrl pkg version) ] [ text (Package.toString pkg) ]
248+ , div [ style "float" "right" ] [ text (Version.toString version) ]
252+toPackageUrl : Package.Name -> Version.Version -> String
253+toPackageUrl name version =
254+ "http://package.elm-lang.org/packages/"
255+ ++ Package.toString name ++ "/" ++ Version.toString version