Shares implmnetation progress

This commit is contained in:
roberto 2025-01-09 18:05:08 +01:00
parent bf34ee71b3
commit 986bf27899
3 changed files with 34 additions and 0 deletions

View File

@ -5,6 +5,11 @@
{{ $fields_present = true }} {{ $fields_present = true }}
{{ end }} {{ end }}
{{ $shares_present := false }}
{{ if (gt (len (index .item.FieldsSection "fields")) 0) }}
{{ $shares_present = true }}
{{ end }}
<form method="POST" hx-post="{{.formAction}}" hx-target="{{.formTarget}}"> <form method="POST" hx-post="{{.formAction}}" hx-target="{{.formTarget}}">
<div class="page-container"> <div class="page-container">
<div class="tab-bar"> <div class="tab-bar">
@ -13,6 +18,7 @@
<a class="tab-button" onclick="bm_open_tab(this, 'tab-button', 'tab', 'fields')">Fields</a> <a class="tab-button" onclick="bm_open_tab(this, 'tab-button', 'tab', 'fields')">Fields</a>
{{ end }} {{ end }}
<a class="tab-button" onclick="bm_open_tab(this, 'tab-button', 'tab', 'relationsSection')">Relations</a> <a class="tab-button" onclick="bm_open_tab(this, 'tab-button', 'tab', 'relationsSection')">Relations</a>
<a class="tab-button" onclick="bm_open_tab(this, 'tab-button', 'tab', 'sharesSection')">Shares</a>
</div> </div>
<div id="general" class="tab" style="display: block"> <div id="general" class="tab" style="display: block">
@ -98,6 +104,14 @@
</div> </div>
</fieldset> </fieldset>
</div> </div>
{{ if $shares_present }}
<div class="tab" id="shares" style="display: none">
<div id="shares">
{{ template "items:fields" (map "FieldsSection" .item.FieldsSection "FieldsValues" .item.FieldsValues "uisection" "fields")}}
</div>
</div>
{{ end }}
</div> </div>
<div id="footer-navbar"> <div id="footer-navbar">

View File

@ -31,6 +31,7 @@ type itemForm struct {
FieldsSection map[string][]models.Field FieldsSection map[string][]models.Field
FieldsValues map[int64]map[int]string FieldsValues map[int64]map[int]string
Relations []models.ItemRelation Relations []models.ItemRelation
Shares []models.ItemShare
Validator validator.Validator `form:"-"` Validator validator.Validator `form:"-"`
} }
@ -462,6 +463,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
Categories: categories, Categories: categories,
Notebooks: notebooks, Notebooks: notebooks,
Relations: nil, Relations: nil,
Shares: nil,
} }
if r.Header.Get("HX-Request") == "true" { if r.Header.Get("HX-Request") == "true" {
@ -562,6 +564,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
notebooks := strings.Split(strings.Trim(item.Notebooks, "|"), "|") notebooks := strings.Split(strings.Trim(item.Notebooks, "|"), "|")
categories := strings.Split(strings.Trim(item.Categories, "|"), "|") categories := strings.Split(strings.Trim(item.Categories, "|"), "|")
relations, _, _ := itemModel.GetRelations(item.Id) relations, _, _ := itemModel.GetRelations(item.Id)
shares, _, _ := itemModel.GetShares(item.Id)
data["item"] = itemForm{ data["item"] = itemForm{
Id: item_id, Id: item_id,
@ -579,6 +582,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
Notebooks: notebooks, Notebooks: notebooks,
Categories: categories, Categories: categories,
Relations: relations, Relations: relations,
Shares: shares,
} }
err = response.HXFragment(fullBuf, []string{"items/form.tmpl", "items/fields.tmpl", "items/relations.tmpl"}, "page:content", data) err = response.HXFragment(fullBuf, []string{"items/form.tmpl", "items/fields.tmpl", "items/relations.tmpl"}, "page:content", data)

View File

@ -468,3 +468,19 @@ func (model *ItemModel) GetRelations(id int64) ([]ItemRelation, bool, error) {
return rows, true, err return rows, true, err
} }
func (model *ItemModel) GetShares(id int64) ([]ItemShare, bool, error) {
ctx, cancel := database.GetContext()
defer cancel()
query := `SELECT * FROM bm_item_shares WHERE item_id=$1`
var rows []ItemShare
err := model.DB.SelectContext(ctx, &rows, query, id)
if errors.Is(err, sql.ErrNoRows) {
return nil, false, nil
}
return rows, true, err
}