From 2658fc20216151e3627f63128dc011369908dadf Mon Sep 17 00:00:00 2001 From: abdulhasib <abdulhasib.reee@gmail.com> Date: Tue, 7 Jul 2020 20:51:57 +0200 Subject: [PATCH] encoder with URL pictureUrl wird erfolgreich kodiert. --- src/Manager/UpdateManager.elm | 4 +--- src/Util/ShapeManager.elm | 26 ++++++++++++++++++++++++-- src/Util/ViewParts.elm | 4 ++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/Manager/UpdateManager.elm b/src/Manager/UpdateManager.elm index 72e992a..3acb6f8 100644 --- a/src/Manager/UpdateManager.elm +++ b/src/Manager/UpdateManager.elm @@ -131,8 +131,6 @@ updateModel msg model = ImgLoaded imgDs -> { model | picture = Picture model.picture.url imgDs.width imgDs.height } GotJson jsonString -> let - -- [{"polygonList":[{"x":42,"y":84}, {"x":42,"y":84}] }] - -- "[{\"shape\": {\"circle\": {\"cx\": \"589\",\"cy\": \"108\",\"r\": \"79\"}},\"shapeprop\": {\"hFC\": \"white\",\"hFO\": \"0.5\", \"hSC\": \"red\", \"hSW\": \"3\", \"hSO\": \"1.0\", \"uFC\": \"white\",\"uFO\": \"0.0\", \"uSC\": \"red\", \"uSW\": \"3\", \"uSO\": \"1.0\", \"title\": \"default\", \"body\": \"default\" }}]" myDecoder : Json.Decode.Decoder (List (Shape, ShapeStyle)) myDecoder = Json.Decode.list @@ -261,4 +259,4 @@ updateCmdMsg msg model = Browser.Internal url -> Nav.pushUrl model.key (Url.toString url) Browser.External href -> Nav.load href - UrlChanged url -> updateCmdMsg (LoadShapes (Ok (Maybe.withDefault "" url.fragment))) model \ No newline at end of file + UrlChanged url -> updateCmdMsg (LoadShapes (Ok (Maybe.withDefault "" url.fragment))) model diff --git a/src/Util/ShapeManager.elm b/src/Util/ShapeManager.elm index 0a67501..124d107 100644 --- a/src/Util/ShapeManager.elm +++ b/src/Util/ShapeManager.elm @@ -4,6 +4,7 @@ import Json.Decode as JD import Json.Encode -- Own import Util.Util exposing (..) +import Url type Shape = Empty @@ -223,7 +224,15 @@ shapesDecoderListPoly var s = x::[] -> x x::xs -> x++["This List is too long"] Err e -> ["ERROR"] --- new Decoder of Shapes +-- new Encoder of Shapes ------------------------------------------------------ +writeAlltoJson : List ( Shape, ShapeStyle ) -> String -> Json.Encode.Value +writeAlltoJson shapeWithProperties picUrl = + let + jsonObj = + Json.Encode.object + ( [ ("Url", pictureInfoToJson picUrl), ("shapes", writeShapeToJson shapeWithProperties )]) + in jsonObj + writeShapeToJson : List ( Shape, ShapeStyle ) -> Json.Encode.Value writeShapeToJson data = Json.Encode.list shapeCoordsToJson data @@ -320,4 +329,17 @@ rectToJson a b c d = ( "height", Json.Encode.string d ) ]) ) ] - in jsonObj \ No newline at end of file + in jsonObj + +pictureInfoToJson : String -> Json.Encode.Value +pictureInfoToJson url = + let + jsonObj = + Json.Encode.object + [ + ( + "pictureInfo" + ,Json.Encode.object ([ ( "url", Json.Encode.string url ) ]) + ) + ] + in jsonObj diff --git a/src/Util/ViewParts.elm b/src/Util/ViewParts.elm index 055d4f6..11814df 100644 --- a/src/Util/ViewParts.elm +++ b/src/Util/ViewParts.elm @@ -563,5 +563,5 @@ viewStringToShapes model = , style "margin-right" "15px" , style "margin-bottom" "15px" ] [ text "string to shapes" ] - , div [] [ Html.pre [][Html.text <| Json.Encode.encode 3 <| writeShapeToJson model.saved] ] - ] \ No newline at end of file + , div [] [ Html.pre [][Html.text <| Json.Encode.encode 3 <| (writeAlltoJson model.saved (Url.toString model.picture.url))] ] + ] -- GitLab