Commit 87b9e31c authored by Emmanuel Raviart's avatar Emmanuel Raviart

Move URLs generation function to new module Urls.

parent 2bf984f7
module AddNew.View exposing (..)
import AddNew.Types exposing (..)
import Configuration
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (on, onClick, onInput, onSubmit, targetValue)
import I18n exposing (getImageUrlOrOgpLogo, getName)
import Json.Decode as Decode
import Urls
publishedDisabled : UploadStatus -> Bool
......@@ -59,7 +59,7 @@ viewImageUploadStatus imageUploadStatus =
Uploaded urlPath ->
img
[ src (Configuration.apiUrlWithPath urlPath)
[ src (Urls.fullApiUrl urlPath)
, style [ ( "max-width", "100%" ) ]
]
[]
......
module AddNewCollection.View exposing (..)
import AddNewCollection.Types exposing (..)
import Configuration
import Json.Decode as Decode
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import I18n
import Urls
publishedDisabled : UploadStatus -> Bool
......@@ -59,7 +59,7 @@ viewImageUploadStatus imageUploadStatus =
Uploaded urlPath ->
img
[ src (Configuration.apiUrlWithPath urlPath)
[ src (Urls.fullApiUrl urlPath)
, style [ ( "max-width", "100%" ) ]
]
[]
......
......@@ -7,9 +7,9 @@ import Http
import I18n exposing (getImageUrlOrOgpLogo, getName, getOneString)
import Ports
import Requests
import Routes
import Task
import Types exposing (..)
import Urls
import WebData exposing (..)
......@@ -76,7 +76,7 @@ update msg ({ editedProperty } as model) authentication language =
getOneString language descriptionKeys card body.data.values
|> Maybe.withDefault (I18n.translate language I18n.MissingDescription)
, imageUrl =
Routes.fullApiUrl <|
Urls.fullApiUrl <|
getImageUrlOrOgpLogo language body.data.id body.data.cards body.data.values
, title = getName language card body.data.values
}
......
......@@ -13,6 +13,7 @@ import Json.Decode as Decode
import Routes
import String
import Types exposing (..)
import Urls
import Views exposing (viewCardListItem, viewLoading, viewWebData)
import WebData exposing (..)
......@@ -1150,7 +1151,7 @@ viewSidebar language card values =
"Untitled Card"
url =
Routes.fullUrl
Urls.fullUrl
(Routes.makeUrlWithLanguage language (Routes.urlPathForCard card))
-- TODO: i18n
......
module Collection.State exposing (..)
import Authenticator.Model
import Collection.Types exposing (..)
import Constants
import Dict exposing (Dict)
import Http
import I18n exposing (getImageUrlOrOgpLogo, getName)
import Ports
import Requests
import Routes
import Collection.Types exposing (..)
import Urls
import WebData exposing (..)
......@@ -49,7 +49,7 @@ update msg model authentication language =
Ports.setDocumentMetatags
{ description = collection.description
, imageUrl =
Routes.fullApiUrl <|
Urls.fullApiUrl <|
(collection.logo |> Maybe.withDefault Constants.logoUrl)
, title = collection.name
}
......
module Collection.View exposing (..)
import Collection.Types exposing (..)
import Configuration
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......@@ -10,6 +9,7 @@ import Http
import I18n
import Routes
import Types exposing (..)
import Urls
import Views exposing (viewCardThumbnail, viewLoading, viewWebData)
import WebData exposing (..)
......@@ -59,7 +59,7 @@ viewBanner language user collection =
[]
Just logo ->
[ img [ class "cover", alt "screen", src (Configuration.apiUrlWithPath logo) ] []
[ img [ class "cover", alt "screen", src (Urls.fullApiUrl logo) ] []
]
)
++ [ div [ class "container" ]
......@@ -143,7 +143,7 @@ viewCollectionContent language user collection cards values =
, href
(let
url =
Routes.fullUrl
Urls.fullUrl
(Routes.makeUrlWithLanguage language ("/collections/" ++ collection.id))
-- TODO: i18n
......
module Collections.View exposing (..)
import Configuration
import Collections.Types exposing (..)
import Dict exposing (Dict)
import Html exposing (..)
......@@ -8,6 +7,7 @@ import Html.Attributes exposing (..)
import Html.Helpers exposing (aForPath)
import I18n
import Types exposing (..)
import Urls
import Views exposing (viewLoading, viewWebData)
import WebData exposing (..)
......@@ -98,7 +98,7 @@ viewCollectionThumbnail language user collection =
[]
Just logo ->
[ img [ alt "screen", src (Configuration.apiUrlWithPath logo) ] []
[ img [ alt "screen", src (Urls.fullApiUrl logo) ] []
]
)
, div [ class "caption" ]
......
module Configuration exposing (..)
import Dict exposing (Dict)
import String
apiUrl : String
......@@ -23,23 +22,3 @@ useItData =
, ( "6228", { frenchGovDeployUrl = "https://consultation.etalab.gouv.fr/tools/assembl" } )
, ( "2333", { frenchGovDeployUrl = "https://consultation.etalab.gouv.fr/tools/democracyos" } )
]
-- HELPERS
apiUrlWithPath : String -> String
apiUrlWithPath urlPath =
let
cleanUrlPath =
String.trim urlPath
in
if String.startsWith "/" cleanUrlPath then
apiUrl ++ (String.dropLeft 1 cleanUrlPath)
else if String.startsWith "http://" cleanUrlPath then
cleanUrlPath
else if String.startsWith "https://" cleanUrlPath then
cleanUrlPath
else
apiUrl ++ cleanUrlPath
module Home exposing (..)
import Configuration
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......@@ -10,6 +9,7 @@ import Navigation
import Routes
import Search.Types exposing (..)
import Types exposing (..)
import Urls
import Views exposing (viewCardThumbnail, viewLoading, viewTagsWithCallToAction, viewWebData)
import WebData exposing (..)
......@@ -408,7 +408,7 @@ viewCollectionThumbnail language user collection =
[]
Just logo ->
[ img [ alt "screen", src (Configuration.apiUrlWithPath logo) ] []
[ img [ alt "screen", src (Urls.fullApiUrl logo) ] []
]
)
, div [ class "caption" ]
......
module I18n exposing (..)
import Configuration
import Constants
import Dict exposing (Dict)
import String
import Types exposing (..)
import Urls
-- STRINGS TO TRANSLATE
......@@ -1391,14 +1391,14 @@ getImageLogoUrl : Language -> String -> Card -> Dict String Value -> Maybe Strin
getImageLogoUrl language dim card values =
getOneString language imageLogoUrlPathKeys card values
|> Maybe.map
(\urlPath -> Configuration.apiUrlWithPath urlPath ++ "?dim=" ++ dim)
(\urlPath -> Urls.fullApiUrl urlPath ++ "?dim=" ++ dim)
getImageScreenshotUrl : Language -> String -> Card -> Dict String Value -> Maybe String
getImageScreenshotUrl language dim card values =
getOneString language imageScreenshotUrlPathKeys card values
|> Maybe.map
(\urlPath -> Configuration.apiUrlWithPath urlPath ++ "?dim=" ++ dim)
(\urlPath -> Urls.fullApiUrl urlPath ++ "?dim=" ++ dim)
getImageUrlOrOgpLogo : Language -> String -> Dict String Card -> Dict String Value -> String
......@@ -1413,7 +1413,7 @@ getImageUrlOrOgpLogo language cardId cards values =
Constants.logoUrl
Just urlPath ->
Configuration.apiUrlWithPath urlPath
Urls.fullApiUrl urlPath
getLocalizedStringFromValueId : Language -> Dict String Value -> String -> String
......
module Routes exposing (..)
import Configuration
import Erl
import Http
import I18n
......@@ -63,46 +62,6 @@ collectionsRouteParser =
]
fullApiUrl : String -> String
fullApiUrl url =
let
parsedApiUrl =
Erl.parse Configuration.apiUrl
parsedUrl =
Erl.parse url
in
if List.isEmpty <| List.filter (not << String.isEmpty) parsedUrl.host then
Erl.toString <|
{ parsedUrl
| host = parsedApiUrl.host
, port_ = parsedApiUrl.port_
, protocol = parsedApiUrl.protocol
}
else
url
fullUrl : String -> String
fullUrl url =
let
parsedAppUrl =
Erl.parse Configuration.appUrl
parsedUrl =
Erl.parse url
in
if List.isEmpty <| List.filter (not << String.isEmpty) parsedUrl.host then
Erl.toString <|
{ parsedUrl
| host = parsedAppUrl.host
, port_ = parsedAppUrl.port_
, protocol = parsedAppUrl.protocol
}
else
url
getQuerySearchTerm : Navigation.Location -> String
getQuerySearchTerm location =
getQuerySingleParameter "q" location
......
module Urls exposing (..)
import Configuration
import Erl
fullApiUrl : String -> String
fullApiUrl url =
let
parsedApiUrl =
Erl.parse Configuration.apiUrl
parsedUrl =
Erl.parse <| String.trim url
in
if List.isEmpty <| List.filter (not << String.isEmpty) parsedUrl.host then
Erl.toString <|
{ parsedUrl
| host = parsedApiUrl.host
, port_ = parsedApiUrl.port_
, protocol = parsedApiUrl.protocol
}
else
url
fullUrl : String -> String
fullUrl url =
let
parsedAppUrl =
Erl.parse Configuration.appUrl
parsedUrl =
Erl.parse <| String.trim url
in
if List.isEmpty <| List.filter (not << String.isEmpty) parsedUrl.host then
Erl.toString <|
{ parsedUrl
| host = parsedAppUrl.host
, port_ = parsedAppUrl.port_
, protocol = parsedAppUrl.protocol
}
else
url
module UserProfile.View exposing (..)
import Configuration
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......@@ -8,6 +7,7 @@ import Html.Helpers exposing (aForPath)
import I18n
import UserProfile.Types exposing (..)
import Types exposing (..)
import Urls
import WebData exposing (..)
......@@ -88,7 +88,7 @@ viewCollectionThumbnail language user collection =
[]
Just logo ->
[ img [ alt "screen", src (Configuration.apiUrlWithPath logo) ] []
[ img [ alt "screen", src (Urls.fullApiUrl logo) ] []
]
)
, div [ class "caption" ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment