Permalink
Browse files

random refactoring

  • Loading branch information...
1 parent 03ac820 commit d1c953e85275c325bfb92aaea7cf30dce38a9b3b @torii-y torii-y committed Nov 25, 2016
Showing with 91 additions and 79 deletions.
  1. +28 −24 src/elm/API/API.elm
  2. +32 −30 src/elm/Component/ObjectNameInput.elm
  3. +10 −10 src/elm/Page/Map/CanvasView.elm
  4. +21 −15 src/elm/Page/Map/Update.elm
View
@@ -47,6 +47,10 @@ import Model.ObjectsChange as ObjectsChange exposing (ObjectsChange)
import API.Serialization exposing (..)
+type alias PersonId = String
+type alias ImageId = String
+type alias UserId = String
+
type alias Error = Http.Error
@@ -75,39 +79,39 @@ saveFloor config floor =
(Http.jsonBody <| encodeFloor floor)
-publishFloor : Config -> String -> Task Error Floor
-publishFloor config id =
+publishFloor : Config -> FloorId -> Task Error Floor
+publishFloor config floorId =
putJson
decodeFloor
- (config.apiRoot ++ "/1/floors/" ++ id ++ "/public")
+ (config.apiRoot ++ "/1/floors/" ++ floorId ++ "/public")
[authorization config.token]
Http.emptyBody
-deleteEditingFloor : Config -> String -> Task Error ()
-deleteEditingFloor config id =
+deleteEditingFloor : Config -> FloorId -> Task Error ()
+deleteEditingFloor config floorId =
deleteJsonNoResponse
- (config.apiRoot ++ "/1/floors/" ++ id)
+ (config.apiRoot ++ "/1/floors/" ++ floorId)
[authorization config.token]
Http.emptyBody
-getEditingFloor : Config -> String -> Task Error Floor
-getEditingFloor config id =
- getFloorHelp config True id
+getEditingFloor : Config -> FloorId -> Task Error Floor
+getEditingFloor config floorId =
+ getFloorHelp config True floorId
-getFloor : Config -> String -> Task Error Floor
-getFloor config id =
- getFloorHelp config False id
+getFloor : Config -> FloorId -> Task Error Floor
+getFloor config floorId =
+ getFloorHelp config False floorId
-getFloorOfVersion : Config -> String -> Int -> Task Error Floor
-getFloorOfVersion config id version =
+getFloorOfVersion : Config -> FloorId -> Int -> Task Error Floor
+getFloorOfVersion config floorId version =
let
url =
makeUrl
- (config.apiRoot ++ "/1/floors/" ++ id ++ "/" ++ toString version)
+ (config.apiRoot ++ "/1/floors/" ++ floorId ++ "/" ++ toString version)
[]
in
get decodeFloor url [authorization config.token]
@@ -219,30 +223,30 @@ personCandidate config name =
[authorization config.token]
-saveEditingImage : Config -> Id -> File -> Task a ()
-saveEditingImage config id file =
+saveEditingImage : Config -> ImageId -> File -> Task a ()
+saveEditingImage config imageId file =
HttpUtil.sendFile
"PUT"
- (config.apiRoot ++ "/1/images/" ++ id)
+ (config.apiRoot ++ "/1/images/" ++ imageId)
[authorizationTuple config.token]
file
-getPerson : Config -> Id -> Task Error Person
-getPerson config id =
+getPerson : Config -> PersonId -> Task Error Person
+getPerson config personId =
HttpUtil.get
decodePerson
- (config.apiRoot ++ "/1/people/" ++ id)
+ (config.apiRoot ++ "/1/people/" ++ personId)
[authorization config.token]
-getPersonByUser : Config -> Id -> Task Error Person
-getPersonByUser config id =
+getPersonByUser : Config -> UserId -> Task Error Person
+getPersonByUser config userId =
let
getUser =
HttpUtil.get
decodeUser
- (config.apiRoot ++ "/1/users/" ++ id)
+ (config.apiRoot ++ "/1/users/" ++ userId)
[authorization config.token]
in
getUser
@@ -23,8 +23,8 @@ type alias ObjectNameInput =
}
-type alias Id = String
-
+type alias ObjectId = String
+type alias PersonId = String
init : ObjectNameInput
init =
@@ -37,18 +37,18 @@ init =
type Msg =
NoOp
- | InputName Id String
+ | InputName ObjectId String
| KeydownOnNameInput (List Person) (Int, Int)
| KeyupOnNameInput Int
- | SelectCandidate Id Id
- | UnsetPerson Id
+ | SelectCandidate ObjectId PersonId
+ | UnsetPerson ObjectId
type Event =
- OnInput Id String
- | OnFinish Id String (Maybe Id)
- | OnSelectCandidate Id Id
- | OnUnsetPerson Id
+ OnInput ObjectId String
+ | OnFinish ObjectId String (Maybe PersonId)
+ | OnSelectCandidate ObjectId PersonId
+ | OnUnsetPerson ObjectId
| None
@@ -93,9 +93,9 @@ update message model =
(newModel, event) =
if keyCode == 13 then
case model.editingObject of
- Just (id, name) ->
+ Just (objectId, name) ->
( updateNewEdit Nothing model
- , OnFinish id name (selectedCandidateId model.candidateIndex candidates)
+ , OnFinish objectId name (selectedCandidateId model.candidateIndex candidates)
)
Nothing ->
@@ -130,13 +130,15 @@ update message model =
( model, OnUnsetPerson objectId )
-selectedCandidateId : Int -> List Person -> Maybe Id
+selectedCandidateId : Int -> List Person -> Maybe PersonId
selectedCandidateId candidateIndex candidates =
if candidateIndex < 0 then
Nothing
else
- Maybe.map (.id) <|
- List.head (List.drop candidateIndex candidates)
+ candidates
+ |> List.drop candidateIndex
+ |> List.head
+ |> Maybe.map .id
updateNewEdit : (Maybe (String, String)) -> ObjectNameInput -> ObjectNameInput
@@ -149,11 +151,11 @@ start =
updateNewEdit << Just
-forceFinish : ObjectNameInput -> (ObjectNameInput, Maybe (Id, String))
+forceFinish : ObjectNameInput -> (ObjectNameInput, Maybe (ObjectId, String))
forceFinish model =
case model.editingObject of
- Just (id, name) ->
- (updateNewEdit Nothing model, Just (id, name))
+ Just (objectId, name) ->
+ (updateNewEdit Nothing model, Just (objectId, name))
Nothing ->
(model, Nothing)
@@ -162,27 +164,27 @@ forceFinish model =
view : (String -> Maybe ((Int, Int, Int, Int), Maybe Person)) -> Bool -> List Person -> ObjectNameInput -> Html Msg
view deskInfoOf transitionDisabled candidates model =
case model.editingObject of
- Just (id, name) ->
- case deskInfoOf id of
+ Just (objectId, name) ->
+ case deskInfoOf objectId of
Just (screenRect, maybePerson) ->
- view_ id name maybePerson screenRect transitionDisabled candidates model
+ view_ objectId name maybePerson screenRect transitionDisabled candidates model
Nothing -> text ""
Nothing ->
text ""
-view_ : Id -> String -> Maybe Person -> (Int, Int, Int, Int) -> Bool -> List Person -> ObjectNameInput -> Html Msg
-view_ id name maybePerson screenRectOfDesk transitionDisabled candidates model =
+view_ : ObjectId -> String -> Maybe Person -> (Int, Int, Int, Int) -> Bool -> List Person -> ObjectNameInput -> Html Msg
+view_ objectId name maybePerson screenRectOfDesk transitionDisabled candidates model =
let
candidates_ =
List.filter (\candidate -> Just candidate /= maybePerson) (List.take 15 candidates)
(relatedPersonExists, reletedpersonView_) =
case maybePerson of
Just person ->
- (True, reletedpersonView id person)
+ (True, reletedpersonView objectId person)
Nothing ->
(False, text "")
@@ -204,30 +206,30 @@ view_ id name maybePerson screenRectOfDesk transitionDisabled candidates model =
[ onWithOptions "mousedown" { stopPropagation = True, preventDefault = False } (Decode.succeed NoOp)
, onWithOptions "mousemove" { stopPropagation = True, preventDefault = False } (Decode.succeed NoOp)
]
- [ ("nameInput" ++ id, input
+ [ ("nameInput" ++ objectId, input
([ Html.Attributes.id "name-input"
-- , Html.Attributes.property "selectionStart" (Encode.int 9999)
-- , Html.Attributes.attribute "selection-start" "9999"
, style (Styles.nameInputTextArea transitionDisabled screenRectOfDesk)
- ] ++ (inputAttributes (InputName id) (KeydownOnNameInput candidates_) KeyupOnNameInput name))
+ ] ++ (inputAttributes (InputName objectId) (KeydownOnNameInput candidates_) KeyupOnNameInput name))
[ ])
, ("candidatesViewContainer", div
[ style (Styles.candidatesViewContainer screenRectOfDesk relatedPersonExists candidatesLength) ]
[ reletedpersonView_
- , candidatesView model.candidateIndex id candidates_
+ , candidatesView model.candidateIndex objectId candidates_
])
, ("pointer", pointer)
]
-reletedpersonView : Id -> Person -> Html Msg
+reletedpersonView : ObjectId -> Person -> Html Msg
reletedpersonView objectId person =
div
[ style (Styles.candidatesViewRelatedPerson) ]
( unsetButton objectId :: ProfilePopup.innerView Nothing person )
-unsetButton : Id -> Html Msg
+unsetButton : ObjectId -> Html Msg
unsetButton objectId =
hover Styles.unsetRelatedPersonButtonHover
div
@@ -237,7 +239,7 @@ unsetButton objectId =
[ text "Unset"]
-candidatesView : Int -> Id -> List Person -> Html Msg
+candidatesView : Int -> ObjectId -> List Person -> Html Msg
candidatesView candidateIndex objectId people =
if List.isEmpty people then
text ""
@@ -247,7 +249,7 @@ candidatesView candidateIndex objectId people =
(List.indexedMap (candidatesViewEach candidateIndex objectId) people)
-candidatesViewEach : Int -> Id -> Int -> Person -> (String, Html Msg)
+candidatesViewEach : Int -> ObjectId -> Int -> Person -> (String, Html Msg)
candidatesViewEach candidateIndex objectId index person =
( person.id
, hover Styles.candidateItemHover
@@ -71,7 +71,7 @@ objectView : ObjectViewOption -> Html Msg
objectView {mode, scale, selected, isGhost, object, rect, contextMenuDisabled, disableTransition} =
let
id =
- idOf object
+ Object.idOf object
(x, y, width, height) =
rect
@@ -258,12 +258,12 @@ objectsView model floor =
Floor.objects floor
isSelected object =
- List.member (idOf object) model.selectedObjects
+ List.member (Object.idOf object) model.selectedObjects
ghostsView =
List.map
(\object ->
- ( idOf object ++ "ghost"
+ ( Object.idOf object ++ "ghost"
, lazy objectView
{ mode = model.mode
, scale = model.scale
@@ -296,7 +296,7 @@ objectsView model floor =
normalView =
List.map
(\object ->
- ( idOf object
+ ( Object.idOf object
, lazy
objectView
{ mode = model.mode
@@ -320,15 +320,15 @@ objectsView model floor =
Floor.objects floor
isSelected object =
- List.member (idOf object) model.selectedObjects
+ List.member (Object.idOf object) model.selectedObjects
isResizing object =
- idOf object == id
+ Object.idOf object == id
ghostsView =
List.map
(\object ->
- ( idOf object ++ "ghost"
+ ( Object.idOf object ++ "ghost"
, lazy objectView
{ mode = model.mode
, scale = model.scale
@@ -354,7 +354,7 @@ objectsView model floor =
normalView =
List.map
(\object ->
- ( idOf object
+ ( Object.idOf object
, lazy objectView
{ mode = model.mode
, scale = model.scale
@@ -374,12 +374,12 @@ objectsView model floor =
_ ->
List.map
(\object ->
- ( idOf object
+ ( Object.idOf object
, lazy objectView
{ mode = model.mode
, scale = model.scale
, rect = (rect object)
- , selected = Mode.isEditMode model.mode && List.member (idOf object) model.selectedObjects
+ , selected = Mode.isEditMode model.mode && List.member (Object.idOf object) model.selectedObjects
, isGhost = False
, object = object
, contextMenuDisabled = model.keys.ctrl
Oops, something went wrong.

0 comments on commit d1c953e

Please sign in to comment.