Skip to content
This repository has been archived by the owner on Nov 11, 2019. It is now read-only.

Commit

Permalink
releng_frontend: switing routing to elm-lang/navigation
Browse files Browse the repository at this point in the history
also fixing css error that were caused when upgrading to newer bootstrap
  • Loading branch information
garbas committed Mar 31, 2017
1 parent 29d3618 commit 8cf4437
Show file tree
Hide file tree
Showing 12 changed files with 336 additions and 363 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
/src/**/.coverage-html
/src/**/build
/src/**/elm-stuff/
/src/**/cache/
/src/**/node_modules/
/tmp
17 changes: 17 additions & 0 deletions lib/frontend_common/TaskclusterLogin.elm
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ decodeCertificate text =
text


isCertificateExpired time user_ =
case user_ of
Just user ->
case user.certificate of
Just certificate ->
if time > (toFloat certificate.expiry) then
True
else
False

Nothing ->
False

Nothing ->
False


convertUrlQueryToUser : Dict String String -> Maybe Credentials
convertUrlQueryToUser query =
let
Expand Down
94 changes: 60 additions & 34 deletions src/releng_frontend/src/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ import Navigation
import TaskclusterLogin
import Time
import UrlParser
import UrlParser exposing ((</>))
import UrlParser exposing ((</>), (<?>))


--
-- ROUTING
--
-- inspired by https://github.com/rofrol/elm-navigation-example
--


type Route
= NotFoundRoute
| HomeRoute
| LoginRoute
| LoginRoute (Maybe String) (Maybe String) (Maybe String)
| LogoutRoute
| TryChooserRoute
| TreeStatusRoute App.TreeStatus.Types.Route
Expand All @@ -30,29 +37,34 @@ pages =
]


routes : UrlParser.Parser (Route -> a) a
routes =
routeParser : UrlParser.Parser (Route -> a) a
routeParser =
pages
|> List.map (\x -> x.matcher)
|> List.append
[ UrlParser.map HomeRoute (UrlParser.s "")
[ UrlParser.map HomeRoute UrlParser.top
, UrlParser.map NotFoundRoute (UrlParser.s "404")
, UrlParser.map LoginRoute (UrlParser.s "login")
, UrlParser.map LoginRoute
(UrlParser.s "login"
<?> UrlParser.stringParam "clientId"
<?> UrlParser.stringParam "accessToken"
<?> UrlParser.stringParam "certificate"
)
, UrlParser.map LogoutRoute (UrlParser.s "logout")
]
|> UrlParser.oneOf


reverse : Route -> String
reverse route =
reverseRoute : Route -> String
reverseRoute route =
case route of
NotFoundRoute ->
"/404"

HomeRoute ->
"/"

LoginRoute ->
LoginRoute _ _ _ ->
"/login"

LogoutRoute ->
Expand All @@ -62,30 +74,45 @@ reverse route =
"/trychooser"

TreeStatusRoute route ->
App.TreeStatus.reverse route
App.TreeStatus.reverseRoute route


parseLocation : Navigation.Location -> Route
parseLocation location =
location
|> UrlParser.parsePath routeParser
|> Maybe.withDefault NotFoundRoute


navigateTo : Route -> Cmd Msg
navigateTo route =
route
|> reverseRoute
|> Navigation.newUrl


urlParser : Navigation.Location -> Msg
urlParser location =
-- TODO: parse location into a route
NavigateTo HomeRoute

--
-- FLAGS
--


type alias Flags =
{ user : TaskclusterLogin.Model
, treestatusUrl : String
, docsUrl : String
, version : String
}



-- let
-- parse address =
-- address
-- |> UrlParser.parse identity routes
-- |> Result.withDefault NotFoundRoute
--
-- resolver =
-- Hop.makeResolver App.Types.hopConfig parse
-- in
-- Navigation.makeParser (.href >> resolver)
-- MODEL
--


type alias Model =
{ location : Navigation.Location
{ history : List Navigation.Location
, route : Route
, user : TaskclusterLogin.Model
, userScopes : App.UserScopes.Model
Expand All @@ -96,19 +123,18 @@ type alias Model =
}



--
-- MESSAGES
--


type Msg
= Tick Time.Time
= UrlChange Navigation.Location
| NavigateTo Route
| Tick Time.Time
| TaskclusterLoginMsg TaskclusterLogin.Msg
| HawkMsg Hawk.Msg
| NavigateTo Route
| UserScopesMsg App.UserScopes.Msg
| TryChooserMsg App.TryChooser.Msg
| TreeStatusMsg App.TreeStatus.Types.Msg


type alias Flags =
{ user : TaskclusterLogin.Model
, treestatusUrl : String
, docsUrl : String
, version : String
}
19 changes: 12 additions & 7 deletions src/releng_frontend/src/App/Layout.elm
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,26 @@ viewUser model =
viewNavBar : App.Model -> List (Html App.Msg)
viewNavBar model =
[ button
[ class "navbar-toggler hidden-md-up"
[ class "navbar-toggler navbar-toggler-right"
, type_ "button"
, attribute "data-toggle" "collapse"
, attribute "data-target" ".navbar-collapse"
, attribute "aria-controls" "navbar-header"
, attribute "data-target" "#navbarNavDropdown"
, attribute "aria-controls" "navbarNavDropdown"
, attribute "aria-expanded" "false"
, attribute "aria-label" "Toggle navigation"
]
[ text "&#9776;" ]
[ span [ class "navbar-toggler-icon" ] [] ]
, a
[ Utils.onClick (App.NavigateTo App.HomeRoute)
, href "#"
, class "navbar-brand"
]
[ text "Release Engineering" ]
, div [ class "collapse navbar-toggleable-sm navbar-collapse" ]
[ ul [ class "nav navbar-nav" ]
, div
[ class "collapse navbar-collapse"
, id "navbarNavDropdown"
]
[ ul [ class "navbar-nav" ]
[ li [ class "nav-item" ] (viewUser model)
]
]
Expand Down Expand Up @@ -141,7 +146,7 @@ view viewRoute model =
div [ id ("page-" ++ routeName) ]
[ nav
[ id "navbar"
, class "navbar navbar-full navbar-light"
, class "navbar navbar-toggleable-md bg-faded navbar-inverse"
]
[ div [ class "container" ] (viewNavBar model) ]
, div [ id "content" ]
Expand Down
20 changes: 10 additions & 10 deletions src/releng_frontend/src/App/TreeStatus.elm
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ import Utils
--


routes : UrlParser.Parser (App.TreeStatus.Types.Route -> a) a
routes =
routeParser : UrlParser.Parser (App.TreeStatus.Types.Route -> a) a
routeParser =
UrlParser.oneOf
[ UrlParser.map App.TreeStatus.Types.ShowTreesRoute (UrlParser.s "")
[ UrlParser.map App.TreeStatus.Types.ShowTreesRoute UrlParser.top
, UrlParser.map App.TreeStatus.Types.AddTreeRoute (UrlParser.s "add")
, UrlParser.map App.TreeStatus.Types.UpdateTreesRoute (UrlParser.s "update")
, UrlParser.map App.TreeStatus.Types.DeleteTreesRoute (UrlParser.s "delete")
, UrlParser.map App.TreeStatus.Types.ShowTreeRoute (UrlParser.s "show" </> UrlParser.string)
]


reverse : App.TreeStatus.Types.Route -> String
reverse route =
reverseRoute : App.TreeStatus.Types.Route -> String
reverseRoute route =
case route of
App.TreeStatus.Types.ShowTreesRoute ->
"/treestatus"
Expand All @@ -57,7 +57,7 @@ page : (App.TreeStatus.Types.Route -> a) -> App.Types.Page a b
page outRoute =
{ title = "TreeStatus"
, description = "Current status of Mozilla's version-control repositories."
, matcher = UrlParser.map outRoute (UrlParser.s "treestatus" </> routes)
, matcher = UrlParser.map outRoute (UrlParser.s "treestatus" </> routeParser)
}


Expand Down Expand Up @@ -176,7 +176,7 @@ update currentRoute msg model =
in
( newModel
, Cmd.batch
[ (reverse newRoute)
[ (reverseRoute newRoute)
|> Navigation.newUrl
, newCmd
]
Expand Down Expand Up @@ -219,7 +219,7 @@ update currentRoute msg model =
, Cmd.batch
[ Utils.performMsg App.TreeStatus.Form.resetAddTree
|> Cmd.map App.TreeStatus.Types.FormAddTreeMsg
, (reverse App.TreeStatus.Types.ShowTreesRoute)
, (reverseRoute App.TreeStatus.Types.ShowTreesRoute)
|> Navigation.newUrl
]
, Nothing
Expand All @@ -242,7 +242,7 @@ update currentRoute msg model =
, App.TreeStatus.Api.fetchRecentChanges model.baseUrl
, Utils.performMsg App.TreeStatus.Form.resetUpdateTree
|> Cmd.map App.TreeStatus.Types.FormUpdateTreesMsg
, (reverse App.TreeStatus.Types.ShowTreesRoute)
, (reverseRoute App.TreeStatus.Types.ShowTreesRoute)
|> Navigation.newUrl
]
, Nothing
Expand Down Expand Up @@ -331,7 +331,7 @@ update currentRoute msg model =

App.TreeStatus.Types.DeleteTreesResult result ->
( { model | treesAlerts = App.Utils.getAlerts result }
, (reverse App.TreeStatus.Types.ShowTreesRoute)
, (reverseRoute App.TreeStatus.Types.ShowTreesRoute)
|> Navigation.newUrl
, Nothing
)
Expand Down
Loading

0 comments on commit 8cf4437

Please sign in to comment.