save "create sync group" table in database
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
{{/* TODO: make the save button disabled based on an api call */}}
|
||||
{{/* .Identity.Account.AccountID, .Accounts */}}
|
||||
|
||||
{{- $dot := or .dot . -}}
|
||||
|
||||
{{- $acctID := $dot.Identity.Account.AccountID }}
|
||||
|
||||
{{- $orderIndex := or $dot.OrderIndex (parseInt $dot.PathParams.orderIndex) -}}
|
||||
{{- $entry := $dot.Accounts.GetSyncGroupListingDraft $acctID $orderIndex }}
|
||||
{{- $selectedShopPlatform := $entry.Platform }}
|
||||
{{- $selectedShopID := $entry.ShopID }}
|
||||
{{- $selectedListingID := $entry.ListingID }}
|
||||
|
||||
|
||||
<tr _="
|
||||
init
|
||||
set @data-filled-out to false
|
||||
|
||||
def setFilledOut(val)
|
||||
set @data-filled-out to val
|
||||
send rowUpdated() to closest <tbody/>
|
||||
end
|
||||
|
||||
on setListing(listing)
|
||||
call setFilledOut(true)
|
||||
|
||||
|
||||
on resetListing
|
||||
call setFilledOut(false)
|
||||
"
|
||||
>
|
||||
<td>
|
||||
{{- $shops := $dot.Accounts.GetShops $acctID -}}
|
||||
<select
|
||||
class="min-w-fit cursor-pointer"
|
||||
hx-put="/accounts/{{$acctID}}/inventory/sync-groups/draft/listings/{{$orderIndex}}/shop"
|
||||
hx-vals='js:{
|
||||
platform: event.target.value.replace(/-[^ ]*/, ""),
|
||||
"shop-id": event.target.value.replace(/[^ ]*-/, "")
|
||||
}'
|
||||
hx-target="closest tr"
|
||||
hx-swap="outerHTML"
|
||||
_="
|
||||
on change
|
||||
send resetListing() to closest <tr/>
|
||||
"
|
||||
>
|
||||
<option disabled {{- if not $selectedShopID }}selected{{- end }}>- Shops -</option>
|
||||
{{- range $shop := $shops }}
|
||||
{{- $isSelectedShop := and
|
||||
(eq $selectedShopPlatform $shop.Platform)
|
||||
(eq $selectedShopID $shop.ShopID)
|
||||
}}
|
||||
<option
|
||||
value="{{$shop.Platform}}-{{$shop.ShopID}}"
|
||||
{{- if $isSelectedShop }}selected{{- end }}
|
||||
>
|
||||
{{ $shop.Name }} - {{$shop.Platform}} - {{$shop.ShopID}}
|
||||
</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{{- $selectedListing := "" }}
|
||||
{{- if $selectedShopID }}
|
||||
{{- $listings := $dot.Accounts.GetListingsForShop $acctID $selectedShopPlatform $selectedShopID }}
|
||||
{{- if $listings }}
|
||||
<select
|
||||
class="min-w-fit cursor-pointer"
|
||||
|
||||
hx-put="/accounts/{{$acctID}}/inventory/sync-groups/draft/listings/{{$orderIndex}}/listing"
|
||||
hx-vals='js:{
|
||||
"listing-id": event.target.value,
|
||||
}'
|
||||
hx-target="closest tr"
|
||||
hx-swap="outerHTML"
|
||||
|
||||
_="
|
||||
on input
|
||||
set dataset to (my selectedOptions)[0].dataset
|
||||
send setListing(listing: dataset) to the closest <tr/>
|
||||
"
|
||||
>
|
||||
<option disabled {{if not $selectedListingID}}selected{{end}}>- Listings -</option>
|
||||
{{- range $i, $listing := $listings }}
|
||||
{{- if eq $selectedListingID $listing.ListingID }}
|
||||
{{ $selectedListing = $listing }}
|
||||
{{- end }}
|
||||
<option
|
||||
value="{{$listing.ListingID}}"
|
||||
{{if eq $selectedListingID $listing.ListingID}}selected{{end}}
|
||||
data-name="{{ $listing.Name }}"
|
||||
data-sku="{{ $listing.SKU }}"
|
||||
data-description="{{ $listing.Description }}"
|
||||
data-count="{{ $listing.Count }}"
|
||||
>
|
||||
{{ $listing.Name }}
|
||||
</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
{{- else }}
|
||||
no listings found
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
-
|
||||
{{- end }}
|
||||
</td>
|
||||
|
||||
<td data-id="sku">
|
||||
{{if $selectedListing}}{{$selectedListing.SKU}}{{else}}-{{end}}
|
||||
</td>
|
||||
|
||||
<td data-id="description">
|
||||
{{if $selectedListing}}{{$selectedListing.Description}}{{else}}-{{end}}
|
||||
</td>
|
||||
|
||||
<td data-id="remove">
|
||||
{{ componentBody "button-dev"
|
||||
"HXDelete" (printf "/accounts/%d/inventory/sync-groups/draft/listings/%d" $acctID $orderIndex)
|
||||
"HXTarget" "closest tr"
|
||||
"HXSwap" "outerHTML"
|
||||
"Text" "Remove"
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
+30
-7
@@ -1,5 +1,3 @@
|
||||
{{/* .Identity.Account.AccountID | .PathParams.acctID | .AccountID */}}
|
||||
|
||||
{{- $dot := or .dot . }}
|
||||
{{- .Auth.ByMatchingAccountID 2 }}
|
||||
|
||||
@@ -16,7 +14,7 @@
|
||||
{{- $stores := $dot.Accounts.GetShops $acctID -}}
|
||||
|
||||
|
||||
<table id="inventory-table-2" class="max-w-full overflow-x-scroll">
|
||||
<table id="inventory-table-2" class="max-w-full overflow-x-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@@ -36,11 +34,36 @@
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{{/* TODO: list existing row */}}
|
||||
{{- componentBody "accounts/{acctID}/inventory/sync-table-v2/new-row" "dot" $dot }}
|
||||
{{/* TODO: save the saved rows */}}
|
||||
<tbody
|
||||
_="
|
||||
init
|
||||
set element allRowsFilledOut to false
|
||||
set element numRows to 0
|
||||
|
||||
def checkIfAllRowsAreFilledOut()
|
||||
set rows to my children
|
||||
set element allRowsFilledOut to true
|
||||
set element numRows to rows.length
|
||||
for row in rows
|
||||
set filledOut to row.dataset.filledOut is 'true'
|
||||
if not filledOut then
|
||||
set element allRowsFilledOut to false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
on rowUpdated
|
||||
checkIfAllRowsAreFilledOut()
|
||||
send setDisabled(disabled: not allRowsFilledOut or numRows < 2) to #create-sync-group-button
|
||||
"
|
||||
>
|
||||
{{- $listings := $dot.Accounts.GetSyncGroupListingDrafts $acctID }}
|
||||
{{- range $i, $listing := $listings }}
|
||||
{{- componentBody "accounts/{acctID}/inventory/sync-groups/draft/listings/{orderIndex}"
|
||||
"dot" ($dot | addPathParam "orderIndex" $i)
|
||||
}}
|
||||
{{- end }}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
{{/* .Identity.Account.AccountID, .Accounts */}}
|
||||
|
||||
{{- $dot := or .dot . -}}
|
||||
|
||||
|
||||
{{- $acctID := $dot.Identity.Account.AccountID }}
|
||||
{{- $shops := $dot.Accounts.GetShops $acctID -}}
|
||||
|
||||
|
||||
<tr _="
|
||||
on setListing(listing)
|
||||
set the innerHTML of (the last <td[data-id=sku]/> in me) to listing.sku
|
||||
set the innerHTML of (the last <td[data-id=description]/> in me) to listing.description
|
||||
-- TODO: only remove if there isn't already a 'new row'
|
||||
remove @disabled from (the <button/> in last <td[data-id=save]/> in me)
|
||||
on resetListing
|
||||
set the innerHTML of (the last <td[data-id=sku]/> in me) to '-'
|
||||
set the innerHTML of (the last <td[data-id=description]/> in me) to '-'
|
||||
add @disabled to (the <button/> in last <td[data-id=save]/> in me)
|
||||
"
|
||||
>
|
||||
<td>
|
||||
<select
|
||||
class="min-w-fit cursor-pointer"
|
||||
hx-get="/accounts/{{$acctID}}/platforms/{platform}/shops/{shopID}/listing-select"
|
||||
hx-vals='js:{
|
||||
platform: event.target.value.replace(/-[^ ]*/, ""),
|
||||
shopID: event.target.value.replace(/[^ ]*-/, "")
|
||||
}'
|
||||
hx-target="next td"
|
||||
_="
|
||||
on change
|
||||
log event.target.value
|
||||
send resetListing() to closest <tr/>
|
||||
"
|
||||
>
|
||||
<option disabled selected>- Shops -</option>
|
||||
{{- range $shop := $shops }}
|
||||
<option value="{{$shop.Platform}}-{{$shop.ShopID}}">
|
||||
{{ $shop.Name }} - {{$shop.Platform}} - {{$shop.ShopID}}
|
||||
</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
-
|
||||
</td>
|
||||
<td data-id="sku">
|
||||
-
|
||||
</td>
|
||||
<td data-id="description">
|
||||
-
|
||||
</td>
|
||||
<td data-id="save">
|
||||
<button
|
||||
disabled
|
||||
hx-get="/accounts/{{$acctID}}/inventory/sync-table-v2/new-row"
|
||||
hx-target="closest tr"
|
||||
hx-swap="afterend"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
{{/* TODO: delete when done with the newer draft */}}
|
||||
{{- $dot := or .dot .}}
|
||||
|
||||
{{- $dot.Auth.ByMatchingAccountID 2 }}
|
||||
@@ -8,7 +9,6 @@
|
||||
|
||||
<tr>
|
||||
{{- range $shop := $shops }}
|
||||
{{- $listings := $dot.Accounts.GetListingsForShop $acctID $shop.ShopID }}
|
||||
<td>
|
||||
<select
|
||||
class="min-w-fit cursor-pointer"
|
||||
@@ -30,6 +30,7 @@
|
||||
"
|
||||
>
|
||||
<option disabled selected>- Listings -</option>
|
||||
{{/*- $listings := $dot.Accounts.GetListingsForShop $acctID $shop.ShopID }}
|
||||
{{- range $listing := $listings }}
|
||||
<option
|
||||
value="{{$listing.ListingID}}"
|
||||
@@ -40,7 +41,7 @@
|
||||
>
|
||||
{{ $listing.Name }}
|
||||
</option>
|
||||
{{- end }}
|
||||
{{- end */}}
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
{{/* .ShopID: default to path param "shopID" */}}
|
||||
|
||||
{{- $shopID := or (and .PathParams .PathParams.shopID) .ShopID }}
|
||||
|
||||
{{ $acctID := .Identity.Account.AccountID }}
|
||||
|
||||
<select
|
||||
class="min-w-fit cursor-pointer"
|
||||
_="
|
||||
on input
|
||||
set dataset to (my selectedOptions)[0].dataset
|
||||
send setListing(listing: dataset) to the closest <tr/>
|
||||
"
|
||||
>
|
||||
{{- $listings := .Accounts.GetListingsForShop $acctID $shopID }}
|
||||
{{- $dot := . }}
|
||||
<option disabled selected>- Listings -</option>
|
||||
{{- range $listing := $listings }}
|
||||
<option
|
||||
value="{{$listing.SKU}}"
|
||||
data-name="{{ $listing.Name }}"
|
||||
data-sku="{{ $listing.SKU }}"
|
||||
data-description="{{ $listing.Description }}"
|
||||
data-count="{{ $listing.Count }}"
|
||||
>
|
||||
{{ $listing.Name }}
|
||||
</option>
|
||||
{{- end }}
|
||||
</select>
|
||||
@@ -0,0 +1,45 @@
|
||||
{{/* .HXGet | .HXPost | .HXDelete, .HXTarget, .HXSwap, .HXVals, ._, .Text, .ID, .Class, .Disabled */}}
|
||||
|
||||
<button
|
||||
class="
|
||||
border-thin
|
||||
bg-card
|
||||
rounded-sm
|
||||
p-[0.5em]
|
||||
font-semibold
|
||||
cursor-pointer
|
||||
hover:underline
|
||||
hover:bg-accent
|
||||
disabled:bg-accent-secondary
|
||||
disabled:cursor-not-allowed
|
||||
disabled:no-underline
|
||||
{{.Class}}
|
||||
"
|
||||
{{- if .ID }}
|
||||
id="{{.ID}}"
|
||||
{{- end }}
|
||||
{{- if .HXGet }}
|
||||
hx-get="{{.HXGet}}"
|
||||
{{- else if .HXPost }}
|
||||
hx-post="{{.HXPost}}"
|
||||
{{- else if .HXDelete }}
|
||||
hx-delete="{{.HXDelete}}"
|
||||
{{- end }}
|
||||
{{- if .HXTarget }}
|
||||
hx-target="{{.HXTarget}}"
|
||||
{{- end }}
|
||||
{{- if .HXSwap }}
|
||||
hx-swap="{{.HXSwap}}"
|
||||
{{- end }}
|
||||
{{- if .HXVals }}
|
||||
hx-vals="{{.HXVals}}"
|
||||
{{- end }}
|
||||
{{- if .Disabled}}
|
||||
disabled
|
||||
{{- end}}
|
||||
{{- if ._ }}
|
||||
_="{{ ._ }}"
|
||||
{{- end }}
|
||||
>
|
||||
{{.Text}}
|
||||
</button>
|
||||
@@ -1,19 +1,55 @@
|
||||
{{- .Auth.ByMatchingAccountID 2 }}
|
||||
|
||||
{{- $acctID := .Identity.Account.AccountID }}
|
||||
{{- $stores := .Accounts.GetShops $acctID -}}
|
||||
|
||||
|
||||
{{- define "title" }} Inventory++ {{ end }}
|
||||
|
||||
<h1 class="text-center mb-[0.5em]">Inventory</h1>
|
||||
|
||||
<h2 class="text-center mb-[0.5em]">Sync Stores</h2>
|
||||
|
||||
{{ $acctID := .Identity.Account.AccountID }}
|
||||
{{ $stores := .Accounts.GetShops $acctID }}
|
||||
<h2 class="text-center mb-[0.5em]">Synced Listings</h2>
|
||||
|
||||
<section class="w-full flex flex-col items-center">
|
||||
<h3>
|
||||
Draft 2
|
||||
Create a Sync Group
|
||||
</h3>
|
||||
<h4>
|
||||
(Draft 2)
|
||||
</h4>
|
||||
{{ componentBody "accounts/{acctID}/inventory/sync-table-v2" "dot" . }}
|
||||
|
||||
<div>
|
||||
{{ componentBody "button-dev"
|
||||
"HXPost" (printf "/accounts/%d/inventory/sync-groups/draft/listings" $acctID)
|
||||
"HXTarget" "previous table > tbody"
|
||||
"HXSwap" "beforeend"
|
||||
"Class" "mt-[1em] mb-[1em]"
|
||||
"Text" "Add Listing"
|
||||
"_" `
|
||||
on click
|
||||
send rowUpdated to the first <tbody/> in #inventory-table-2
|
||||
`
|
||||
}}
|
||||
|
||||
{{/* TODO: enable the button when all listings are filled and there are at least two listings */}}
|
||||
{{/* TODO: save the listings as a sync group on click */}}
|
||||
{{ componentBody "button-dev"
|
||||
"ID" "create-sync-group-button"
|
||||
"HXPost" (printf "/accounts/%d/sync-groups" $acctID)
|
||||
"Class" "mt-[1em] mb-[1em]"
|
||||
"Text" "Save Sync Group"
|
||||
"Disabled" true
|
||||
"_" `
|
||||
on setDisabled(disabled)
|
||||
if disabled then
|
||||
add @disabled to me
|
||||
else
|
||||
remove @disabled from me
|
||||
end
|
||||
`
|
||||
}}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="w-full flex flex-col items-center">
|
||||
@@ -28,12 +64,11 @@
|
||||
</section>
|
||||
|
||||
<section class="w-full flex justify-center mt-[1em]">
|
||||
<button
|
||||
class="border-thin bg-card rounded-sm p-[0.5em] font-semibold cursor-pointer hover:underline hover:bg-accent"
|
||||
hx-get="/accounts/{{$acctID}}/inventory/sync-table/new-row"
|
||||
hx-target="#inventory-table > tbody"
|
||||
hx-swap="beforeend"
|
||||
>
|
||||
Add Row
|
||||
</button>
|
||||
{{ componentBody "button-dev"
|
||||
"HXGet" (printf "/accounts/%d/inventory/sync-table/new-row" $acctID)
|
||||
"HXTarget" "#inventory-table > tbody"
|
||||
"HXSwap" "beforeend"
|
||||
"Class" "mt-[1em] mb-[1em]"
|
||||
"Text" "Add Row"
|
||||
}}
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user