web


git clone https://radroots.dev/git/web.git
Log | Files | Refs | Submodules | README | LICENSE

commit 36ab4b74e667a8bfb479b7e836b4413f748b3499
parent 13d415fcafa2bf21749669235fa1146720368297
Author: triesap <137732411+triesap@users.noreply.github.com>
Date:   Wed, 11 Sep 2024 16:08:33 +0000

Add `models/trade-product/add` quantity field, edit models routes, edit lib utils

Diffstat:
Rsrc/lib/utils/models.ts -> src/lib/utils/location_gcs.ts | 0
Msrc/lib/utils/trade_product.ts | 39+++++----------------------------------
Msrc/routes/(app)/models/location-gcs/+page.svelte | 2+-
Msrc/routes/(app)/models/trade-product/add/+page.svelte | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------
4 files changed, 119 insertions(+), 62 deletions(-)

diff --git a/src/lib/utils/models.ts b/src/lib/utils/location_gcs.ts diff --git a/src/lib/utils/trade_product.ts b/src/lib/utils/trade_product.ts @@ -1,32 +1,9 @@ -import { goto } from "$app/navigation"; -import { lc } from "$lib/client"; -import { parse_trade_product_form_keys, trade_product_form_fields, trade_product_form_vals, type LocationGcs, type TradeProductFormFields } from "@radroots/client"; +import { parse_trade_product_form_keys, trade_product_form_fields, trade_product_form_vals, type TradeProductFormFields } from "@radroots/client"; import { kv } from "@radroots/svelte-lib"; -export const trade_product_submit_preview = async (kv_pref: string): Promise<{ - trade_product_fields: TradeProductFormFields; - location_gcs: LocationGcs -} | undefined> => { +export const trade_product_kv_vals = async (kv_pref: string): Promise<TradeProductFormFields | undefined> => { try { - const location_gcs_id = await kv.get(`${kv_pref}-location_gcs_id`) - if (!location_gcs_id || typeof location_gcs_id !== `string`) { - await lc.dialog.alert(`The product location is missing.`); - return; - } - - const location_gcs_res = await lc.db.location_gcs_get({ - id: location_gcs_id, - }); - - if (typeof location_gcs_res === `string`) { - await lc.dialog.alert( - `There was an error finding the selected location`, - ); - await goto(`/`); - return; - } - - const trade_product_fields = { + const vals = { ...trade_product_form_vals } @@ -38,17 +15,11 @@ export const trade_product_submit_preview = async (kv_pref: string): Promise<{ const field_id = `${kv_pref}-${field_k}` let field_val = ``; field_val = await kv.get(field_id); - if (field_val) trade_product_fields[field_k] = field_val; + if (field_val) vals[field_k] = field_val; //@todo add validation } - - trade_product_fields.price_qty_unit = trade_product_fields.qty_unit; - - return { - trade_product_fields, - location_gcs: location_gcs_res[0] - }; + return vals; } catch (e) { console.log(`(error) trade_product_submit_preview `, e); } diff --git a/src/routes/(app)/models/location-gcs/+page.svelte b/src/routes/(app)/models/location-gcs/+page.svelte @@ -3,7 +3,7 @@ import LayoutTrellis from "$lib/components/layout-trellis.svelte"; import LayoutView from "$lib/components/layout-view.svelte"; import { app_tabs_visible } from "$lib/stores"; - import { location_gcs_add } from "$lib/utils/models"; + import { location_gcs_add } from "$lib/utils/location_gcs"; import { type LocationGcs } from "@radroots/client"; import { Nav, Trellis } from "@radroots/svelte-lib"; import { onMount } from "svelte"; diff --git a/src/routes/(app)/models/trade-product/add/+page.svelte b/src/routes/(app)/models/trade-product/add/+page.svelte @@ -1,19 +1,26 @@ <script lang="ts"> - import ButtonSubmit from "$lib/components/button-submit.svelte"; + import { goto } from "$app/navigation"; + import { lc } from "$lib/client"; import LayoutTrellisLine from "$lib/components/layout-trellis-line.svelte"; import LayoutTrellis from "$lib/components/layout-trellis.svelte"; import LayoutView from "$lib/components/layout-view.svelte"; + import { location_gcs_add } from "$lib/utils/location_gcs"; import { trade_product_kv_init, - trade_product_submit_preview, + trade_product_kv_vals, } from "$lib/utils/trade_product"; - import { mass_units, trade_product_form_fields } from "@radroots/client"; + import { + mass_units, + trade_product_form_fields, + type LocationGcs, + } from "@radroots/client"; import { fmt_id, InputForm, InputSelect, kv, Nav, + sleep, t, } from "@radroots/svelte-lib"; import { @@ -28,13 +35,16 @@ const trade_key_default: TradeKey = `coffee`; let loading_submit = false; + let loading_location = false; - let sel_key = ``; + let sel_key: string = trade_key_default; let show_sel_key_other = false; + let sel_location_gcs_id = ``; + let ls_location_gcs: LocationGcs[] = []; + let sel_price_qty_amt = ``; let sel_price_qty_unit = ``; - let show_sel_price_qty_amt_other = false; $: sel_key_parsed = parse_trade_key(sel_key); @@ -46,15 +56,13 @@ ? fmt_trade_quantity_val(trade_quantities[sel_key_parsed][0]) : fmt_trade_quantity_val(trade_quantities[trade_key_default][0]); + $: { + if (ls_location_gcs.length && !sel_location_gcs_id) { + sel_location_gcs_id = ls_location_gcs[0].id; + } + } onMount(async () => { try { - sel_key = trade_key_default; - /* - sel_key = trade_keys[0]; - sel_price_qty_amt = sel_key_parsed - ? fmt_trade_quantity_val(trade_quantities[sel_key_parsed][0]) - : ``; - */ } catch (e) { } finally { } @@ -62,6 +70,7 @@ onMount(async () => { try { + await fetch_models_location_gcs(); } catch (e) { } finally { } @@ -100,13 +109,55 @@ } }; + const fetch_models_location_gcs = async (): Promise<void> => { + try { + const res = await lc.db.location_gcs_get({ + list: [`all`], + }); + if (typeof res !== `string`) ls_location_gcs = res; + } catch (e) { + console.log(`(error) fetch_models_location_gcs `, e); + } + }; + + const add_model_location_gcs = async (): Promise<void> => { + try { + loading_location = true; + await location_gcs_add(); + await fetch_models_location_gcs(); + } catch (e) { + console.log(`(error) add_model_location_gcs `, e); + } finally { + loading_location = false; + } + }; + const submit = async (): Promise<void> => { try { loading_submit = true; - const res = await trade_product_submit_preview(fmt_id()); + const location_gcs_id = await kv.get(fmt_id(`location_gcs_id`)); + if (!location_gcs_id || typeof location_gcs_id !== `string`) { + await lc.dialog.alert(`The product location is missing.`); + return; + } + + const location_gcs_res = await lc.db.location_gcs_get({ + id: location_gcs_id, + }); - console.log(JSON.stringify(res, null, 4), `res`); + if (typeof location_gcs_res === `string`) { + await lc.dialog.alert( + `There was an error finding the selected location`, + ); + await goto(`/`); + return; + } + + const vals = await trade_product_kv_vals(fmt_id()); + console.log(JSON.stringify(vals, null, 4), `vals`); + + await sleep(1000); } catch (e) { console.log(`(error) submit `, e); } finally { @@ -182,6 +233,51 @@ <LayoutTrellisLine basis={{ label: { + value: `Location`, + }, + }} + > + <InputSelect + bind:value={sel_location_gcs_id} + basis={{ + id: fmt_id(`location_gcs_id`), + sync: true, + loading: loading_location, + options: ls_location_gcs.length + ? [ + ...ls_location_gcs.map((i) => ({ + value: i.id, + label: `${i.label}`, + })), + { + value: `add-new`, + label: `${$t(`common.add_new_location`)}`, + }, + ] + : [ + { + value: ``, + disabled: true, + selected: true, + label: `${$t(`common.no_locations_saved`)}`, + }, + { + value: `add-new`, + label: `${$t(`common.add_new_location`)}`, + }, + ], + callback: async (val) => { + if (val === `add-new`) { + sel_location_gcs_id = ``; + await add_model_location_gcs(); + } + }, + }} + /> + </LayoutTrellisLine> + <LayoutTrellisLine + basis={{ + label: { value: `Quantity`, }, notify: show_sel_price_qty_amt_other @@ -249,7 +345,7 @@ options: [ ...ls_trade_product_quantities.map((i) => ({ value: `${i.qty_amt}-${i.qty_unit}`, - label: `${i.qty_amt} ${$t(`trade.quantity.mass_unit.${i.qty_unit}_ab`, { default: i.qty_unit })}${i.label ? ` ${i.label}` : ``}`, + label: `${i.qty_amt} ${i.qty_unit}${i.label ? ` ${i.label}` : ``}`, })), { value: `other`, @@ -266,17 +362,6 @@ {/if} </div> </LayoutTrellisLine> - <div class={`flex flex-row w-full pt-4 justify-end items-center`}> - <ButtonSubmit - basis={{ - loading: loading_submit, - label: `preview`, - callback: async () => { - await submit(); - }, - }} - /> - </div> </LayoutTrellis> </LayoutView> <Nav @@ -292,12 +377,13 @@ label: `Add Product`, }, option: { + loading: loading_submit, label: { value: `Preview`, classes: `text-layer-1-glyph-hl tap-scale`, }, callback: async () => { - alert(`@todo!`); + await submit(); }, }, }}