on master help sign in
Simplify ui/browser/src code a bunch

Just have Index, NotFound, and Errors Will need to clean those up a bit later on.

commit71ed5c8a72a2e7f58c997fe0f7db98b98195ce3d authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 5 Apr 2018, 12:51 (9 years ago) parent790e0f3
8 files changed+264−1075
ui/browser/src/Errors.elm+35−127 ui/browser/src/Index.elm+214−28 ui/browser/src/Index/Dashboard.elm−228 ui/browser/src/Index/Skeleton.elm+1−14 ui/browser/src/Main.elm−273 ui/browser/src/NotFound.elm+14 ui/browser/src/Page/Directory.elm−202 ui/browser/src/Start.elm−203
ui/browser/src/Errors.elm+35−127
@@ -1,5 +1,7 @@
11module Errors exposing (main)
22
3+
4+import Browser
35import Char
46import Html exposing (..)
57import Html.Attributes exposing (..)
@@ -7,139 +9,45 @@ import String
79
810
911
12+-- MAIN
13+
14+
1015main =
11− Html.programWithFlags
12− { init = init
13− , update = update
16+ Browser.fullscreen
17+ { init = \env -> (env.flags, Cmd.none)
18+ , update = \_ model -> (model, Cmd.none)
1419 , view = view
15− , subscriptions = always Sub.none
20+ , subscriptions = \_ -> Sub.none
21+ , onNavigation = Nothing
1622 }
1723
1824
1925
20−-- MODEL
21−
22−
23−type alias Model =
24− String
25−
26−
27−init : String -> (Model, Cmd msg)
28−init errorMessage =
29− (errorMessage, Cmd.none)
30−
31−
32−
33−-- UPDATE
34−
35−
36−update : msg -> Model -> (Model, Cmd msg)
37−update _ model =
38− (model, Cmd.none)
39−
40−
41−
4226-- VIEW
4327
4428
45−view : Model -> Html msg
46−view model =
47− div
48− [ style "width" "100%"
49− , style "min-height" "100%"
50− , style "display" "flex"
51− , style "flex-direction" "column"
52− , style "align-items" "center"
53− , style "background-color" "black"
54− , style "color" "rgb(233, 235, 235)"
55− , style "font-family" "monospace"
56− ]
57− [ div
58− [ style "display" "block"
59− , style "white-space" "pre"
60− , style "background-color" "rgb(39, 40, 34)"
61− , style "padding" "2em"
62− ]
63− (addColors model)
64− ]
65−
66−
67−addColors : String -> List (Html msg)
68−addColors message =
69− message
70− |> String.lines
71− |> List.concatMap addColorToLine
72−
73−
74−addColorToLine : String -> List (Html msg)
75−addColorToLine line =
76− flip (++) [ text "\n" ] <|
77− if isBreaker line then
78− [ colorful "rgb(51, 187, 200)" ("\n\n" ++ line) ]
79−
80− else if isBigBreaker line then
81− [ colorful "rgb(211, 56, 211)" line ]
82−
83− else if isUnderline line then
84− [ colorful "#D5200C" line ]
85−
86− else if String.startsWith " " line then
87− [ colorful "#9A9A9A" line ]
88−
89− else
90− processLine line
91−
92−
93−colorful : String -> String -> Html msg
94−colorful color msg =
95− span [ style "color" color ] [ text msg ]
96−
97−
98−isBreaker : String -> Bool
99−isBreaker line =
100− String.startsWith "-- " line
101− &&
102− String.contains "----------" line
103−
104−
105−isBigBreaker : String -> Bool
106−isBigBreaker line =
107− String.startsWith "===============" line
108−
109−
110−isUnderline : String -> Bool
111−isUnderline line =
112− String.all (\c -> c == ' ' || c == '^') line
113−
114−
115−isLineNumber : String -> Bool
116−isLineNumber string =
117− String.all (\c -> c == ' ' || Char.isDigit c) string
118−
119−
120−processLine : String -> List (Html msg)
121−processLine line =
122− case String.split "|" line of
123− [] ->
124− [ text line ]
125−
126− starter :: rest ->
127− if not (isLineNumber starter) then
128− [ text line ]
129−
130− else
131− let
132− restOfLine =
133− String.join "|" rest
134−
135− marker =
136− if String.left 1 restOfLine == ">" then
137− colorful "#D5200C" ">"
138−
139− else
140− text " "
141− in
142− [ colorful "#9A9A9A" (starter ++ "|")
143− , marker
144− , colorful "#9A9A9A" (String.dropLeft 1 restOfLine)
145− ]
29+view : String -> Browser.View msg
30+view message =
31+ { title = "Error"
32+ , body =
33+ [ div
34+ [ style "width" "100%"
35+ , style "min-height" "100%"
36+ , style "display" "flex"
37+ , style "flex-direction" "column"
38+ , style "align-items" "center"
39+ , style "background-color" "black"
40+ , style "color" "rgb(233, 235, 235)"
41+ , style "font-family" "monospace"
42+ ]
43+ [ div
44+ [ style "display" "block"
45+ , style "white-space" "pre"
46+ , style "background-color" "rgb(39, 40, 34)"
47+ , style "padding" "2em"
48+ ]
49+ [ text message
50+ ]
51+ ]
52+ ]
53+ }
ui/browser/src/Index.elm+214−28
@@ -1,69 +1,255 @@
11module Index exposing (main)
22
3−import Html exposing (Html)
4−import Json.Decode as Decode
53
6−import Index.Dashboard as Dashboard
7−import Index.Project as Project exposing (Project)
4+import Browser
5+import Dict
6+import Html exposing (..)
7+import Html.Attributes exposing (class, href, src, style, title)
8+import Json.Decode as D
9+
10+import Elm.License as License
11+import Elm.Package as Package
12+import Elm.Project as Project
13+import Elm.Version as Version
14+
15+import Index.Icon as Icon
16+import Index.Navigator as Navigator
17+import Index.Skeleton as Skeleton
818
919
1020
1121-- MAIN
1222
1323
24+main : Program D.Value Model Never
1425main =
15− Html.programWithFlags
16− { init = init
26+ Browser.fullscreen
27+ { init = \env -> (D.decodeValue decoder env.flags, Cmd.none)
28+ , update = \_ model -> (model, Cmd.none)
29+ , subscriptions = \_ -> Sub.none
1730 , view = view
18− , update = update
19− , subscriptions = subscriptions
31+ , onNavigation = Nothing
2032 }
2133
2234
2335
36+-- FLAGS
37+
38+
39+type alias Flags =
40+ { root : String
41+ , pwd : List String
42+ , dirs : List String
43+ , files : List File
44+ , readme : Maybe String
45+ , project : Project.Project
46+ , exactDeps : Dict.Dict String Version.Version
47+ }
48+
49+
50+type alias File =
51+ { name : String
52+ , runnable : Bool
53+ }
54+
55+
56+
57+-- DECODER
58+
59+
60+decoder : D.Decoder Flags
61+decoder =
62+ D.map7 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))
70+
71+
72+fileDecoder : D.Decoder File
73+fileDecoder =
74+ D.map2 File
75+ (D.field "name" D.string)
76+ (D.field "runnable" D.bool)
77+
78+
79+
2480-- MODEL
2581
2682
2783type alias Model =
28− Project
84+ Result D.Error Flags
2985
3086
3187
32−-- INIT
88+-- VIEW
3389
3490
35−init : Decode.Value -> (Model, Cmd msg)
36−init flags =
37− case Project.decode flags of
91+view : Model -> Browser.View msg
92+view model =
93+ case model of
3894 Err _ ->
39− Debug.crash "TODO"
95+ { title = "???"
96+ , body =
97+ [ text "Something went wrong!"
98+ ]
99+ }
40100
41− Ok project ->
42− (project, Cmd.none)
101+ Ok { root, pwd, dirs, files, readme, project, exactDeps } ->
102+ { title = String.join "/" ("~" :: pwd)
103+ , body =
104+ [ header [ class "header" ] []
105+ , div [ class "content" ]
106+ [ Navigator.view root pwd
107+ , section [ class "left-column" ]
108+ [ viewFiles dirs files
109+ , viewReadme readme
110+ ]
111+ , section [ class "right-column" ]
112+ [ viewProjectSummary project
113+ , viewDeps exactDeps project
114+ , viewTestDeps exactDeps project
115+ ]
116+ , div [ style "clear" "both" ] []
117+ ]
118+ ]
119+ }
43120
44121
45122
46−-- UPDATE
123+-- VIEW README
47124
48125
49−update : msg -> Model -> (Model, Cmd msg)
50−update _ model =
51− (model, Cmd.none)
126+viewReadme : Maybe String -> Html msg
127+viewReadme readme =
128+ case readme of
129+ Nothing ->
130+ text ""
52131
132+ Just markdown ->
133+ Skeleton.readmeBox markdown
53134
54135
55−-- SUBSCRIPTIONS
56136
137+-- VIEW FILES
57138
58−subscriptions : Model -> Sub msg
59−subscriptions model =
60− Sub.none
61139
140+viewFiles : List String -> List File -> Html msg
141+viewFiles dirs files =
142+ Skeleton.box
143+ { title = "File Navigation"
144+ , items = List.map viewDir dirs ++ List.map viewFile files
145+ , footer = Nothing
146+ }
62147
63148
64−-- VIEW
149+viewDir : String -> List (Html msg)
150+viewDir dir =
151+ [ a [ href dir ] [ Icon.folder, text dir ]
152+ ]
153+
154+
155+viewFile : File -> List (Html msg)
156+viewFile {name} =
157+ [ a [ href name ] [ Icon.lookup name, text name ]
158+ ]
159+
160+
161+
162+-- VIEW PAGE SUMMARY
163+
164+
165+viewProjectSummary : Project.Project -> Html msg
166+viewProjectSummary project =
167+ case project of
168+ Project.Application info ->
169+ Skeleton.box
170+ { title = "Source Directories"
171+ , items = List.map (\dir -> [text dir]) info.dirs
172+ , footer = Nothing
173+ }
174+ -- TODO show estimated bundle size here
175+
176+ Project.Package info ->
177+ Skeleton.box
178+ { title = "Package Info"
179+ , items =
180+ [ [ text ("Name: " ++ Package.toString info.name) ]
181+ , [ text ("Version: " ++ Version.toString info.version) ]
182+ , [ text ("License: " ++ License.toString info.license) ]
183+ ]
184+ , footer = Nothing
185+ }
186+
187+
188+
189+-- VIEW DEPENDENCIES
190+
191+
192+type alias ExactDeps =
193+ Dict.Dict String Version.Version
194+
195+
196+viewDeps : ExactDeps -> Project.Project -> Html msg
197+viewDeps exactDeps project =
198+ let
199+ dependencies =
200+ case project of
201+ Project.Application info ->
202+ List.map (viewDependency exactDeps) info.deps
203+
204+ Project.Package info ->
205+ List.map (viewDependency exactDeps) info.deps
206+ in
207+ Skeleton.box
208+ { title = "Dependencies"
209+ , items = dependencies
210+ , footer = Nothing -- TODO Just ("/_elm/dependencies", "Add more dependencies?")
211+ }
212+
213+
214+viewTestDeps : ExactDeps -> Project.Project -> Html msg
215+viewTestDeps exactDeps project =
216+ let
217+ dependencies =
218+ case project of
219+ Project.Application info ->
220+ List.map (viewDependency exactDeps) info.testDeps
221+
222+ Project.Package info ->
223+ List.map (viewDependency exactDeps) info.testDeps
224+ in
225+ Skeleton.box
226+ { title = "Test Dependencies"
227+ , items = dependencies
228+ , footer = Nothing -- TODO Just ("/_elm/test-dependencies", "Add more test dependencies?")
229+ }
65230
66231
67−view : Model -> Html msg
68−view =
69− Dashboard.view
232+viewDependency : ExactDeps -> (Package.Name, vsn) -> List (Html msg)
233+viewDependency exactDeps (pkg, _) =
234+ case Dict.get (Package.toString pkg) exactDeps of
235+ Nothing ->
236+ [ div [ style "float" "left" ]
237+ [ Icon.package
238+ , text (Package.toString pkg)
239+ ]
240+ , div [ style "float" "right" ] [ text "???" ]
241+ ]
242+
243+ Just version ->
244+ [ div [ style "float" "left" ]
245+ [ Icon.package
246+ , a [ href (toPackageUrl pkg version) ] [ text (Package.toString pkg) ]
247+ ]
248+ , div [ style "float" "right" ] [ text (Version.toString version) ]
249+ ]
250+
251+
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
ui/browser/src/Index/Dashboard.elmdeleted−228
@@ -1,228 +0,0 @@
1−module Index.Dashboard exposing
2− ( view
3− )
4−
5−
6−import Html exposing (..)
7−import Html.Attributes exposing (class, href, style, title)
8−
9−import Elm.Config as Config exposing (Config)
10−import Elm.License as License
11−import Elm.Repo as Repo exposing (Repo)
12−import Elm.Version as Version exposing (Version)
13−import Index.Icon as Icon
14−import Index.Navigator as Navigator exposing ((</>))
15−import Index.Project as Project exposing (Project, File(..))
16−import Index.Skeleton as Skeleton
17−
18−
19−
20−-- VIEW
21−
22−
23−view : Project -> Html msg
24−view { root, pwd, dirs, files, readme, config } =
25− Skeleton.view
26− [ Navigator.view root pwd
27− , viewLeftColumn dirs files readme
28− , viewRightColumn config
29− , clearfix
30− ]
31−
32−
33−clearfix : Html msg
34−clearfix =
35− div [ style "clear" "both" ] []
36−
37−
38−
39−-- VIEW LEFT COLUMN
40−
41−
42−viewLeftColumn : List String -> List File -> Maybe String -> Html msg
43−viewLeftColumn dirs files readme =
44− section [ class "left-column" ]
45− [ viewFiles dirs files
46− , viewReadme readme
47− ]
48−
49−
50−
51−-- VIEW README
52−
53−
54−viewReadme : Maybe String -> Html msg
55−viewReadme readme =
56− case readme of
57− Nothing ->
58− text ""
59−
60− Just markdown ->
61− Skeleton.readmeBox markdown
62−
63−
64−
65−-- VIEW FILES
66−
67−
68−viewFiles : List String -> List File -> Html msg
69−viewFiles dirs files =
70− Skeleton.box
71− { title = "File Navigation"
72− , items = List.map viewDir dirs ++ List.map viewFile files
73− , footer = Nothing
74− }
75−
76−
77−viewDir : String -> List (Html msg)
78−viewDir dir =
79− [ a [ href dir ] [ Icon.folder, text dir ]
80− ]
81−
82−
83−viewFile : File -> List (Html msg)
84−viewFile file =
85− case file of
86− HasMain name ->
87− [ a [ href name ] [ Icon.lookup name, text name ]
88− ]
89−
90− NoMain name ->
91− [ a [ href name ] [ Icon.lookup name, text name ]
92− ]
93−
94− Other name ->
95− [ a [ href name ] [ Icon.lookup name, text name ]
96− ]
97−
98−
99−
100−-- VIEW RIGHT COLUMN
101−
102−
103−viewRightColumn : Config -> Html msg
104−viewRightColumn config =
105− div [ class "right-column" ] <|
106− case config of
107− Config.App info ->
108− [ viewPageSummary info.pages
109− , viewDeps info.dependencies
110− , viewTestDeps info.testDependencies
111− ]
112−
113− Config.Pkg info ->
114− [ viewPackageSummary info
115− , viewDeps (exactify info.dependencies)
116− , viewTestDeps (exactify info.testDependencies)
117− ]
118−
119−
120−
121−-- VIEW PAGE SUMMARY
122−
123−
124−viewPageSummary : List String -> Html msg
125−viewPageSummary pages =
126− Skeleton.box
127− { title = "Pages"
128− , items = List.map viewPage pages
129− , footer = Nothing
130− }
131−
132−
133−viewPage : String -> List (Html msg)
134−viewPage name =
135− [ div
136− [ style "float" "left"
137− ]
138− [ Icon.gift
139− , text name
140− ]
141− , div
142− [ style "float" "right"
143− ]
144− [ text "7kb"
145− , bundleSize 10
146− ]
147− ]
148−
149−
150−bundleSize : Int -> Html msg
151−bundleSize size =
152− span
153− [ style "color" "#e1e1e1"
154− ]
155− [ text (" + " ++ String.fromInt size ++ "kb")
156− ]
157−
158−
159−
160−-- VIEW PACKAGE SUMMARY
161−
162−
163−viewPackageSummary : Config.PkgInfo -> Html msg
164−viewPackageSummary { summary, license, version } =
165− Skeleton.box
166− { title = "Package Information"
167− , items =
168− [ [ text ("Version: " ++ Version.toString version) ]
169− , [ text ("License: " ++ license.code) ]
170− ]
171− , footer = Nothing
172− }
173−
174−
175−
176−-- VIEW DEPENDENCIES
177−
178−
179−viewDeps : Config.Deps Version -> Html msg
180−viewDeps deps =
181− Skeleton.box
182− { title = "Dependencies"
183− , items = List.map viewDep deps
184− , footer =
185− Just
186− ( "/_elm/dependencies"
187− , "Add more dependencies?"
188− )
189− }
190−
191−
192−viewTestDeps : Config.Deps Version -> Html msg
193−viewTestDeps deps =
194− Skeleton.box
195− { title = "Test Dependencies"
196− , items = List.map viewDep deps
197− , footer =
198− Just
199− ( "/_elm/test-dependencies"
200− , "Add more test dependencies?"
201− )
202− }
203−
204−
205−viewDep : (Repo, Version) -> List (Html msg)
206−viewDep (repo, version) =
207− [ div
208− [ style "float" "left" ]
209− [ Icon.package
210− , a [ href (toPackageUrl repo version) ] [ text (Repo.toString repo) ]
211− ]
212− , div
213− [ style "float" "right" ]
214− [ text (Version.toString version) ]
215− ]
216−
217−
218−toPackageUrl : Repo -> Version -> String
219−toPackageUrl name version =
220− "http://package.elm-lang.org/packages"
221− </> Repo.toString name
222− </> Version.toString version
223−
224−
225−-- TODO - make this actually work!
226−exactify : Config.Deps a -> Config.Deps Version
227−exactify deps =
228− List.map (\(name, _) -> (name, Version 0 0 0)) deps
ui/browser/src/Index/Skeleton.elm+1−14
@@ -1,6 +1,5 @@
11module Index.Skeleton exposing
2− ( view
3− , box
2+ ( box
43 , readmeBox
54 )
65
@@ -12,18 +11,6 @@ import Index.Icon as Icon
1211
1312
1413
15−-- VIEW
16−
17−
18−view : List (Html msg) -> Html msg
19−view content =
20− div []
21− [ header [ class "header" ] []
22− , div [class "content"] content
23− ]
24−
25−
26−
2714-- VIEW BOXES
2815
2916
ui/browser/src/Main.elmdeleted−273
@@ -1,273 +0,0 @@
1−module Main exposing (main)
2−
3−
4−import Browser
5−import Dict
6−import Html exposing (..)
7−import Html.Attributes exposing (class, href, src, style, title)
8−import Json.Decode as D
9−
10−import Elm.License as License
11−import Elm.Package as Package
12−import Elm.Project as Project
13−import Elm.Version as Version
14−import Index.Icon as Icon
15−import Index.Skeleton as Skeleton
16−
17−
18−
19−-- MAIN
20−
21−
22−main : Program () () ()
23−main =
24− Browser.fullscreen
25− { init = Debug.crash "init"
26− , update = Debug.crash "update"
27− , subscriptions = Debug.crash "subscriptions"
28− , view = Debug.crash "view"
29− , onNavigation = Nothing
30− }
31−
32−
33−
34−-- MODEL
35−
36−
37−type alias Model =
38− { path : String
39− , status : ProjectStatus
40− , directory : DirectoryStatus
41− }
42−
43−
44−type ProjectStatus
45− = ProjectIsNew
46− | ProjectIsInvalid
47− | ProjectIsValid
48− { root : String
49− , project : Project.Project
50− , exactDeps : Dict.Dict String Version.Version
51− }
52−
53−
54−type DirectoryStatus
55− = NotFound
56− | Waiting
57− | Found Directory
58−
59−
60−
61−-- DIRECTORY
62−
63−
64−type alias Directory =
65− { dirs : List String
66− , files : List File
67− , readme : Maybe String
68− }
69−
70−
71−type alias File =
72− { name : String
73− , runnable : Bool
74− }
75−
76−
77−
78−-- DECODER
79−
80−
81−decoder : D.Decoder Directory
82−decoder =
83− D.map3 Directory
84− (D.field "dirs" (D.list D.string))
85− (D.field "files" (D.list fileDecoder))
86− (D.field "readme" (D.nullable D.string))
87−
88−
89−fileDecoder : D.Decoder File
90−fileDecoder =
91− D.map2 File
92− (D.field "name" D.string)
93− (D.field "runnable" D.bool)
94−
95−
96−
97−-- NOT FOUND
98−
99−
100−notFound : Html msg
101−notFound =
102− div [ class "not-found" ]
103− [ div [ style "font-size" "12em" ] [ text "404" ]
104− , div [ style "font-size" "3em" ] [ text "Page not found" ]
105− ]
106−
107−
108−
109−-- WAITING
110−
111−
112−waiting : Html msg
113−waiting =
114− div [ class "waiting" ]
115− [ img [ src "/_elm/waiting.gif" ] []
116− ]
117−
118−
119−
120−-- VIEW DIRECTORY
121−
122−
123−viewDirectory : ExactDeps -> Project.Project -> Directory -> Html msg
124−viewDirectory exactDeps project directory =
125− Skeleton.view
126− -- Navigator.view pwd TODO
127− [ section [ class "left-column" ]
128− [ viewFiles directory.dirs directory.files
129− , viewReadme directory.readme
130− ]
131− , section [ class "right-column" ]
132− [ viewProjectSummary project
133− , viewDeps exactDeps project
134− , viewTestDeps exactDeps project
135− ]
136− , div [ style "clear" "both" ] []
137− ]
138−
139−
140−
141−-- VIEW README
142−
143−
144−viewReadme : Maybe String -> Html msg
145−viewReadme readme =
146− case readme of
147− Nothing ->
148− text ""
149−
150− Just markdown ->
151− Skeleton.readmeBox markdown
152−
153−
154−
155−-- VIEW FILES
156−
157−
158−viewFiles : List String -> List File -> Html msg
159−viewFiles dirs files =
160− Skeleton.box
161− { title = "File Navigation"
162− , items = List.map viewDir dirs ++ List.map viewFile files
163− , footer = Nothing
164− }
165−
166−
167−viewDir : String -> List (Html msg)
168−viewDir dir =
169− [ a [ href dir ] [ Icon.folder, text dir ]
170− ]
171−
172−
173−viewFile : File -> List (Html msg)
174−viewFile {name} =
175− [ a [ href name ] [ Icon.lookup name, text name ]
176− ]
177−
178−
179−
180−-- VIEW PAGE SUMMARY
181−
182−
183−viewProjectSummary : Project.Project -> Html msg
184−viewProjectSummary project =
185− case project of
186− Project.Application info ->
187− Skeleton.box
188− { title = "Source Directories"
189− , items = List.map (\dir -> [text dir]) info.dirs
190− , footer = Nothing
191− }
192− -- TODO show estimated bundle size here
193−
194− Project.Package info ->
195− Skeleton.box
196− { title = "Package Info"
197− , items =
198− [ [ text ("Name: " ++ Package.toString info.name) ]
199− , [ text ("Version: " ++ Version.toString info.version) ]
200− , [ text ("License: " ++ License.toString info.license) ]
201− ]
202− , footer = Nothing
203− }
204−
205−
206−
207−-- VIEW DEPENDENCIES
208−
209−
210−type alias ExactDeps =
211− Dict.Dict String Version.Version
212−
213−
214−viewDeps : ExactDeps -> Project.Project -> Html msg
215−viewDeps exactDeps project =
216− let
217− dependencies =
218− case project of
219− Project.Application info ->
220− List.map (viewDependency exactDeps) info.deps
221−
222− Project.Package info ->
223− List.map (viewDependency exactDeps) info.deps
224− in
225− Skeleton.box
226− { title = "Dependencies"
227− , items = dependencies
228− , footer = Nothing -- TODO Just ("/_elm/dependencies", "Add more dependencies?")
229− }
230−
231−
232−viewTestDeps : ExactDeps -> Project.Project -> Html msg
233−viewTestDeps exactDeps project =
234− let
235− dependencies =
236− case project of
237− Project.Application info ->
238− List.map (viewDependency exactDeps) info.testDeps
239−
240− Project.Package info ->
241− List.map (viewDependency exactDeps) info.testDeps
242− in
243− Skeleton.box
244− { title = "Test Dependencies"
245− , items = dependencies
246− , footer = Nothing -- TODO Just ("/_elm/test-dependencies", "Add more test dependencies?")
247− }
248−
249−
250−viewDependency : ExactDeps -> (Package.Name, vsn) -> List (Html msg)
251−viewDependency exactDeps (pkg, _) =
252− case Dict.get (Package.toString pkg) exactDeps of
253− Nothing ->
254− [ div [ style "float" "left" ]
255− [ Icon.package
256− , text (Package.toString pkg)
257− ]
258− , div [ style "float" "right" ] [ text "???" ]
259− ]
260−
261− Just version ->
262− [ div [ style "float" "left" ]
263− [ Icon.package
264− , a [ href (toPackageUrl pkg version) ] [ text (Package.toString pkg) ]
265− ]
266− , div [ style "float" "right" ] [ text (Version.toString version) ]
267− ]
268−
269−
270−toPackageUrl : Package.Name -> Version.Version -> String
271−toPackageUrl name version =
272− "http://package.elm-lang.org/packages/"
273− ++ Package.toString name ++ "/" ++ Version.toString version
ui/browser/src/NotFound.elm+14
@@ -0,0 +1,14 @@
1+module NotFound exposing (main)
2+
3+
4+import Html exposing (..)
5+import Html.Attributes exposing (..)
6+
7+
8+
9+main : Html msg
10+main =
11+ div [ class "not-found" ]
12+ [ div [ style "font-size" "12em" ] [ text "404" ]
13+ , div [ style "font-size" "3em" ] [ text "Page not found" ]
14+ ]
ui/browser/src/Page/Directory.elmdeleted−202
@@ -1,202 +0,0 @@
1−module Page.Directory exposing
2− ( Info
3− , File(..)
4− , decoder
5− )
6−
7−
8−import Json.Decode as D
9−
10−import Elm.Project as Project
11−
12−
13−
14−
15−-- DIRECTORY
16−
17−
18−type alias Directory =
19− { path : List String
20− , dirs : List String
21− , files : List File
22− , readme : Maybe String
23− }
24−
25−
26−type alias File =
27− { name : String
28− , runnable : Bool
29− }
30−
31−
32−
33−-- DECODER
34−
35−
36−decoder : D.Decoder Directory
37−decoder =
38− D.map4 Directory
39− (D.field "path" (D.list D.string))
40− (D.field "dirs" (D.list D.string))
41− (D.field "files" (D.list fileDecoder))
42− (D.field "readme" (D.nullable D.string))
43−
44−
45−fileDecoder : D.Decoder File
46−fileDecoder =
47− D.map2 File
48− (D.field "name" D.string)
49− (D.field "runnable" D.bool)
50−
51−
52−
53−-- VIEW
54−
55−
56−view : Project -> Directory -> Html msg
57−view project directory =
58− Skeleton.view
59− [ Navigator.view pwd
60− , section [ class "left-column" ]
61− [ viewFiles directory.dirs directory.files
62− , viewReadme directory.readme
63− ]
64− , section [ class "right-column" ]
65− [ viewProjectSummary project
66− , viewDeps project
67− , viewTestDeps project
68− ]
69− , div [ style "clear" "both" ] []
70− ]
71−
72−
73−
74−-- VIEW README
75−
76−
77−viewReadme : Maybe String -> Html msg
78−viewReadme readme =
79− case readme of
80− Nothing ->
81− text ""
82−
83− Just markdown ->
84− Skeleton.readmeBox markdown
85−
86−
87−
88−-- VIEW FILES
89−
90−
91−viewFiles : List String -> List File -> Html msg
92−viewFiles dirs files =
93− Skeleton.box
94− { title = "File Navigation"
95− , items = List.map viewDir dirs ++ List.map viewFile files
96− , footer = Nothing
97− }
98−
99−
100−viewDir : String -> List (Html msg)
101−viewDir dir =
102− [ a [ href dir ] [ Icon.folder, text dir ]
103− ]
104−
105−
106−viewFile : File -> List (Html msg)
107−viewFile {name} =
108− [ a [ href name ] [ Icon.lookup name, text name ]
109− ]
110−
111−
112−
113−-- VIEW PAGE SUMMARY
114−
115−
116−viewProjectSummary : Project.Project -> Html msg
117−viewProjectSummary project =
118− case project of
119− Project.Browser info ->
120− Skeleton.box
121− { title = "Source Directories"
122− , items = List.map (\dir -> [text dir]) info.dirs
123− , footer = Nothing
124− }
125− -- TODO show estimated bundle size here
126−
127− Project.Package info ->
128− Skeleton.box
129− { title = "Package Info"
130− , items =
131− [ [ text ("Name: " ++ info.name) ]
132− , [ text ("Version: " ++ Version.toString info.version) ]
133− , [ text ("License: " ++ License.toString info.license) ]
134− ]
135− , footer = Nothing
136− }
137−
138−
139−
140−-- VIEW DEPENDENCIES
141−
142−
143−viewDeps : ExactDeps -> Project.Project -> Html msg
144−viewDeps exactDeps project =
145− let
146− dependencies =
147− case project of
148− Project.Browser info ->
149− List.map (viewDependency exactDeps) info.deps
150−
151− Project.Package info ->
152− List.map (viewDependency exactDeps) info.deps
153− in
154− Skeleton.box
155− { title = "Dependencies"
156− , items = dependencies
157− , footer = Nothing -- TODO Just ("/_elm/dependencies", "Add more dependencies?")
158− }
159−
160−
161−viewTestDeps : ExactDeps -> Project.Project -> Html msg
162−viewTestDeps exactDeps project =
163− let
164− dependencies =
165− case project of
166− Project.Browser info ->
167− List.map (viewDependency exactDeps) info.testDeps
168−
169− Project.Package info ->
170− List.map (viewDependency exactDeps) info.testDeps
171− in
172− Skeleton.box
173− { title = "Test Dependencies"
174− , items = dependencies
175− , footer = Nothing -- TODO Just ("/_elm/test-dependencies", "Add more test dependencies?")
176− }
177−
178−
179−viewDependency : ExactDeps -> (Package.Name, vsn) -> List (Html msg)
180−viewDependency exactDeps (pkg, _) =
181− case Dict.get (Package.toString pkg) exactDeps of
182− Nothing ->
183− [ div [ style "float" "left" ]
184− [ Icon.package
185− , text (Package.toString pkg)
186− ]
187− , div [ style "float" "right" ] [ text "???" ]
188− ]
189−
190− Just version ->
191− [ div [ style "float" "left" ]
192− [ Icon.package
193− , a [ href (toPackageUrl pkg version) ] [ text (Package.toString pkg) ]
194− ]
195− , div [ style "float" "right" ] [ text (Version.toString version) ]
196− ]
197−
198−
199−toPackageUrl : Package.Name -> Version.Version -> String
200−toPackageUrl name version =
201− "http://package.elm-lang.org/packages/"
202− ++ Package.toString name ++ "/" ++ Version.toString version
ui/browser/src/Start.elmdeleted−203
@@ -1,203 +0,0 @@
1−module Start exposing (..)
2−
3−
4−import Html exposing (..)
5−import Html.Attributes exposing (..)
6−import Html.Events exposing (..)
7−import Html.Lazy exposing (lazy)
8−import Http
9−import Navigation
10−import String
11−
12−
13−main =
14− Html.programWithFlags
15− { init = init
16− , update = update
17− , view = view
18− , subscriptions = subscriptions
19− }
20−
21−
22−
23−-- MODEL
24−
25−
26−type Model
27− = NoProject String
28− | PotentialProject String String
29− | Waiting
30−
31−
32−
33−-- INIT
34−
35−
36−type alias Flags =
37− { root : String
38− , suggestion : Maybe String
39− }
40−
41−
42−init : Flags -> ( Model, Cmd Msg )
43−init flags =
44− case flags.suggestion of
45− Nothing ->
46− ( NoProject flags.root, Cmd.none )
47−
48− Just suggestion ->
49− ( PotentialProject flags.root suggestion, Cmd.none )
50−
51−
52−
53−-- UPDATE
54−
55−
56−type Msg
57− = RequestNewProject
58− | NewProjectReady
59− | IgnoreSuggestion String
60− | MoveReactor
61−
62−
63−update : Msg -> Model -> ( Model, Cmd Msg )
64−update msg model =
65− case msg of
66− RequestNewProject ->
67− ( Waiting, createNewProject )
68−
69− NewProjectReady ->
70− ( Waiting, Navigation.reload )
71−
72− IgnoreSuggestion root ->
73− ( NoProject root, Cmd.none )
74−
75− MoveReactor ->
76− ( Waiting, moveReactor )
77−
78−
79−createNewProject : Cmd Msg
80−createNewProject =
81− Http.send (\_ -> NewProjectReady) <|
82− Http.getString "/_elm/create-new-project"
83−
84−
85−moveReactor : Cmd Msg
86−moveReactor =
87− Http.send (\_ -> NewProjectReady) <|
88− Http.getString "/_elm/move-to-root"
89−
90−
91−
92−-- SUBSCRIPTIONS
93−
94−
95−subscriptions : Model -> Sub Msg
96−subscriptions _ =
97− Sub.none
98−
99−
100−
101−-- VIEW
102−
103−
104−view : Model -> Html Msg
105−view model =
106− case model of
107− NoProject root ->
108− viewNoProject root
109−
110− PotentialProject root suggestion ->
111− viewPotentialProject root suggestion
112−
113− Waiting ->
114− viewWaiting
115−
116−
117−
118−-- VIEW NO PROJECT
119−
120−
121−viewNoProject : String -> Html Msg
122−viewNoProject root =
123− div [ class "start" ]
124− [ div [ class "start-hello" ]
125− [ h1 [] [ text "Hello!" ]
126− , para "Looks like you are starting a new Elm project. Exciting!"
127− , para "I will help you get set up. Just press this button!"
128− , div [ class "button" ]
129− [ a [ onClick RequestNewProject ] [ text "Create New Project" ]
130− ]
131− ]
132− , div [ class "start-details" ]
133− [ h2 [] [ text "What does this button do exactly?" ]
134− , p []
135− [ text "In the "
136− , code [] [ text root ]
137− , text " directory, I will create:"
138− ]
139− , ul []
140− [ file "elm.json" "describes which packages you need."
141− , file "src/" "a directory for all your Elm code."
142− , file "src/Main.elm" "an example Elm program."
143− , file "tests/" "a directory for any tests you write."
144− ]
145− , para "I will share more details on all this after you press the button!"
146− ]
147− ]
148−
149−
150−para : String -> Html msg
151−para str =
152− p [] [ text str ]
153−
154−
155−file : String -> String -> Html msg
156−file fileName description =
157− li []
158− [ code [] [ text fileName ]
159− , text " – "
160− , text description
161− ]
162−
163−
164−
165−-- VIEW WAITING
166−
167−
168−viewWaiting : Html msg
169−viewWaiting =
170− div [ class "waiting" ]
171− [ img [ src "/_elm/waiting.gif" ] []
172− ]
173−
174−
175−
176−-- VIEW POTENTIAL PROJECT
177−
178−
179−viewPotentialProject : String -> String -> Html Msg
180−viewPotentialProject root suggestion =
181− div [ class "start potential" ]
182− [ h1 [] [ text "Existing Project?" ]
183− , p []
184− [ text "You ran "
185− , code [] [ text "elm-reactor" ]
186− , text " from "
187− , code [] [ text root ]
188− , text " which is not the root of an Elm project."
189− ]
190− , p []
191− [ text "I found an Elm project at "
192− , code [] [ text suggestion ]
193− , text " though. Would you like to continue developing that one?"
194− ]
195− , div [ class "button" ]
196− [ a [ onClick MoveReactor ] [ text "Continue Existing Project" ]
197− ]
198− , h1 [] [ text "Or New Project?" ]
199− , para "Or maybe you want some weird nested Elm project, where you have Elm projects within other Elm projects. It is probably better to have them separated, but I can get you set up if that is what you really want!"
200− , div [ class "button" ]
201− [ a [ onClick (IgnoreSuggestion root) ] [ text "New Project" ]
202− ]
203− ]