Item sharing progress, fixed click on checkboxes and relative labels and colors
This commit is contained in:
parent
7b2cf94ad6
commit
6523c2aed6
8 changed files with 128 additions and 19 deletions
|
@ -1,10 +1,11 @@
|
||||||
CREATE TABLE "bm_item_shares" (
|
CREATE TABLE "bm_item_shares" (
|
||||||
"id" INTEGER,
|
"id" INTEGER,
|
||||||
"token" TEXT NOT NULL UNIQUE,
|
"token" TEXT NOT NULL UNIQUE,
|
||||||
"item_id" INTEGER DEFAULT 0,
|
"item_id" INTEGER DEFAULT '',
|
||||||
"read" INTEGER DEFAULT 0,
|
"read" INTEGER DEFAULT '',
|
||||||
"update" INTEGER DEFAULT 0,
|
"update" INTEGER DEFAULT '',
|
||||||
"start_datetime" TEXT DEFAULT 0,
|
"start_datetime" TEXT DEFAULT '',
|
||||||
"end_datetime" TEXT DEFAULT 0,
|
"end_datetime" TEXT DEFAULT '',
|
||||||
|
"password" TEXT DEFAULT '',
|
||||||
PRIMARY KEY("id" AUTOINCREMENT)
|
PRIMARY KEY("id" AUTOINCREMENT)
|
||||||
);
|
);
|
|
@ -517,7 +517,8 @@ a {
|
||||||
width: 18px;
|
width: 18px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 6px
|
top: 6px;
|
||||||
|
accent-color: #2b5797;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w3-sidebar {
|
.w3-sidebar {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const cacheVersion = "0.266"
|
const cacheVersion = "0.267"
|
||||||
const cacheName = "speedtech-brainminder"
|
const cacheName = "speedtech-brainminder"
|
||||||
const cacheFiles = [
|
const cacheFiles = [
|
||||||
'/static/bootstrap-icons/font/bootstrap-icons.min.css',
|
'/static/bootstrap-icons/font/bootstrap-icons.min.css',
|
||||||
|
|
|
@ -112,6 +112,7 @@
|
||||||
<p>
|
<p>
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
<input
|
<input
|
||||||
|
id="on_dashboard"
|
||||||
class="w3-check"
|
class="w3-check"
|
||||||
name="On_dashboard"
|
name="On_dashboard"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -125,7 +126,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
/>
|
/>
|
||||||
<span class="slider round"></span>
|
<span class="slider round"></span>
|
||||||
</label><span class="label-checkbox">On dashboard</span>
|
</label><label for="on_dashboard" class="label-checkbox">On dashboard</label>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@
|
||||||
<p>
|
<p>
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
<input
|
<input
|
||||||
|
id="show_summary"
|
||||||
class="w3-check"
|
class="w3-check"
|
||||||
name="Show_summary"
|
name="Show_summary"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -77,12 +78,13 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
/>
|
/>
|
||||||
<span class="slider round"></span>
|
<span class="slider round"></span>
|
||||||
</label><span class="label-checkbox">Show summary</span>
|
</label><label for="show_summary" class="label-checkbox">Show summary</label>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
<input
|
<input
|
||||||
|
id="show_description"
|
||||||
class="w3-check"
|
class="w3-check"
|
||||||
name="Show_description"
|
name="Show_description"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -92,7 +94,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
/>
|
/>
|
||||||
<span class="slider round"></span>
|
<span class="slider round"></span>
|
||||||
</label><span class="label-checkbox">Show description</span>
|
</label><label for="show_description" class="label-checkbox">Show description</label>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,18 @@ type itemForm struct {
|
||||||
Validator validator.Validator `form:"-"`
|
Validator validator.Validator `form:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
func (form *itemForm) Validate(w http.ResponseWriter, r *http.Request, app *application, data map[string]any) bool {
|
func (form *itemForm) Validate(w http.ResponseWriter, r *http.Request, app *application, data map[string]any) bool {
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
|
@ -60,6 +72,32 @@ func (form *itemForm) Validate(w http.ResponseWriter, r *http.Request, app *appl
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (form *itemShareForm) Validate(w http.ResponseWriter, r *http.Request, app *application, data map[string]any) bool {
|
||||||
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
|
//form.Validator.CheckField(form.Title != "", "Title", "Title is required")
|
||||||
|
//form.Validator.CheckField(form.Description != "", "Description", "Description is required")
|
||||||
|
|
||||||
|
if form.Validator.HasErrors() {
|
||||||
|
w.Header().Add("HX-Retarget", "#message")
|
||||||
|
|
||||||
|
data["messageType"] = "failure"
|
||||||
|
data["messageContent"] = "Impossible to save the item"
|
||||||
|
data["messageFieldErrors"] = form.Validator.FieldErrors
|
||||||
|
|
||||||
|
err := response.HXFragment(fullBuf, []string{"partials/message.tmpl"}, "message", data)
|
||||||
|
if err != nil {
|
||||||
|
app.serverError(w, r, err)
|
||||||
|
}
|
||||||
|
fullBuf.WriteTo(w)
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (app *application) itemsRelationAdd(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemsRelationAdd(w http.ResponseWriter, r *http.Request) {
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
|
@ -862,19 +900,47 @@ func (app *application) itemShare(w http.ResponseWriter, r *http.Request) {
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
item, _, _ := itemModel.One(item_id)
|
item, _, _ := itemModel.One(item_id)
|
||||||
var fullBuf = new(bytes.Buffer)
|
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["item"] = item
|
data["item"] = item
|
||||||
data["baseUrl"] = app.config.baseURL
|
data["baseUrl"] = app.config.baseURL
|
||||||
data["shareToken"] = app.generateSecureToken(18)
|
|
||||||
|
|
||||||
err := response.HXFragment(fullBuf, []string{"items/share.tmpl"}, "page:content", data)
|
switch r.Method {
|
||||||
if err != nil {
|
case http.MethodGet:
|
||||||
app.serverError(w, r, err)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
|
data["shareToken"] = app.generateSecureToken(18)
|
||||||
|
|
||||||
|
err := response.HXFragment(fullBuf, []string{"items/share.tmpl"}, "page:content", data)
|
||||||
|
if err != nil {
|
||||||
|
app.serverError(w, r, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fullBuf.WriteTo(w)
|
||||||
|
case http.MethodPost:
|
||||||
|
var itemShareFromForm itemShareForm
|
||||||
|
|
||||||
|
err := request.DecodePostForm(r, &itemShareFromForm)
|
||||||
|
if err != nil {
|
||||||
|
app.serverError(w, r, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !itemShareFromForm.Validate(w, r, app, data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
itemShare := &models.ItemShare{
|
||||||
|
Item_id: item_id,
|
||||||
|
Token: itemShareFromForm.Token,
|
||||||
|
}
|
||||||
|
|
||||||
|
itemshareModel := &models.ItemShareModel{DB: app.db}
|
||||||
|
_, err = itemshareModel.Create(itemShare)
|
||||||
|
if err != nil {
|
||||||
|
app.badRequest(w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fullBuf.WriteTo(w)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) itemAddToDashboard(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemAddToDashboard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -419,8 +419,8 @@ func widget_checkboxes(name string, label string, value any, options []WidgetOpt
|
||||||
}
|
}
|
||||||
id_str := strings.ReplaceAll(name+"-"+option.Key, " ", "-")
|
id_str := strings.ReplaceAll(name+"-"+option.Key, " ", "-")
|
||||||
o = o + "<p>"
|
o = o + "<p>"
|
||||||
o = o + fmt.Sprintf(`<label for="%v" class="switch"><input id="%v" type="checkbox" name="%v" %v value="%v" %v /><span class="slider round"></span></label>`, id_str, id_str, name, checked, option.Key, attributes)
|
o = o + fmt.Sprintf(`<label class="switch"><input id="%v" type="checkbox" name="%v" %v value="%v" %v /><span class="slider round"></span></label>`, id_str, name, checked, option.Key, attributes)
|
||||||
o = o + fmt.Sprintf(`<span class="label-checkbox" for="%v">%v</span>`, id_str, option.Value)
|
o = o + fmt.Sprintf(`<label class="label-checkbox" for="%v">%v</label>`, id_str, option.Value)
|
||||||
o = o + "</p>"
|
o = o + "</p>"
|
||||||
}
|
}
|
||||||
o = o + "</fiedlset>"
|
o = o + "</fiedlset>"
|
||||||
|
|
38
models/itemshare.go
Normal file
38
models/itemshare.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import "brainminder.speedtech.it/internal/database"
|
||||||
|
|
||||||
|
type ItemShareModel struct {
|
||||||
|
DB *database.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
type ItemShare struct {
|
||||||
|
Id int64 `db:"id"`
|
||||||
|
Token string `db:"token"`
|
||||||
|
Summary string `db:"summary"`
|
||||||
|
Item_id int64 `db:"item_id"`
|
||||||
|
Read int `db:"crypted"`
|
||||||
|
Update int `db:"hidden"`
|
||||||
|
Start_datetime string `db:"start_datetime"`
|
||||||
|
End_datetime string `db:"end_datetime"`
|
||||||
|
password string `db:"password"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (model *ItemShareModel) Create(ItemShare *ItemShare) (int64, error) {
|
||||||
|
ctx, cancel := database.GetContext()
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
query := `INSERT INTO bm_items_share (title, description, icon, hidden) VALUES (:title, :description, :icon, :hidden)`
|
||||||
|
|
||||||
|
result, err := model.DB.NamedExecContext(ctx, query, ItemShare)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := result.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return id, err
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue