Commit b94bf422 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Rename constants and move them to Constants.elm. Replace getDebatePorperties…

Rename constants and move them to Constants.elm. Replace getDebatePorperties with getObjectProperties using its new API.
parent 9c765ff7
module Cards.Helpers exposing (..)
import Constants exposing (licenseKeyIds, openSourceKeyIds, repoKeyIds, sourceCodeKeyIds)
import Dict exposing (Dict)
import I18n
import Types exposing (..)
......@@ -9,7 +10,7 @@ isOpenSource : I18n.Language -> Dict String TypedValue -> Card -> Bool
isOpenSource language values card =
let
repo =
(case I18n.getOneString language repoKeys card values of
(case I18n.getOneString language repoKeyIds card values of
Just value ->
String.length value > 8
......@@ -18,7 +19,7 @@ isOpenSource language values card =
)
sourceCode =
(case I18n.getOneString language sourceCodeKeys card values of
(case I18n.getOneString language sourceCodeKeyIds card values of
Just value ->
String.length value > 8
......@@ -27,7 +28,7 @@ isOpenSource language values card =
)
openSource =
(case I18n.getOneString language openSourceKeys card values of
(case I18n.getOneString language openSourceKeyIds card values of
Just value ->
let
lowerValue =
......@@ -40,7 +41,7 @@ isOpenSource language values card =
)
license =
(case I18n.getOneString language licenseKeys card values of
(case I18n.getOneString language licenseKeyIds card values of
Just value ->
String.toLower value
......
......@@ -2,6 +2,7 @@ module Cards.Item.State exposing (..)
import Authenticator.Types exposing (Authentication)
import Cards.Item.Types exposing (..)
import Constants exposing (debateKeyIds, descriptionKeyIds)
import Http
import I18n
import Ports
......@@ -187,7 +188,7 @@ update msg model =
cmd =
Ports.setDocumentMetadata
{ description =
I18n.getOneString language descriptionKeys card data.values
I18n.getOneString language descriptionKeyIds card data.values
|> Maybe.withDefault (I18n.translate language I18n.MissingDescription)
, imageUrl =
Urls.imageOrAppLogoFullUrl
......@@ -276,7 +277,7 @@ update msg model =
debatedId
[ "TextField" ]
}
, Requests.getDebateProperties model.authentication debatedId
, Requests.getObjectProperties model.authentication False debatedId debateKeyIds []
|> Http.send (ForSelf << GotDebateProperties)
)
......@@ -301,7 +302,7 @@ update msg model =
(validFieldTypes keyId)
, sameKeyPropertyIds = []
}
, Requests.getObjectProperties model.authentication model.cardId keyId
, Requests.getObjectProperties model.authentication False model.cardId [ keyId ] []
|> Http.send (ForSelf << GotProperties)
)
......
......@@ -3,6 +3,16 @@ module Cards.Item.View exposing (..)
import Cards.Helpers exposing (..)
import Cards.Item.Types exposing (..)
import Configuration
import Constants
exposing
( cardTypesForOrganization
, cardTypesForSoftware
, cardTypesForTool
, descriptionKeyIds
, imagePathKeyIds
, licenseKeyIds
, urlKeyIds
)
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......@@ -271,7 +281,7 @@ viewCardContent model card =
cardType =
getCardType card
in
case I18n.getOneString language descriptionKeys card values of
case I18n.getOneString language descriptionKeyIds card values of
Nothing ->
[ div [ class "panel-heading" ]
[ div [ class "row" ]
......@@ -295,7 +305,7 @@ viewCardContent model card =
[ panelTitle
, div [ class "col-xs-4 text-right up7" ]
[ a [ class "show-more" ]
[ bestOf descriptionKeys ]
[ bestOf descriptionKeyIds ]
, button
[ attribute "data-target" "#edit-content"
, attribute "data-toggle" "modal"
......@@ -652,7 +662,7 @@ viewCardContent model card =
]
, div [ class "col-xs-4 text-right up7" ]
-- [ a [ class "show-more" ]
-- [ bestOf usedByKeys ]
-- [ bestOf usedByKeyIds ]
[ button
[ class "btn btn-default btn-xs btn-action"
, onClick (ForSelf (LoadProperties "used-by"))
......@@ -1291,7 +1301,7 @@ viewSidebar model card =
(List.concat
[ let
license =
I18n.getOneString language licenseKeys card values
I18n.getOneString language licenseKeyIds card values
|> Maybe.withDefault ""
in
if String.isEmpty license then
......@@ -1320,7 +1330,7 @@ viewSidebar model card =
td [ class "table-label" ]
[ text (I18n.translate language I18n.Website) ]
in
case I18n.getOneString language urlKeys card values of
case I18n.getOneString language urlKeyIds card values of
Nothing ->
tr []
[ firstTd
......@@ -1435,7 +1445,7 @@ viewSidebar model card =
I18n.getName language card values
imageUrl =
I18n.getOneString language imagePathKeys card values
I18n.getOneString language imagePathKeyIds card values
|> Maybe.withDefault Urls.appLogoFullUrl
url =
......
module Cards.ViewsHelpers exposing (..)
import Constants exposing (descriptionKeyIds)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Attributes.Aria exposing (..)
......@@ -75,7 +76,7 @@ viewCardThumbnail language navigate onRemoveCard extraClass data card =
, div [ class "caption" ]
[ h4 []
[ text name ]
, case I18n.getOneString language descriptionKeys card data.values of
, case I18n.getOneString language descriptionKeyIds card data.values of
Just description ->
p [] [ text description ]
......
......@@ -3,6 +3,7 @@ module Collections.Edit.State exposing (..)
import Authenticator.Types exposing (Authentication)
import Cards.Autocomplete.State
import Collections.Edit.Types exposing (..)
import Constants exposing (cardTypesForTool, cardTypesForUseCase)
import Dict exposing (Dict)
import Http
import Http.Error
......
......@@ -3,6 +3,7 @@ module Collections.Item.View exposing (..)
import Authenticator.Types exposing (Authentication, canEditUserResource)
import Cards.ViewsHelpers exposing (..)
import Collections.Item.Types exposing (..)
import Constants exposing (cardTypesForTool, cardTypesForUseCase)
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......
module Collections.ViewsHelpers exposing (..)
import Constants exposing (cardTypesForTool, cardTypesForUseCase)
import Cards.ViewsHelpers exposing (..)
import Html exposing (Html)
import I18n
......
module Constants exposing (..)
-- KEYS
debateKeyIds : List String
debateKeyIds =
[ "cons", "pros" ]
descriptionKeyIds : List String
descriptionKeyIds =
[ "description" ]
imageLogoPathKeyIds : List String
imageLogoPathKeyIds =
[ "logo" ]
imageScreenshotPathKeyIds : List String
imageScreenshotPathKeyIds =
[ "screenshot" ]
imagePathKeyIds : List String
imagePathKeyIds =
imageLogoPathKeyIds ++ imageScreenshotPathKeyIds
licenseKeyIds : List String
licenseKeyIds =
[ "license" ]
nameKeyIds : List String
nameKeyIds =
[ "name" ]
openSourceKeyIds : List String
openSourceKeyIds =
[ "9647" ]
repoKeyIds : List String
repoKeyIds =
[ "12795" ]
sourceCodeKeyIds : List String
sourceCodeKeyIds =
[ "source-code" ]
urlKeyIds : List String
urlKeyIds =
[ "website" ]
usedByKeyIds : List String
usedByKeyIds =
[ "used-by" ]
-- CARD TYPES
cardTypesForOrganization : List String
cardTypesForOrganization =
[ "organization" ]
cardTypesForSoftware : List String
cardTypesForSoftware =
[ "software" ]
cardTypesForTool : List String
cardTypesForTool =
[ "software", "platform" ]
cardTypesForUseCase : List String
cardTypesForUseCase =
[ "use-case" ]
module I18n exposing (..)
import Constants exposing (..)
import Dict exposing (Dict)
import String
import Types exposing (..)
......@@ -3579,7 +3580,7 @@ getOneStringFromValueType language values valueType =
getName : Language -> Card -> Dict String TypedValue -> String
getName language card values =
-- Note: Name can be Nothing, if down-voted.
getOneString language nameKeys card values
getOneString language nameKeyIds card values
|> Maybe.withDefault (translate language UntitledCard)
......
......@@ -225,25 +225,30 @@ getCollectionsForAuthor authentication =
}
getDebateProperties : Maybe Authentication -> String -> Http.Request DataIdsBody
getDebateProperties authentication objectId =
getObjectProperties : Maybe Authentication -> Bool -> String -> List String -> List String -> Http.Request DataIdsBody
getObjectProperties authentication showTrashed objectId keyIds valueIds =
Http.request
{ method = "GET"
, headers = authenticationHeaders authentication
, url = apiUrl ++ "objects/" ++ objectId ++ "/debate-properties" ++ "?show=ballots&show=values&depth=1"
, body = Http.emptyBody
, expect = Http.expectJson dataIdsBodyDecoder
, timeout = Nothing
, withCredentials = False
}
getObjectProperties : Maybe Authentication -> String -> String -> Http.Request DataIdsBody
getObjectProperties authentication objectId keyId =
Http.request
{ method = "GET"
, headers = authenticationHeaders authentication
, url = apiUrl ++ "objects/" ++ objectId ++ "/properties/" ++ keyId ++ "?show=ballots&show=values&depth=1"
, url =
apiUrl
++ "objects/"
++ objectId
++ "/properties"
++ Urls.paramsToQuery
([ ( "depth", Just "1" )
, ( "show", Just "ballots" )
, ( "show"
, if showTrashed then
Just "trashed"
else
Nothing
)
, ( "show", Just "values" )
]
++ (List.map (\keyId -> ( "keyId", Just keyId )) keyIds)
++ (List.map (\valueId -> ( "valueId", Just valueId )) valueIds)
)
, body = Http.emptyBody
, expect = Http.expectJson dataIdsBodyDecoder
, timeout = Nothing
......
module Search.State exposing (..)
import Authenticator.Types
import Constants exposing (cardTypesForOrganization, cardTypesForTool, cardTypesForUseCase)
import Dict exposing (Dict)
import Erl
import Http
......
module Types exposing (..)
import Constants exposing (..)
import Dict exposing (Dict)
import Json.Decode
......@@ -374,86 +375,3 @@ mergeDataIds new old =
{ mergedData
| ids = List.append old.ids new.ids
}
-- KEYS
descriptionKeys : List String
descriptionKeys =
[ "description" ]
imageLogoPathKeys : List String
imageLogoPathKeys =
[ "logo" ]
imageScreenshotPathKeys : List String
imageScreenshotPathKeys =
[ "screenshot" ]
imagePathKeys : List String
imagePathKeys =
imageLogoPathKeys ++ imageScreenshotPathKeys
licenseKeys : List String
licenseKeys =
[ "license" ]
openSourceKeys : List String
openSourceKeys =
[ "9647" ]
repoKeys : List String
repoKeys =
[ "12795" ]
sourceCodeKeys : List String
sourceCodeKeys =
[ "source-code" ]
nameKeys : List String
nameKeys =
[ "name" ]
urlKeys : List String
urlKeys =
[ "website" ]
usedByKeys : List String
usedByKeys =
[ "used-by" ]
-- CARD TYPES
cardTypesForOrganization : List String
cardTypesForOrganization =
[ "organization" ]
cardTypesForSoftware : List String
cardTypesForSoftware =
[ "software" ]
cardTypesForTool : List String
cardTypesForTool =
[ "software", "platform" ]
cardTypesForUseCase : List String
cardTypesForUseCase =
[ "use-case" ]
module Urls exposing (..)
import Configuration
import Constants exposing (..)
import Dict exposing (Dict)
import Erl
import Http
......@@ -96,7 +97,7 @@ imageOrAppLogoFullUrl language cardId cards values =
appLogoFullUrl
Just card ->
case I18n.getOneString language imagePathKeys card values of
case I18n.getOneString language imagePathKeyIds card values of
Nothing ->
appLogoFullUrl
......@@ -111,7 +112,7 @@ languagePath language path =
logoFullUrl : I18n.Language -> String -> Card -> Dict String TypedValue -> Maybe String
logoFullUrl language dim card values =
I18n.getOneString language imageLogoPathKeys card values
I18n.getOneString language imageLogoPathKeyIds card values
|> Maybe.map
(\path -> fullApiUrl path ++ "?dim=" ++ dim)
......@@ -208,7 +209,7 @@ replaceLanguageInLocation language location =
screenshotFullUrl : I18n.Language -> String -> Card -> Dict String TypedValue -> Maybe String
screenshotFullUrl language dim card values =
I18n.getOneString language imageScreenshotPathKeys card values
I18n.getOneString language imageScreenshotPathKeyIds card values
|> Maybe.map
(\path -> fullApiUrl path ++ "?dim=" ++ dim)
......
......@@ -2,6 +2,7 @@ module Values.New.State exposing (..)
import Authenticator.Types exposing (Authentication)
import Cards.Autocomplete.State
import Constants exposing (cardTypesForOrganization, cardTypesForTool, cardTypesForUseCase)
import Dict exposing (Dict)
import Http
import Http.Error
......@@ -11,7 +12,7 @@ import Navigation
import Ports
import Requests
import Task
import Types exposing (cardTypesForOrganization, cardTypesForTool, cardTypesForUseCase, Field(..))
import Types exposing (Field(..))
import Urls
import Values.New.Types exposing (..)
......
module Values.ViewsHelpers exposing (..)
import Constants exposing (nameKeyIds)
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......@@ -24,7 +25,7 @@ viewCardLine : I18n.Language -> Maybe (String -> msg) -> DataProxy a -> Card ->
viewCardLine language navigate data card =
let
cardName =
I18n.getOneString language nameKeys card data.values
I18n.getOneString language nameKeyIds card data.values
|> Maybe.withDefault card.id
in
case navigate of
......
module Views exposing (..)
import Constants exposing (descriptionKeyIds)
import Dict exposing (Dict)
import Html exposing (..)
import Html.Attributes exposing (..)
......@@ -128,7 +129,7 @@ viewCardListItem navigate language values card =
-- , text "TODO The White House"
-- ]
, p []
(case I18n.getOneString language descriptionKeys card values of
(case I18n.getOneString language descriptionKeyIds card values of
Just description ->
[ text description ]
......
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