From 34c0634dc224f3111c340d46850049455bdeffee Mon Sep 17 00:00:00 2001
From: Edward <sabinusedward@yahoo.de>
Date: Wed, 8 Jul 2020 19:32:48 +0200
Subject: [PATCH] Die Grundfunktion, dass ein im Internet gespeichertes
 ShapePicture.json geladen werden kann funktioniert nun.

---
 src/Manager/UpdateManager.elm | 190 ++++++----------------------------
 src/Manager/ViewManager.elm   |  12 ++-
 src/ShapePicture_Editor.elm   |  38 +++----
 src/TypeHolder.elm            |  27 ++---
 src/Util/ShapeManager.elm     | 101 +++++++++++++++++-
 src/Util/Util.elm             |  52 ++++++----
 src/Util/ViewParts.elm        |  38 ++++---
 7 files changed, 223 insertions(+), 235 deletions(-)

diff --git a/src/Manager/UpdateManager.elm b/src/Manager/UpdateManager.elm
index 741c9d5..7cb4f1c 100644
--- a/src/Manager/UpdateManager.elm
+++ b/src/Manager/UpdateManager.elm
@@ -9,7 +9,7 @@ import Url
 -- Json
 import Json.Decode
 -- Own
-import TypeHolder exposing (Model, ErweitertertesBild, Msg(..))
+import TypeHolder exposing (Model, Msg(..))
 import Manager.StateManager exposing (..)
 import Manager.ModalManager exposing (..)
 import Util.ShapeManager exposing (..)
@@ -112,172 +112,46 @@ updateModel msg model =
                                                       )
                                                       mPos
                                    }
-      LoadShapes result ->
+      InitialJsonStringLoaded result ->
         case result of
-          Ok ""           -> { model | shapesLoadResult = Err (Http.BadBody "Empty result for LoadShapes") }
-          Ok "LoadExample"-> model
-          Ok "Fenster"    -> model
-          Ok "T%C3%BCren" -> model --%C3%BC = ü
-          Ok s  -> { model | shapesLoadResult = result
-                           , saved = shapeListToShape_ShapeStyleList (shapesDecoder s)
-                   }
-          Err e -> { model | shapesLoadResult = result }
-      ShapesLoaded result ->
-        case result of
-          Ok shapes-> { model | saved = shapeListToShape_ShapeStyleList shapes, shapesLoadResult = Ok "shapes"}
-          Err e    -> { model | saved = [] , shapesLoadResult = (Err e )}
+          Ok "" -> { model | httpLoadResult = Err (Http.BadBody "Empty result for LoadShapes") }
+          Ok s  -> updateModel (DecodeJson s) { model | httpLoadResult = result }
+          Err e -> { model | httpLoadResult = result }
       LinkClicked urlRequest -> model
       UrlChanged  url        -> { model | url     = url }
-      SavePicture pic        -> { model | picture = pic }
-      ImgLoaded  imgDs       -> { model | picture = Picture model.picture.url imgDs.width imgDs.height }
-      GotJson jsonString ->
-            let
-                myDecoder : Json.Decode.Decoder (List (Shape, ShapeStyle))
-                myDecoder =
-                        (Json.Decode.list
-                          (Json.Decode.map2 (\a b -> (a, b))
-                            (Json.Decode.field ("shape")
-                              (Json.Decode.oneOf  [
-
-                                (Json.Decode.field ( "circle")
-                                        (Json.Decode.map3
-                                            (\a b c ->  Circle a b c)
-                                            (Json.Decode.field "cx" Json.Decode.string)
-                                            (Json.Decode.field "cy" Json.Decode.string)
-                                            (Json.Decode.field "r" Json.Decode.string)
-                                        )
-                                ),
-                                (Json.Decode.field ( "rect")
-                                        (Json.Decode.map4
-                                            (\a b c d ->  Rectangle a b c d)
-                                            (Json.Decode.field "x" Json.Decode.string)
-                                            (Json.Decode.field "y" Json.Decode.string)
-                                            (Json.Decode.field "width" Json.Decode.string)
-                                            (Json.Decode.field "height" Json.Decode.string)
-                                        )
-                                ),
-                                (Json.Decode.field ( "ellipse")
-                                        (Json.Decode.map4
-                                            (\a b c d ->  Rectangle a b c d)
-                                            (Json.Decode.field "cx" Json.Decode.string)
-                                            (Json.Decode.field "cy" Json.Decode.string)
-                                            (Json.Decode.field "rx" Json.Decode.string)
-                                            (Json.Decode.field "ry" Json.Decode.string)
-                                        )
-                                ),
-
-                                  (Json.Decode.map (\l -> Polygon l) (
-                                  (Json.Decode.field ( "polygon")
-                                      (Json.Decode.list
-                                          (Json.Decode.map2
-                                              (\a b -> ( a, b ))
-                                              (Json.Decode.field "x" Json.Decode.string)
-                                              (Json.Decode.field "y" Json.Decode.string)
-                                          )
-                                      )
-                                  )
-                                  )
-                                  )
-                                  ]
-                                )
-                              )
-
-                            ((Json.Decode.field ("shapeprop") (
-                            Json.Decode.map4 (\( a, b, c ) ( d, e, f )
-                                                ( g, h, i ) ( j, k, l )
-                                            -> ShapeStyle a b c d e f g h i j k l)
-                                (Json.Decode.map3
-                                (\a b c -> ( a, b, c ))
-                                (Json.Decode.field "hFC" Json.Decode.string)
-                                (Json.Decode.field "hFO" Json.Decode.string)
-                                (Json.Decode.field "hSC" Json.Decode.string)
-                                )
-                                (Json.Decode.map3 (\a b c -> ( a, b, c ))
-                                (Json.Decode.field "hSW" Json.Decode.string)
-                                (Json.Decode.field "hSO" Json.Decode.string)
-                                (Json.Decode.field "uFC" Json.Decode.string)
-                                )
-                                (Json.Decode.map3 (\a b c -> ( a, b, c ))
-                                (Json.Decode.field "uFO" Json.Decode.string)
-                                (Json.Decode.field "uSC" Json.Decode.string)
-                                (Json.Decode.field "uSW" Json.Decode.string)
-                                )
-                                (Json.Decode.map3 (\a b c -> ( a, b, c ))
-                                (Json.Decode.field "uSO" Json.Decode.string)
-                                (Json.Decode.field "title" Json.Decode.string)
-                                (Json.Decode.field "body" Json.Decode.string)
-                              )
-                           ))
-                           )
-                           )
-                          )
-                erweitertesBildDecoder : Json.Decode.Decoder ErweitertertesBild
-                erweitertesBildDecoder = Json.Decode.map2
-                  (\a b ->
-                    let
-                      maybeUrl = (Url.fromString a)
-                      maybePicture = Maybe.map (\u -> Picture u 0 0) maybeUrl
-                    in
-                    ErweitertertesBild maybePicture b
-                  )
-                        ( Json.Decode.field ("pictureUrl") Json.Decode.string)
-                        (Json.Decode.field ( "shapes") myDecoder)
-
-                resultDecode : Result Json.Decode.Error ErweitertertesBild
-                resultDecode =
-                    Json.Decode.decodeString erweitertesBildDecoder jsonString
-            in
-            case resultDecode of
-                Err jsonError ->
-                    { model | errorString = Json.Decode.errorToString jsonError }
-
-                Ok pl ->
-                    { model |  saved = pl.shapes, errorString = "",
-                      picture = Maybe.withDefault { url= ( Url.Url Url.Http
-                                            "www.informatik.uni-halle.de"
-                                            Nothing
-                                            "/im/1285058520_1381_00_800.jpg"
-                                            Nothing
-                                            Nothing
-                                           )
-                                  , w = 0 , h = 0} pl.picture}
+      SavePicture pic        -> { model | picture = Just pic }
+      ImgLoaded  imgDs       -> { model | picture = Just (Picture (maybePictureToPicture model.picture).url imgDs.width imgDs.height) }
+      DecodeJson jsonText ->
+        case resultDecode jsonText of
+            Err jsonError ->
+                { model | jsonFile = { text  = model.jsonFile.text
+                                     , error = Json.Decode.errorToString jsonError
+                                     }
+                }
+            Ok pl ->
+                { model | saved       = pl.shapes
+                        , jsonFile    = { text  = jsonText
+                                        , error = ""
+                                        }
+                        , picture     = pl.picture
+                }
 
 updateCmdMsg : Msg -> Model -> Cmd Msg
 updateCmdMsg msg model =
     case msg of
-      ManageModal    _ _ -> Cmd.none
-      ManageShapes   _ _ -> Cmd.none
-      SvgShapeHover  _   -> Cmd.none
-      UpdateMousePos _   -> Cmd.none
-      InputDrawShape     -> Cmd.none
-      ShapesLoaded   _   -> Cmd.none
-      OpenDrawShape  _   -> Cmd.none
-      SavePicture    _   -> Cmd.none
-      ImgLoaded      _   -> Cmd.none
-      GotJson _          -> Cmd.none
-      LoadShapes  result ->
-        case result of
-          Ok "LoadExample" ->
-            Http.get
-              { url = "https://cors-anywhere.herokuapp.com/"
-                    --++"https://users.informatik.uni-halle.de/~hinnebur/shapes-circ-rect-ploy.json" --don't works yet
-                    ++"https://users.informatik.uni-halle.de/~hinnebur/shapes-list-circ-rect-poly.json"
-                    --++"https://users.informatik.uni-halle.de/~hinnebur/shapes-list-circ-rect.json"
-              , expect = Http.expectString LoadShapes
-              }
-          Ok s  -> if (s=="Fenster" || s=="T%C3%BCren") --%C3%BC = ü
-                     then Http.get
-                            { url = "https://cors-anywhere.herokuapp.com/" ++        (if (s=="Fenster") then
-                                    "https://users.informatik.uni-halle.de/~hinnebur/fenster-liste.json"else
-                                    "https://users.informatik.uni-halle.de/~hinnebur/tueren-liste.json")
-                            , expect = Http.expectJson ShapesLoaded rectListDecoder
-                            --, expect = Http.expectJson ShapesLoaded ellipseListDecoder
-                            }
-                     else Cmd.none
-          Err e -> Cmd.none
+      ManageModal             _ _ -> Cmd.none
+      ManageShapes            _ _ -> Cmd.none
+      SvgShapeHover           _   -> Cmd.none
+      UpdateMousePos          _   -> Cmd.none
+      InputDrawShape              -> Cmd.none
+      OpenDrawShape           _   -> Cmd.none
+      SavePicture             _   -> Cmd.none
+      ImgLoaded               _   -> Cmd.none
+      DecodeJson              _   -> Cmd.none
+      InitialJsonStringLoaded _   -> Cmd.none
       LinkClicked urlReq ->
         case urlReq of
           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
+      UrlChanged     url -> Cmd.none
diff --git a/src/Manager/ViewManager.elm b/src/Manager/ViewManager.elm
index 1f6b3bf..4b8bc55 100644
--- a/src/Manager/ViewManager.elm
+++ b/src/Manager/ViewManager.elm
@@ -13,7 +13,7 @@ import Util.ShapeManager exposing (..)
 import Util.Util         exposing (..)
 
 documentView : Model -> Browser.Document Msg
-documentView model = if model.edit
+documentView model = if model.queryInfo.edit
                        then { title = "ShapePicture_Editor"
                             , body = [viewEditor model]
                             }
@@ -29,8 +29,8 @@ viewEditor model =
         ,[ viewHeader_Buttons model.state
          , Html.section [class "section"] []
          , viewImage model
-         , case model.shapesLoadResult of
-             Ok  s -> text ""
+         , case model.httpLoadResult of
+             Ok  s -> text s
              Err e -> text ("Could not load shapes: "++(httpErrorToString e))
          ]
         , case (getModalFromState model.state) of
@@ -48,7 +48,11 @@ viewEditor model =
                                       ]
             ShowJson                    -> [viewJsonModal           model                      ]
             EditShape id shapeStyle     -> [viewEditShapeModal      id shapeStyle              ]
-            ShowManagePicture s url w h -> [viewManagePictureModal  s url model.picture.url w h]
+            ShowManagePicture s url w h -> [viewManagePictureModal  s url (case model.picture of
+                                                                             Just picture -> Just picture.url
+                                                                             Nothing      -> Nothing
+                                                                          ) w h
+                                           ]
         ]
       )
 
diff --git a/src/ShapePicture_Editor.elm b/src/ShapePicture_Editor.elm
index 3114c46..bd8a17d 100644
--- a/src/ShapePicture_Editor.elm
+++ b/src/ShapePicture_Editor.elm
@@ -4,12 +4,14 @@ import Browser
 import Browser.Navigation as Nav
 -- Url
 import Url
+--
+import Http
 -- Own
 import TypeHolder exposing (Model, Msg(..))
 import Manager.UpdateManager exposing (update)
 import Manager.ViewManager   exposing (documentView)
 import Manager.StateManager  as StM
-import Util.Util exposing (Picture, isEdit)
+import Util.Util exposing (QueryInfo, JsonFile, getQueryInfo)
 
 main = Browser.application
         { init = init
@@ -22,29 +24,27 @@ main = Browser.application
 -- INIT
 init : () -> Url.Url -> Nav.Key-> (Model, Cmd Msg)
 init _ url key =
-    ( { state = StM.Standby
+    let queryInfo = getQueryInfo url
+    in
+     ({ state = StM.Standby
       , saved = []
       , svgShapeHover = 0
-      , shapesLoadResult = (Ok " Init")
-      , picture = { url= ( Url.Url
-                              Url.Http
-                              "www.informatik.uni-halle.de"
-                              Nothing
-                              "/im/1285058520_1381_00_800.jpg"
-                              Nothing
-                              Nothing
-                           )
-                  , w = 0
-                  , h = 0
-                  }
-      , edit = (isEdit url)
+      , httpLoadResult = (Ok " Init")
+      , picture = Nothing
+      , queryInfo = queryInfo
+      , jsonFile = { text  = "{\"pictureUrl\":\"https://i2-prod.mirror.co.uk/incoming/article9690209.ece/ALTERNATES/s1200/Namibia.jpg\",\"shapes\":[{\"shape\":{\"circle\":{\"cx\":\"50\",\"cy\":\"50\",\"r\":\"40\"}},\"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\"}},{\"shape\":{\"rect\":{\"x\":\"100\",\"y\":\"100\",\"width\":\"50\",\"height\":\"60\"}},\"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\"}},{\"shape\":{\"polygon\":[{\"x\":\"200\",\"y\":\"150\"},{\"x\":\"250\",\"y\":\"400\"},{\"x\":\"120\",\"y\":\"340\"},{\"x\":\"160\",\"y\":\"250\"},{\"x\":\"180\",\"y\":\"170\"}]},\"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\"}}]}"
+                   , error = ""
+                   }
       , url  = url
       , key  = key
-      , errorString = ""
-      , stringToShapes = "{\"pictureUrl\":\"https://i2-prod.mirror.co.uk/incoming/article9690209.ece/ALTERNATES/s1200/Namibia.jpg\",\"shapes\":[{\"shape\":{\"circle\":{\"cx\":\"50\",\"cy\":\"50\",\"r\":\"40\"}},\"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\"}},{\"shape\":{\"rect\":{\"x\":\"100\",\"y\":\"100\",\"width\":\"50\",\"height\":\"60\"}},\"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\"}},{\"shape\":{\"polygon\":[{\"x\":\"200\",\"y\":\"150\"},{\"x\":\"250\",\"y\":\"400\"},{\"x\":\"120\",\"y\":\"340\"},{\"x\":\"160\",\"y\":\"250\"},{\"x\":\"180\",\"y\":\"170\"}]},\"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\"}}]}"
       }
-    , Cmd.none
-    )
+     , case queryInfo.jsonUrl of
+         Just jsonUrl -> Http.get { url = Url.toString jsonUrl
+                                  , expect = Http.expectString InitialJsonStringLoaded
+                                  }
+         Nothing -> Cmd.none
+
+     )
 -- SUBSCRIPTIONS
 subscriptions : Model -> Sub Msg
 subscriptions model = Sub.none
\ No newline at end of file
diff --git a/src/TypeHolder.elm b/src/TypeHolder.elm
index 01d82a6..1187c15 100644
--- a/src/TypeHolder.elm
+++ b/src/TypeHolder.elm
@@ -1,4 +1,4 @@
-module TypeHolder exposing (Model, ErweitertertesBild, Msg(..))
+module TypeHolder exposing (Model, Msg(..))
 -- Http
 import Http
 -- Browser
@@ -10,25 +10,18 @@ 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, Picture, ImgDimensions)
+import Util.Util         exposing (MousePosition, Picture, ImgDimensions, QueryInfo, JsonFile)
 
 type alias Model =
   { state : State
   , saved : List (Shape, ShapeStyle)
   , svgShapeHover : Int
-  , shapesLoadResult : (Result Http.Error String)
-  , picture : Picture
-  , edit: Bool
+  , httpLoadResult : (Result Http.Error String)
+  , picture :  Maybe Picture
+  , queryInfo : QueryInfo
+  , jsonFile : JsonFile
   , url : Url.Url
   , key : Nav.Key
-  , errorString : String
-  , stringToShapes : String
-  }
-
-type alias ErweitertertesBild =
-  {
-     picture : Maybe Picture
-     ,shapes : List (Shape, ShapeStyle)
   }
 
 type Msg
@@ -41,13 +34,13 @@ type Msg
   | OpenDrawShape Shape
   | UpdateMousePos MousePosition
   | InputDrawShape
-  -- for loading shapes with http
-  | LoadShapes   (Result Http.Error String)
-  | ShapesLoaded (Result Http.Error (List Shape))
+  -- for loading Strings with http
+  | InitialJsonStringLoaded (Result Http.Error String)
   -- Url
   | LinkClicked Browser.UrlRequest
   | UrlChanged Url.Url
-  | GotJson String
+  -- Json Decoder
+  | DecodeJson String
   -- for saving pictureUrl
   | SavePicture Picture
   | ImgLoaded ImgDimensions
\ No newline at end of file
diff --git a/src/Util/ShapeManager.elm b/src/Util/ShapeManager.elm
index 560bd8f..5fbb2f5 100644
--- a/src/Util/ShapeManager.elm
+++ b/src/Util/ShapeManager.elm
@@ -6,6 +6,7 @@ import Json.Encode
 import Util.Util exposing (..)
 import Url
 
+-- main types
 type Shape
   = Empty
   | Circle String String String
@@ -34,6 +35,11 @@ type ShapesMsg
   | SaveEditedShape Int ShapeStyle
   | SaveShapeStyle  Int ShapeStyle String String
 
+-- Other Types with Shapes
+type alias ShapePicture =
+    { picture : Maybe Picture
+    , shapes  : List (Shape, ShapeStyle)
+    }
 -- Update
 updateShapes : ShapesMsg -> List (Shape, ShapeStyle) -> List (Shape, ShapeStyle)
 updateShapes shapesMsg shapeList =
@@ -224,7 +230,100 @@ shapesDecoderListPoly var s =
                       x::[] -> x
                       x::xs -> x++["This List is too long"]
          Err e   -> ["ERROR"]
--- new Encoder of Shapes ------------------------------------------------------
+-- new Decoder of Shapes
+resultDecode : String -> Result JD.Error ShapePicture
+resultDecode jsonString =
+    let shapeDecoder : JD.Decoder (List (Shape, ShapeStyle))
+        shapeDecoder =
+                (JD.list
+                  (JD.map2 (\a b -> (a, b))
+                    (JD.field ("shape")
+                      (JD.oneOf  [
+
+                        (JD.field ( "circle")
+                                (JD.map3
+                                    (\a b c ->  Circle a b c)
+                                    (JD.field "cx" JD.string)
+                                    (JD.field "cy" JD.string)
+                                    (JD.field "r" JD.string)
+                                )
+                        ),
+                        (JD.field ( "rect")
+                                (JD.map4
+                                    (\a b c d ->  Rectangle a b c d)
+                                    (JD.field "x" JD.string)
+                                    (JD.field "y" JD.string)
+                                    (JD.field "width" JD.string)
+                                    (JD.field "height" JD.string)
+                                )
+                        ),
+                        (JD.field ( "ellipse")
+                                (JD.map4
+                                    (\a b c d ->  Rectangle a b c d)
+                                    (JD.field "cx" JD.string)
+                                    (JD.field "cy" JD.string)
+                                    (JD.field "rx" JD.string)
+                                    (JD.field "ry" JD.string)
+                                )
+                        ),
+
+                          (JD.map (\l -> Polygon l) (
+                          (JD.field ( "polygon")
+                              (JD.list
+                                  (JD.map2
+                                      (\a b -> ( a, b ))
+                                      (JD.field "x" JD.string)
+                                      (JD.field "y" JD.string)
+                                  )
+                              )
+                          )
+                          )
+                          )
+                          ]
+                        )
+                      )
+
+                    ((JD.field ("shapeprop") (
+                    JD.map4 (\( a, b, c ) ( d, e, f )
+                                        ( g, h, i ) ( j, k, l )
+                                    -> ShapeStyle a b c d e f g h i j k l)
+                        (JD.map3
+                        (\a b c -> ( a, b, c ))
+                        (JD.field "hFC" JD.string)
+                        (JD.field "hFO" JD.string)
+                        (JD.field "hSC" JD.string)
+                        )
+                        (JD.map3 (\a b c -> ( a, b, c ))
+                        (JD.field "hSW" JD.string)
+                        (JD.field "hSO" JD.string)
+                        (JD.field "uFC" JD.string)
+                        )
+                        (JD.map3 (\a b c -> ( a, b, c ))
+                        (JD.field "uFO" JD.string)
+                        (JD.field "uSC" JD.string)
+                        (JD.field "uSW" JD.string)
+                        )
+                        (JD.map3 (\a b c -> ( a, b, c ))
+                        (JD.field "uSO" JD.string)
+                        (JD.field "title" JD.string)
+                        (JD.field "body" JD.string)
+                      )
+                   ))
+                   )
+                   )
+                  )
+        shapePictureDecoder : JD.Decoder ShapePicture
+        shapePictureDecoder = JD.map2
+          (\a b ->
+            let
+              maybePicture = Maybe.map (\u -> Picture u 0 0) (Url.fromString a)
+            in
+            ShapePicture maybePicture b
+          )
+          ( JD.field "pictureUrl" JD.string)
+          ( JD.field "shapes"     shapeDecoder      )
+    in JD.decodeString shapePictureDecoder jsonString
+-- new Encoder of Shapes
 writeAlltoJson : List ( Shape, ShapeStyle ) -> String -> Json.Encode.Value
 writeAlltoJson shapeWithProperties picUrl =
   let
diff --git a/src/Util/Util.elm b/src/Util/Util.elm
index 6014c59..db269c3 100644
--- a/src/Util/Util.elm
+++ b/src/Util/Util.elm
@@ -89,30 +89,44 @@ offsetMousePosition =
     JD.map2 MousePosition (JD.field "offsetX" JD.int)
                           (JD.field "offsetY" JD.int)
 -- useful Types
-type alias Picture =
-    { url: Url.Url, w: Int, h: Int }
-type alias ImgDimensions =
-    { width : Int
-    , height : Int
-    }
+type alias Picture = { url: Url.Url, w: Int, h: Int }
+  -- Methods for Picture
+newPicture : Url.Url -> Picture
+newPicture pictureUrl = { url = pictureUrl, w = 0, h = 0 }
+emptyPicture : Picture
+emptyPicture = { url = Url.Url Url.Http "" Nothing "" Nothing Nothing
+               , w = -1, h = -1
+               }
+maybePictureToPicture : Maybe Picture -> Picture
+maybePictureToPicture mayPic = Maybe.withDefault emptyPicture mayPic
+type alias ImgDimensions = { width : Int, height : Int }
 decodeImgLoad msg =
     JD.map msg <|
         JD.field "target" <|
             JD.map2 ImgDimensions
                 (JD.field "width"  JD.int)
                 (JD.field "height" JD.int)
+type alias JsonFile = { text : String, error : String }
+type alias QueryInfo = { edit : Bool, jsonUrl : Maybe Url.Url }
 -- Working with Url
-isEdit : Url.Url -> Bool
-isEdit url =
-    let urlPath = List.drop 1 (String.split "/" url.path)
-        urlParserCreator_pathWalker path =
+urlParserCreator_pathWalker : List String -> String -> UP.Parser (Maybe String -> Maybe String) (Maybe String)
+urlParserCreator_pathWalker path query =
           case path of
-            []    -> UP.s "" <?> UPQ.string "edit" -- ERROR, returns Nothing
-            x::[] -> UP.s x  <?> UPQ.string "edit"
-            x::xs -> UP.s x  </> (urlParserCreator_pathWalker xs)
-        myParser = urlParserCreator_pathWalker urlPath
-    in let res = Maybe.withDefault "Nothing" (Maybe.withDefault (Just "Nothing") (UP.parse myParser url))
-       in case res of
-            "true"  -> True
-            "false" -> False
-            _       -> True
+            []    -> UP.s "" <?> UPQ.string query -- ERROR, returns Nothing
+            x::[] -> UP.s x  <?> UPQ.string query
+            x::xs -> UP.s x  </> (urlParserCreator_pathWalker xs query)
+urlPath : Url.Url -> List String
+urlPath url = List.drop 1 (String.split "/" url.path)
+getQueryInfo : Url.Url -> QueryInfo
+getQueryInfo url =
+    let editParser    = urlParserCreator_pathWalker (urlPath url) "edit"
+        jsonUrlParser = urlParserCreator_pathWalker (urlPath url) "url"
+    in let edit    = Maybe.withDefault "Nothing" (Maybe.withDefault (Just "Nothing") (UP.parse editParser    url))
+           jsonUrl = Maybe.withDefault "Nothing" (Maybe.withDefault (Just "Nothing") (UP.parse jsonUrlParser url))
+       in { edit = case edit of
+                     "true"  -> True
+                     "false" -> False
+                     _       -> True
+          , jsonUrl = Url.fromString jsonUrl
+          }
+
diff --git a/src/Util/ViewParts.elm b/src/Util/ViewParts.elm
index d4cf803..2a6ce99 100644
--- a/src/Util/ViewParts.elm
+++ b/src/Util/ViewParts.elm
@@ -96,10 +96,11 @@ viewHeader_Buttons state =
         ]
 viewImage : Model -> Html Msg
 viewImage model =
-    let picW = String.fromInt model.picture.w
-        picH = String.fromInt model.picture.h
+    let picture = maybePictureToPicture model.picture
+        picW = String.fromInt picture.w
+        picH = String.fromInt picture.h
         loading =  Html.img [ Html.Events.on "load" (decodeImgLoad ImgLoaded)
-                            , src (Url.toString model.picture.url)
+                            , src (Url.toString picture.url)
                             ] []
     in
     div [ style "margin-left" "25px", style "margin-top" "15px", class "container"]
@@ -108,7 +109,7 @@ viewImage model =
                  [ svg [ width "100%", viewBox ("0 0 "++picW++" "++picH), version "1.1"]
                        ( List.concat
                            [[image [ width picW, height picH--, Svg.Attributes.preserveAspectRatio "xMinYMin"
-                                   , xlinkHref (Url.toString model.picture.url)
+                                   , xlinkHref (Url.toString picture.url)
                                    ] []
                             ]
                            , viewSvgShapes model.saved model.svgShapeHover 1
@@ -411,7 +412,7 @@ viewEditShapeModal id shapeStyle =
                                     , shapeDeleteButton id "6"
                                     ] 41.1
                       ]
-viewManagePictureModal : String -> Maybe Url.Url -> Url.Url -> Int -> Int -> Html Msg
+viewManagePictureModal : String -> Maybe Url.Url -> Maybe Url.Url -> Int -> Int -> Html Msg
 viewManagePictureModal s mayUrl currentUrl w h=
     let picUrlState = case mayUrl of
                         Just url -> "Url ist gültig."
@@ -419,7 +420,9 @@ viewManagePictureModal s mayUrl currentUrl w h=
         w1 = String.fromInt w
         h1 = String.fromInt h
     in modalCard [ modalHeader "Bild auswählen"
-                 , modalCardBody [ text ("Aktuelles Bild: "++(Url.toString currentUrl))
+                 , modalCardBody [ case currentUrl of
+                                     Just curUrl -> text ("Aktuelles Bild: "++(Url.toString curUrl))
+                                     Nothing     -> text "Bisher wurde kein Bild ausgewählt"
                                  , label [class "label"] [text "Url zum Bild"]
                                  , label [] [ input [class "input", Html.Attributes.placeholder "Url zum Bild"
                                                     , value s, onInput (ManageModal (OpenManagePicture "i1" "")) ] [] ]
@@ -434,17 +437,18 @@ viewManagePictureModal s mayUrl currentUrl w h=
                  ]
 viewJsonModal : Model -> Html Msg
 viewJsonModal model =
-    modalCard [ modalHeader "Json Datei"
-              , modalCardBody [   button [ onClick (GotJson model.stringToShapes)
-                                         , class "button is-success is-pulled-left is-size-6"
-                                         , style "margin-right" "15px"
-                                         , style "margin-bottom" "15px"
-                                         ] [ text "string to shapes" ]
-                              , div [] [ Html.pre [] [Html.text <| Json.Encode.encode 3 <| (writeAlltoJson model.saved (Url.toString model.picture.url))] ]
-                              , Html.p [] [text <| model.errorString]
-                              ]
-              , modalFooter [] 0.0
-              ]
+    let picture = maybePictureToPicture model.picture
+    in modalCard [ modalHeader "Json Datei"
+                 , modalCardBody [ button [ onClick (DecodeJson model.jsonFile.text)
+                                          , class "button is-success is-pulled-left is-size-6"
+                                          , style "margin-right" "15px"
+                                          , style "margin-bottom" "15px"
+                                          ] [ text "string to shapes" ]
+                                 , div [] [ Html.pre [] [Html.text <| Json.Encode.encode 3 <| (writeAlltoJson model.saved (Url.toString picture.url))] ]
+                                 , Html.p [] [text <| model.jsonFile.error]
+                                 ]
+                 , modalFooter [] 0.0
+                 ]
 -- Helping Methods for the VIEW
 viewDropDownMenue : String -> Bool -> String -> List(Attribute Msg) -> List(Svg Msg) -> Html Msg
 viewDropDownMenue header isGreen iconType attributes dropDownItems =
-- 
GitLab