Item sharing
This commit is contained in:
parent
b4d3d1cb7e
commit
bf34ee71b3
@ -2,8 +2,7 @@ CREATE TABLE "bm_item_shares" (
|
||||
"id" INTEGER,
|
||||
"token" TEXT NOT NULL UNIQUE,
|
||||
"item_id" INTEGER DEFAULT '',
|
||||
"read" INTEGER DEFAULT '',
|
||||
"update" INTEGER DEFAULT '',
|
||||
"permission_edit" INTEGER DEFAULT '',
|
||||
"start_datetime" TEXT DEFAULT '',
|
||||
"end_datetime" TEXT DEFAULT '',
|
||||
"password" TEXT DEFAULT '',
|
||||
|
@ -261,6 +261,11 @@ document.addEventListener("DOMContentLoaded", function(event){
|
||||
document.getElementById("dialog").showModal();
|
||||
});
|
||||
|
||||
document.body.addEventListener("closeModalDialog", function(evt){
|
||||
document.getElementById('dialog').close();
|
||||
document.getElementById('dialog').remove();
|
||||
});
|
||||
|
||||
document.body.addEventListener("quickboxNoteClear", function(evt){
|
||||
document.getElementById("quickbox-notetext").value = ''
|
||||
});
|
||||
|
@ -11,13 +11,13 @@
|
||||
<div class="col l6">
|
||||
<p style="margin-right: 6px">
|
||||
<label for="share-start-datetime">Start date time</label>
|
||||
<input name="start-datetime" id="share-start-datetime" type="datetime-local" value=""/>
|
||||
<input name="Start_datetime" id="share-start-datetime" type="datetime-local" value=""/>
|
||||
</p>
|
||||
</div>
|
||||
<div class="col l6">
|
||||
<p>
|
||||
<label for="share-end-datetime">End date time</label>
|
||||
<input name="end-datetime" id="share-end-datetime" type="datetime-local" value=""/>
|
||||
<input name="End_datetime" id="share-end-datetime" type="datetime-local" value=""/>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@ -27,7 +27,7 @@
|
||||
<label for="share-token">Share Url</label>
|
||||
<div class="input-container">
|
||||
<span class="prefix">{{ .baseUrl }}/</span>
|
||||
<input name="token" id="share-token" type="url" readonly="readonly" value="{{ .shareToken }}" />
|
||||
<input name="Token" id="share-token" type="url" readonly="readonly" value="{{ .shareToken }}" />
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
@ -36,15 +36,14 @@
|
||||
<div class="col l12">
|
||||
<p style="margin-right: 6px">
|
||||
<label for="share-password">Password</label>
|
||||
<input name="password" id="share-password" type="password" value=""/>
|
||||
<input name="Password" id="share-password" type="password" value=""/>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Permissions</legend>
|
||||
<div class="row">
|
||||
<div class="col l6">{{ widget_checkbox "read" "Read" "1" "" }}</div>
|
||||
<div class="col l6">{{ widget_checkbox "edit" "Edit" "1" "" }}</div>
|
||||
<div class="col l6">{{ widget_checkbox "Permission_edit" "Edit" "1" "" }}</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div id="footer-navbar">
|
||||
|
4
before-compile.sh
Executable file
4
before-compile.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
PATH="/home/roberto/.nvm/versions/node/v20.18.0/bin:$PATH"
|
||||
DIR=$(dirname "$0")
|
||||
handlebars "$DIR"/assets/jstemplates/items/ -f "$DIR"/assets/static/js/templates.js
|
@ -35,15 +35,14 @@ type itemForm struct {
|
||||
}
|
||||
|
||||
type itemShareForm struct {
|
||||
Id int64 `form:"Id"`
|
||||
Item_id int64 `form:"Item_id"`
|
||||
Token string `form:"Token"`
|
||||
Start_datetime string `form:"start_datetime"`
|
||||
End_datetime string `form:"end_datetime"`
|
||||
Password string `form:"password"`
|
||||
Permission_read int `form:"read"`
|
||||
Permission_edit int `form:"edit"`
|
||||
Validator validator.Validator `form:"-"`
|
||||
Id int64 `form:"Id"`
|
||||
ItemId int64 `form:"Item_id"`
|
||||
Token string `form:"Token"`
|
||||
StartDatetime string `form:"Start_datetime"`
|
||||
EndDatetime string `form:"End_datetime"`
|
||||
Password string `form:"Password"`
|
||||
PermissionEdit int `form:"Permission_edit"`
|
||||
Validator validator.Validator `form:"-"`
|
||||
}
|
||||
|
||||
func (form *itemForm) Validate(w http.ResponseWriter, r *http.Request, app *application, data map[string]any) bool {
|
||||
@ -937,8 +936,12 @@ func (app *application) itemShare(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
itemShare := &models.ItemShare{
|
||||
Item_id: item_id,
|
||||
Token: itemShareFromForm.Token,
|
||||
ItemId: item_id,
|
||||
Token: itemShareFromForm.Token,
|
||||
Password: itemShareFromForm.Password,
|
||||
PermissionEdit: itemShareFromForm.PermissionEdit,
|
||||
StartDatetime: itemShareFromForm.StartDatetime,
|
||||
EndDatetime: itemShareFromForm.EndDatetime,
|
||||
}
|
||||
|
||||
itemshareModel := &models.ItemShareModel{DB: app.db}
|
||||
@ -947,6 +950,20 @@ func (app *application) itemShare(w http.ResponseWriter, r *http.Request) {
|
||||
app.badRequest(w, err)
|
||||
return
|
||||
}
|
||||
var fullBuf = new(bytes.Buffer)
|
||||
|
||||
dataMessage := make(map[string]string)
|
||||
dataMessage["messageType"] = "success"
|
||||
dataMessage["messageContent"] = "Item shared successfully"
|
||||
err = response.HXFragment(fullBuf, []string{"partials/message.tmpl"}, "message", dataMessage)
|
||||
if err != nil {
|
||||
app.serverError(w, r, err)
|
||||
}
|
||||
|
||||
w.Header().Add("HX-Reswap", `beforeend`)
|
||||
w.Header().Add("HX-Trigger-After-Settle", `{"showMessage": "", "closeModalDialog": ""}`)
|
||||
|
||||
fullBuf.WriteTo(w)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,10 @@ type ItemShareModel struct {
|
||||
type ItemShare struct {
|
||||
Id int64 `db:"id"`
|
||||
Token string `db:"token"`
|
||||
Item_id int64 `db:"item_id"`
|
||||
Update int `db:"hidden"`
|
||||
Start_datetime string `db:"start_datetime"`
|
||||
End_datetime string `db:"end_datetime"`
|
||||
ItemId int64 `db:"item_id"`
|
||||
PermissionEdit int `db:"permission_edit"`
|
||||
StartDatetime string `db:"start_datetime"`
|
||||
EndDatetime string `db:"end_datetime"`
|
||||
Password string `db:"password"`
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) {
|
||||
ctx, cancel := database.GetContext()
|
||||
defer cancel()
|
||||
|
||||
query := `INSERT INTO bm_items_share (token, item_id, update, start_datetime, end_datetime, password) VALUES (:token, :item_id, :update, :start_datetime, :end_datetime, :password)`
|
||||
query := `INSERT INTO bm_item_shares (token, item_id, permission_edit, start_datetime, end_datetime, password) VALUES (:token, :item_id, :permission_edit, :start_datetime, :end_datetime, :password)`
|
||||
|
||||
result, err := model.DB.NamedExecContext(ctx, query, ItemShare)
|
||||
if err != nil {
|
||||
@ -43,7 +43,7 @@ func (model *ItemShareModel) Delete(id int) (bool, error) {
|
||||
ctx, cancel := database.GetContext()
|
||||
defer cancel()
|
||||
|
||||
_, err := model.DB.ExecContext(ctx, `DELETE FROM bm_item_share WHERE id = $1`, id)
|
||||
_, err := model.DB.ExecContext(ctx, `DELETE FROM bm_item_shares WHERE id = $1`, id)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user