Improve entry flow a little

This commit is contained in:
Paul Brinkmeier 2024-05-14 16:43:04 +02:00
parent 63ffd98ae8
commit 91157f970d
3 changed files with 45 additions and 11 deletions

View File

@ -133,8 +133,11 @@ type alias Context =
type alias Globals = type alias Globals =
{ locations : List Location { locations : List Location
, defaultLocation : Location
, groups : List Group , groups : List Group
, defaultGroup : Group
, taxGroups : List TaxGroup , taxGroups : List TaxGroup
, defaultTaxGroup : TaxGroup
} }
type State type State
@ -158,7 +161,7 @@ type Msg
= SetSearchTerm String = SetSearchTerm String
| SubmitSearch | SubmitSearch
| ReceiveSearchResults (Result Http.Error (List SearchResult)) | ReceiveSearchResults (Result Http.Error (List SearchResult))
| GotoItemEditor SearchResult | GotoItemEditor IEInit
| SetBarcode String | SetBarcode String
| SetName String | SetName String
| SetSalesUnits String | SetSalesUnits String
@ -169,6 +172,10 @@ type Msg
| SetLocation String | SetLocation String
| SetTaxGroup String | SetTaxGroup String
type IEInit
= IEInitBarcode String
| IEInitSearchResult SearchResult
-- Update logic: State machine etc. -- Update logic: State machine etc.
update msg { globals, state } = update msg { globals, state } =
@ -190,7 +197,21 @@ updateState msg globals state = case state of
) )
ReceiveSearchResults (Ok searchResults) -> ReceiveSearchResults (Ok searchResults) ->
(ItemSearch { model | searchResults = searchResults }, Cmd.none) (ItemSearch { model | searchResults = searchResults }, Cmd.none)
GotoItemEditor searchResult -> GotoItemEditor (IEInitBarcode barcode) ->
( ItemEditor
{ barcode = barcode
, name = ""
, calculator = Calculator.init 0
, netUnitPrice = NumberInput.fromFloat 0
, grossUnitPrice = NumberInput.fromFloat 0
, salesUnits = NumberInput.fromInt 0
, group = Select.init (.id >> String.fromInt) (.name) globals.defaultGroup globals.groups
, location = Select.init (.id >> String.fromInt) (.name) globals.defaultLocation globals.locations
, taxGroup = Select.init (.id >> String.fromInt) (.description) globals.defaultTaxGroup globals.taxGroups
}
, Cmd.none
)
GotoItemEditor (IEInitSearchResult searchResult) ->
case find (\tg -> tg.id == searchResult.taxGroupId) globals.taxGroups of case find (\tg -> tg.id == searchResult.taxGroupId) globals.taxGroups of
Nothing -> (state, Cmd.none) Nothing -> (state, Cmd.none)
Just taxGroup -> Just taxGroup ->
@ -245,14 +266,21 @@ suggestedGrossPrice netPrice percentage =
view { globals, state } = case state of view { globals, state } = case state of
ItemSearch model -> ItemSearch model ->
fieldset [] div []
[ legend [] [ text "Vorlage für Auftrag wählen" ] [ div []
, Html.form [ onSubmit SubmitSearch ] [ if model.searchTerm == ""
[ div [ class "form-input" ] then button [ disabled True ] [ text "Neuer Artikel" ]
[ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ] else button [ onClick <| GotoItemEditor <| IEInitBarcode model.searchTerm ] [ text <| "Neuer Artikel mit Barcode " ++ model.searchTerm ]
, input [ onInput SetSearchTerm, value model.searchTerm, id "search-term" ] [] ]
, fieldset []
[ legend [] [ text "Vorlage für Auftrag wählen" ]
, Html.form [ onSubmit SubmitSearch ]
[ div [ class "form-input" ]
[ label [ for "search-term", title "Barcode oder Name" ] [ text "Suchbegriff" ]
, input [ onInput SetSearchTerm, value model.searchTerm, id "search-term" ] []
]
, table [] <| searchResultHeaders :: List.map viewSearchResult model.searchResults
] ]
, table [] <| searchResultHeaders :: List.map viewSearchResult model.searchResults
] ]
] ]
ItemEditor model -> ItemEditor model ->
@ -385,7 +413,7 @@ viewSearchResult model =
, td [] [ text model.locationName ] , td [] [ text model.locationName ]
, td [] [ text <| showBool model.available ] , td [] [ text <| showBool model.available ]
, td [] , td []
[ Html.form [ onSubmit <| GotoItemEditor model ] [ Html.form [ onSubmit <| GotoItemEditor <| IEInitSearchResult model ]
[ button [] [ text "Als Vorlage verwenden" ] [ button [] [ text "Als Vorlage verwenden" ]
] ]
] ]

View File

@ -94,10 +94,13 @@ def new_order():
with db.run_query("entry/get_tax_groups.sql") as cursor: with db.run_query("entry/get_tax_groups.sql") as cursor:
tax_groups = cursor.fetchall() tax_groups = cursor.fetchall()
selected_location = current_user.data.location
return render_template( return render_template(
"entry/new-order.html", "entry/new-order.html",
groups=groups, groups=groups,
locations=locations, locations=locations,
default_location=next(location for location in locations if location["id"] == selected_location["location_id"]) if selected_location is not None else locations[0],
tax_groups=tax_groups tax_groups=tax_groups
) )

View File

@ -8,8 +8,11 @@ Elm.Entry.init({
node: document.querySelector('.entry-app'), node: document.querySelector('.entry-app'),
flags: { flags: {
locations: {{ to_json(locations) | safe }}, locations: {{ to_json(locations) | safe }},
defaultLocation: {{ to_json(default_location) | safe }},
groups: {{ to_json(groups) | safe }}, groups: {{ to_json(groups) | safe }},
taxGroups: {{ to_json(tax_groups) | safe }} defaultGroup: {{ to_json(groups[0]) | safe }},
taxGroups: {{ to_json(tax_groups) | safe }},
defaultTaxGroup: {{ to_json(tax_groups[0]) | safe }},
} }
}); });
</script> </script>