From 0c2136e265c546f8fda466368281ef83e259fb1e Mon Sep 17 00:00:00 2001
From: Edward <sabinusedward@yahoo.de>
Date: Fri, 10 Jul 2020 16:42:27 +0200
Subject: [PATCH] =?UTF-8?q?ShapePicture=5FEditor=20fertig=20bis=20auf=20Gu?=
 =?UTF-8?q?ide=20aktualisieren=20und=20evtl=20Beispiel=20anf=C3=BCgen?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/Manager/UpdateManager.elm | 22 ++++++++--
 src/Manager/ViewManager.elm   | 13 +++---
 src/TypeHolder.elm            |  5 ++-
 src/Util/ViewParts.elm        | 81 +++++++++++++++++++----------------
 4 files changed, 72 insertions(+), 49 deletions(-)

diff --git a/src/Manager/UpdateManager.elm b/src/Manager/UpdateManager.elm
index 021f04f..52ea503 100644
--- a/src/Manager/UpdateManager.elm
+++ b/src/Manager/UpdateManager.elm
@@ -119,7 +119,9 @@ updateModel msg model =
           Ok s  -> updateModel (DecodeJson s) { model | httpLoadResult = result }
           Err e -> { model | httpLoadResult = result }
       LinkClicked urlRequest -> model
-      UrlChanged  url        -> { model | url     = url }
+      UrlChanged  url        -> { model | url       = url
+                                        , queryInfo = getQueryInfo url
+                                }
       SavePicture pic        -> { model | picture = Just pic
                                         , saved   = []
                                 }
@@ -138,7 +140,13 @@ updateModel msg model =
                                         }
                         , picture     = pl.picture
                 }
-      LoadShapePicture url -> { model | url = let thisUrl = model.url in { thisUrl | query = Just ("url="++url) } }
+      LoadShapePicture    _ -> model
+      ShapePicturePreview   -> { model | queryInfo = let queryInfo = model.queryInfo in { queryInfo | edit = False }
+                                       , url       = let thisUrl   = model.url       in { thisUrl   | query = case thisUrl.query of
+                                                                                                                Just q  -> Just ("edit=false&"++q)
+                                                                                                                Nothing -> Just "edit=false"
+                                                                                        }
+                               }
 updateCmdMsg : Msg -> Model -> Cmd Msg
 updateCmdMsg msg model =
     case msg of
@@ -152,9 +160,15 @@ updateCmdMsg msg model =
       ImgLoaded                    _   -> Cmd.none
       DecodeJson                   _   -> Cmd.none
       ShapePictureJsonStringLoaded _   -> Cmd.none
-      LoadShapePicture             url -> Http.get { url = url
-                                                   , expect = Http.expectString ShapePictureJsonStringLoaded
+      LoadShapePicture             url -> Nav.load (Url.toString (let thisUrl = model.url in { thisUrl | query = Just ("url="++url) }))
+      ShapePicturePreview              ->
+        Nav.replaceUrl model.key (Url.toString (let thisUrl = model.url
+                                                in {thisUrl | query = case thisUrl.query of
+                                                                        Just q  -> Just ("edit=false&"++q)
+                                                                        Nothing -> Just "edit=false"
                                                    }
+                                               )
+                                 )
       LinkClicked urlReq ->
         case urlReq of
           Browser.Internal url  -> Nav.pushUrl model.key (Url.toString url)
diff --git a/src/Manager/ViewManager.elm b/src/Manager/ViewManager.elm
index 7ec6b23..3df52ed 100644
--- a/src/Manager/ViewManager.elm
+++ b/src/Manager/ViewManager.elm
@@ -28,8 +28,9 @@ viewEditor model =
         [ standardViewPart
         ,[ viewHeader_Buttons model.state
          , Html.section [class "section"] []
-         , viewImage model
-         , case model.httpLoadResult of
+         ]
+        , viewImage model "Editor"
+        ,[ case model.httpLoadResult of
              Ok  s -> text ""
              Err e -> text ("Could not load shapes: "++(httpErrorToString e))
          ]
@@ -44,7 +45,7 @@ viewEditor model =
                                               |> List.head
                                               |> Maybe.withDefault (Empty,defaultShapeStyle)
                                               |> Tuple.second
-                                          )
+                                          ) "Editor"
                                       ]
             ShowJson                    -> [viewJsonModal           model         ]
             EditShape id shapeStyle     -> [viewEditShapeModal      id shapeStyle ]
@@ -59,10 +60,10 @@ viewEditor model =
 
 viewViewer : Model -> Html Msg
 viewViewer model =
-  div [style "background-color" "#fff"]
+  div [style "background-color" "#000"]
       (List.concat
         [ standardViewPart
-        ,[viewImage model]
+        ,viewImage model "Viewer"
         , case (getModalFromState model.state) of
             NoModal           -> []
             ShowInput _ _ _   -> []
@@ -74,7 +75,7 @@ viewViewer model =
                                         |> List.head
                                         |> Maybe.withDefault (Empty,defaultShapeStyle)
                                         |> Tuple.second
-                                    )
+                                    ) "Viewer"
                                  ]
             ShowJson                  -> []
             EditShape _ _             -> []
diff --git a/src/TypeHolder.elm b/src/TypeHolder.elm
index 32c1b4e..70d9008 100644
--- a/src/TypeHolder.elm
+++ b/src/TypeHolder.elm
@@ -44,5 +44,6 @@ type Msg
   -- for saving pictureUrl
   | SavePicture Picture
   | ImgLoaded ImgDimensions
-  -- for loading ShapePicture
-  | LoadShapePicture String
\ No newline at end of file
+  -- Navigating the Browser
+  | LoadShapePicture String
+  | ShapePicturePreview
\ No newline at end of file
diff --git a/src/Util/ViewParts.elm b/src/Util/ViewParts.elm
index 63be61a..f86cd95 100644
--- a/src/Util/ViewParts.elm
+++ b/src/Util/ViewParts.elm
@@ -36,31 +36,13 @@ viewHeader_Buttons state =
         [ div [class "section"]
               [ h1 [class "title"] [text "ShapePicture Editor"] ]
         , div [ style "margin-left" "25px"]
-              [  button [ onClick (ManageModal (OpenLoadShapePicture "") "")
-                       , class "button is-success is-pulled-left is-size-6"
-                       , style "margin-bottom" "15px"
-                       , style "margin-right" "15px"
-                       ] [ text "Ein ShapePicture laden" ]
-              , button [ onClick (ManageModal (OpenManagePicture "" "") "")
-                       , class "button is-success is-pulled-left is-size-6"
-                       , style "margin-bottom" "15px"
-                       , style "margin-right" "15px"
-                       ] [ text "Bild auswählen" ]
-              , button [ onClick (ManageModal OpenShowJson "")
-                       , class "button is-success is-pulled-left is-size-6"
-                       , style "margin-bottom" "15px"
-                       , style "margin-right" "15px"
-                       ] [ text "Json Datei anzeigen" ]
-              , button [ onClick (ManageModal OpenShowInput "")
-                       , class "button is-success is-pulled-left is-size-6"
-                       , style "margin-bottom" "15px"
-                       , style "margin-right" "15px"
-                       ] [ text "Neue Form hinzüfügen" ]
-              , button [ onClick (ManageModal OpenShowTable "")
-                       , class "button is-success is-pulled-left is-size-6"
-                       , style "margin-right" "15px"
-                       , style "margin-bottom" "15px"
-                       ] [ text "Tabelle mit Formen zeigen" ]
+              [ viewDropDownMenue "Datei" True "angle-down" []
+                  [ dropdownItem "Ein ShapePicture laden"         (ManageModal (OpenLoadShapePicture "") "")
+                  , dropdownItem "Bild auswählen"                 (ManageModal (OpenManagePicture "" "") "")
+                  , dropdownItem "Json Datei anzeigen"            (ManageModal OpenShowJson "")
+                  , dropdownItem "ShapePicture Vorschau"          ShapePicturePreview
+                  ]
+              , viewDropDownMenue "Neue Form hinzüfügen"      True "" [onClick (ManageModal OpenShowInput "")] []
               , if (eq_String_State "DrawShape" state)
                   then let iShape = getInputShapeFromState state
                        in if (eq_String_Shape "Polygon" iShape)
@@ -97,20 +79,27 @@ viewHeader_Buttons state =
                              , href ""
                              ] [text "Vieleck"]
                          ]
+              , viewDropDownMenue "Tabelle mit Formen zeigen" True "" [onClick (ManageModal OpenShowTable "")] []
               ]
         ]
-viewImage : Model -> Html Msg
-viewImage model =
+viewImage : Model -> String -> List (Html Msg)
+viewImage model mode =
     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 picture.url)
                             ] []
+        isOnlyView = case mode of
+                       "Editor" -> False
+                       "Viewer" -> True
+                       _        -> False
     in
-    div [ style "margin-left" "25px", style "margin-top" "15px", class "container"]
-        [ if picW=="0" then loading else text ""
-        , figure [ class "image"]
+    [ if picW=="0" then loading else text ""
+    , (if isOnlyView then div []
+                     else div [style "margin-left" "25px", style "margin-top" "15px", class "container"]
+      )
+        [ figure [ class "image"]
                  [ svg [ width "100%", viewBox ("0 0 "++picW++" "++picH), version "1.1"]
                        ( List.concat
                            [[image [ width picW, height picH--, Svg.Attributes.preserveAspectRatio "xMinYMin"
@@ -190,6 +179,7 @@ viewImage model =
 
                  ]
         ]
+    ]
 viewNewShapeInputModal : Shape -> String -> String -> Html Msg
 viewNewShapeInputModal iShape ix iy =
     modalCard
@@ -318,8 +308,14 @@ viewTableModal modelSaved =
           )
       , modalFooter [] 0
       ]
-viewShapeModal : Int -> Int -> ShapeStyle -> Html Msg
-viewShapeModal id edit shapeStyle =
+viewShapeModal : Int -> Int -> ShapeStyle -> String -> Html Msg
+viewShapeModal id edit0 shapeStyle mode =
+    let isOnlyView = case mode of
+                       "Editor" -> False
+                       "Viewer" -> True
+                       _        -> False
+        edit = if isOnlyView then 0 else edit0
+    in
     if id <= 0 then div [] [] -- ERROR
                else modalCard [  modalStrongHeader [Html.Events.onDoubleClick (ManageModal (OpenShowShape id 1) "")
                                                    ,Html.Events.onMouseLeave  (ManageModal (OpenShowShape id 0) "")
@@ -356,9 +352,12 @@ viewShapeModal id edit shapeStyle =
                                                                                            x::xs-> (div [] [text x, Html.br [] []])::(writeLines xs)
                                                                                    in div [] (writeLines lines)
                                                       ]
-                                , modalFooter [ shapeEditButton   id shapeStyle "6"
-                                              , shapeDeleteButton id "6"
-                                              ] 49.1
+                                , modalFooter ( if isOnlyView then []
+                                                              else [ shapeEditButton   id shapeStyle "6"
+                                                                   , shapeDeleteButton id "6"
+                                                                   ]
+                                              )
+                                              ( if isOnlyView then 0.0 else 49.1 )
                                 ]
 viewEditShapeModal : Int -> ShapeStyle -> Html Msg
 viewEditShapeModal id shapeStyle =
@@ -477,8 +476,11 @@ viewDropDownMenue header isGreen iconType attributes dropDownItems =
                                        ++" aria-haspopup=true aria-controls=dropdown-menu")
                      ]
                      [ Html.span [] [text header]
-                     , Html.span [ class "icon is-small"]
-                                 [ Html.i [class ("fas fa-"++iconType++" aria-hidden=true")] [] ]
+                     , if iconType == ""
+                         then text ""
+                         else Html.span [ class "icon is-small"]
+                                        [ Html.i [class ("fas fa-"++iconType++" aria-hidden=true")] [] ]
+
                      ]
             ]
       , if dropDownItems==[]
@@ -486,6 +488,11 @@ viewDropDownMenue header isGreen iconType attributes dropDownItems =
           else div [ class "dropdown-menu role=menu"]
                    [ div [ class "dropdown-content"] dropDownItems ]
       ]
+dropdownItem : String -> Msg -> Svg Msg
+dropdownItem title msg = a [class "dropdown-item"
+                           , onClick msg
+                           , href ""
+                           ] [text title]
 viewSvgShapes : List (Shape, ShapeStyle) -> Int -> Int -> List (Svg Msg)
 viewSvgShapes shapes activeShape id =
     case shapes of
-- 
GitLab