diff --git a/src/Manager/ModalManager.elm b/src/Manager/ModalManager.elm index 9950c0910885698115f6d1ea29677ee46ba0cc06..30c429710a9b0df31117e5ba46402315549fe090 100644 --- a/src/Manager/ModalManager.elm +++ b/src/Manager/ModalManager.elm @@ -2,7 +2,7 @@ module Manager.ModalManager exposing (..) -- Url import Url -- Own -import Util.Util exposing (MousePosition) +import Util.Util exposing (MousePosition,Picture) import Util.ShapeManager exposing (..) type Modal @@ -11,7 +11,7 @@ type Modal | ShowInput Shape String String | ShowShape Int Int | EditShape Int ShapeStyle - | ShowManagePicUrl String (Maybe Url.Url) + | ShowManagePicture String (Maybe Url.Url) Int Int type ModalMsg = CloseModal @@ -20,7 +20,7 @@ type ModalMsg | OpenShowInput | OpenShowShape Int Int | OpenEditShape Int ShapeStyle String String - | OpenManagePicUrl String + | OpenManagePicture String String -- for input / delete Shapes | ResetShowInput | Check String @@ -62,9 +62,21 @@ updateModal msg modal = else shapeStyle _ -> shapeStyle ) - OpenManagePicUrl string -> case Url.fromString string of - Just url -> ShowManagePicUrl "" (Just url) - Nothing -> ShowManagePicUrl "Ungültige Url." Nothing + OpenManagePicture iT value -> case modal of + NoModal -> ShowManagePicture value Nothing 0 0 + ShowTable -> modal -- ERROR + ShowShape _ _ -> modal -- ERROR + ShowInput _ _ _ -> modal -- ERROR + EditShape _ _ -> modal -- ERROR + ShowManagePicture s url w h -> + case iT of + "i1" -> case Url.fromString value of + Just newUrl -> ShowManagePicture value (Just newUrl) w h + Nothing -> ShowManagePicture value Nothing w h + "i2" -> ShowManagePicture s url (Maybe.withDefault 0 (String.toInt value)) h + "i3" -> ShowManagePicture s url w (Maybe.withDefault 0 (String.toInt value)) + _ -> modal + ResetShowInput -> ShowInput (deleteCoordsFromShape (getInputShapeFromModal modal) @@ -76,19 +88,19 @@ updateModal msg modal = else modal Input inputType value -> case modal of - NoModal -> modal -- ERROR - ShowTable -> modal -- ERROR - ShowShape _ _ -> modal -- ERROR - ShowInput iShape ix iy -> updateInput inputType value modal "ShowInput" iShape ix iy {x = 0, y = 0} - EditShape _ _ -> modal -- ERROR - ShowManagePicUrl _ _ -> modal -- ERROR + NoModal -> modal -- ERROR + ShowTable -> modal -- ERROR + ShowShape _ _ -> modal -- ERROR + ShowInput iShape ix iy -> updateInput inputType value modal "ShowInput" iShape ix iy {x = 0, y = 0} + EditShape _ _ -> modal -- ERROR + ShowManagePicture _ _ _ _-> modal -- ERROR InputPoint -> case modal of - NoModal -> modal -- ERROR - ShowTable -> modal -- ERROR - ShowShape _ _ -> modal -- ERROR - ShowInput iShape ix iy -> ShowInput (Polygon ((ix,iy)::(getPointListFromPolygon iShape))) "" "" - EditShape _ _ -> modal -- ERROR - ShowManagePicUrl _ _ -> modal -- ERROR + NoModal -> modal -- ERROR + ShowTable -> modal -- ERROR + ShowShape _ _ -> modal -- ERROR + ShowInput iShape ix iy -> ShowInput (Polygon ((ix,iy)::(getPointListFromPolygon iShape))) "" "" + EditShape _ _ -> modal -- ERROR + ShowManagePicture _ _ _ _ -> modal -- ERROR updateInput : Char -> String -> Modal -> String -> Shape -> String -> String -> MousePosition -> Modal updateInput inputType value modal modalType iShape ix iy mouse = case inputType of @@ -130,28 +142,28 @@ eq_String_Modal string modal = string==(modalNameToString modal) getUrlFromModal : Modal -> Maybe Url.Url getUrlFromModal modal = case modal of - NoModal -> Nothing - ShowTable -> Nothing - ShowInput _ _ _ -> Nothing - ShowShape _ _ -> Nothing - EditShape _ _ -> Nothing - ShowManagePicUrl _ url -> url + NoModal -> Nothing + ShowTable -> Nothing + ShowInput _ _ _ -> Nothing + ShowShape _ _ -> Nothing + EditShape _ _ -> Nothing + ShowManagePicture _ url _ _ -> url getInputShapeFromModal : Modal -> Shape getInputShapeFromModal modal = case modal of - NoModal -> Empty - ShowTable -> Empty - ShowInput shape _ _ -> shape - ShowShape _ _ -> Empty - EditShape _ _ -> Empty - ShowManagePicUrl _ _-> Empty + NoModal -> Empty + ShowTable -> Empty + ShowInput shape _ _ -> shape + ShowShape _ _ -> Empty + EditShape _ _ -> Empty + ShowManagePicture _ _ _ _ -> Empty -- Transform Modal to other Types modalNameToString : Modal -> String modalNameToString modal = case modal of - NoModal -> "NoModal" - ShowTable -> "ShowTable" - ShowInput _ _ _ -> "ShowInput" - ShowShape _ _ -> "ShowShape" - EditShape _ _ -> "EditShape" - ShowManagePicUrl _ _-> "ShowManagePicUrl" \ No newline at end of file + NoModal -> "NoModal" + ShowTable -> "ShowTable" + ShowInput _ _ _ -> "ShowInput" + ShowShape _ _ -> "ShowShape" + EditShape _ _ -> "EditShape" + ShowManagePicture _ _ _ _ -> "ShowManagePicture" \ No newline at end of file diff --git a/src/Manager/UpdateManager.elm b/src/Manager/UpdateManager.elm index af8d8023a4203bb7d268e1fafa5d37117d0579a0..7365c32a2378fbeccb363866108e88fb87b08a21 100644 --- a/src/Manager/UpdateManager.elm +++ b/src/Manager/UpdateManager.elm @@ -31,18 +31,13 @@ updateModel msg model = OpenShowTable -> updateModal modalMsg modal OpenShowShape _ _ -> updateModal modalMsg modal OpenEditShape id ss iT _ -> updateModal (OpenEditShape id ss iT value) modal - OpenManagePicUrl _ -> updateModal modalMsg modal + OpenManagePicture iT _ -> updateModal (OpenManagePicture iT value) modal ResetShowInput -> updateModal modalMsg modal Check _ -> updateModal modalMsg modal Input inputType _ -> updateModal (Input inputType value) modal InputPoint -> updateModal modalMsg modal ) ) - , pictureUrl = if (eq_String_Modal "ShowManagePicUrl" modal) - then case getUrlFromModal modal of - Just url -> url - Nothing -> model.pictureUrl - else model.pictureUrl } ManageShapes shapesMsg value-> case shapesMsg of @@ -129,7 +124,8 @@ updateModel msg model = Ok shapes-> { model | saved = shapeListToShape_ShapeStyleList shapes, shapesLoadResult = Ok "shapes"} Err e -> { model | saved = [] , shapesLoadResult = (Err e )} LinkClicked urlRequest -> model - UrlChanged url -> { model | url = url} + UrlChanged url -> { model | url = url } + SavePicture pic -> { model | picture = pic } updateCmdMsg : Msg -> Model -> Cmd Msg updateCmdMsg msg model = case msg of @@ -140,6 +136,7 @@ updateCmdMsg msg model = InputDrawShape -> Cmd.none ShapesLoaded _ -> Cmd.none OpenDrawShape _ -> Cmd.none + SavePicture _ -> Cmd.none LoadShapes result -> case result of Ok "LoadExample" -> diff --git a/src/Manager/ViewManager.elm b/src/Manager/ViewManager.elm index 5697e7efeac663bb087e53cb308fad365e4f47b3..cf4c1fbcbf6ad3503ff6735c5b8099b45490cc62 100644 --- a/src/Manager/ViewManager.elm +++ b/src/Manager/ViewManager.elm @@ -50,8 +50,8 @@ view model = |> Tuple.second ) ] - EditShape id shapeStyle-> [viewEditShapeModal id shapeStyle] - ShowManagePicUrl s url -> [] -- not implemented + EditShape id shapeStyle -> [viewEditShapeModal id shapeStyle ] + ShowManagePicture s url w h -> [viewManagePicture s url model.picture.url w h] ] ) -- Parts of the VIEW @@ -61,7 +61,7 @@ viewHeader_Buttons state = [ div [class "section"] [ h1 [class "title"] [text "ShapePicture Editor"] ] , div [ style "margin-left" "25px"] - [ button [ onClick (ManageModal (OpenManagePicUrl "") "") + [ button [ onClick (ManageModal (OpenManagePicture "" "") "") , class "button is-success is-pulled-left is-size-6" , style "margin-bottom" "15px" , style "margin-right" "15px" @@ -130,12 +130,15 @@ viewHeader_Buttons state = ] viewImage : Model -> Html Msg viewImage model = + let picW = String.fromInt model.picture.w + picH = String.fromInt model.picture.h + in div [ style "margin-left" "25px", style "margin-top" "15px", class "container"] [ figure [ class "image"] - [ svg [ width "100%", viewBox "0 0 800 600", version "1.1"] + [ svg [ width "100%", viewBox ("0 0 "++picW++" "++picH), version "1.1"] ( List.concat - [[image [ width "800", height "600" - , xlinkHref (Url.toString model.pictureUrl) + [[image [ width picW, height picH + , xlinkHref (Url.toString model.picture.url) ] [] ] , viewSvgShapes model.saved model.svgShapeHover 1 @@ -199,7 +202,7 @@ viewImage model = ) ) ] [] - , rect [ x "0", y "0", width "800", height "600" + , rect [ x "0", y "0", width picW, height picH , Svg.Attributes.style "fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" , onMouseMove UpdateMousePos @@ -356,18 +359,22 @@ viewShapeModal id edit shapeStyle = ,Html.Events.onMouseLeave (ManageModal (OpenShowShape id 0) "") ] [ if edit==2 - then label [] [ input [ class "input" - , value shapeStyle.body - , onInput (ManageShapes (SaveShapeStyle id shapeStyle "B" "")) - ] [] - ] + then Html.textarea [ class "textarea has-fixed-size" + , value shapeStyle.body + , onInput (ManageShapes (SaveShapeStyle id shapeStyle "B" "")) + ] [] else if shapeStyle.body=="default" then text ("Form "++String.fromInt id++" wurde gefunden!") else case Url.fromString shapeStyle.body of Just url -> Html.iframe [ src shapeStyle.body , style "width" "100%" , style "height" "100%"] [] - Nothing -> text shapeStyle.body + Nothing -> let lines = String.split "\n" shapeStyle.body + writeLines lines2 = + case lines2 of + [] -> [] + x::xs-> (div [] [text x, Html.br [] []])::(writeLines xs) + in div [] (writeLines lines) ] , modalFooter [ shapeEditButton id shapeStyle "6" , shapeDeleteButton id "6" @@ -386,40 +393,40 @@ viewEditShapeModal id shapeStyle = , th [] [text "Werte"] ] , tr [] [ td [] [ Html.textarea [class "textarea has-fixed-size is-medium" - , Html.Attributes.rows 10 - , Html.Attributes.cols 20 - , Html.Attributes.readonly True - ] [ - text "hoveredFillColor \n" - , text "hoveredFillOpacity \n" - , text "hoveredStrokeColor \n" - , text "hoveredStrokeWidth \n" - , text "hoveredStrokeOpacity\n" - , text "unHoveredFillColor \n" - , text "unHoveredFillOpacity\n" - , text "unHoveredStrokeColor\n" - , text "unHoveredStrokeWidth\n" - , text "unHoveredStrokeOpacity" - ] - ] - , td [] [ Html.textarea [ class "textarea has-fixed-size is-medium" - , Html.Attributes.rows 10 - , Html.Attributes.cols 10 - , onInput (ManageModal (OpenEditShape id shapeStyle "TA" "")) - ] [ - text (shapeStyle.hoveredFillColor ++"\n") - , text (shapeStyle.hoveredFillOpacity ++"\n") - , text (shapeStyle.hoveredStrokeColor ++"\n") - , text (shapeStyle.hoveredStrokeWidth ++"\n") - , text (shapeStyle.hoveredStrokeOpacity++"\n") - , text (shapeStyle.unHoveredFillColor ++"\n") - , text (shapeStyle.unHoveredFillOpacity++"\n") - , text (shapeStyle.unHoveredStrokeColor++"\n") - , text (shapeStyle.unHoveredStrokeWidth++"\n") - , text shapeStyle.unHoveredStrokeOpacity - ] - ] - ] + , Html.Attributes.rows 10 + , Html.Attributes.cols 20 + , Html.Attributes.readonly True + ] [ + text "hoveredFillColor \n" + , text "hoveredFillOpacity \n" + , text "hoveredStrokeColor \n" + , text "hoveredStrokeWidth \n" + , text "hoveredStrokeOpacity\n" + , text "unHoveredFillColor \n" + , text "unHoveredFillOpacity\n" + , text "unHoveredStrokeColor\n" + , text "unHoveredStrokeWidth\n" + , text "unHoveredStrokeOpacity" + ] + ] + , td [] [ Html.textarea [ class "textarea has-fixed-size is-medium" + , Html.Attributes.rows 10 + , Html.Attributes.cols 10 + , onInput (ManageModal (OpenEditShape id shapeStyle "TA" "")) + ] [ + text (shapeStyle.hoveredFillColor ++"\n") + , text (shapeStyle.hoveredFillOpacity ++"\n") + , text (shapeStyle.hoveredStrokeColor ++"\n") + , text (shapeStyle.hoveredStrokeWidth ++"\n") + , text (shapeStyle.hoveredStrokeOpacity++"\n") + , text (shapeStyle.unHoveredFillColor ++"\n") + , text (shapeStyle.unHoveredFillOpacity++"\n") + , text (shapeStyle.unHoveredStrokeColor++"\n") + , text (shapeStyle.unHoveredStrokeWidth++"\n") + , text shapeStyle.unHoveredStrokeOpacity + ] + ] + ] ] ] ] @@ -430,6 +437,33 @@ viewEditShapeModal id shapeStyle = , shapeDeleteButton id "6" ] 41.1 ] +viewManagePicture : String -> Maybe Url.Url -> Url.Url -> Int -> Int -> Html Msg +viewManagePicture s mayUrl currentUrl w h= + let picUrlState = case mayUrl of + Just url -> "Url ist gültig." + Nothing -> "Ungültige Url." + w1 = String.fromInt w + h1 = String.fromInt h + in modalCard [ modalHeader "Bild auswählen" + , modalCardBody [ text ("Aktuelles Bild: "++(Url.toString currentUrl)) + , label [class "label"] [text "Url zum Bild"] + , label [] [ input [class "input", Html.Attributes.placeholder "Url zum Bild" + , value s, onInput (ManageModal (OpenManagePicture "i1" "")) ] [] ] + , label [class "label"] [text "Breite des Bildes"] + , label [] [ input [class "input", Html.Attributes.placeholder "Breite des Bildes" + , value w1, onInput (ManageModal (OpenManagePicture "i2" "")) ] [] ] + , label [class "label"] [text "Höhe des Bildes"] + , label [] [ input [class "input", Html.Attributes.placeholder "Höhe des Bildes" + , value h1, onInput (ManageModal (OpenManagePicture "i3" "")) ] [] ] + , text ("Status: "++picUrlState) + ] + , modalFooter [ button [class "button is-success" + , case mayUrl of + Just url -> onClick (SavePicture (Picture url w h)) + Nothing -> Html.Attributes.disabled True + ] [text "Übernehmen"] + ] 22.0 + ] -- Helping Methods for the VIEW viewDropDownMenue : String -> Bool -> String -> List(Attribute Msg) -> List(Svg Msg) -> Html Msg viewDropDownMenue header isGreen iconType attributes dropDownItems = diff --git a/src/ShapePicture_Editor.elm b/src/ShapePicture_Editor.elm index 3ccbc43876acd0a8feb3e20e1fc1a23973fb62bd..362e20ef0820860bb662e5c19b9b85face4da32e 100644 --- a/src/ShapePicture_Editor.elm +++ b/src/ShapePicture_Editor.elm @@ -9,6 +9,7 @@ import TypeHolder exposing (Model, Msg(..)) import Manager.UpdateManager exposing (update) import Manager.ViewManager exposing (view) import Manager.StateManager as StM +import Util.Util exposing (Picture) main = Browser.application { init = init @@ -26,13 +27,17 @@ init _ url key = [] 0 (Ok " Init") - ( Url.Url - Url.Http - "www.informatik.uni-halle.de" - Nothing - "/im/1285058520_1381_00_800.jpg" - Nothing - Nothing + ( Picture + ( Url.Url + Url.Http + "www.informatik.uni-halle.de" + Nothing + "/im/1285058520_1381_00_800.jpg" + Nothing + Nothing + ) + 800 + 600 ) url key diff --git a/src/TypeHolder.elm b/src/TypeHolder.elm index 6faa9ac04aa7bf8865eeb0b4f664e76f434fb2bc..5a8c3273fb87e08b710569310ed1512fa7b3c349 100644 --- a/src/TypeHolder.elm +++ b/src/TypeHolder.elm @@ -10,14 +10,14 @@ import Url import Manager.StateManager exposing (State) import Manager.ModalManager exposing (Modal, ModalMsg) import Util.ShapeManager exposing (Shape, ShapeStyle, ShapesMsg) -import Util.Util exposing (MousePosition) +import Util.Util exposing (MousePosition, Picture) type alias Model = { state : State , saved : List (Shape, ShapeStyle) , svgShapeHover : Int , shapesLoadResult : (Result Http.Error String) - , pictureUrl : Url.Url + , picture : Picture , url : Url.Url , key : Nav.Key } @@ -36,4 +36,6 @@ type Msg | ShapesLoaded (Result Http.Error (List Shape)) -- Url | LinkClicked Browser.UrlRequest - | UrlChanged Url.Url \ No newline at end of file + | UrlChanged Url.Url + -- for saving pictureUrl + | SavePicture Picture \ No newline at end of file diff --git a/src/Util/Util.elm b/src/Util/Util.elm index cc39b4dd5c23d606411442fb234fff2d5e7b2dbf..c081341ab35c698ad06e28ee7d7ad6d010d5935c 100644 --- a/src/Util/Util.elm +++ b/src/Util/Util.elm @@ -8,6 +8,8 @@ import Svg.Events import Http -- Html import Html exposing (Html, Attribute, node) +-- Url +import Url -- Html Elements link : List (Attribute msg) -> List (Html msg) -> Html msg @@ -75,4 +77,6 @@ onMouseMove mapMousePositionToMsg = offsetMousePosition : JD.Decoder MousePosition offsetMousePosition = JD.map2 MousePosition (JD.field "offsetX" JD.int) - (JD.field "offsetY" JD.int) \ No newline at end of file + (JD.field "offsetY" JD.int) +type alias Picture = + { url: Url.Url, w: Int, h: Int } \ No newline at end of file