Shares implmnetation progress
This commit is contained in:
parent
bf34ee71b3
commit
986bf27899
@ -5,6 +5,11 @@
|
||||
{{ $fields_present = true }}
|
||||
{{ 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}}">
|
||||
<div class="page-container">
|
||||
<div class="tab-bar">
|
||||
@ -13,6 +18,7 @@
|
||||
<a class="tab-button" onclick="bm_open_tab(this, 'tab-button', 'tab', 'fields')">Fields</a>
|
||||
{{ 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', 'sharesSection')">Shares</a>
|
||||
</div>
|
||||
|
||||
<div id="general" class="tab" style="display: block">
|
||||
@ -98,6 +104,14 @@
|
||||
</div>
|
||||
</fieldset>
|
||||
</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 id="footer-navbar">
|
||||
|
@ -31,6 +31,7 @@ type itemForm struct {
|
||||
FieldsSection map[string][]models.Field
|
||||
FieldsValues map[int64]map[int]string
|
||||
Relations []models.ItemRelation
|
||||
Shares []models.ItemShare
|
||||
Validator validator.Validator `form:"-"`
|
||||
}
|
||||
|
||||
@ -462,6 +463,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||
Categories: categories,
|
||||
Notebooks: notebooks,
|
||||
Relations: nil,
|
||||
Shares: nil,
|
||||
}
|
||||
|
||||
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, "|"), "|")
|
||||
categories := strings.Split(strings.Trim(item.Categories, "|"), "|")
|
||||
relations, _, _ := itemModel.GetRelations(item.Id)
|
||||
shares, _, _ := itemModel.GetShares(item.Id)
|
||||
|
||||
data["item"] = itemForm{
|
||||
Id: item_id,
|
||||
@ -579,6 +582,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||
Notebooks: notebooks,
|
||||
Categories: categories,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
}
|
||||
|
||||
err = response.HXFragment(fullBuf, []string{"items/form.tmpl", "items/fields.tmpl", "items/relations.tmpl"}, "page:content", data)
|
||||
|
@ -468,3 +468,19 @@ func (model *ItemModel) GetRelations(id int64) ([]ItemRelation, bool, error) {
|
||||
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user