diff --git a/index.html b/index.html index 5d89536426a2872b60f36a6138b80a78d67e9970..fd5148c537e3e8996b3d175e7ae542da2c50b616 100644 --- a/index.html +++ b/index.html @@ -5360,6 +5360,18 @@ var $elm$core$List$concat = function (lists) { return A3($elm$core$List$foldr, $elm$core$List$append, _List_Nil, lists); }; var $elm$html$Html$div = _VirtualDom_node('div'); +var $author$project$Manager$ModalManager$NoModal = {$: 'NoModal'}; +var $author$project$Manager$StateManager$getModalFromState = function (state) { + switch (state.$) { + case 'Standby': + return $author$project$Manager$ModalManager$NoModal; + case 'ActiveModal': + var modal = state.a; + return modal; + default: + return $author$project$Manager$ModalManager$NoModal; + } +}; var $elm$html$Html$Attributes$href = function (url) { return A2( $elm$html$Html$Attributes$stringProperty, @@ -5404,16 +5416,17 @@ var $author$project$Util$ShapeManager$Circle = F3( function (a, b, c) { return {$: 'Circle', a: a, b: b, c: c}; }); -var $author$project$TypeHolder$CloseModal = {$: 'CloseModal'}; +var $author$project$Manager$ModalManager$CloseModal = {$: 'CloseModal'}; var $author$project$TypeHolder$LoadShapes = function (a) { return {$: 'LoadShapes', a: a}; }; -var $author$project$Manager$ModalManager$OpenDrawShape = function (a) { +var $author$project$TypeHolder$ManageModal = F2( + function (a, b) { + return {$: 'ManageModal', a: a, b: b}; + }); +var $author$project$TypeHolder$OpenDrawShape = function (a) { return {$: 'OpenDrawShape', a: a}; }; -var $author$project$TypeHolder$OpenModal = function (a) { - return {$: 'OpenModal', a: a}; -}; var $author$project$Manager$ModalManager$OpenShowInput = {$: 'OpenShowInput'}; var $author$project$Manager$ModalManager$OpenShowTable = {$: 'OpenShowTable'}; var $author$project$Util$ShapeManager$Polygon = function (a) { @@ -5426,26 +5439,6 @@ var $author$project$Util$ShapeManager$Rectangle = F4( 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$Manager$ModalManager$modalNameToString = function (modal) { - switch (modal.$) { - case 'NoModal': - return 'NoModal'; - case 'ShowTable': - return 'ShowTable'; - case 'ShowInput': - return 'ShowInput'; - case 'ShowShape': - return 'ShowShape'; - default: - return 'DrawShape'; - } -}; -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$shapeNameToString = function (shape) { switch (shape.$) { case 'Empty': @@ -5464,6 +5457,23 @@ var $author$project$Util$ShapeManager$eq_String_Shape = F2( string, $author$project$Util$ShapeManager$shapeNameToString(shape)); }); +var $author$project$Manager$StateManager$stateNameToString = function (state) { + switch (state.$) { + case 'Standby': + return 'Standby'; + case 'ActiveModal': + var modal = state.a; + return 'ActiveModal'; + default: + return 'DrawShape'; + } +}; +var $author$project$Manager$StateManager$eq_String_State = F2( + function (string, state) { + return _Utils_eq( + string, + $author$project$Manager$StateManager$stateNameToString(state)); + }); var $author$project$Util$ShapeManager$Empty = {$: 'Empty'}; var $author$project$Manager$ModalManager$getInputShapeFromModal = function (modal) { switch (modal.$) { @@ -5474,10 +5484,19 @@ var $author$project$Manager$ModalManager$getInputShapeFromModal = function (moda case 'ShowInput': var shape = modal.a; return shape; - case 'ShowShape': + default: return $author$project$Util$ShapeManager$Empty; + } +}; +var $author$project$Manager$StateManager$getInputShapeFromState = function (state) { + switch (state.$) { + case 'Standby': + return $author$project$Util$ShapeManager$Empty; + case 'ActiveModal': + var modal = state.a; + return $author$project$Manager$ModalManager$getInputShapeFromModal(modal); default: - var shape = modal.a; + var shape = state.a; return shape; } }; @@ -5590,7 +5609,7 @@ var $author$project$Manager$ViewManager$viewDropDownMenue = F5( ])) ])); }); -var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { +var $author$project$Manager$ViewManager$viewHeader_Buttons = function (state) { return A2( $elm$html$Html$div, _List_Nil, @@ -5638,7 +5657,7 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal($author$project$Manager$ModalManager$OpenShowInput)), + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$OpenShowInput, '')), $elm$html$Html$Attributes$class('button is-success is-pulled-left is-size-6'), A2($elm$html$Html$Attributes$style, 'margin-bottom', '15px'), A2($elm$html$Html$Attributes$style, 'margin-right', '15px') @@ -5652,7 +5671,7 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal($author$project$Manager$ModalManager$OpenShowTable)), + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$OpenShowTable, '')), $elm$html$Html$Attributes$class('button is-success is-pulled-left is-size-6'), A2($elm$html$Html$Attributes$style, 'margin-right', '15px'), A2($elm$html$Html$Attributes$style, 'margin-bottom', '15px') @@ -5709,8 +5728,8 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { ])) ])), function () { - if (A2($author$project$Manager$ModalManager$eq_String_Modal, 'DrawShape', modal)) { - var iShape = $author$project$Manager$ModalManager$getInputShapeFromModal(modal); + if (A2($author$project$Manager$StateManager$eq_String_State, 'DrawShape', state)) { + var iShape = $author$project$Manager$StateManager$getInputShapeFromState(state); return A2($author$project$Util$ShapeManager$eq_String_Shape, 'Polygon', iShape) ? A5( $author$project$Manager$ViewManager$viewDropDownMenue, 'Polygon wird gezeichnet', @@ -5736,7 +5755,8 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { _List_fromArray( [ $elm$html$Html$Attributes$class('dropdown-item'), - $elm$html$Html$Events$onClick($author$project$TypeHolder$CloseModal), + $elm$html$Html$Events$onClick( + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$CloseModal, '')), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -5747,12 +5767,13 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { $author$project$Manager$ViewManager$viewDropDownMenue, $author$project$Util$ShapeManager$shapeNameStringToGerman( $author$project$Util$ShapeManager$shapeNameToString( - $author$project$Manager$ModalManager$getInputShapeFromModal(modal))) + ' zeichnen: abbrechen ', + $author$project$Manager$StateManager$getInputShapeFromState(state))) + ' zeichnen: abbrechen ', false, 'times', _List_fromArray( [ - $elm$html$Html$Events$onClick($author$project$TypeHolder$CloseModal) + $elm$html$Html$Events$onClick( + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$CloseModal, '')) ]), _List_Nil); } else { @@ -5770,9 +5791,8 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { [ $elm$html$Html$Attributes$class('dropdown-item'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$OpenDrawShape( - A3($author$project$Util$ShapeManager$Circle, '', '', '')))), + $author$project$TypeHolder$OpenDrawShape( + A3($author$project$Util$ShapeManager$Circle, '', '', ''))), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -5785,9 +5805,8 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { [ $elm$html$Html$Attributes$class('dropdown-item'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$OpenDrawShape( - A4($author$project$Util$ShapeManager$Rectangle, '', '', '', '')))), + $author$project$TypeHolder$OpenDrawShape( + A4($author$project$Util$ShapeManager$Rectangle, '', '', '', ''))), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -5800,9 +5819,8 @@ var $author$project$Manager$ViewManager$viewHeader_Buttons = function (modal) { [ $elm$html$Html$Attributes$class('dropdown-item'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$OpenDrawShape( - $author$project$Util$ShapeManager$Polygon(_List_Nil)))), + $author$project$TypeHolder$OpenDrawShape( + $author$project$Util$ShapeManager$Polygon(_List_Nil))), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -6027,8 +6045,10 @@ var $author$project$Manager$ViewManager$svgShapeStyle = F2( $elm$svg$Svg$Events$onMouseOut( $author$project$TypeHolder$SvgShapeHover(0)), $elm$svg$Svg$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$OpenShowShape(id))) + A2( + $author$project$TypeHolder$ManageModal, + $author$project$Manager$ModalManager$OpenShowShape(id), + '')) ]); }); var $elm$svg$Svg$Attributes$width = _VirtualDom_attribute('width'); @@ -6151,15 +6171,11 @@ var $author$project$Manager$ViewManager$viewImage = function (model) { ]), A3($author$project$Manager$ViewManager$viewSvgShapes, model.saved, model.svgShapeHover, 1), function () { - var _v0 = model.modal; + var _v0 = model.state; switch (_v0.$) { - case 'NoModal': - return _List_Nil; - case 'ShowTable': - return _List_Nil; - case 'ShowShape': + case 'Standby': return _List_Nil; - case 'ShowInput': + case 'ActiveModal': return _List_Nil; default: var iShape = _v0.a; @@ -6318,10 +6334,6 @@ var $author$project$Manager$ModalManager$Input = F2( return {$: 'Input', a: a, b: b}; }); var $author$project$Manager$ModalManager$InputPoint = {$: 'InputPoint'}; -var $author$project$TypeHolder$OnInputModal = F2( - function (a, b) { - return {$: 'OnInputModal', a: a, b: b}; - }); var $elm$html$Html$footer = _VirtualDom_node('footer'); var $elm$html$Html$input = _VirtualDom_node('input'); var $elm$html$Html$label = _VirtualDom_node('label'); @@ -6351,7 +6363,8 @@ var $author$project$Manager$ViewManager$modalHeader = function (title) { _List_fromArray( [ $elm$html$Html$Attributes$class('delete aria-label=close'), - $elm$html$Html$Events$onClick($author$project$TypeHolder$CloseModal) + $elm$html$Html$Events$onClick( + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$CloseModal, '')) ]), _List_Nil) ])); @@ -6441,8 +6454,10 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( [ $elm$html$Html$Attributes$class('dropdown-item'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$Check('Circle'))), + A2( + $author$project$TypeHolder$ManageModal, + $author$project$Manager$ModalManager$Check('Circle'), + '')), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -6455,8 +6470,10 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( [ $elm$html$Html$Attributes$class('dropdown-item'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$Check('Rectangle'))), + A2( + $author$project$TypeHolder$ManageModal, + $author$project$Manager$ModalManager$Check('Rectangle'), + '')), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -6469,8 +6486,10 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( [ $elm$html$Html$Attributes$class('dropdown-item'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$Check('Polygon'))), + A2( + $author$project$TypeHolder$ManageModal, + $author$project$Manager$ModalManager$Check('Polygon'), + '')), $elm$html$Html$Attributes$href('') ]), _List_fromArray( @@ -6524,7 +6543,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('X-Position'), $elm$html$Html$Attributes$value(a), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('1'), @@ -6555,7 +6574,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('Y-Position'), $elm$html$Html$Attributes$value(b), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('2'), @@ -6586,7 +6605,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('Radius'), $elm$html$Html$Attributes$value(c), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('3'), @@ -6631,7 +6650,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('X1-Position'), $elm$html$Html$Attributes$value(a), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('1'), @@ -6662,7 +6681,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('Y1-Position'), $elm$html$Html$Attributes$value(b), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('2'), @@ -6693,7 +6712,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('X2-Position'), $elm$html$Html$Attributes$value(c), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('3'), @@ -6724,7 +6743,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('Y2-Position'), $elm$html$Html$Attributes$value(d), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('4'), @@ -6765,7 +6784,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('X-Position'), $elm$html$Html$Attributes$value(ix), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('1'), @@ -6796,7 +6815,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( $elm$html$Html$Attributes$placeholder('Y-Position'), $elm$html$Html$Attributes$value(iy), $elm$html$Html$Events$onInput( - $author$project$TypeHolder$OnInputModal( + $author$project$TypeHolder$ManageModal( A2( $author$project$Manager$ModalManager$Input, _Utils_chr('2'), @@ -6826,7 +6845,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( _List_fromArray( [ $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal($author$project$Manager$ModalManager$InputPoint)), + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$InputPoint, '')), $elm$html$Html$Attributes$class('button is-success is-size-7'), A2($elm$html$Html$Attributes$style, 'margin-top', '10px') ]), @@ -6853,7 +6872,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( [ $elm$html$Html$Attributes$class('button is-success'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal($author$project$Manager$ModalManager$AddShape)) + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$AddShape, '')) ]), _List_fromArray( [ @@ -6864,7 +6883,8 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( _List_fromArray( [ $elm$html$Html$Attributes$class('button'), - $elm$html$Html$Events$onClick($author$project$TypeHolder$CloseModal) + $elm$html$Html$Events$onClick( + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$CloseModal, '')) ]), _List_fromArray( [ @@ -6875,7 +6895,7 @@ var $author$project$Manager$ViewManager$viewNewShapeInputModal = F3( ])); }); var $author$project$Manager$ViewManager$viewShapeModal = function (id) { - return (!id) ? A2($elm$html$Html$div, _List_Nil, _List_Nil) : A2( + return (id <= 0) ? A2($elm$html$Html$div, _List_Nil, _List_Nil) : A2( $elm$html$Html$div, _List_fromArray( [ @@ -6924,7 +6944,8 @@ var $author$project$Manager$ViewManager$viewShapeModal = function (id) { _List_fromArray( [ $elm$html$Html$Attributes$class('button'), - $elm$html$Html$Events$onClick($author$project$TypeHolder$CloseModal) + $elm$html$Html$Events$onClick( + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$CloseModal, '')) ]), _List_fromArray( [ @@ -6996,8 +7017,10 @@ var $author$project$Manager$ViewManager$writeShapeToTable = F2( [ $elm$html$Html$Attributes$class('button is-danger is-size-7'), $elm$html$Html$Events$onClick( - $author$project$TypeHolder$OpenModal( - $author$project$Manager$ModalManager$DeleteShape(id))) + A2( + $author$project$TypeHolder$ManageModal, + $author$project$Manager$ModalManager$DeleteShape(id), + '')) ]), _List_fromArray( [ @@ -7110,7 +7133,8 @@ var $author$project$Manager$ViewManager$viewTableModal = function (modelSaved) { _List_fromArray( [ $elm$html$Html$Attributes$class('button'), - $elm$html$Html$Events$onClick($author$project$TypeHolder$CloseModal) + $elm$html$Html$Events$onClick( + A2($author$project$TypeHolder$ManageModal, $author$project$Manager$ModalManager$CloseModal, '')) ]), _List_fromArray( [ @@ -7156,7 +7180,7 @@ var $author$project$Manager$ViewManager$view = function (model) { $elm$html$Html$Attributes$href('https://use.fontawesome.com/releases/v5.8.1/css/all.css') ]), _List_Nil), - $author$project$Manager$ViewManager$viewHeader_Buttons(model.modal), + $author$project$Manager$ViewManager$viewHeader_Buttons(model.state), A2( $elm$html$Html$section, _List_fromArray( @@ -7178,7 +7202,7 @@ var $author$project$Manager$ViewManager$view = function (model) { }() ]), function () { - var _v1 = model.modal; + var _v1 = $author$project$Manager$StateManager$getModalFromState(model.state); switch (_v1.$) { case 'NoModal': return _List_Nil; @@ -7195,15 +7219,12 @@ var $author$project$Manager$ViewManager$view = function (model) { [ $author$project$Manager$ViewManager$viewTableModal(model.saved) ]); - case 'ShowShape': + default: var id = _v1.a; return _List_fromArray( [ $author$project$Manager$ViewManager$viewShapeModal(id) ]); - default: - var iShape = _v1.a; - return _List_Nil; } }() ]))); @@ -7218,10 +7239,10 @@ var $author$project$ShapePicture_Editor$documentView = function (model) { }; }; var $author$project$TypeHolder$Model = F6( - function (modal, saved, svgShapeHover, shapesLoadResult, url, key) { - return {key: key, modal: modal, saved: saved, shapesLoadResult: shapesLoadResult, svgShapeHover: svgShapeHover, url: url}; + function (state, saved, svgShapeHover, shapesLoadResult, url, key) { + return {key: key, saved: saved, shapesLoadResult: shapesLoadResult, state: state, svgShapeHover: svgShapeHover, url: url}; }); -var $author$project$Manager$ModalManager$NoModal = {$: 'NoModal'}; +var $author$project$Manager$StateManager$Standby = {$: 'Standby'}; var $elm$core$Platform$Cmd$batch = _Platform_batch; var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil); var $author$project$ShapePicture_Editor$init = F3( @@ -7229,7 +7250,7 @@ var $author$project$ShapePicture_Editor$init = F3( return _Utils_Tuple2( A6( $author$project$TypeHolder$Model, - $author$project$Manager$ModalManager$NoModal, + $author$project$Manager$StateManager$Standby, _List_Nil, 0, $elm$core$Result$Ok(' Init'), @@ -7245,7 +7266,7 @@ var $author$project$ShapePicture_Editor$subscriptions = function (model) { var $elm$http$Http$BadBody = function (a) { return {$: 'BadBody', a: a}; }; -var $author$project$Manager$ModalManager$DrawShape = F2( +var $author$project$Manager$StateManager$DrawShape = F2( function (a, b) { return {$: 'DrawShape', a: a, b: b}; }); @@ -8203,6 +8224,9 @@ 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}; @@ -8232,6 +8256,24 @@ var $elm$core$List$drop = F2( } } }); +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 $author$project$Util$ShapeManager$getPointListFromPolygon = function (shape) { switch (shape.$) { case 'Empty': @@ -8385,13 +8427,10 @@ var $elm$core$List$take = F2( }); var $author$project$Manager$ModalManager$modalInputConstruktor = F5( function (modalType, shape, x, y, mouse) { - switch (modalType) { - case 'ShowInput': - return A3($author$project$Manager$ModalManager$ShowInput, shape, x, y); - case 'DrawShape': - return A2($author$project$Manager$ModalManager$DrawShape, shape, mouse); - default: - return $author$project$Manager$ModalManager$NoModal; + if (modalType === 'ShowInput') { + return A3($author$project$Manager$ModalManager$ShowInput, shape, x, y); + } else { + return $author$project$Manager$ModalManager$NoModal; } }); var $author$project$Manager$UpdateManager$updateInput = F8( @@ -8407,13 +8446,14 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A3($author$project$Util$ShapeManager$Circle, value, b, c), - ix, - iy, - mouse) + 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; @@ -8422,19 +8462,21 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, value, b, c, d), - ix, - iy, - mouse) + 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, { - modal: A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, value, iy, mouse) + state: $author$project$Manager$StateManager$ActiveModal( + A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, value, iy, mouse)) }); } case '2': @@ -8447,13 +8489,14 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A3($author$project$Util$ShapeManager$Circle, a, value, c), - ix, - iy, - mouse) + 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; @@ -8462,19 +8505,21 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, a, value, c, d), - ix, - iy, - mouse) + 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, { - modal: A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, ix, value, mouse) + state: $author$project$Manager$StateManager$ActiveModal( + A5($author$project$Manager$ModalManager$modalInputConstruktor, modalType, iShape, ix, value, mouse)) }); } case '3': @@ -8487,13 +8532,14 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A3($author$project$Util$ShapeManager$Circle, a, b, value), - ix, - iy, - mouse) + 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; @@ -8502,13 +8548,14 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, a, b, value, d), - ix, - iy, - mouse) + 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; @@ -8526,13 +8573,14 @@ var $author$project$Manager$UpdateManager$updateInput = F8( return _Utils_update( model, { - modal: A5( - $author$project$Manager$ModalManager$modalInputConstruktor, - modalType, - A4($author$project$Util$ShapeManager$Rectangle, a, b, c, value), - ix, - iy, - mouse) + 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; @@ -8544,28 +8592,37 @@ var $author$project$Manager$UpdateManager$updateInput = F8( 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', model.modal) ? (A2( + 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$ModalManager$getInputShapeFromModal(model.modal)) ? _Utils_update( + $author$project$Manager$StateManager$getInputShapeFromState(model.state)) ? _Utils_update( model, { - modal: A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', '') + state: $author$project$Manager$StateManager$ActiveModal( + A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', '')) }) : _Utils_update( model, { - modal: A3( - $author$project$Manager$ModalManager$ShowInput, - $author$project$Util$ShapeManager$shapeDefaultConstruktor(shape), - '', - '') + 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 = model.modal; + var _v1 = $author$project$Manager$StateManager$getModalFromState(model.state); switch (_v1.$) { case 'NoModal': return model; @@ -8573,10 +8630,6 @@ var $author$project$Manager$UpdateManager$updateModal = F2( return model; case 'ShowShape': return model; - case 'DrawShape': - var iShape = _v1.a; - var mouse = _v1.b; - return A8($author$project$Manager$UpdateManager$updateInput, inputType, value, model, 'DrawShape', iShape, '', '', mouse); default: var iShape = _v1.a; var ix = _v1.b; @@ -8593,7 +8646,7 @@ var $author$project$Manager$UpdateManager$updateModal = F2( {x: 0, y: 0}); } case 'InputPoint': - var _v2 = model.modal; + var _v2 = $author$project$Manager$StateManager$getModalFromState(model.state); switch (_v2.$) { case 'NoModal': return model; @@ -8601,8 +8654,6 @@ var $author$project$Manager$UpdateManager$updateModal = F2( return model; case 'ShowShape': return model; - case 'DrawShape': - return model; default: var iShape = _v2.a; var ix = _v2.b; @@ -8610,32 +8661,34 @@ var $author$project$Manager$UpdateManager$updateModal = F2( return _Utils_update( model, { - modal: 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))), - '', - '') + 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, { - modal: A3( - $author$project$Manager$ModalManager$ShowInput, - $author$project$Util$ShapeManager$shapeDefaultConstruktor( - $author$project$Util$ShapeManager$shapeNameToString( - $author$project$Manager$ModalManager$getInputShapeFromModal(model.modal))), - '', - ''), saved: A2( $elm$core$List$cons, - $author$project$Manager$ModalManager$getInputShapeFromModal(model.modal), - model.saved) + $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; @@ -8648,37 +8701,37 @@ var $author$project$Manager$UpdateManager$updateModal = F2( A2($elm$core$List$drop, id, model.saved)) }); case 'OpenShowInput': - return A2($author$project$Manager$ModalManager$eq_String_Modal, 'ShowInput', model.modal) ? _Utils_update( + return A2( + $author$project$Manager$ModalManager$eq_String_Modal, + 'ShowInput', + $author$project$Manager$StateManager$getModalFromState(model.state)) ? _Utils_update( model, - {modal: $author$project$Manager$ModalManager$NoModal}) : _Utils_update( + {state: $author$project$Manager$StateManager$Standby}) : _Utils_update( model, { - modal: A3($author$project$Manager$ModalManager$ShowInput, $author$project$Util$ShapeManager$Empty, '', '') + 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', model.modal) ? _Utils_update( - model, - {modal: $author$project$Manager$ModalManager$NoModal}) : _Utils_update( - model, - {modal: $author$project$Manager$ModalManager$ShowTable}); - case 'OpenShowShape': - var id = msg.a; - return (!id) ? _Utils_update( + return A2( + $author$project$Manager$ModalManager$eq_String_Modal, + 'ShowTable', + $author$project$Manager$StateManager$getModalFromState(model.state)) ? _Utils_update( model, - {modal: $author$project$Manager$ModalManager$NoModal}) : _Utils_update( + {state: $author$project$Manager$StateManager$Standby}) : _Utils_update( model, { - modal: $author$project$Manager$ModalManager$ShowShape(id) + state: $author$project$Manager$StateManager$ActiveModal($author$project$Manager$ModalManager$ShowTable) }); default: - var shape = msg.a; - return _Utils_update( + var id = msg.a; + return (!id) ? _Utils_update( + model, + {state: $author$project$Manager$StateManager$Standby}) : _Utils_update( model, { - modal: A2( - $author$project$Manager$ModalManager$DrawShape, - shape, - {x: 0, y: 0}) + state: $author$project$Manager$StateManager$ActiveModal( + $author$project$Manager$ModalManager$ShowShape(id)) }); } }); @@ -8687,16 +8740,15 @@ var $author$project$Manager$UpdateManager$update = F2( return _Utils_Tuple2( function () { switch (msg.$) { - case 'OpenModal': - var modalMsg = msg.a; - return A2($author$project$Manager$UpdateManager$updateModal, modalMsg, model); - case 'OnInputModal': + 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': @@ -8712,33 +8764,33 @@ var $author$project$Manager$UpdateManager$update = F2( return modalMsg; case 'OpenShowTable': return modalMsg; - case 'OpenShowShape': - return modalMsg; default: return modalMsg; } }(), model); - case 'CloseModal': - return _Utils_update( - model, - {modal: $author$project$Manager$ModalManager$NoModal}); case 'SvgShapeHover': var id = msg.a; return _Utils_update( model, {svgShapeHover: id}); + case 'OpenDrawShape': + var shape = msg.a; + return _Utils_update( + model, + { + state: A2( + $author$project$Manager$StateManager$DrawShape, + shape, + {x: 0, y: 0}) + }); case 'UpdateMousePos': var mouse = msg.a; - var _v2 = model.modal; + var _v2 = model.state; switch (_v2.$) { - case 'NoModal': + case 'Standby': return model; - case 'ShowTable': - return model; - case 'ShowShape': - return model; - case 'ShowInput': + case 'ActiveModal': return model; default: var iShape = _v2.a; @@ -8746,19 +8798,15 @@ var $author$project$Manager$UpdateManager$update = F2( return _Utils_update( model, { - modal: A2($author$project$Manager$ModalManager$DrawShape, iShape, mouse) + state: A2($author$project$Manager$StateManager$DrawShape, iShape, mouse) }); } case 'InputDrawShape': - var _v3 = model.modal; + var _v3 = model.state; switch (_v3.$) { - case 'NoModal': - return model; - case 'ShowTable': - return model; - case 'ShowShape': + case 'Standby': return model; - case 'ShowInput': + case 'ActiveModal': return model; default: var iShape = _v3.a; @@ -8773,8 +8821,8 @@ var $author$project$Manager$UpdateManager$update = F2( return (x === '') ? _Utils_update( model, { - modal: A2( - $author$project$Manager$ModalManager$DrawShape, + state: A2( + $author$project$Manager$StateManager$DrawShape, A3( $author$project$Util$ShapeManager$Circle, $elm$core$String$fromInt(mPos.x), @@ -8784,7 +8832,6 @@ var $author$project$Manager$UpdateManager$update = F2( }) : _Utils_update( model, { - modal: $author$project$Manager$ModalManager$NoModal, saved: A2( $elm$core$List$cons, A3( @@ -8792,7 +8839,8 @@ var $author$project$Manager$UpdateManager$update = F2( x, y, A3($author$project$Util$Util$abstand, x, y, mPos)), - model.saved) + model.saved), + state: $author$project$Manager$StateManager$Standby }); case 'Rectangle': var a = iShape.a; @@ -8803,8 +8851,8 @@ var $author$project$Manager$UpdateManager$update = F2( return _Utils_update( model, { - modal: A2( - $author$project$Manager$ModalManager$DrawShape, + state: A2( + $author$project$Manager$StateManager$DrawShape, A4( $author$project$Util$ShapeManager$Rectangle, $elm$core$String$fromInt(mPos.x), @@ -8830,11 +8878,11 @@ var $author$project$Manager$UpdateManager$update = F2( return _Utils_update( model, { - modal: $author$project$Manager$ModalManager$NoModal, saved: A2( $elm$core$List$cons, A4($author$project$Util$ShapeManager$Rectangle, coords.x, coords.y, coords.w, coords.h), - model.saved) + model.saved), + state: $author$project$Manager$StateManager$Standby }); } default: @@ -8842,8 +8890,8 @@ var $author$project$Manager$UpdateManager$update = F2( return _Utils_update( model, { - modal: A2( - $author$project$Manager$ModalManager$DrawShape, + state: A2( + $author$project$Manager$StateManager$DrawShape, $author$project$Util$ShapeManager$Polygon( A2( $elm$core$List$cons, @@ -8859,11 +8907,11 @@ var $author$project$Manager$UpdateManager$update = F2( return _Utils_update( model, { - modal: $author$project$Manager$ModalManager$NoModal, saved: A2( $elm$core$List$cons, - $author$project$Manager$ModalManager$getInputShapeFromModal(model.modal), - model.saved) + $author$project$Manager$StateManager$getInputShapeFromState(model.state), + model.saved), + state: $author$project$Manager$StateManager$Standby }); case 'LoadShapes': var result = msg.a; @@ -8928,11 +8976,7 @@ var $author$project$Manager$UpdateManager$update = F2( }(), function () { switch (msg.$) { - case 'OpenModal': - return $elm$core$Platform$Cmd$none; - case 'OnInputModal': - return $elm$core$Platform$Cmd$none; - case 'CloseModal': + case 'ManageModal': return $elm$core$Platform$Cmd$none; case 'SvgShapeHover': return $elm$core$Platform$Cmd$none; @@ -8944,6 +8988,8 @@ var $author$project$Manager$UpdateManager$update = F2( return $elm$core$Platform$Cmd$none; case 'ShapesLoaded': return $elm$core$Platform$Cmd$none; + case 'OpenDrawShape': + return $elm$core$Platform$Cmd$none; case 'LoadShapes': var result = msg.a; if (result.$ === 'Ok') { diff --git a/src/Manager/ModalManager.elm b/src/Manager/ModalManager.elm index 6e439b54f04cb1a9a64ba5c7941377a293a76001..4ec4ace837d0c8956b0f98cae331fcdb1ae240e2 100644 --- a/src/Manager/ModalManager.elm +++ b/src/Manager/ModalManager.elm @@ -8,55 +8,42 @@ type Modal | ShowTable | ShowInput Shape String String | ShowShape Int - | DrawShape Shape MousePosition type ModalMsg + = CloseModal -- show Modal - = OpenShowTable + | OpenShowTable | OpenShowInput | OpenShowShape Int - -- for input / delete Forms + -- for input / delete Shapes | Check String | Input Char String | InputPoint | AddShape | DeleteShape Int - -- for drawing shapes - needs refactor - | OpenDrawShape Shape -- Modal Construktors modalInputConstruktor : String -> Shape -> String -> String -> MousePosition -> Modal modalInputConstruktor modalType shape x y mouse = case modalType of "ShowInput" -> ShowInput shape x y - "DrawShape" -> DrawShape shape mouse _ -> NoModal - -- Operations on Modal +-- Operations on Modal eq_String_Modal : String -> Modal -> Bool eq_String_Modal string modal = string==(modalNameToString modal) - -- Get Methods : Parameter of Modal +-- Get Methods : Parameter of Modal getInputShapeFromModal : Modal -> Shape -getInputShapeFromModal modal = +getInputShapeFromModal modal = case modal of NoModal -> Empty ShowTable -> Empty ShowInput shape _ _ -> shape ShowShape _ -> Empty - DrawShape shape _ -> shape -getMousePosFromModal : Modal -> MousePosition -getMousePosFromModal modal = - case modal of - NoModal -> {x=0,y=0} - ShowTable -> {x=0,y=0} - ShowInput _ _ _ -> {x=0,y=0} - ShowShape _ -> {x=0,y=0} - DrawShape _ mouse -> mouse - -- Transform Modal to other Types +-- Transform Modal to other Types modalNameToString : Modal -> String modalNameToString modal = - case modal of + case modal of NoModal -> "NoModal" ShowTable -> "ShowTable" ShowInput _ _ _ -> "ShowInput" - ShowShape _ -> "ShowShape" - DrawShape _ _ -> "DrawShape" \ No newline at end of file + ShowShape _ -> "ShowShape" \ No newline at end of file diff --git a/src/Manager/StateManager.elm b/src/Manager/StateManager.elm new file mode 100644 index 0000000000000000000000000000000000000000..9c6d9d076d7b5f24af268de8b3487d900788fa4c --- /dev/null +++ b/src/Manager/StateManager.elm @@ -0,0 +1,33 @@ +module Manager.StateManager exposing (..) +-- Own +import Manager.ModalManager exposing (Modal(..), modalNameToString, getInputShapeFromModal) +import Util.ShapeManager exposing (Shape(..)) +import Util.Util exposing (MousePosition) + +type State + = Standby + | ActiveModal Modal + | DrawShape Shape MousePosition + +eq_String_State : String -> State -> Bool +eq_String_State string state = string==(stateNameToString state) +-- Transform State to other Types +stateNameToString : State -> String +stateNameToString state = + case state of + Standby -> "Standby" + ActiveModal modal -> "ActiveModal" + DrawShape _ _ -> "DrawShape" +-- Get Methods : Parameter of State +getInputShapeFromState : State -> Shape +getInputShapeFromState state = + case state of + Standby -> Empty + ActiveModal modal -> getInputShapeFromModal modal + DrawShape shape _ -> shape +getModalFromState : State -> Modal +getModalFromState state = + case state of + Standby -> NoModal + ActiveModal modal -> modal + DrawShape _ _ -> NoModal diff --git a/src/Manager/UpdateManager.elm b/src/Manager/UpdateManager.elm index 9b9905fe9589724d3e4e235bfd96cf3f0f2e17d6..e4085528972c99aeba988f2fb17c6a1060da22d5 100644 --- a/src/Manager/UpdateManager.elm +++ b/src/Manager/UpdateManager.elm @@ -3,21 +3,22 @@ module Manager.UpdateManager exposing (update) import Browser import Browser.Navigation as Nav -- Http -import Http +import Http -- Url import Url -- Own import TypeHolder exposing (Model, Msg(..)) +import Manager.StateManager exposing (..) import Manager.ModalManager exposing (..) import Util.ShapeManager exposing (..) import Util.Util exposing (..) -- UPDATE update : Msg -> Model -> (Model, Cmd Msg) -update msg model = - (case msg of - OpenModal modalMsg -> updateModal modalMsg model - OnInputModal modalMsg value -> updateModal (case modalMsg of +update msg model = + (case msg of + ManageModal modalMsg value -> updateModal (case modalMsg of + CloseModal -> modalMsg Check _ -> modalMsg Input inputType _ -> Input inputType value InputPoint -> modalMsg @@ -25,32 +26,27 @@ update msg model = DeleteShape _ -> modalMsg OpenShowInput -> modalMsg OpenShowTable -> modalMsg - OpenShowShape _ -> modalMsg - OpenDrawShape _ -> modalMsg) model - CloseModal -> { model | modal = NoModal } - SvgShapeHover id -> { model | svgShapeHover = id} - UpdateMousePos mouse -> case model.modal of - NoModal -> model -- ERROR - ShowTable -> model -- ERROR - ShowShape _ -> model -- ERROR - ShowInput _ _ _ -> model -- ERROR - DrawShape iShape mOld -> { model | modal = DrawShape iShape mouse } - InputDrawShape -> case model.modal of - NoModal -> model -- ERROR - ShowTable -> model -- ERROR - ShowShape _ -> model -- ERROR - ShowInput _ _ _ -> model -- ERROR + OpenShowShape _ -> modalMsg) model + SvgShapeHover id -> { model | svgShapeHover = id} + OpenDrawShape shape -> { model | state = DrawShape shape {x = 0, y = 0} } + UpdateMousePos mouse -> case model.state of + Standby -> model -- ERROR + ActiveModal _ -> model -- ERROR + DrawShape iShape mOld -> { model | state = DrawShape iShape mouse } + InputDrawShape -> case model.state of + Standby -> model -- ERROR + ActiveModal _ -> model -- ERROR DrawShape iShape mPos -> case iShape of Empty -> model -- ERROR - Circle x y r -> - if x=="" then { model | modal = DrawShape (Circle (String.fromInt mPos.x) - (String.fromInt mPos.y) r) mPos} + Circle x y r -> + if x=="" then { model | state = DrawShape (Circle (String.fromInt mPos.x) + (String.fromInt mPos.y) r ) mPos } else { model | saved = (Circle x y (abstand x y mPos))::model.saved - , modal = NoModal + , state = Standby } - Rectangle a b w h -> - if a=="" - then { model | modal = DrawShape + Rectangle a b w h -> + if a=="" + then { model | state = DrawShape (Rectangle (String.fromInt mPos.x) (String.fromInt mPos.y) w h) mPos } @@ -59,11 +55,11 @@ update msg model = ,y= b ,w= (abstand1D mPos.x (stringToInt a)) ,h= (abstand1D mPos.y (stringToInt b)) - } + } in { model | saved = (Rectangle coords.x coords.y coords.w coords.h)::model.saved - , modal = NoModal + , state = Standby } - Polygon pList -> { model | modal = DrawShape + Polygon pList -> { model | state = DrawShape (Polygon (( String.fromInt mPos.x , String.fromInt mPos.y )::pList @@ -71,10 +67,10 @@ update msg model = ) mPos } - SaveAndCloseModal -> { model | saved = ((getInputShapeFromModal model.modal)::model.saved) - , modal = NoModal + SaveAndCloseModal -> { model | saved = ((getInputShapeFromState model.state)::model.saved) + , state = Standby } - LoadShapes result -> + LoadShapes result -> case result of Ok "" -> { model | shapesLoadResult = Err (Http.BadBody "Empty result for LoadShapes") } Ok "LoadExample"-> model @@ -85,30 +81,29 @@ update msg model = } Err e -> { model | shapesLoadResult = result } ShapesLoaded result -> - case result of + case result of Ok shapes-> { model | saved = shapes, shapesLoadResult = Ok "shapes"} Err e -> { model | saved = [] , shapesLoadResult = (Err e )} LinkClicked urlRequest -> model UrlChanged url -> { model | url = url} - ,case msg of - OpenModal _ -> Cmd.none - OnInputModal _ _ -> Cmd.none - CloseModal -> Cmd.none + ,case msg of + ManageModal _ _ -> Cmd.none SvgShapeHover _ -> Cmd.none UpdateMousePos _ -> Cmd.none InputDrawShape -> Cmd.none - SaveAndCloseModal -> Cmd.none - ShapesLoaded _ -> Cmd.none - LoadShapes result -> + SaveAndCloseModal -> Cmd.none + ShapesLoaded _ -> Cmd.none + OpenDrawShape _ -> Cmd.none + LoadShapes result -> case result of Ok "LoadExample" -> - Http.get + 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 @@ -118,80 +113,79 @@ update msg model = } else Cmd.none Err e -> Cmd.none - LinkClicked urlReq -> + LinkClicked urlReq -> case urlReq of Browser.Internal url -> Nav.pushUrl model.key (Url.toString url) - Browser.External href -> Nav.load href + Browser.External href -> Nav.load href 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 - Check shape -> if (eq_String_Modal "ShowInput" model.modal) - then if (eq_String_Shape shape (getInputShapeFromModal model.modal)) - then { model | modal = ShowInput Empty "" "" } - else { model | modal = ShowInput (shapeDefaultConstruktor shape) "" "" } - else model - Input inputType value -> - case model.modal 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 + ShowTable -> model -- ERROR ShowShape _ -> model -- ERROR - DrawShape iShape mouse -> updateInput inputType value model "DrawShape" iShape "" "" mouse ShowInput iShape ix iy -> updateInput inputType value model "ShowInput" iShape ix iy {x = 0, y = 0} - InputPoint -> case model.modal of + InputPoint -> case (getModalFromState model.state) of NoModal -> model -- ERROR - ShowTable -> model -- ERROR - ShowShape _ -> model -- ERROR - DrawShape _ _ -> model -- ERROR? - ShowInput iShape ix iy -> - { model | modal = ShowInput (Polygon ((ix,iy)::(getPointListFromPolygon iShape))) "" "" } - AddShape -> { model | saved = (getInputShapeFromModal model.modal)::model.saved - , modal = ShowInput - (shapeDefaultConstruktor - (shapeNameToString - (getInputShapeFromModal model.modal) - ) - ) "" "" + 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) + DeleteShape id -> { model | saved = List.append (List.take (id-1) model.saved) (List.drop (id) model.saved) } - OpenShowInput -> if (eq_String_Modal "ShowInput" model.modal) - then { model | modal = NoModal } - else { model | modal = ShowInput Empty "" "" } - OpenShowTable -> if (eq_String_Modal "ShowTable" model.modal) - then { model | modal = NoModal } - else { model | modal = ShowTable } + 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 | modal = NoModal } - else { model | modal = ShowShape id} - OpenDrawShape shape -> { model | modal = DrawShape shape {x = 0, y = 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 | modal = modalInputConstruktor modalType (Circle value b c ) ix iy mouse} - Rectangle _ b c d -> { model | modal = modalInputConstruktor modalType (Rectangle value b c d) ix iy mouse} - Polygon _ -> { model | modal = modalInputConstruktor modalType iShape value iy mouse} + 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 | modal = modalInputConstruktor modalType (Circle a value c ) ix iy mouse} - Rectangle a _ c d -> { model | modal = modalInputConstruktor modalType (Rectangle a value c d) ix iy mouse} - Polygon _ -> { model | modal = modalInputConstruktor modalType iShape ix value mouse} + 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 | modal = modalInputConstruktor modalType (Circle a b value ) ix iy mouse} - Rectangle a b _ d -> { model | modal = modalInputConstruktor modalType (Rectangle a b value d) ix iy mouse} + 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 | modal = modalInputConstruktor modalType (Rectangle a b c value) ix iy mouse} + 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 diff --git a/src/Manager/ViewManager.elm b/src/Manager/ViewManager.elm index 1c05de775349651eb5d46cbdf94fc4700a2f4dc6..2f3b321dc1099bffa6504143c749aceca0fdd355 100644 --- a/src/Manager/ViewManager.elm +++ b/src/Manager/ViewManager.elm @@ -3,12 +3,13 @@ module Manager.ViewManager exposing (view) import Html exposing (Html, Attribute, div, text, node, button, a, h1, h2, label, figure, input, td, th, tr, table) import Html.Attributes exposing (class, style, href, rel, id, title, value) import Html.Events exposing (onClick, onInput) --- Svg +-- Svg import Svg exposing (Svg,svg, image,rect,circle,polygon,g) -import Svg.Attributes exposing (width,height, viewBox, version, xlinkHref, x, y, cx, cy, r) +import Svg.Attributes exposing (width,height, viewBox, version, xlinkHref, x, y, cx, cy, r) import Svg.Events -- Own import TypeHolder exposing (Model,Msg(..)) +import Manager.StateManager exposing (..) import Manager.ModalManager exposing (..) import Util.ShapeManager exposing (..) import Util.Util exposing (..) @@ -20,7 +21,7 @@ link attributes children = node "link" attributes children view : Model -> Html Msg view model = div [style "background-color" "#fff"] - (List.concat + (List.concat [[ link [ rel "stylesheet" -- Bluma , href "https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css" ] [] @@ -29,37 +30,36 @@ view model = ] [] , link [ rel "stylesheet" -- Icon für DropdownMenue , href "https://use.fontawesome.com/releases/v5.8.1/css/all.css" - ] [] - , viewHeader_Buttons model.modal + ] [] + , viewHeader_Buttons model.state , Html.section [class "section"] [] , viewImage model - , case model.shapesLoadResult of + , case model.shapesLoadResult of Ok s -> text "" Err e -> text ("Could not load shapes: "++(httpErrorToString e)) - ] - , case model.modal of - NoModal -> [] + ] + , case (getModalFromState model.state) of + NoModal -> [] ShowInput iShape ix iy -> [viewNewShapeInputModal iShape ix iy] ShowTable -> [viewTableModal model.saved ] ShowShape id -> [viewShapeModal id ] - DrawShape iShape _ -> [] -- Nothing need to do here - ] + ] ) --- Parts of the VIEW -viewHeader_Buttons : Modal -> Html Msg -viewHeader_Buttons modal = +-- Parts of the VIEW +viewHeader_Buttons : State -> Html Msg +viewHeader_Buttons state = div [] [ div [class "section"] [ h1 [class "title"] [text "Formen über der Informatik"] , h2 [class "subtitle"] [text "Eingeben, Anzeigen, Finden und Clicken"] ] - , div [ style "margin-left" "25px"] - [ button [ onClick (OpenModal OpenShowInput) + , div [ style "margin-left" "25px"] + [ 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 (OpenModal OpenShowTable) + , button [ onClick (ManageModal OpenShowTable "") , class "button is-success is-pulled-left is-size-6" , style "margin-right" "15px" , style "margin-bottom" "15px" @@ -77,9 +77,9 @@ viewHeader_Buttons modal = , a [class "dropdown-item" , href "#Türen" ] [text "Lade Türen"] - ] - , if (eq_String_Modal "DrawShape" modal) - then let iShape = getInputShapeFromModal modal + ] + , if (eq_String_State "DrawShape" state) + then let iShape = getInputShapeFromState state in if (eq_String_Shape "Polygon" iShape) then viewDropDownMenue "Polygon wird gezeichnet" True "angle-down" [] [ a [class "dropdown-item" @@ -87,49 +87,47 @@ viewHeader_Buttons modal = , href "" ] [text "Speichern"] , a [class "dropdown-item" - , onClick CloseModal + , onClick (ManageModal CloseModal "") , href "" ] [text "Abbrechen"] ] - else viewDropDownMenue + else viewDropDownMenue (shapeNameStringToGerman (shapeNameToString - (getInputShapeFromModal modal))++" zeichnen: abbrechen ") - False "times" [onClick CloseModal] [] + (getInputShapeFromState state))++" zeichnen: abbrechen ") + False "times" [onClick (ManageModal CloseModal "")] [] else viewDropDownMenue "Neue Form zeichnen" True "angle-down" [] [ a [class "dropdown-item" - , onClick (OpenModal (OpenDrawShape (Circle "" "" ""))) + , onClick (OpenDrawShape (Circle "" "" "")) , href "" ] [text "Kreis"] , a [class "dropdown-item" - , onClick (OpenModal (OpenDrawShape (Rectangle "" "" "" ""))) + , onClick (OpenDrawShape (Rectangle "" "" "" "")) , href "" ] [text "Rechteck"] , a [class "dropdown-item" - , onClick (OpenModal (OpenDrawShape (Polygon []))) + , onClick (OpenDrawShape (Polygon [])) , href "" ] [text "Vieleck"] - ] - ] + ] + ] ] viewImage : Model -> Html Msg -viewImage model = +viewImage model = div [ style "margin-left" "25px", style "margin-top" "15px", class "container"] - [ figure [ class "image"] + [ figure [ class "image"] [ svg [ width "100%", viewBox "0 0 800 600", version "1.1"] ( List.concat [[image [ width "800", height "600" , xlinkHref "http://www.informatik.uni-halle.de/im/1285058520_1381_00_800.jpg" ] [] - ] + ] , viewSvgShapes model.saved model.svgShapeHover 1 - , case model.modal of - NoModal -> [] - ShowTable -> [] - ShowShape _ -> [] - ShowInput _ _ _ -> [] - DrawShape iShape mPos -> - [ case iShape of + , case model.state of + Standby -> [] + ActiveModal _ -> [] + DrawShape iShape mPos -> + [ case iShape of Empty -> rect [] [] Circle x y rad -> if x=="" then circle [cx (String.fromInt mPos.x) @@ -144,7 +142,7 @@ viewImage model = ,y= b ,w= (abstand1D mPos.x (stringToInt a)) ,h= (abstand1D mPos.y (stringToInt b)) - } + } in rect [ x coords.x , y coords.y , width coords.w @@ -161,8 +159,8 @@ viewImage model = , Svg.Attributes.y2 (String.fromInt mPos.y) , Svg.Attributes.style "stroke:#000;stroke-width:2" ] [] - p::ps -> polygon [ Svg.Attributes.points - (shapeCoordsToHtmlCoords + p::ps -> polygon [ Svg.Attributes.points + (shapeCoordsToHtmlCoords (Polygon (( String.fromInt mPos.x , String.fromInt mPos.y )::pList @@ -171,7 +169,7 @@ viewImage model = ) ] [] , rect [ x "0", y "0", width "800", height "600" - , Svg.Attributes.style + , Svg.Attributes.style "fill:blue;stroke:pink;stroke-width:5;fill-opacity:0.1;stroke-opacity:0.9" , onMouseMove UpdateMousePos , Svg.Events.onClick InputDrawShape @@ -179,34 +177,34 @@ viewImage model = ] ] ) - + ] ] viewNewShapeInputModal : Shape -> String -> String -> Html Msg -viewNewShapeInputModal iShape ix iy = +viewNewShapeInputModal iShape ix iy = div [class "modal is-active"] [ div [class "modal-background"] [] , div [class "modal-card"] [ modalHeader "Neue Form hinzufügen" , Html.section [class "modal-card-body"] - (List.append [ viewDropDownMenue (if (shapeNameToString iShape)=="" + (List.append [ viewDropDownMenue (if (shapeNameToString iShape)=="" then "Form auswählen" else (shapeNameStringToGerman(shapeNameToString iShape)) ) False "angle-down" [] [ a [ class "dropdown-item" - , onClick (OpenModal (Check "Circle")) + , onClick (ManageModal (Check "Circle") "") , href "" ] [text "Kreis"] , a [ class "dropdown-item" - , onClick (OpenModal (Check "Rectangle")) + , onClick (ManageModal (Check "Rectangle") "") , href "" ] [text "Rechteck"] , a [ class "dropdown-item" - , onClick (OpenModal (Check "Polygon" )) + , onClick (ManageModal (Check "Polygon" ) "") , href "" ] [text "Vieleck"] ] - , if (shapeNameToString iShape)=="" + , if (shapeNameToString iShape)=="" then div [style "margin-top" "120px"] [] else div [] [] ] @@ -216,113 +214,113 @@ viewNewShapeInputModal iShape ix iy = [ div [] [ label [class "label"] [text "X-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "X-Position" - , value a, onInput (OnInputModal (Input '1' "")) ] [] ] + , value a, onInput (ManageModal (Input '1' "")) ] [] ] , label [class "label"] [text "Y-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "Y-Position" - , value b, onInput (OnInputModal (Input '2' "")) ] [] ] + , value b, onInput (ManageModal (Input '2' "")) ] [] ] , label [class "label"] [text "Radius"] , label [] [ input [class "input", Html.Attributes.placeholder "Radius" - , value c, onInput (OnInputModal (Input '3' "")) ] [] ] + , value c, onInput (ManageModal (Input '3' "")) ] [] ] ] ] Rectangle a b c d -> [ div [] [ label [class "label"] [text "X1-Position-"] , label [] [ input [class "input", Html.Attributes.placeholder "X1-Position" - , value a, onInput (OnInputModal (Input '1' "")) ] [] ] + , value a, onInput (ManageModal (Input '1' "")) ] [] ] , label [class "label"] [text "Y1-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "Y1-Position" - , value b, onInput (OnInputModal (Input '2' "")) ] [] ] + , value b, onInput (ManageModal (Input '2' "")) ] [] ] , label [class "label"] [text "X2-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "X2-Position" - , value c, onInput (OnInputModal (Input '3' "")) ] [] ] + , value c, onInput (ManageModal (Input '3' "")) ] [] ] , label [class "label"] [text "Y2-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "Y2-Position" - , value d, onInput (OnInputModal (Input '4' "")) ] [] ] + , value d, onInput (ManageModal (Input '4' "")) ] [] ] ] ] Polygon _ -> [ div [] [ label [class "label"] [text "X-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "X-Position" - , value ix, onInput (OnInputModal (Input '1' "")) ] [] ] + , value ix, onInput (ManageModal (Input '1' "")) ] [] ] , label [class "label"] [text "Y-Position"] , label [] [ input [class "input", Html.Attributes.placeholder "Y-Position" - , value iy, onInput (OnInputModal (Input '2' "")) ] [] ] + , value iy, onInput (ManageModal (Input '2' "")) ] [] ] , label [class "label"] [text "Eingegebene Vieleck Koordinaten: "] , text (shapeCoordsToString iShape) - , div [] [ button [ onClick (OpenModal InputPoint) - , class "button is-success is-size-7" + , div [] [ button [ onClick (ManageModal InputPoint "") + , class "button is-success is-size-7" , style "margin-top" "10px" ] [ text "Punkt hinzufügen" ] - ] + ] ] - ] + ] ) ) - , Html.footer [class "modal-card-foot"] + , Html.footer [class "modal-card-foot"] [ button [ class "button is-success" - , onClick (OpenModal AddShape) + , onClick (ManageModal AddShape "") ] [text "Form hinzufügen"] , button [ class "button" - , onClick CloseModal + , onClick (ManageModal CloseModal "") ][text "Schließen"] ] - ] + ] ] viewTableModal : List (Shape) -> Html Msg -viewTableModal modelSaved = - div [class "modal is-active"] +viewTableModal modelSaved = + div [class "modal is-active"] [ div [class "modal-background"] [] , div [class "modal-card"] [ modalHeader "Tabelle mit Formen" , Html.section [class "modal-card-body"] - ( if List.length modelSaved == 0 + ( if List.length modelSaved == 0 then [ div [] [text "Es sind keine Formen vorhanden!"] ] - else [ table [class "table"] - ( List.append [ tr [] + else [ table [class "table"] + ( List.append [ tr [] [ th [] [text "ID"] , th [] [text "Form"] , th [] [text "Koordinaten"] , th [] [text ""] - ] - ] - ( writeShapeToTable modelSaved 1) + ] + ] + ( writeShapeToTable modelSaved 1) ) ] - ) - , Html.footer [class "modal-card-foot"] + ) + , Html.footer [class "modal-card-foot"] [ button [ class "button" - , onClick CloseModal + , onClick (ManageModal CloseModal "") ][text "Schließen"] - ] + ] ] - ] + ] viewShapeModal : Int -> Html Msg -viewShapeModal id = - if id == 0 then div [] [] +viewShapeModal id = + if id <= 0 then div [] [] else div [class "modal is-active"] [ div [class "modal-background"] [] , div [class "modal-card"] [ modalHeader ("Form "++String.fromInt id) , Html.section [ class "modal-card-body"] [ text ("Form "++String.fromInt id++" wurde gefunden!")] - , Html.footer [class "modal-card-foot"] + , Html.footer [class "modal-card-foot"] [ button [ class "button" - , onClick CloseModal + , onClick (ManageModal CloseModal "") ][text "Schließen"] - ] + ] ] ] -- Helping Methods for the VIEW viewDropDownMenue : String -> Bool -> String -> List(Attribute Msg) -> List(Svg Msg) -> Html Msg viewDropDownMenue header isGreen iconType attributes dropDownItems = - div (List.append + div (List.append [ class "dropdown is-hoverable" , style "margin-right" "15px" , style "margin-bottom" "15px" ] attributes - ) + ) [ div [ class "dropdown-trigger"] [ button [ class ("button "++(if isGreen then "is-success" else "") ++" aria-haspopup=true aria-controls=dropdown-menu") @@ -338,7 +336,7 @@ viewDropDownMenue header isGreen iconType attributes dropDownItems = [ div [ class "dropdown-content"] dropDownItems ] ] viewSvgShapes : List Shape -> Int -> Int -> List (Svg Msg) -viewSvgShapes shapes activeShape id = +viewSvgShapes shapes activeShape id = case shapes of [] -> [] x::xs -> ( case x of @@ -351,17 +349,17 @@ viewSvgShapes shapes activeShape id = ++svgShapeStyle activeShape id) [] )::viewSvgShapes xs activeShape (id+1) svgShapeStyle : Int -> Int -> List( Svg.Attribute Msg) -svgShapeStyle activeShape id = +svgShapeStyle activeShape id = [ Svg.Attributes.fill "white" , Svg.Attributes.fillOpacity (if activeShape==id then "0.5" else "0.0") , Svg.Attributes.stroke "red" , Svg.Attributes.strokeWidth "3" , Svg.Events.onMouseOver (SvgShapeHover id) - , Svg.Events.onMouseOut (SvgShapeHover 0) - , Svg.Events.onClick (OpenModal (OpenShowShape id)) - ] + , Svg.Events.onMouseOut (SvgShapeHover 0) + , Svg.Events.onClick (ManageModal (OpenShowShape id) "") + ] writeShapeToTable : List ( Shape ) -> Int -> List ( Html Msg ) -writeShapeToTable shapeList id = +writeShapeToTable shapeList id = case shapeList of [] -> [] x::xs -> tr [Html.Attributes.id ("Shape"++String.fromInt id)] @@ -369,12 +367,12 @@ writeShapeToTable shapeList id = , td [] [text (shapeNameStringToGerman(shapeNameToString x))] , td [] [text (shapeCoordsToString x)] , td [] [button [ class "button is-danger is-size-7" - , onClick (OpenModal (DeleteShape id))] [ text "Form löschen" ] ] + , onClick (ManageModal (DeleteShape id) "")] [ text "Form löschen" ] ] ] :: (writeShapeToTable xs (id+1)) -- Modal Elements modalHeader : String -> Html Msg modalHeader title = Html.header [class "modal-card-head"] [ Html.p [class "modal-card-title" ] [text title] - , button [class "delete aria-label=close", onClick CloseModal] [] + , button [class "delete aria-label=close", onClick (ManageModal CloseModal "")] [] ] \ No newline at end of file diff --git a/src/ShapePicture_Editor.elm b/src/ShapePicture_Editor.elm index 61040b95072524d019e5c2224ebee64364f348b7..334683e7f4d70631bc22f498e54c707196c9a1dd 100644 --- a/src/ShapePicture_Editor.elm +++ b/src/ShapePicture_Editor.elm @@ -10,29 +10,29 @@ import Url import TypeHolder exposing (Model, Msg(..)) import Manager.UpdateManager exposing (update) import Manager.ViewManager exposing (view) -import Manager.ModalManager as MM +import Manager.StateManager as StM main = Browser.application - { init = init - , subscriptions = subscriptions + { init = init + , subscriptions = subscriptions , update = update - , view = documentView + , view = documentView , onUrlChange = UrlChanged , onUrlRequest = LinkClicked - } + } -- INIT init : () -> Url.Url -> Nav.Key-> (Model, Cmd Msg) -init _ url key = - ( Model - MM.NoModal - [] - 0 - (Ok " Init") - url - key +init _ url key = + ( Model + StM.Standby + [] + 0 + (Ok " Init") + url + key , Cmd.none - ) + ) -- SUBSCRIPTIONS subscriptions : Model -> Sub Msg subscriptions model = Sub.none diff --git a/src/TypeHolder.elm b/src/TypeHolder.elm index e15503b8505c786bb3c12c29de83a3b9ed1b0737..f665d5bc922d6780bfa184a0a7d8da190cbb9755 100644 --- a/src/TypeHolder.elm +++ b/src/TypeHolder.elm @@ -7,26 +7,26 @@ import Browser.Navigation as Nav -- Url import Url -- Own +import Manager.StateManager exposing (State) import Manager.ModalManager exposing (Modal, ModalMsg) import Util.ShapeManager exposing (Shape) import Util.Util exposing (MousePosition) type alias Model = - { modal : Modal + { state : State , saved : List (Shape) , svgShapeHover : Int - , shapesLoadResult : (Result Http.Error String) + , shapesLoadResult : (Result Http.Error String) , url : Url.Url , key : Nav.Key - } + } type Msg -- Modal - = OpenModal ModalMsg - | OnInputModal ModalMsg String - | CloseModal - -- svg + = ManageModal ModalMsg String + -- svg | SvgShapeHover Int - -- for drawing shapes - needs refactor + -- for drawing shapes + | OpenDrawShape Shape | UpdateMousePos MousePosition | InputDrawShape | SaveAndCloseModal @@ -35,4 +35,5 @@ type Msg | ShapesLoaded (Result Http.Error (List Shape)) -- Url | LinkClicked Browser.UrlRequest - | UrlChanged Url.Url \ No newline at end of file + | UrlChanged Url.Url + diff --git a/src/Util/ShapeManager.elm b/src/Util/ShapeManager.elm index ce8606864b7a627a8a7c9ebe8b9e0e201bd28b3e..82e8b1629312b85115ccd1c9a817924806427abe 100644 --- a/src/Util/ShapeManager.elm +++ b/src/Util/ShapeManager.elm @@ -2,38 +2,38 @@ module Util.ShapeManager exposing (..) import Json.Decode as JD -type Shape +type Shape = Empty | Circle String String String | Rectangle String String String String - | Polygon (List ( String, String ) ) + | Polygon (List ( String, String ) ) -- Shape Construktors shapeDefaultConstruktor : String -> Shape shapeDefaultConstruktor shape = - case shape of + case shape of "Circle" -> Circle "" "" "" "Rectangle"-> Rectangle "" "" "" "" "Polygon" -> Polygon [] _ -> Empty shapesDecoder : String -> List Shape -shapesDecoder s = +shapesDecoder s = if (String.contains "shapes" s) then [] else List.concat - [ if (String.contains "circle" s) - then [ Circle (shapesDecoderList "circle" "x" s) + [ if (String.contains "circle" s) + then [ Circle (shapesDecoderList "circle" "x" s) (shapesDecoderList "circle" "y" s) (shapesDecoderList "circle" "r" s) - ] + ] else [] - , if (String.contains "rectangle" s) + , if (String.contains "rectangle" s) then [ Rectangle (shapesDecoderList "rectangle" "x" s) (shapesDecoderList "rectangle" "y" s) (shapesDecoderList "rectangle" "width" s) (shapesDecoderList "rectangle" "height" s) - ] + ] else [] , if (String.contains "polygon" s) then [ Polygon (List.map2 Tuple.pair @@ -47,24 +47,24 @@ shapesDecoder s = eq_String_Shape : String -> Shape -> Bool eq_String_Shape string shape = string==(shapeNameToString shape) -- Get Methods : Parameter of Shapes -getPointListFromPolygon : Shape -> List (String,String) +getPointListFromPolygon : Shape -> List (String,String) getPointListFromPolygon shape = - case shape of - Empty -> [] - Circle _ _ _ -> [] - Rectangle _ _ _ _ -> [] + case shape of + Empty -> [] + Circle _ _ _ -> [] + Rectangle _ _ _ _ -> [] Polygon pointList -> pointList -- Transform Shape to other Types shapeNameToString : Shape -> String shapeNameToString shape = - case shape of + case shape of Empty -> "" Circle _ _ _ -> "Circle" Rectangle _ _ _ _ -> "Rectangle" Polygon _ -> "Polygon" shapeNameStringToGerman : String -> String shapeNameStringToGerman shape = - case shape of + case shape of "Circle" -> "Kreis" "Rectangle"-> "Rechteck" "Polygon" -> "Vieleck" @@ -75,25 +75,25 @@ shapeCoordsToString shape = Empty -> "" Circle x_center y_center radius -> x_center++","++y_center++","++radius Rectangle x_left y_upper x_right y_lower -> x_left++","++y_upper++","++x_right++","++y_lower - Polygon pointList -> + Polygon pointList -> case pointList of [] -> "" (x,y)::xs -> "("++x++","++y++") "++(shapeCoordsToString (Polygon xs)) -shapeCoordsToHtmlCoords : Shape -> String -shapeCoordsToHtmlCoords shape = - case shape of +shapeCoordsToHtmlCoords : Shape -> String +shapeCoordsToHtmlCoords shape = + case shape of Empty -> "" Circle _ _ _ -> shapeCoordsToString shape Rectangle _ _ _ _ -> shapeCoordsToString shape Polygon _ -> String.left ((String.length (shapeCoordsToHtmlCoordsHelper shape))-1) (shapeCoordsToHtmlCoordsHelper shape) -shapeCoordsToHtmlCoordsHelper : Shape -> String +shapeCoordsToHtmlCoordsHelper : Shape -> String shapeCoordsToHtmlCoordsHelper shape = - case shape of + case shape of Empty -> "" Circle _ _ _ -> shapeCoordsToString shape Rectangle _ _ _ _ -> shapeCoordsToString shape - Polygon pointList -> + Polygon pointList -> case pointList of [] -> "" (x,y)::xs -> x++","++y++","++(shapeCoordsToHtmlCoordsHelper (Polygon xs)) @@ -106,9 +106,9 @@ rectListDecoder = JD.field "rectangle" (JD.list (JD.map4 (JD.field "width" JD.string) (JD.field "height" JD.string) ) - ) + ) shapesDecoderList : String -> String -> String -> String -shapesDecoderList shape var s = +shapesDecoderList shape var s = let res = JD.decodeString (JD.field shape (JD.list (JD.field var JD.string))) s @@ -123,9 +123,9 @@ shapesDecoderListPoly var s = let res = JD.decodeString (JD.field "polygon" (JD.list (JD.field "points" (JD.list (JD.field var JD.string))))) s - in case res of + in case res of Ok list -> case list of [] -> [] x::[] -> x x::xs -> x++["This List is too long"] - Err e -> ["ERROR"] \ No newline at end of file + Err e -> ["ERROR"] \ No newline at end of file