Code cleanup
This commit is contained in:
parent
f76f9e42d6
commit
7bc82447cc
4 changed files with 186 additions and 186 deletions
|
@ -24,14 +24,14 @@ type application struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) getCurrentNotebok_id(r *http.Request) int64 {
|
func (app *application) getCurrentNotebookId(r *http.Request) int64 {
|
||||||
session, _ := app.sessionStore.Get(r, "session")
|
session, _ := app.sessionStore.Get(r, "session")
|
||||||
current_notebook_id := session.Values["current_notebook_id"]
|
currentNotebookId := session.Values["current_notebook_id"]
|
||||||
var notebook_id int64 = -1
|
var notebookId int64 = -1
|
||||||
if current_notebook_id != nil {
|
if currentNotebookId != nil {
|
||||||
notebook_id, _ = strconv.ParseInt(current_notebook_id.(string), 10, 64)
|
notebookId, _ = strconv.ParseInt(currentNotebookId.(string), 10, 64)
|
||||||
}
|
}
|
||||||
return notebook_id
|
return notebookId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) saveSessionValue(w http.ResponseWriter, r *http.Request, name string, value any) {
|
func (app *application) saveSessionValue(w http.ResponseWriter, r *http.Request, name string, value any) {
|
||||||
|
@ -91,7 +91,7 @@ func (app *application) getCategoriesAsMap() map[string]string {
|
||||||
func (app *application) getTypesAsOptions(r *http.Request) []funcs.WidgetOption {
|
func (app *application) getTypesAsOptions(r *http.Request) []funcs.WidgetOption {
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"notebook_id": app.getCurrentNotebok_id(r),
|
"notebook_id": app.getCurrentNotebookId(r),
|
||||||
}
|
}
|
||||||
return typeModel.FindAsOptions(criteria)
|
return typeModel.FindAsOptions(criteria)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,18 +16,18 @@ import (
|
||||||
|
|
||||||
type itemForm struct {
|
type itemForm struct {
|
||||||
Id int64 `form:"Id"`
|
Id int64 `form:"Id"`
|
||||||
Type_id int64 `form:"Type_id"`
|
TypeId int64 `form:"Type_id"`
|
||||||
Title string `form:"Title"`
|
Title string `form:"Title"`
|
||||||
Summary string `form:"Summary"`
|
Summary string `form:"Summary"`
|
||||||
Description string `form:"Description"`
|
Description string `form:"Description"`
|
||||||
Notebooks []string `form:"Notebooks"`
|
Notebooks []string `form:"Notebooks"`
|
||||||
Tags string `form:"Tags"`
|
Tags string `form:"Tags"`
|
||||||
On_dashboard int `form:"On_dashboard"`
|
OnDashboard int `form:"On_dashboard"`
|
||||||
Categories []string `form:"Categories"`
|
Categories []string `form:"Categories"`
|
||||||
Type_icon string
|
TypeIcon string
|
||||||
Type_title string
|
TypeTitle string
|
||||||
Type_show_summary int
|
TypeShowSummary int
|
||||||
Type_show_description int
|
TypeShowDescription int
|
||||||
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
|
||||||
|
@ -105,9 +105,9 @@ func (app *application) itemsRelationAdd(w http.ResponseWriter, r *http.Request)
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
related_item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "related_item_id"), 10, 64)
|
relatedItemId, _ := strconv.ParseInt(flow.Param(r.Context(), "related_item_id"), 10, 64)
|
||||||
|
|
||||||
relatedItem, _, _ := itemModel.One(related_item_id)
|
relatedItem, _, _ := itemModel.One(relatedItemId)
|
||||||
data["relatedItem"] = relatedItem
|
data["relatedItem"] = relatedItem
|
||||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||||
|
|
||||||
|
@ -199,11 +199,11 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
params := r.URL.Query()
|
params := r.URL.Query()
|
||||||
|
|
||||||
offset_str := r.URL.Query().Get("offset")
|
offsetStr := r.URL.Query().Get("offset")
|
||||||
if len(offset_str) == 0 {
|
if len(offsetStr) == 0 {
|
||||||
offset_str = "0"
|
offsetStr = "0"
|
||||||
}
|
}
|
||||||
offset, _ := strconv.ParseInt(offset_str, 10, 64)
|
offset, _ := strconv.ParseInt(offsetStr, 10, 64)
|
||||||
data["offset"] = offset
|
data["offset"] = offset
|
||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
|
@ -217,9 +217,9 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
||||||
criteriaParam := r.URL.Query()["criteriaName"]
|
criteriaParam := r.URL.Query()["criteriaName"]
|
||||||
if len(criteriaParam) > 0 {
|
if len(criteriaParam) > 0 {
|
||||||
if criteriaParam[0] == criteriaName {
|
if criteriaParam[0] == criteriaName {
|
||||||
criteria_values := app.getSessionValue(w, r, criteriaName)
|
criteriaValues := app.getSessionValue(w, r, criteriaName)
|
||||||
if criteria_values != nil {
|
if criteriaValues != nil {
|
||||||
criteria = criteria_values.(map[string]any)
|
criteria = criteriaValues.(map[string]any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,11 +267,11 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
category_id, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
categoryId, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"Title": r.PostForm.Get("Title"),
|
"Title": r.PostForm.Get("Title"),
|
||||||
"Tags": r.PostForm.Get("Tags"),
|
"Tags": r.PostForm.Get("Tags"),
|
||||||
"category_id": category_id,
|
"category_id": categoryId,
|
||||||
}
|
}
|
||||||
|
|
||||||
criteriaName := "itemsSearch"
|
criteriaName := "itemsSearch"
|
||||||
|
@ -300,14 +300,14 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
|
|
||||||
type_id, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
typeId, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
||||||
|
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
aType, _, _ := typeModel.One(type_id)
|
aType, _, _ := typeModel.One(typeId)
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
|
|
||||||
fields, _, _ := fieldModel.ByTypeOnList(type_id)
|
fields, _, _ := fieldModel.ByTypeOnList(typeId)
|
||||||
data["type"] = &aType
|
data["type"] = &aType
|
||||||
data["Fields"] = fields
|
data["Fields"] = fields
|
||||||
|
|
||||||
|
@ -316,11 +316,11 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
params := r.URL.Query()
|
params := r.URL.Query()
|
||||||
|
|
||||||
offset_str := params.Get("offset")
|
offsetStr := params.Get("offset")
|
||||||
if len(offset_str) == 0 {
|
if len(offsetStr) == 0 {
|
||||||
offset_str = "0"
|
offsetStr = "0"
|
||||||
}
|
}
|
||||||
offset, _ := strconv.ParseInt(offset_str, 10, 64)
|
offset, _ := strconv.ParseInt(offsetStr, 10, 64)
|
||||||
data["offset"] = offset
|
data["offset"] = offset
|
||||||
|
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
@ -330,22 +330,22 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
criteria := make(map[string]any)
|
criteria := make(map[string]any)
|
||||||
|
|
||||||
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", type_id)
|
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", typeId)
|
||||||
data["criteriaName"] = criteriaName
|
data["criteriaName"] = criteriaName
|
||||||
|
|
||||||
criteriaParam := r.URL.Query()["criteriaName"]
|
criteriaParam := r.URL.Query()["criteriaName"]
|
||||||
if len(criteriaParam) > 0 {
|
if len(criteriaParam) > 0 {
|
||||||
if criteriaParam[0] == criteriaName {
|
if criteriaParam[0] == criteriaName {
|
||||||
criteria_values := app.getSessionValue(w, r, criteriaName)
|
criteriaValues := app.getSessionValue(w, r, criteriaName)
|
||||||
if criteria_values != nil {
|
if criteriaValues != nil {
|
||||||
criteria = criteria_values.(map[string]any)
|
criteria = criteriaValues.(map[string]any)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.removeSessionValue(w, r, criteriaName)
|
app.removeSessionValue(w, r, criteriaName)
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria["type_id"] = type_id
|
criteria["type_id"] = typeId
|
||||||
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
||||||
|
|
||||||
rows, _, _ := itemModel.Find(criteria, offset)
|
rows, _, _ := itemModel.Find(criteria, offset)
|
||||||
|
@ -389,15 +389,15 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
category_id, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
categoryId, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"Title": r.PostForm.Get("Title"),
|
"Title": r.PostForm.Get("Title"),
|
||||||
"Tags": r.PostForm.Get("Tags"),
|
"Tags": r.PostForm.Get("Tags"),
|
||||||
"category_id": category_id,
|
"category_id": categoryId,
|
||||||
"type_id": type_id,
|
"type_id": typeId,
|
||||||
}
|
}
|
||||||
|
|
||||||
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", type_id)
|
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", typeId)
|
||||||
data["criteriaName"] = criteriaName
|
data["criteriaName"] = criteriaName
|
||||||
app.saveSessionValue(w, r, criteriaName, criteria)
|
app.saveSessionValue(w, r, criteriaName, criteria)
|
||||||
|
|
||||||
|
@ -422,13 +422,13 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
|
|
||||||
type_id, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
typeId, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
||||||
|
|
||||||
aType, _, _ := typeModel.One(type_id)
|
aType, _, _ := typeModel.One(typeId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["type"] = aType
|
data["type"] = aType
|
||||||
data["formAction"] = fmt.Sprint("/item/create/", type_id)
|
data["formAction"] = fmt.Sprint("/item/create/", typeId)
|
||||||
data["formTarget"] = "#page-content"
|
data["formTarget"] = "#page-content"
|
||||||
data["categories"] = categoryModel.AllAsOptions()
|
data["categories"] = categoryModel.AllAsOptions()
|
||||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||||
|
@ -444,7 +444,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
var categories []string
|
var categories []string
|
||||||
|
|
||||||
fieldsSection, _, _ := fieldModel.ByTypeSection(int64(type_id))
|
fieldsSection, _, _ := fieldModel.ByTypeSection(typeId)
|
||||||
fieldsValues := make(map[int64]map[int]string)
|
fieldsValues := make(map[int64]map[int]string)
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
|
@ -452,9 +452,9 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
data["item"] = itemForm{
|
data["item"] = itemForm{
|
||||||
Title: "",
|
Title: "",
|
||||||
Type_id: type_id,
|
TypeId: typeId,
|
||||||
Type_show_summary: aType.Show_summary,
|
TypeShowSummary: aType.Show_summary,
|
||||||
Type_show_description: aType.Show_description,
|
TypeShowDescription: aType.Show_description,
|
||||||
Summary: "",
|
Summary: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Tags: "",
|
Tags: "",
|
||||||
|
@ -489,7 +489,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
case http.MethodPost:
|
case http.MethodPost:
|
||||||
var itemFromForm itemForm
|
var itemFromForm itemForm
|
||||||
var item_id int64
|
var itemId int64
|
||||||
|
|
||||||
err := request.DecodePostForm(r, &itemFromForm)
|
err := request.DecodePostForm(r, &itemFromForm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -501,19 +501,19 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
item := &models.Item{
|
item := &models.Item{
|
||||||
Type_id: itemFromForm.Type_id,
|
TypeId: itemFromForm.TypeId,
|
||||||
Title: itemFromForm.Title,
|
Title: itemFromForm.Title,
|
||||||
Summary: itemFromForm.Summary,
|
Summary: itemFromForm.Summary,
|
||||||
Description: itemFromForm.Description,
|
Description: itemFromForm.Description,
|
||||||
Tags: itemFromForm.Tags,
|
Tags: itemFromForm.Tags,
|
||||||
On_dashboard: itemFromForm.On_dashboard,
|
On_dashboard: itemFromForm.OnDashboard,
|
||||||
}
|
}
|
||||||
|
|
||||||
notebooks_str := strings.Join(itemFromForm.Notebooks, "|")
|
notebooksStr := strings.Join(itemFromForm.Notebooks, "|")
|
||||||
if len(notebooks_str) > 0 {
|
if len(notebooksStr) > 0 {
|
||||||
notebooks_str = "|" + notebooks_str + "|"
|
notebooksStr = "|" + notebooksStr + "|"
|
||||||
}
|
}
|
||||||
item.Notebooks = notebooks_str
|
item.Notebooks = notebooksStr
|
||||||
|
|
||||||
categories_str := strings.Join(itemFromForm.Categories, "|")
|
categories_str := strings.Join(itemFromForm.Categories, "|")
|
||||||
if len(categories_str) > 0 {
|
if len(categories_str) > 0 {
|
||||||
|
@ -521,8 +521,8 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
item.Categories = categories_str
|
item.Categories = categories_str
|
||||||
|
|
||||||
item_id, err = itemModel.Create(item)
|
itemId, err = itemModel.Create(item)
|
||||||
item.Id = item_id
|
item.Id = itemId
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.badRequest(w, err)
|
app.badRequest(w, err)
|
||||||
return
|
return
|
||||||
|
@ -555,7 +555,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Type_title = aType.Title
|
item.Type_title = aType.Title
|
||||||
fields, _, _ := fieldModel.ByType(int64(type_id))
|
fields, _, _ := fieldModel.ByType(type_id)
|
||||||
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
||||||
|
|
||||||
data["formAction"] = fmt.Sprint("/item/update/", item_id)
|
data["formAction"] = fmt.Sprint("/item/update/", item_id)
|
||||||
|
@ -568,15 +568,15 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
data["item"] = itemForm{
|
data["item"] = itemForm{
|
||||||
Id: item_id,
|
Id: item_id,
|
||||||
Type_id: type_id,
|
TypeId: type_id,
|
||||||
Type_show_summary: aType.Show_summary,
|
TypeShowSummary: aType.Show_summary,
|
||||||
Type_show_description: aType.Show_description,
|
TypeShowDescription: aType.Show_description,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Summary: item.Summary,
|
Summary: item.Summary,
|
||||||
Description: item.Description,
|
Description: item.Description,
|
||||||
Tags: item.Tags,
|
Tags: item.Tags,
|
||||||
Type_icon: item.Type_icon,
|
TypeIcon: item.Type_icon,
|
||||||
Type_title: item.Type_title,
|
TypeTitle: item.Type_title,
|
||||||
FieldsSection: fieldsSection,
|
FieldsSection: fieldsSection,
|
||||||
FieldsValues: fieldsValues,
|
FieldsValues: fieldsValues,
|
||||||
Notebooks: notebooks,
|
Notebooks: notebooks,
|
||||||
|
@ -714,16 +714,16 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
data["item"] = itemForm{
|
data["item"] = itemForm{
|
||||||
Id: item.Id,
|
Id: item.Id,
|
||||||
Type_id: item.Type_id,
|
TypeId: item.Type_id,
|
||||||
Type_show_summary: item.Type_show_summary,
|
TypeShowSummary: item.Type_show_summary,
|
||||||
Type_show_description: item.Type_show_description,
|
TypeShowDescription: item.Type_show_description,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Summary: item.Summary,
|
Summary: item.Summary,
|
||||||
Description: item.Description,
|
Description: item.Description,
|
||||||
Tags: item.Tags,
|
Tags: item.Tags,
|
||||||
On_dashboard: item.On_dashboard,
|
OnDashboard: item.On_dashboard,
|
||||||
Type_icon: item.Type_icon,
|
TypeIcon: item.Type_icon,
|
||||||
Type_title: item.Type_title,
|
TypeTitle: item.Type_title,
|
||||||
FieldsSection: fieldsSection,
|
FieldsSection: fieldsSection,
|
||||||
FieldsValues: fieldsValues,
|
FieldsValues: fieldsValues,
|
||||||
Categories: categories,
|
Categories: categories,
|
||||||
|
@ -774,11 +774,11 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Title = itemFromForm.Title
|
item.Title = itemFromForm.Title
|
||||||
item.Type_id = itemFromForm.Type_id
|
item.Type_id = itemFromForm.TypeId
|
||||||
item.Summary = itemFromForm.Summary
|
item.Summary = itemFromForm.Summary
|
||||||
item.Description = itemFromForm.Description
|
item.Description = itemFromForm.Description
|
||||||
item.Tags = itemFromForm.Tags
|
item.Tags = itemFromForm.Tags
|
||||||
item.On_dashboard = itemFromForm.On_dashboard
|
item.On_dashboard = itemFromForm.OnDashboard
|
||||||
|
|
||||||
notebooks_str := strings.Join(itemFromForm.Notebooks, "|")
|
notebooks_str := strings.Join(itemFromForm.Notebooks, "|")
|
||||||
if len(notebooks_str) > 0 {
|
if len(notebooks_str) > 0 {
|
||||||
|
@ -855,8 +855,8 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
data["item"] = itemForm{
|
data["item"] = itemForm{
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Type_icon: item.Type_icon,
|
TypeIcon: item.Type_icon,
|
||||||
Type_title: item.Type_title,
|
TypeTitle: item.Type_title,
|
||||||
Relations: relations,
|
Relations: relations,
|
||||||
Shares: shares,
|
Shares: shares,
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,36 +14,36 @@ type Item struct {
|
||||||
Id int64 `db:"id"`
|
Id int64 `db:"id"`
|
||||||
Title string `db:"title"`
|
Title string `db:"title"`
|
||||||
Summary string `db:"summary"`
|
Summary string `db:"summary"`
|
||||||
Summary_rendered string `db:"summary_rendered"`
|
SummaryRendered string `db:"summary_rendered"`
|
||||||
Description string `db:"description"`
|
Description string `db:"description"`
|
||||||
Description_rendered string `db:"description_rendered"`
|
DescriptionRendered string `db:"description_rendered"`
|
||||||
Active int `db:"active"`
|
Active int `db:"active"`
|
||||||
Tags string `db:"tags"`
|
Tags string `db:"tags"`
|
||||||
Type_id int64 `db:"type_id"`
|
TypeId int64 `db:"type_id"`
|
||||||
Categories string `db:"categories"`
|
Categories string `db:"categories"`
|
||||||
Notebooks string `db:"notebooks"`
|
Notebooks string `db:"notebooks"`
|
||||||
Crypted int `db:"crypted"`
|
Crypted int `db:"crypted"`
|
||||||
Hidden int `db:"hidden"`
|
Hidden int `db:"hidden"`
|
||||||
On_dashboard int `db:"on_dashboard"`
|
OnDashboard int `db:"on_dashboard"`
|
||||||
On_dashboard_position int `db:"on_dashboard_position"`
|
OnDashboardPosition int `db:"on_dashboard_position"`
|
||||||
Type_title string `db:"type_title"`
|
TypeTitle string `db:"type_title"`
|
||||||
Type_icon string `db:"type_icon"`
|
TypeIcon string `db:"type_icon"`
|
||||||
Type_show_summary int `db:"type_show_summary"`
|
TypeShowSummary int `db:"type_show_summary"`
|
||||||
Type_show_description int `db:"type_show_description"`
|
TypeShowDescription int `db:"type_show_description"`
|
||||||
FieldsOnList []Field
|
FieldsOnList []Field
|
||||||
FieldsValues []FieldValue
|
FieldsValues []FieldValue
|
||||||
FieldsValuesMap map[int64]map[int]string
|
FieldsValuesMap map[int64]map[int]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemRelation struct {
|
type ItemRelation struct {
|
||||||
Item_id int64 `db:"item_id"`
|
ItemId int64 `db:"item_id"`
|
||||||
Related_item_id int64 `db:"related_item_id"`
|
RelatedItemId int64 `db:"related_item_id"`
|
||||||
Relation_type string `db:"relation_type"`
|
RelationType string `db:"relation_type"`
|
||||||
Title string `db:"title"`
|
Title string `db:"title"`
|
||||||
Categories string `db:"categories"`
|
Categories string `db:"categories"`
|
||||||
Tags string `db:"tags"`
|
Tags string `db:"tags"`
|
||||||
Type_title string `db:"type_title"`
|
TypeTitle string `db:"type_title"`
|
||||||
Type_icon string `db:"type_icon"`
|
TypeIcon string `db:"type_icon"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ItemModel struct {
|
type ItemModel struct {
|
||||||
|
@ -103,8 +103,8 @@ func (model *ItemModel) Search(searchText string, criteria map[string]any) ([]It
|
||||||
var conditions []string
|
var conditions []string
|
||||||
var cond string
|
var cond string
|
||||||
|
|
||||||
var conditions_criteria []string
|
var conditionsCriteria []string
|
||||||
var cond_criteria string
|
var condCriteria string
|
||||||
|
|
||||||
query := `SELECT DISTINCT bmi.*, bmt.title AS type_title, bmt.icon AS type_icon FROM bm_item bmi
|
query := `SELECT DISTINCT bmi.*, bmt.title AS type_title, bmt.icon AS type_icon FROM bm_item bmi
|
||||||
INNER JOIN bm_type bmt ON bmi.type_id=bmt.id
|
INNER JOIN bm_type bmt ON bmi.type_id=bmt.id
|
||||||
|
@ -118,7 +118,7 @@ func (model *ItemModel) Search(searchText string, criteria map[string]any) ([]It
|
||||||
if valint > 0 {
|
if valint > 0 {
|
||||||
valstr := "|" + strconv.FormatInt(valint, 10) + "|"
|
valstr := "|" + strconv.FormatInt(valint, 10) + "|"
|
||||||
params = append(params, valstr)
|
params = append(params, valstr)
|
||||||
conditions_criteria = append(conditions_criteria, "INSTR(bmi.notebooks, ?) > 0 ")
|
conditionsCriteria = append(conditionsCriteria, "INSTR(bmi.notebooks, ?) > 0 ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,27 +144,27 @@ func (model *ItemModel) Search(searchText string, criteria map[string]any) ([]It
|
||||||
cond = cond + condition
|
cond = cond + condition
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range conditions_criteria {
|
for _, condition := range conditionsCriteria {
|
||||||
if len(cond_criteria) > 0 {
|
if len(condCriteria) > 0 {
|
||||||
cond_criteria = cond_criteria + " AND "
|
condCriteria = condCriteria + " AND "
|
||||||
}
|
}
|
||||||
cond_criteria = cond_criteria + condition
|
condCriteria = condCriteria + condition
|
||||||
}
|
}
|
||||||
|
|
||||||
len_cond := len(cond)
|
lenCond := len(cond)
|
||||||
len_cond_criteria := len(cond_criteria)
|
lenCondCriteria := len(condCriteria)
|
||||||
|
|
||||||
if len_cond_criteria > 0 || len_cond > 0 {
|
if lenCondCriteria > 0 || lenCond > 0 {
|
||||||
query = query + "WHERE "
|
query = query + "WHERE "
|
||||||
}
|
}
|
||||||
|
|
||||||
if len_cond_criteria > 0 {
|
if lenCondCriteria > 0 {
|
||||||
query = query + cond_criteria
|
query = query + condCriteria
|
||||||
if len_cond > 0 {
|
if lenCond > 0 {
|
||||||
query = query + " AND (" + cond + ")"
|
query = query + " AND (" + cond + ")"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len_cond > 0 {
|
if lenCond > 0 {
|
||||||
query = query + " (" + cond + ")"
|
query = query + " (" + cond + ")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,11 +273,11 @@ func (model *ItemModel) Create(Item *Item) (int64, error) {
|
||||||
|
|
||||||
var bufSummary bytes.Buffer
|
var bufSummary bytes.Buffer
|
||||||
markdown.Convert([]byte(Item.Summary), &bufSummary)
|
markdown.Convert([]byte(Item.Summary), &bufSummary)
|
||||||
Item.Summary_rendered = bufSummary.String()
|
Item.SummaryRendered = bufSummary.String()
|
||||||
|
|
||||||
var bufDescription bytes.Buffer
|
var bufDescription bytes.Buffer
|
||||||
markdown.Convert([]byte(Item.Description), &bufDescription)
|
markdown.Convert([]byte(Item.Description), &bufDescription)
|
||||||
Item.Description_rendered = bufDescription.String()
|
Item.DescriptionRendered = bufDescription.String()
|
||||||
|
|
||||||
query := `INSERT INTO bm_item (type_id, title, summary, summary_rendered, description, description_rendered, on_dashboard, tags, notebooks, categories)
|
query := `INSERT INTO bm_item (type_id, title, summary, summary_rendered, description, description_rendered, on_dashboard, tags, notebooks, categories)
|
||||||
VALUES (:type_id, :title, :summary, :summary_rendered, :description, :description_rendered, :on_dashboard, :tags, :notebooks, :categories)`
|
VALUES (:type_id, :title, :summary, :summary_rendered, :description, :description_rendered, :on_dashboard, :tags, :notebooks, :categories)`
|
||||||
|
@ -303,11 +303,11 @@ func (model *ItemModel) Update(Item *Item) error {
|
||||||
|
|
||||||
var bufSummary bytes.Buffer
|
var bufSummary bytes.Buffer
|
||||||
markdown.Convert([]byte(Item.Summary), &bufSummary)
|
markdown.Convert([]byte(Item.Summary), &bufSummary)
|
||||||
Item.Summary_rendered = bufSummary.String()
|
Item.SummaryRendered = bufSummary.String()
|
||||||
|
|
||||||
var bufDescription bytes.Buffer
|
var bufDescription bytes.Buffer
|
||||||
markdown.Convert([]byte(Item.Description), &bufDescription)
|
markdown.Convert([]byte(Item.Description), &bufDescription)
|
||||||
Item.Description_rendered = bufDescription.String()
|
Item.DescriptionRendered = bufDescription.String()
|
||||||
|
|
||||||
query := `UPDATE bm_item SET title=:title, type_id=:type_id, summary=:summary, summary_rendered=:summary_rendered,
|
query := `UPDATE bm_item SET title=:title, type_id=:type_id, summary=:summary, summary_rendered=:summary_rendered,
|
||||||
description=:description, description_rendered=:description_rendered, tags=:tags, on_dashboard=:on_dashboard,
|
description=:description, description_rendered=:description_rendered, tags=:tags, on_dashboard=:on_dashboard,
|
||||||
|
@ -354,17 +354,17 @@ func (model *ItemModel) SaveKeywords(Item *Item, fields *[]Field, fieldsValues m
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
var keywords []string
|
var keywords []string
|
||||||
keywords = append(keywords, Item.Type_title)
|
keywords = append(keywords, Item.TypeTitle)
|
||||||
|
|
||||||
var categories_int []int64
|
var categoriesInt []int64
|
||||||
categories_str := strings.Split(strings.Trim(Item.Categories, "|"), "|")
|
categoriesStr := strings.Split(strings.Trim(Item.Categories, "|"), "|")
|
||||||
for _, category_str := range categories_str {
|
for _, categoryStr := range categoriesStr {
|
||||||
category_int, _ := strconv.ParseInt(category_str, 10, 64)
|
categoryInt, _ := strconv.ParseInt(categoryStr, 10, 64)
|
||||||
categories_int = append(categories_int, category_int)
|
categoriesInt = append(categoriesInt, categoryInt)
|
||||||
}
|
}
|
||||||
|
|
||||||
categoryModel := &CategoryModel{DB: model.DB}
|
categoryModel := &CategoryModel{DB: model.DB}
|
||||||
categories, _, _ := categoryModel.Find(categories_int)
|
categories, _, _ := categoryModel.Find(categoriesInt)
|
||||||
for _, category := range categories {
|
for _, category := range categories {
|
||||||
keywords = append(keywords, category.Name)
|
keywords = append(keywords, category.Name)
|
||||||
}
|
}
|
||||||
|
@ -405,12 +405,12 @@ func (model *ItemModel) SaveKeywords(Item *Item, fields *[]Field, fieldsValues m
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *ItemModel) AddRelation(id int64, related_id int64, relation_type string) error {
|
func (model *ItemModel) AddRelation(id int64, relatedId int64, relationType string) error {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
query := `INSERT INTO bm_item_relations (item_id, related_item_id, relation_type) VALUES($1, $2, $3)`
|
query := `INSERT INTO bm_item_relations (itemId, relatedItemId, relationType) VALUES($1, $2, $3)`
|
||||||
_, err := model.DB.ExecContext(ctx, query, id, related_id, relation_type)
|
_, err := model.DB.ExecContext(ctx, query, id, relatedId, relationType)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -418,12 +418,12 @@ func (model *ItemModel) AddRelation(id int64, related_id int64, relation_type st
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *ItemModel) UpdateRelation(id int64, related_id int64, relation_type string) error {
|
func (model *ItemModel) UpdateRelation(id int64, relatedId int64, relationType string) error {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
query := `UPDATE bm_item_relations SET relation_type=$1 WHERE item_id=$2 AND related_item_id=$3`
|
query := `UPDATE bm_item_relations SET relation_type=$1 WHERE item_id=$2 AND related_item_id=$3`
|
||||||
_, err := model.DB.ExecContext(ctx, query, relation_type, id, related_id)
|
_, err := model.DB.ExecContext(ctx, query, relationType, id, relatedId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -431,12 +431,12 @@ func (model *ItemModel) UpdateRelation(id int64, related_id int64, relation_type
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *ItemModel) DeleteRelation(id int64, related_id int64) error {
|
func (model *ItemModel) DeleteRelation(id int64, relatedId int64) error {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
query := `DELETE FROM bm_item_relations WHERE item_id=$1 AND related_item_id=$2`
|
query := `DELETE FROM bm_item_relations WHERE item_id=$1 AND related_item_id=$2`
|
||||||
_, err := model.DB.ExecContext(ctx, query, id, related_id)
|
_, err := model.DB.ExecContext(ctx, query, id, relatedId)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -15,7 +15,7 @@ type QuicknoteModel struct {
|
||||||
type Quicknote struct {
|
type Quicknote struct {
|
||||||
Id int64 `db:"id"`
|
Id int64 `db:"id"`
|
||||||
Note string `db:"note"`
|
Note string `db:"note"`
|
||||||
Note_rendered string `db:"note_rendered"`
|
NoteRendered string `db:"note_rendered"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *QuicknoteModel) One(id int64) (*Quicknote, bool, error) {
|
func (model *QuicknoteModel) One(id int64) (*Quicknote, bool, error) {
|
||||||
|
@ -133,7 +133,7 @@ func (model *QuicknoteModel) Create(Quicknote *Quicknote) (int64, error) {
|
||||||
|
|
||||||
var bufNote bytes.Buffer
|
var bufNote bytes.Buffer
|
||||||
markdown.Convert([]byte(Quicknote.Note), &bufNote)
|
markdown.Convert([]byte(Quicknote.Note), &bufNote)
|
||||||
Quicknote.Note_rendered = bufNote.String()
|
Quicknote.NoteRendered = bufNote.String()
|
||||||
|
|
||||||
query := `INSERT INTO bm_quicknote (note, note_rendered) VALUES (:note, :note_rendered)`
|
query := `INSERT INTO bm_quicknote (note, note_rendered) VALUES (:note, :note_rendered)`
|
||||||
|
|
||||||
|
@ -158,7 +158,7 @@ func (model *QuicknoteModel) Update(Quicknote *Quicknote) error {
|
||||||
|
|
||||||
var bufNote bytes.Buffer
|
var bufNote bytes.Buffer
|
||||||
markdown.Convert([]byte(Quicknote.Note), &bufNote)
|
markdown.Convert([]byte(Quicknote.Note), &bufNote)
|
||||||
Quicknote.Note_rendered = bufNote.String()
|
Quicknote.NoteRendered = bufNote.String()
|
||||||
|
|
||||||
query := `UPDATE bm_quicknote SET note=:note, note_rendered=:note_rendered WHERE id = :id`
|
query := `UPDATE bm_quicknote SET note=:note, note_rendered=:note_rendered WHERE id = :id`
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue