From afe97977753731188600dcdfacd92971ae10cc5c Mon Sep 17 00:00:00 2001 From: Edward <sabinusedward@yahoo.de> Date: Sun, 31 May 2020 13:06:57 +0200 Subject: [PATCH] =?UTF-8?q?Einf=C3=BChrung=20ShapeMsg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 757 ++++++++++++++++------------------ src/Manager/ModalManager.elm | 63 ++- src/Manager/StateManager.elm | 9 +- src/Manager/UpdateManager.elm | 110 ++--- src/Manager/ViewManager.elm | 10 +- src/TypeHolder.elm | 8 +- src/Util/ShapeManager.elm | 21 +- 7 files changed, 480 insertions(+), 498 deletions(-) diff --git a/index.html b/index.html index fd5148c..6527e83 100644 --- a/index.html +++ b/index.html @@ -5412,11 +5412,15 @@ var $elm$virtual_dom$VirtualDom$style = _VirtualDom_style; var $elm$html$Html$Attributes$style = $elm$virtual_dom$VirtualDom$style; var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text; +var $author$project$Util$ShapeManager$AddShape = function (a) { + return {$: 'AddShape', a: a}; +}; var $author$project$Util$ShapeManager$Circle = F3( function (a, b, c) { return {$: 'Circle', a: a, b: b, c: c}; }); var $author$project$Manager$ModalManager$CloseModal = {$: 'CloseModal'}; +var $author$project$Util$ShapeManager$Empty = {$: 'Empty'}; var $author$project$TypeHolder$LoadShapes = function (a) { return {$: 'LoadShapes', a: a}; }; @@ -5424,6 +5428,9 @@ var $author$project$TypeHolder$ManageModal = F2( function (a, b) { return {$: 'ManageModal', a: a, b: b}; }); +var $author$project$TypeHolder$ManageShapes = function (a) { + return {$: 'ManageShapes', a: a}; +}; var $author$project$TypeHolder$OpenDrawShape = function (a) { return {$: 'OpenDrawShape', a: a}; }; @@ -5436,7 +5443,6 @@ var $author$project$Util$ShapeManager$Rectangle = F4( function (a, b, c, d) { return {$: 'Rectangle', a: a, b: b, c: c, d: d}; }); -var $author$project$TypeHolder$SaveAndCloseModal = {$: 'SaveAndCloseModal'}; var $elm$html$Html$a = _VirtualDom_node('a'); var $elm$html$Html$button = _VirtualDom_node('button'); var $author$project$Util$ShapeManager$shapeNameToString = function (shape) { @@ -5474,7 +5480,6 @@ var $author$project$Manager$StateManager$eq_String_State = F2( string, $author$project$Manager$StateManager$stateNameToString(state)); }); -var $author$project$Util$ShapeManager$Empty = {$: 'Empty'}; var $author$project$Manager$ModalManager$getInputShapeFromModal = function (modal) { switch (modal.$) { case 'NoModal': @@ -5743,7 +5748,9 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (state) { _List_fromArray( [ $elm$html$Html$Attributes$class('dropdown-item'), - $elm$html$Html$Events$onClick($author$project$TypeHolder$SaveAndCloseModal), + $elm$html$Html$Events$onClick( + $author$project$TypeHolder$ManageShapes( + $author$project$Util$ShapeManager$AddShape($author$project$Util$ShapeManager$Empty))), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -6325,7 +6332,6 @@ var $author$project$Manager$ViewManager$viewImage = function (model) { ])) ])); }; -var $author$project$Manager$ModalManager$AddShape = {$: 'AddShape'}; var $author$project$Manager$ModalManager$Check = function (a) { return {$: 'Check', a: a}; }; @@ -6872,7 +6878,8 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( [ $elm$html$Html$Attributes$class('button is-success'), $elm$html$Html$Events$onClick( - A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$AddShape, '')) + $author$project$TypeHolder$ManageShapes( + $author$project$Util$ShapeManager$AddShape($author$project$Util$ShapeManager$Empty))) ]), _List_fromArray( [ @@ -6958,7 +6965,7 @@ var $author$project$Manager$ViewManager$viewShapeModal = function (id) { var $elm$html$Html$table = _VirtualDom_node('table'); var $elm$html$Html$th = _VirtualDom_node('th'); var $elm$html$Html$tr = _VirtualDom_node('tr'); -var $author$project$Manager$ModalManager$DeleteShape = function (a) { +var $author$project$Util$ShapeManager$DeleteShape = function (a) { return {$: 'DeleteShape', a: a}; }; var $elm$html$Html$Attributes$id = $elm$html$Html$Attributes$stringProperty('id'); @@ -7017,10 +7024,8 @@ var $author$project$Manager$ViewManager$writeShapeToTable = F2( [ $elm$html$Html$Attributes$class('button is-danger is-size-7'), $elm$html$Html$Events$onClick( - A2( - $author$project$TypeHolder$ManageModal, - $author$project$Manager$ModalManager$DeleteShape(id), - '')) + $author$project$TypeHolder$ManageShapes( + $author$project$Util$ShapeManager$DeleteShape(id))) ]), _List_fromArray( [ @@ -7263,6 +7268,9 @@ var $elm$core$Platform$Sub$none = $elm$core$Platform$Sub$batch(_List_Nil); var $author$project$ShapePicture_Editor$subscriptions = function (model) { return $elm$core$Platform$Sub$none; }; +var $author$project$Manager$StateManager$ActiveModal = function (a) { + return {$: 'ActiveModal', a: a}; +}; var $elm$http$Http$BadBody = function (a) { return {$: 'BadBody', a: a}; }; @@ -7270,9 +7278,28 @@ var $author$project$Manager$StateManager$DrawShape = F2( function (a, b) { return {$: 'DrawShape', a: a, b: b}; }); +var $author$project$Manager$ModalManager$ResetShowInput = {$: 'ResetShowInput'}; var $author$project$TypeHolder$ShapesLoaded = function (a) { return {$: 'ShapesLoaded', a: a}; }; +var $author$project$Manager$ModalManager$modalNameToString = function (modal) { + switch (modal.$) { + case 'NoModal': + return 'NoModal'; + case 'ShowTable': + return 'ShowTable'; + case 'ShowInput': + return 'ShowInput'; + default: + return 'ShowShape'; + } +}; +var $author$project$Manager$ModalManager$eq_String_Modal = F2( + function (string, modal) { + return _Utils_eq( + string, + $author$project$Manager$ModalManager$modalNameToString(modal)); + }); var $elm$json$Json$Decode$decodeString = _Json_runOnString; var $elm$http$Http$BadStatus_ = F2( function (a, b) { @@ -8064,6 +8091,12 @@ var $elm$http$Http$get = function (r) { {body: $elm$http$Http$emptyBody, expect: r.expect, headers: _List_Nil, method: 'GET', timeout: $elm$core$Maybe$Nothing, tracker: $elm$core$Maybe$Nothing, url: r.url}); }; var $elm$browser$Browser$Navigation$load = _Browser_load; +var $author$project$Manager$StateManager$manageState = function (state) { + return (A2($author$project$Manager$StateManager$eq_String_State, 'ActiveModal', state) && A2( + $author$project$Manager$ModalManager$eq_String_Modal, + 'NoModal', + $author$project$Manager$StateManager$getModalFromState(state))) ? $author$project$Manager$StateManager$Standby : state; +}; var $elm$browser$Browser$Navigation$pushUrl = _Browser_pushUrl; var $elm$json$Json$Decode$list = _Json_decodeList; var $elm$json$Json$Decode$map4 = _Json_map4; @@ -8224,9 +8257,6 @@ var $elm$url$Url$toString = function (url) { _Utils_ap(http, url.host)), url.path))); }; -var $author$project$Manager$StateManager$ActiveModal = function (a) { - return {$: 'ActiveModal', a: a}; -}; var $author$project$Manager$ModalManager$ShowInput = F3( function (a, b, c) { return {$: 'ShowInput', a: a, b: b, c: c}; @@ -8235,45 +8265,18 @@ var $author$project$Manager$ModalManager$ShowShape = function (a) { return {$: 'ShowShape', a: a}; }; var $author$project$Manager$ModalManager$ShowTable = {$: 'ShowTable'}; -var $elm$core$List$drop = F2( - function (n, list) { - drop: - while (true) { - if (n <= 0) { - return list; - } else { - if (!list.b) { - return list; - } else { - var x = list.a; - var xs = list.b; - var $temp$n = n - 1, - $temp$list = xs; - n = $temp$n; - list = $temp$list; - continue drop; - } - } - } - }); -var $author$project$Manager$ModalManager$modalNameToString = function (modal) { - switch (modal.$) { - case 'NoModal': - return 'NoModal'; - case 'ShowTable': - return 'ShowTable'; - case 'ShowInput': - return 'ShowInput'; +var $author$project$Util$ShapeManager$deleteCoordsFromShape = function (shape) { + switch (shape.$) { + case 'Empty': + return $author$project$Util$ShapeManager$Empty; + case 'Circle': + return A3($author$project$Util$ShapeManager$Circle, '', '', ''); + case 'Rectangle': + return A4($author$project$Util$ShapeManager$Rectangle, '', '', '', ''); default: - return 'ShowShape'; + return $author$project$Util$ShapeManager$Polygon(_List_Nil); } }; -var $author$project$Manager$ModalManager$eq_String_Modal = F2( - function (string, modal) { - return _Utils_eq( - string, - $author$project$Manager$ModalManager$modalNameToString(modal)); - }); var $author$project$Util$ShapeManager$getPointListFromPolygon = function (shape) { switch (shape.$) { case 'Empty': @@ -8299,6 +8302,224 @@ var $author$project$Util$ShapeManager$shapeDefaultConstruktor = function (shape) return $author$project$Util$ShapeManager$Empty; } }; +var $author$project$Manager$ModalManager$modalInputConstruktor = F5( + function (modalType, shape, x, y, mouse) { + if (modalType === 'ShowInput') { + return A3($author$project$Manager$ModalManager$ShowInput, shape, x, y); + } else { + return $author$project$Manager$ModalManager$NoModal; + } + }); +var $author$project$Manager$ModalManager$updateInput = F8( + function (inputType, value, modal, modalType, iShape, ix, iy, mouse) { + switch (inputType.valueOf()) { + case '1': + switch (iShape.$) { + case 'Empty': + return modal; + case 'Circle': + var b = iShape.b; + var c = iShape.c; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A3($author$project$Util$ShapeManager$Circle, value, b, c), + ix, + iy, + mouse); + case 'Rectangle': + var b = iShape.b; + var c = iShape.c; + var d = iShape.d; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A4($author$project$Util$ShapeManager$Rectangle, value, b, c, d), + ix, + iy, + mouse); + default: + return A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, value, iy, mouse); + } + case '2': + switch (iShape.$) { + case 'Empty': + return modal; + case 'Circle': + var a = iShape.a; + var c = iShape.c; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A3($author$project$Util$ShapeManager$Circle, a, value, c), + ix, + iy, + mouse); + case 'Rectangle': + var a = iShape.a; + var c = iShape.c; + var d = iShape.d; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A4($author$project$Util$ShapeManager$Rectangle, a, value, c, d), + ix, + iy, + mouse); + default: + return A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, ix, value, mouse); + } + case '3': + switch (iShape.$) { + case 'Empty': + return modal; + case 'Circle': + var a = iShape.a; + var b = iShape.b; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A3($author$project$Util$ShapeManager$Circle, a, b, value), + ix, + iy, + mouse); + case 'Rectangle': + var a = iShape.a; + var b = iShape.b; + var d = iShape.d; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A4($author$project$Util$ShapeManager$Rectangle, a, b, value, d), + ix, + iy, + mouse); + default: + return modal; + } + case '4': + switch (iShape.$) { + case 'Empty': + return modal; + case 'Circle': + return modal; + case 'Rectangle': + var a = iShape.a; + var b = iShape.b; + var c = iShape.c; + return A5( + $author$project$Manager$ModalManager$modalInputConstruktor, + modalType, + A4($author$project$Util$ShapeManager$Rectangle, a, b, c, value), + ix, + iy, + mouse); + default: + return modal; + } + default: + return modal; + } + }); +var $author$project$Manager$ModalManager$updateModal = F2( + function (msg, modal) { + switch (msg.$) { + case 'CloseModal': + return $author$project$Manager$ModalManager$NoModal; + case 'OpenShowTable': + return A2($author$project$Manager$ModalManager$eq_String_Modal, 'ShowTable', modal) ? $author$project$Manager$ModalManager$NoModal : $author$project$Manager$ModalManager$ShowTable; + case 'OpenShowInput': + return A2($author$project$Manager$ModalManager$eq_String_Modal, 'ShowInput', modal) ? $author$project$Manager$ModalManager$NoModal : A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', ''); + case 'OpenShowShape': + var id = msg.a; + return (id <= 0) ? $author$project$Manager$ModalManager$NoModal : $author$project$Manager$ModalManager$ShowShape(id); + case 'ResetShowInput': + return A3( + $author$project$Manager$ModalManager$ShowInput, + $author$project$Util$ShapeManager$deleteCoordsFromShape( + $author$project$Manager$ModalManager$getInputShapeFromModal(modal)), + '', + ''); + case 'Check': + var shape = msg.a; + return A2($author$project$Manager$ModalManager$eq_String_Modal, 'ShowInput', modal) ? (A2( + $author$project$Util$ShapeManager$eq_String_Shape, + shape, + $author$project$Manager$ModalManager$getInputShapeFromModal(modal)) ? A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', '') : A3( + $author$project$Manager$ModalManager$ShowInput, + $author$project$Util$ShapeManager$shapeDefaultConstruktor(shape), + '', + '')) : modal; + case 'Input': + var inputType = msg.a; + var value = msg.b; + switch (modal.$) { + case 'NoModal': + return modal; + case 'ShowTable': + return modal; + case 'ShowShape': + return modal; + default: + var iShape = modal.a; + var ix = modal.b; + var iy = modal.c; + return A8( + $author$project$Manager$ModalManager$updateInput, + inputType, + value, + modal, + 'ShowInput', + iShape, + ix, + iy, + {x: 0, y: 0}); + } + default: + switch (modal.$) { + case 'NoModal': + return modal; + case 'ShowTable': + return modal; + case 'ShowShape': + return modal; + default: + var iShape = modal.a; + var ix = modal.b; + var iy = modal.c; + return A3( + $author$project$Manager$ModalManager$ShowInput, + $author$project$Util$ShapeManager$Polygon( + A2( + $elm$core$List$cons, + _Utils_Tuple2(ix, iy), + $author$project$Util$ShapeManager$getPointListFromPolygon(iShape))), + '', + ''); + } + } + }); +var $elm$core$List$drop = F2( + function (n, list) { + drop: + while (true) { + if (n <= 0) { + return list; + } else { + if (!list.b) { + return list; + } else { + var x = list.a; + var xs = list.b; + var $temp$n = n - 1, + $temp$list = xs; + n = $temp$n; + list = $temp$list; + continue drop; + } + } + } + }); var $elm$core$List$takeReverse = F3( function (n, list, kept) { takeReverse: @@ -8425,314 +8646,17 @@ var $elm$core$List$take = F2( function (n, list) { return A3($elm$core$List$takeFast, 0, n, list); }); -var $author$project$Manager$ModalManager$modalInputConstruktor = F5( - function (modalType, shape, x, y, mouse) { - if (modalType === 'ShowInput') { - return A3($author$project$Manager$ModalManager$ShowInput, shape, x, y); +var $author$project$Util$ShapeManager$updateShapes = F2( + function (shapesMsg, shapeList) { + if (shapesMsg.$ === 'DeleteShape') { + var id = shapesMsg.a; + return A2( + $elm$core$List$append, + A2($elm$core$List$take, id - 1, shapeList), + A2($elm$core$List$drop, id, shapeList)); } else { - return $author$project$Manager$ModalManager$NoModal; - } - }); -var $author$project$Manager$UpdateManager$updateInput = F8( - function (inputType, value, model, modalType, iShape, ix, iy, mouse) { - switch (inputType.valueOf()) { - case '1': - switch (iShape.$) { - case 'Empty': - return model; - case 'Circle': - var b = iShape.b; - var c = iShape.c; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A3($author$project$Util$ShapeManager$Circle, value, b, c), - ix, - iy, - mouse)) - }); - case 'Rectangle': - var b = iShape.b; - var c = iShape.c; - var d = iShape.d; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, value, b, c, d), - ix, - iy, - mouse)) - }); - default: - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, value, iy, mouse)) - }); - } - case '2': - switch (iShape.$) { - case 'Empty': - return model; - case 'Circle': - var a = iShape.a; - var c = iShape.c; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A3($author$project$Util$ShapeManager$Circle, a, value, c), - ix, - iy, - mouse)) - }); - case 'Rectangle': - var a = iShape.a; - var c = iShape.c; - var d = iShape.d; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, a, value, c, d), - ix, - iy, - mouse)) - }); - default: - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, ix, value, mouse)) - }); - } - case '3': - switch (iShape.$) { - case 'Empty': - return model; - case 'Circle': - var a = iShape.a; - var b = iShape.b; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A3($author$project$Util$ShapeManager$Circle, a, b, value), - ix, - iy, - mouse)) - }); - case 'Rectangle': - var a = iShape.a; - var b = iShape.b; - var d = iShape.d; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, a, b, value, d), - ix, - iy, - mouse)) - }); - default: - return model; - } - case '4': - switch (iShape.$) { - case 'Empty': - return model; - case 'Circle': - return model; - case 'Rectangle': - var a = iShape.a; - var b = iShape.b; - var c = iShape.c; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, a, b, c, value), - ix, - iy, - mouse)) - }); - default: - return model; - } - default: - return model; - } - }); -var $author$project$Manager$UpdateManager$updateModal = F2( - function (msg, model) { - switch (msg.$) { - case 'CloseModal': - return _Utils_update( - model, - {state: $author$project$Manager$StateManager$Standby}); - case 'Check': - var shape = msg.a; - return A2( - $author$project$Manager$ModalManager$eq_String_Modal, - 'ShowInput', - $author$project$Manager$StateManager$getModalFromState(model.state)) ? (A2( - $author$project$Util$ShapeManager$eq_String_Shape, - shape, - $author$project$Manager$StateManager$getInputShapeFromState(model.state)) ? _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', '')) - }) : _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A3( - $author$project$Manager$ModalManager$ShowInput, - $author$project$Util$ShapeManager$shapeDefaultConstruktor(shape), - '', - '')) - })) : model; - case 'Input': - var inputType = msg.a; - var value = msg.b; - var _v1 = $author$project$Manager$StateManager$getModalFromState(model.state); - switch (_v1.$) { - case 'NoModal': - return model; - case 'ShowTable': - return model; - case 'ShowShape': - return model; - default: - var iShape = _v1.a; - var ix = _v1.b; - var iy = _v1.c; - return A8( - $author$project$Manager$UpdateManager$updateInput, - inputType, - value, - model, - 'ShowInput', - iShape, - ix, - iy, - {x: 0, y: 0}); - } - case 'InputPoint': - var _v2 = $author$project$Manager$StateManager$getModalFromState(model.state); - switch (_v2.$) { - case 'NoModal': - return model; - case 'ShowTable': - return model; - case 'ShowShape': - return model; - default: - var iShape = _v2.a; - var ix = _v2.b; - var iy = _v2.c; - return _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A3( - $author$project$Manager$ModalManager$ShowInput, - $author$project$Util$ShapeManager$Polygon( - A2( - $elm$core$List$cons, - _Utils_Tuple2(ix, iy), - $author$project$Util$ShapeManager$getPointListFromPolygon(iShape))), - '', - '')) - }); - } - case 'AddShape': - return _Utils_update( - model, - { - saved: A2( - $elm$core$List$cons, - $author$project$Manager$StateManager$getInputShapeFromState(model.state), - model.saved), - state: $author$project$Manager$StateManager$ActiveModal( - A3( - $author$project$Manager$ModalManager$ShowInput, - $author$project$Util$ShapeManager$shapeDefaultConstruktor( - $author$project$Util$ShapeManager$shapeNameToString( - $author$project$Manager$StateManager$getInputShapeFromState(model.state))), - '', - '')) - }); - case 'DeleteShape': - var id = msg.a; - return _Utils_update( - model, - { - saved: A2( - $elm$core$List$append, - A2($elm$core$List$take, id - 1, model.saved), - A2($elm$core$List$drop, id, model.saved)) - }); - case 'OpenShowInput': - return A2( - $author$project$Manager$ModalManager$eq_String_Modal, - 'ShowInput', - $author$project$Manager$StateManager$getModalFromState(model.state)) ? _Utils_update( - model, - {state: $author$project$Manager$StateManager$Standby}) : _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', '')) - }); - case 'OpenShowTable': - return A2( - $author$project$Manager$ModalManager$eq_String_Modal, - 'ShowTable', - $author$project$Manager$StateManager$getModalFromState(model.state)) ? _Utils_update( - model, - {state: $author$project$Manager$StateManager$Standby}) : _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal($author$project$Manager$ModalManager$ShowTable) - }); - default: - var id = msg.a; - return (!id) ? _Utils_update( - model, - {state: $author$project$Manager$StateManager$Standby}) : _Utils_update( - model, - { - state: $author$project$Manager$StateManager$ActiveModal( - $author$project$Manager$ModalManager$ShowShape(id)) - }); + var shape = shapesMsg.a; + return A2($elm$core$List$cons, shape, shapeList); } }); var $author$project$Manager$UpdateManager$update = F2( @@ -8743,32 +8667,71 @@ var $author$project$Manager$UpdateManager$update = F2( case 'ManageModal': var modalMsg = msg.a; var value = msg.b; - return A2( - $author$project$Manager$UpdateManager$updateModal, - function () { - switch (modalMsg.$) { - case 'CloseModal': - return modalMsg; - case 'Check': - return modalMsg; - case 'Input': - var inputType = modalMsg.a; - return A2($author$project$Manager$ModalManager$Input, inputType, value); - case 'InputPoint': - return modalMsg; - case 'AddShape': - return modalMsg; - case 'DeleteShape': - return modalMsg; - case 'OpenShowInput': - return modalMsg; - case 'OpenShowTable': - return modalMsg; - default: - return modalMsg; - } - }(), - model); + var modal = $author$project$Manager$StateManager$getModalFromState(model.state); + return _Utils_update( + model, + { + state: $author$project$Manager$StateManager$manageState( + $author$project$Manager$StateManager$ActiveModal( + function () { + switch (modalMsg.$) { + case 'CloseModal': + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + case 'OpenShowInput': + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + case 'OpenShowTable': + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + case 'OpenShowShape': + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + case 'ResetShowInput': + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + case 'Check': + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + case 'Input': + var inputType = modalMsg.a; + return A2( + $author$project$Manager$ModalManager$updateModal, + A2($author$project$Manager$ModalManager$Input, inputType, value), + modal); + default: + return A2($author$project$Manager$ModalManager$updateModal, modalMsg, modal); + } + }())) + }); + case 'ManageShapes': + var shapesMsg = msg.a; + if (shapesMsg.$ === 'DeleteShape') { + return _Utils_update( + model, + { + saved: A2($author$project$Util$ShapeManager$updateShapes, shapesMsg, model.saved) + }); + } else { + return A2( + $author$project$Manager$ModalManager$eq_String_Modal, + 'ShowInput', + $author$project$Manager$StateManager$getModalFromState(model.state)) ? A2( + $author$project$Manager$UpdateManager$update, + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$ResetShowInput, ''), + _Utils_update( + model, + { + saved: A2( + $author$project$Util$ShapeManager$updateShapes, + $author$project$Util$ShapeManager$AddShape( + $author$project$Manager$StateManager$getInputShapeFromState(model.state)), + model.saved) + })).a : _Utils_update( + model, + { + saved: A2( + $author$project$Util$ShapeManager$updateShapes, + $author$project$Util$ShapeManager$AddShape( + $author$project$Manager$StateManager$getInputShapeFromState(model.state)), + model.saved), + state: $author$project$Manager$StateManager$Standby + }); + } case 'SvgShapeHover': var id = msg.a; return _Utils_update( @@ -8786,15 +8749,15 @@ var $author$project$Manager$UpdateManager$update = F2( }); case 'UpdateMousePos': var mouse = msg.a; - var _v2 = model.state; - switch (_v2.$) { + var _v3 = model.state; + switch (_v3.$) { case 'Standby': return model; case 'ActiveModal': return model; default: - var iShape = _v2.a; - var mOld = _v2.b; + var iShape = _v3.a; + var mOld = _v3.b; return _Utils_update( model, { @@ -8802,15 +8765,15 @@ var $author$project$Manager$UpdateManager$update = F2( }); } case 'InputDrawShape': - var _v3 = model.state; - switch (_v3.$) { + var _v4 = model.state; + switch (_v4.$) { case 'Standby': return model; case 'ActiveModal': return model; default: - var iShape = _v3.a; - var mPos = _v3.b; + var iShape = _v4.a; + var mPos = _v4.b; switch (iShape.$) { case 'Empty': return model; @@ -8903,16 +8866,6 @@ var $author$project$Manager$UpdateManager$update = F2( }); } } - case 'SaveAndCloseModal': - return _Utils_update( - model, - { - saved: A2( - $elm$core$List$cons, - $author$project$Manager$StateManager$getInputShapeFromState(model.state), - model.saved), - state: $author$project$Manager$StateManager$Standby - }); case 'LoadShapes': var result = msg.a; if (result.$ === 'Ok') { @@ -8978,14 +8931,14 @@ var $author$project$Manager$UpdateManager$update = F2( switch (msg.$) { case 'ManageModal': return $elm$core$Platform$Cmd$none; + case 'ManageShapes': + return $elm$core$Platform$Cmd$none; case 'SvgShapeHover': return $elm$core$Platform$Cmd$none; case 'UpdateMousePos': return $elm$core$Platform$Cmd$none; case 'InputDrawShape': return $elm$core$Platform$Cmd$none; - case 'SaveAndCloseModal': - return $elm$core$Platform$Cmd$none; case 'ShapesLoaded': return $elm$core$Platform$Cmd$none; case 'OpenDrawShape': diff --git a/src/Manager/ModalManager.elm b/src/Manager/ModalManager.elm index 4ec4ace..2e39cd6 100644 --- a/src/Manager/ModalManager.elm +++ b/src/Manager/ModalManager.elm @@ -1,7 +1,7 @@ module Manager.ModalManager exposing (..) -- Own import Util.Util exposing (MousePosition) -import Util.ShapeManager exposing (Shape(..)) +import Util.ShapeManager exposing (..) type Modal = NoModal @@ -16,12 +16,69 @@ type ModalMsg | OpenShowInput | OpenShowShape Int -- for input / delete Shapes + | ResetShowInput | Check String | Input Char String | InputPoint - | AddShape - | DeleteShape Int +-- Update +updateModal : ModalMsg -> Modal -> Modal +updateModal msg modal = + case msg of + CloseModal -> NoModal + OpenShowTable -> if (eq_String_Modal "ShowTable" modal) + then NoModal + else ShowTable + OpenShowInput -> if (eq_String_Modal "ShowInput" modal) + then NoModal + else ShowInput Empty "" "" + OpenShowShape id -> if (id <= 0) + then NoModal + else ShowShape id + ResetShowInput -> ShowInput + (deleteCoordsFromShape + (getInputShapeFromModal modal) + ) "" "" + Check shape -> if (eq_String_Modal "ShowInput" modal) + then if (eq_String_Shape shape (getInputShapeFromModal modal)) + then ShowInput Empty "" "" + else ShowInput (shapeDefaultConstruktor shape) "" "" + 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} + InputPoint -> case modal of + NoModal -> modal -- ERROR + ShowTable -> modal -- ERROR + ShowShape _ -> modal -- ERROR + ShowInput iShape ix iy -> ShowInput (Polygon ((ix,iy)::(getPointListFromPolygon iShape))) "" "" +updateInput : Char -> String -> Modal -> String -> Shape -> String -> String -> MousePosition -> Modal +updateInput inputType value modal modalType iShape ix iy mouse = + case inputType of + '1' -> case iShape of + Empty -> modal -- ERROR + Circle _ b c -> modalInputConstruktor modalType (Circle value b c ) ix iy mouse + Rectangle _ b c d -> modalInputConstruktor modalType (Rectangle value b c d) ix iy mouse + Polygon _ -> modalInputConstruktor modalType iShape value iy mouse + '2' -> case iShape of + Empty -> modal -- ERROR + Circle a _ c -> modalInputConstruktor modalType (Circle a value c ) ix iy mouse + Rectangle a _ c d -> modalInputConstruktor modalType (Rectangle a value c d) ix iy mouse + Polygon _ -> modalInputConstruktor modalType iShape ix value mouse + '3' -> case iShape of + Empty -> modal -- ERROR + Circle a b _ -> modalInputConstruktor modalType (Circle a b value ) ix iy mouse + Rectangle a b _ d -> modalInputConstruktor modalType (Rectangle a b value d) ix iy mouse + Polygon _ -> modal -- ERROR + '4' -> case iShape of + Empty -> modal -- ERROR + Circle _ _ _ -> modal -- ERROR + Rectangle a b c _ -> modalInputConstruktor modalType (Rectangle a b c value) ix iy mouse + Polygon _ -> modal -- ERROR + _ -> modal -- ERROR -- Modal Construktors modalInputConstruktor : String -> Shape -> String -> String -> MousePosition -> Modal modalInputConstruktor modalType shape x y mouse = diff --git a/src/Manager/StateManager.elm b/src/Manager/StateManager.elm index 9c6d9d0..418131b 100644 --- a/src/Manager/StateManager.elm +++ b/src/Manager/StateManager.elm @@ -1,6 +1,6 @@ module Manager.StateManager exposing (..) -- Own -import Manager.ModalManager exposing (Modal(..), modalNameToString, getInputShapeFromModal) +import Manager.ModalManager exposing (Modal(..), eq_String_Modal, modalNameToString, getInputShapeFromModal) import Util.ShapeManager exposing (Shape(..)) import Util.Util exposing (MousePosition) @@ -9,8 +9,15 @@ type State | ActiveModal Modal | DrawShape Shape MousePosition +-- Operations on State eq_String_State : String -> State -> Bool eq_String_State string state = string==(stateNameToString state) +manageState : State -> State +manageState state = if ( (eq_String_State "ActiveModal" state) + &&(eq_String_Modal "NoModal" (getModalFromState state)) + ) + then Standby + else state -- Transform State to other Types stateNameToString : State -> String stateNameToString state = diff --git a/src/Manager/UpdateManager.elm b/src/Manager/UpdateManager.elm index e408552..7ce6c93 100644 --- a/src/Manager/UpdateManager.elm +++ b/src/Manager/UpdateManager.elm @@ -17,16 +17,32 @@ import Util.Util exposing (..) update : Msg -> Model -> (Model, Cmd Msg) update msg model = (case msg of - ManageModal modalMsg value -> updateModal (case modalMsg of - CloseModal -> modalMsg - Check _ -> modalMsg - Input inputType _ -> Input inputType value - InputPoint -> modalMsg - AddShape -> modalMsg - DeleteShape _ -> modalMsg - OpenShowInput -> modalMsg - OpenShowTable -> modalMsg - OpenShowShape _ -> modalMsg) model + ManageModal modalMsg value -> + let modal = getModalFromState model.state + in { model | state = manageState (ActiveModal + (case modalMsg of + CloseModal -> updateModal modalMsg modal + OpenShowInput -> updateModal modalMsg modal + OpenShowTable -> updateModal modalMsg modal + OpenShowShape _ -> updateModal modalMsg modal + ResetShowInput -> updateModal modalMsg modal + Check _ -> updateModal modalMsg modal + Input inputType _ -> updateModal (Input inputType value) modal + InputPoint -> updateModal modalMsg modal + ) + ) + } + ManageShapes shapesMsg -> + case shapesMsg of + DeleteShape _ -> { model | saved = updateShapes shapesMsg model.saved} + AddShape _ -> if (eq_String_Modal "ShowInput" (getModalFromState model.state)) + then Tuple.first + (update (ManageModal ResetShowInput "") + { model | saved = updateShapes (AddShape (getInputShapeFromState model.state)) model.saved} + ) + else { model | saved = updateShapes (AddShape (getInputShapeFromState model.state)) model.saved + , state = Standby + } SvgShapeHover id -> { model | svgShapeHover = id} OpenDrawShape shape -> { model | state = DrawShape shape {x = 0, y = 0} } UpdateMousePos mouse -> case model.state of @@ -67,9 +83,6 @@ update msg model = ) mPos } - SaveAndCloseModal -> { model | saved = ((getInputShapeFromState model.state)::model.saved) - , state = Standby - } LoadShapes result -> case result of Ok "" -> { model | shapesLoadResult = Err (Http.BadBody "Empty result for LoadShapes") } @@ -88,10 +101,10 @@ update msg model = UrlChanged url -> { model | url = url} ,case msg of ManageModal _ _ -> Cmd.none + ManageShapes _ -> Cmd.none SvgShapeHover _ -> Cmd.none UpdateMousePos _ -> Cmd.none InputDrawShape -> Cmd.none - SaveAndCloseModal -> Cmd.none ShapesLoaded _ -> Cmd.none OpenDrawShape _ -> Cmd.none LoadShapes result -> @@ -121,71 +134,4 @@ update msg model = UrlChanged url -> Tuple.second ( update (LoadShapes (Ok (Maybe.withDefault "" url.fragment))) model ) - ) --- Parts of the UPDATE -updateModal : ModalMsg -> Model -> Model -updateModal msg model = - case msg of - CloseModal -> { model | state = Standby} - Check shape -> if (eq_String_Modal "ShowInput" (getModalFromState model.state)) - then if (eq_String_Shape shape (getInputShapeFromState model.state)) - then { model | state = ActiveModal (ShowInput Empty "" "") } - else { model | state = ActiveModal (ShowInput (shapeDefaultConstruktor shape) "" "") } - else model - Input inputType value -> - case (getModalFromState model.state) of - NoModal -> model -- ERROR - ShowTable -> model -- ERROR - ShowShape _ -> model -- ERROR - ShowInput iShape ix iy -> updateInput inputType value model "ShowInput" iShape ix iy {x = 0, y = 0} - InputPoint -> case (getModalFromState model.state) of - NoModal -> model -- ERROR - ShowTable -> model -- ERROR - ShowShape _ -> model -- ERROR - ShowInput iShape ix iy -> - { model | state = ActiveModal (ShowInput (Polygon ((ix,iy)::(getPointListFromPolygon iShape))) "" "") } - AddShape -> { model | saved = (getInputShapeFromState model.state)::model.saved - , state = ActiveModal (ShowInput - (shapeDefaultConstruktor - (shapeNameToString - (getInputShapeFromState model.state) - ) - ) "" "" - ) - } - DeleteShape id -> { model | saved = List.append (List.take (id-1) model.saved) - (List.drop (id) model.saved) - } - OpenShowInput -> if (eq_String_Modal "ShowInput" (getModalFromState model.state)) - then { model | state = Standby } - else { model | state = ActiveModal (ShowInput Empty "" "") } - OpenShowTable -> if (eq_String_Modal "ShowTable" (getModalFromState model.state)) - then { model | state = Standby } - else { model | state = ActiveModal ShowTable } - OpenShowShape id -> if (id == 0) - then { model | state = Standby } - else { model | state = ActiveModal (ShowShape id) } -updateInput : Char -> String -> Model -> String -> Shape -> String -> String -> MousePosition -> Model -updateInput inputType value model modalType iShape ix iy mouse = - case inputType of - '1' -> case iShape of - Empty -> model -- ERROR - Circle _ b c -> { model | state = ActiveModal (modalInputConstruktor modalType (Circle value b c ) ix iy mouse) } - Rectangle _ b c d -> { model | state = ActiveModal (modalInputConstruktor modalType (Rectangle value b c d) ix iy mouse) } - Polygon _ -> { model | state = ActiveModal (modalInputConstruktor modalType iShape value iy mouse) } - '2' -> case iShape of - Empty -> model -- ERROR - Circle a _ c -> { model | state = ActiveModal (modalInputConstruktor modalType (Circle a value c ) ix iy mouse) } - Rectangle a _ c d -> { model | state = ActiveModal (modalInputConstruktor modalType (Rectangle a value c d) ix iy mouse) } - Polygon _ -> { model | state = ActiveModal (modalInputConstruktor modalType iShape ix value mouse) } - '3' -> case iShape of - Empty -> model -- ERROR - Circle a b _ -> { model | state = ActiveModal (modalInputConstruktor modalType (Circle a b value ) ix iy mouse) } - Rectangle a b _ d -> { model | state = ActiveModal (modalInputConstruktor modalType (Rectangle a b value d) ix iy mouse) } - Polygon _ -> model -- ERROR - '4' -> case iShape of - Empty -> model -- ERROR - Circle _ _ _ -> model -- ERROR - Rectangle a b c _ -> { model | state = ActiveModal (modalInputConstruktor modalType (Rectangle a b c value) ix iy mouse) } - Polygon _ -> model -- ERROR - _ -> model -- ERROR \ No newline at end of file + ) \ No newline at end of file diff --git a/src/Manager/ViewManager.elm b/src/Manager/ViewManager.elm index 2f3b321..3af30b0 100644 --- a/src/Manager/ViewManager.elm +++ b/src/Manager/ViewManager.elm @@ -10,7 +10,7 @@ import Svg.Events -- Own import TypeHolder exposing (Model,Msg(..)) import Manager.StateManager exposing (..) -import Manager.ModalManager exposing (..) +import Manager.ModalManager exposing (Modal(..), ModalMsg(..)) import Util.ShapeManager exposing (..) import Util.Util exposing (..) @@ -83,7 +83,7 @@ viewHeader_Buttons state = in if (eq_String_Shape "Polygon" iShape) then viewDropDownMenue "Polygon wird gezeichnet" True "angle-down" [] [ a [class "dropdown-item" - , onClick SaveAndCloseModal + , onClick (ManageShapes (AddShape Empty)) , href "" ] [text "Speichern"] , a [class "dropdown-item" @@ -260,7 +260,7 @@ viewNewShapeInputModal iShape ix iy = ) , Html.footer [class "modal-card-foot"] [ button [ class "button is-success" - , onClick (ManageModal AddShape "") + , onClick (ManageShapes (AddShape Empty)) ] [text "Form hinzufügen"] , button [ class "button" , onClick (ManageModal CloseModal "") @@ -298,7 +298,7 @@ viewTableModal modelSaved = ] viewShapeModal : Int -> Html Msg viewShapeModal id = - if id <= 0 then div [] [] + if id <= 0 then div [] [] -- ERROR else div [class "modal is-active"] [ div [class "modal-background"] [] , div [class "modal-card"] @@ -367,7 +367,7 @@ writeShapeToTable shapeList id = , td [] [text (shapeNameStringToGerman(shapeNameToString x))] , td [] [text (shapeCoordsToString x)] , td [] [button [ class "button is-danger is-size-7" - , onClick (ManageModal (DeleteShape id) "")] [ text "Form löschen" ] ] + , onClick (ManageShapes (DeleteShape id))] [ text "Form löschen" ] ] ] :: (writeShapeToTable xs (id+1)) -- Modal Elements diff --git a/src/TypeHolder.elm b/src/TypeHolder.elm index f665d5b..04c5faf 100644 --- a/src/TypeHolder.elm +++ b/src/TypeHolder.elm @@ -9,7 +9,7 @@ import Url -- Own import Manager.StateManager exposing (State) import Manager.ModalManager exposing (Modal, ModalMsg) -import Util.ShapeManager exposing (Shape) +import Util.ShapeManager exposing (Shape, ShapesMsg) import Util.Util exposing (MousePosition) type alias Model = @@ -21,15 +21,15 @@ type alias Model = , key : Nav.Key } type Msg - -- Modal - = ManageModal ModalMsg String + -- Manage Objects + = ManageModal ModalMsg String + | ManageShapes ShapesMsg -- svg | SvgShapeHover Int -- for drawing shapes | OpenDrawShape Shape | UpdateMousePos MousePosition | InputDrawShape - | SaveAndCloseModal -- for loading shapes with http | LoadShapes (Result Http.Error String) | ShapesLoaded (Result Http.Error (List Shape)) diff --git a/src/Util/ShapeManager.elm b/src/Util/ShapeManager.elm index 82e8b16..9806afd 100644 --- a/src/Util/ShapeManager.elm +++ b/src/Util/ShapeManager.elm @@ -1,5 +1,5 @@ module Util.ShapeManager exposing (..) - +-- Json import Json.Decode as JD type Shape @@ -8,6 +8,18 @@ type Shape | Rectangle String String String String | Polygon (List ( String, String ) ) +type ShapesMsg + = DeleteShape Int + | AddShape Shape + +-- Update +updateShapes : ShapesMsg -> List Shape -> List Shape +updateShapes shapesMsg shapeList = + case shapesMsg of + DeleteShape id -> List.append (List.take (id-1) shapeList) + (List.drop (id) shapeList) + AddShape shape -> shape::shapeList + -- Shape Construktors shapeDefaultConstruktor : String -> Shape shapeDefaultConstruktor shape = @@ -46,6 +58,13 @@ shapesDecoder s = -- Operations on Shapes eq_String_Shape : String -> Shape -> Bool eq_String_Shape string shape = string==(shapeNameToString shape) +deleteCoordsFromShape : Shape -> Shape +deleteCoordsFromShape shape = + case shape of + Empty -> Empty + Circle _ _ _ -> Circle "" "" "" + Rectangle _ _ _ _ -> Rectangle "" "" "" "" + Polygon _ -> Polygon [] -- Get Methods : Parameter of Shapes getPointListFromPolygon : Shape -> List (String,String) getPointListFromPolygon shape = -- GitLab