Code style cleanup
This commit is contained in:
parent
7bc82447cc
commit
008f26e9c1
24 changed files with 398 additions and 398 deletions
|
@ -1,16 +1,16 @@
|
||||||
{{define "item:add_relation"}}
|
{{define "item:add_relation"}}
|
||||||
{{ $relation_name := printf "%s%v" "ItemRelation-New-" .relatedItem.Id }}
|
{{ $relationName := printf "%s%v" "ItemRelation-New-" .relatedItem.Id }}
|
||||||
<tr id="{{$relation_name}}-Row">
|
<tr id="{{$relationName}}-Row">
|
||||||
<td class="no-label"><i class="{{.relatedItem.Type_icon}}"></i> {{.relatedItem.Type_title}} :
|
<td class="no-label"><i class="{{.relatedItem.TypeIcon}}"></i> {{.relatedItem.TypeTitle}} :
|
||||||
<a href="/item/view/{{.relatedItem.Id}}" hx-get="/item/view/{{.relatedItem.Id}}" hx-target="body" hx-swap="beforeend">{{.relatedItem.Title}}</a>
|
<a href="/item/view/{{.relatedItem.Id}}" hx-get="/item/view/{{.relatedItem.Id}}" hx-target="body" hx-swap="beforeend">{{.relatedItem.Title}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="no-label">
|
<td class="no-label">
|
||||||
{{ if gt (len .relatedItem.Categories) 0 }}
|
{{ if gt (len .relatedItem.Categories) 0 }}
|
||||||
<i class="hide-medium hide-large bi bi-bookmark-star-fill"></i>
|
<i class="hide-medium hide-large bi bi-bookmark-star-fill"></i>
|
||||||
{{ range (stringToArray .relatedItem.Categories "|")}}
|
{{ range (stringToArray .relatedItem.Categories "|")}}
|
||||||
{{ $category_name := index $.categoriesMap .}}
|
{{ $categoryName := index $.categoriesMap .}}
|
||||||
<div class="tag" style="padding: 3px">
|
<div class="tag" style="padding: 3px">
|
||||||
{{ $category_name }}
|
{{ $categoryName }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -25,9 +25,9 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</td>
|
</td>
|
||||||
<td class="no-label">{{ widget_relation_type $relation_name "Link" `id="$relation_name"` }}</td>
|
<td class="no-label">{{ widget_relation_type $relationName "Link" `id="$relationName"` }}</td>
|
||||||
<td class="no-label">
|
<td class="no-label">
|
||||||
<a class="button delete" href="#" onclick="document.getElementById('{{$relation_name}}-Row').remove()"><i class="bi bi-link-45deg" title="Remove relation"></i><span>Remove</span></a>
|
<a class="button delete" href="#" onclick="document.getElementById('{{$relationName}}-Row').remove()"><i class="bi bi-link-45deg" title="Remove relation"></i><span>Remove</span></a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -14,15 +14,15 @@
|
||||||
>
|
>
|
||||||
<td class="title no-label">
|
<td class="title no-label">
|
||||||
<a class="hide-xsmall" href="/item/view/{{.Id}}" hx-get="/item/view/{{.Id}}" hx-target="body" hx-swap="beforeend">{{.Title}}</a>
|
<a class="hide-xsmall" href="/item/view/{{.Id}}" hx-get="/item/view/{{.Id}}" hx-target="body" hx-swap="beforeend">{{.Title}}</a>
|
||||||
<a class="hide-medium hide-large" href="/item/read/{{.Id}}" hx-get="/item/read/{{.Id}}" hx-target="#page-content" hx-push-url="true"><i title="{{.Type_title}}" class="{{.Type_icon}}"></i> {{.Title}}</a>
|
<a class="hide-medium hide-large" href="/item/read/{{.Id}}" hx-get="/item/read/{{.Id}}" hx-target="#page-content" hx-push-url="true"><i title="{{.TypeTitle}}" class="{{.TypeIcon}}"></i> {{.Title}}</a>
|
||||||
</td>
|
</td>
|
||||||
<td data-label="Type" class="hide-xsmall" nowrap="nowrap"><i class="{{.Type_icon}}"></i> {{.Type_title}}</td>
|
<td data-label="Type" class="hide-xsmall" nowrap="nowrap"><i class="{{.TypeIcon}}"></i> {{.TypeTitle}}</td>
|
||||||
<td data-label="Categories" class="no-label links-list">
|
<td data-label="Categories" class="no-label links-list">
|
||||||
{{ if gt (len .Categories) 0 }}
|
{{ if gt (len .Categories) 0 }}
|
||||||
<i class="hide-medium hide-large bi bi-tags-fill"></i>
|
<i class="hide-medium hide-large bi bi-tags-fill"></i>
|
||||||
{{ range (stringToArray .Categories "|")}}
|
{{ range (stringToArray .Categories "|")}}
|
||||||
{{ $category_id := index $.categoriesMap .}}
|
{{ $categoryId := index $.categoriesMap .}}
|
||||||
<a hx-post="/items" hx-target="#page-content" hx-push-url="true" href="#" hx-vals="{"category_id" : "{{ . }}"}">{{ $category_id }}</a>
|
<a hx-post="/items" hx-target="#page-content" hx-push-url="true" href="#" hx-vals="{"category_id" : "{{ . }}"}">{{ $categoryId }}</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</td>
|
</td>
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
</td>
|
</td>
|
||||||
<td data-label="" class="operations" nowrap="nowrap">
|
<td data-label="" class="operations" nowrap="nowrap">
|
||||||
|
|
||||||
{{ if eq .On_dashboard 1}}
|
{{ if eq .OnDashboard 1}}
|
||||||
{{ template "item:remove_from_dashboard" .Id }}
|
{{ template "item:remove_from_dashboard" .Id }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ template "item:add_to_dashboard" .Id }}
|
{{ template "item:add_to_dashboard" .Id }}
|
||||||
|
|
|
@ -2,28 +2,28 @@
|
||||||
|
|
||||||
{{ range (index .FieldsSection .uisection) }}
|
{{ range (index .FieldsSection .uisection) }}
|
||||||
{{ $field := .}}
|
{{ $field := .}}
|
||||||
{{ $values := (index $.FieldsValues .Type_field_id)}}
|
{{ $values := (index $.FieldsValues .TypeFieldId)}}
|
||||||
|
|
||||||
{{ if eq .Is_multiple 1}}
|
{{ if eq .IsMultiple 1}}
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label>{{ .Title }}</label>
|
<label>{{ .Title }}</label>
|
||||||
<div id="fields-{{ .Type_field_id }}">
|
<div id="fields-{{ .TypeFieldId }}">
|
||||||
{{ $g_counter := 0 }}
|
{{ $g_counter := 0 }}
|
||||||
{{ range $counter, $value := $values}}
|
{{ range $counter, $value := $values}}
|
||||||
<input type="hidden" id="FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}}" name="FieldsValuesToRemove-{{$field.Type_field_id}}-{{$counter}}" value="0"/>
|
<input type="hidden" id="FieldsValuesToRemove-{{$field.TypeFieldId}}-{{$counter}}" name="FieldsValuesToRemove-{{$field.TypeFieldId}}-{{$counter}}" value="0"/>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div id="FieldsValues-{{$field.Type_field_id}}-{{$counter}}" class="field-value">{{ field_widget $field.Widget $field.Type_field_id $counter "" $value $field.Valid_values ""}}</div>
|
<div id="FieldsValues-{{$field.TypeFieldId}}-{{$counter}}" class="field-value">{{ field_widget $field.Widget $field.TypeFieldId $counter "" $value $field.Valid_values ""}}</div>
|
||||||
<div class="field-buttons">
|
<div class="field-buttons">
|
||||||
<button onclick="bm_item_field_delete(this, '{{$field.Type_field_id}}-{{$counter}}')" id="Delete-{{$field.Type_field_id}}-{{$counter}}" class="delete" type="button"><i class="bi bi-dash-square" title="Remove"></i></button>
|
<button onclick="bm_item_field_delete(this, '{{$field.TypeFieldId}}-{{$counter}}')" id="Delete-{{$field.TypeFieldId}}-{{$counter}}" class="delete" type="button"><i class="bi bi-dash-square" title="Remove"></i></button>
|
||||||
<button onclick="bm_item_field_undelete(this, '{{$field.Type_field_id}}-{{$counter}}')" id="Undelete-{{$field.Type_field_id}}-{{$counter}}" hidden class="main" type="button"><i class="bi bi-arrow-counterclockwise" title="Undo"></i></button>
|
<button onclick="bm_item_field_undelete(this, '{{$field.TypeFieldId}}-{{$counter}}')" id="Undelete-{{$field.TypeFieldId}}-{{$counter}}" hidden class="main" type="button"><i class="bi bi-arrow-counterclockwise" title="Undo"></i></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ $g_counter = $counter}}
|
{{ $g_counter = $counter}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="hide" id="fields-{{.Type_field_id}}-counter">{{incr $g_counter }}</span>
|
<span class="hide" id="fields-{{.TypeFieldId}}-counter">{{incr $g_counter }}</span>
|
||||||
<button type="button" onclick="bm_item_field_add('{{.Type_field_id}}', '{{.Widget}}')" class="main"><i class='bi bi-plus-square-fill'></i> <span> Add value</span></button>
|
<button type="button" onclick="bm_item_field_add('{{.TypeFieldId}}', '{{.Widget}}')" class="main"><i class='bi bi-plus-square-fill'></i> <span> Add value</span></button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<p>
|
<p>
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
{{ if gt (len $values) 0 }}
|
{{ if gt (len $values) 0 }}
|
||||||
{{ $value = index $values 0 }}
|
{{ $value = index $values 0 }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ field_widget .Widget .Type_field_id 0 .Title $value .Valid_values ""}}
|
{{ field_widget .Widget .TypeFieldId 0 .Title $value .Valid_values ""}}
|
||||||
</p>
|
</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<input name="Title" id="item-title" type="text" value="{{.item.Title}}" />
|
<input name="Title" id="item-title" type="text" value="{{.item.Title}}" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
{{ widget_select "Type_id" "Type" .item.Type_id .types `style="width: 100%"` }}
|
{{ widget_select "Type_id" "Type" .item.TypeId .types `style="width: 100%"` }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col s12 m6 l6">
|
<div class="col s12 m6 l6">
|
||||||
|
@ -45,14 +45,14 @@
|
||||||
{{ template "items:fields" (map "FieldsSection" .item.FieldsSection "FieldsValues" .item.FieldsValues "uisection" "general")}}
|
{{ template "items:fields" (map "FieldsSection" .item.FieldsSection "FieldsValues" .item.FieldsValues "uisection" "general")}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ if eq .item.Type_show_summary 1}}
|
{{ if eq .item.TypeShowSummary 1}}
|
||||||
<p>
|
<p>
|
||||||
<label for="item-summary">Summary</label>
|
<label for="item-summary">Summary</label>
|
||||||
<textarea name="Summary" id="item-summary" type="text" rows="5">{{.item.Summary}}</textarea>
|
<textarea name="Summary" id="item-summary" type="text" rows="5">{{.item.Summary}}</textarea>
|
||||||
</p>
|
</p>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ if eq .item.Type_show_description 1}}
|
{{ if eq .item.TypeShowDescription 1}}
|
||||||
<p>
|
<p>
|
||||||
<label for="item-description">Description</label>
|
<label for="item-description">Description</label>
|
||||||
<textarea name="Description" id="item-description" rows="10">{{.item.Description}}</textarea>
|
<textarea name="Description" id="item-description" rows="10">{{.item.Description}}</textarea>
|
||||||
|
@ -73,7 +73,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{{ widget_checkbox "On_dashboard" "On dashboard" "1" .item.On_dashboard }}
|
{{ widget_checkbox "On_dashboard" "On dashboard" "1" .item.OnDashboard }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -17,16 +17,16 @@
|
||||||
href="/item/view/{{.Id}}"
|
href="/item/view/{{.Id}}"
|
||||||
hx-get="/item/view/{{.Id}}"
|
hx-get="/item/view/{{.Id}}"
|
||||||
hx-target="#modal-container"
|
hx-target="#modal-container"
|
||||||
><i class="{{.Type_icon}}" title="{{.Type_title}}"></i> {{.Title}}</a
|
><i class="{{.TypeIcon}}" title="{{.TypeTitle}}"></i> {{.Title}}</a
|
||||||
>
|
>
|
||||||
</td>
|
</td>
|
||||||
<td class="no-label">
|
<td class="no-label">
|
||||||
{{ if gt (len .Categories) 0 }}
|
{{ if gt (len .Categories) 0 }}
|
||||||
<i class="hide-medium hide-large bi bi-tags-fill"></i>
|
<i class="hide-medium hide-large bi bi-tags-fill"></i>
|
||||||
{{ range (stringToArray .Categories "|")}}
|
{{ range (stringToArray .Categories "|")}}
|
||||||
{{ $category_name := index $.categoriesMap .}}
|
{{ $categoryName := index $.categoriesMap .}}
|
||||||
<div class="tag" style="padding: 3px">
|
<div class="tag" style="padding: 3px">
|
||||||
{{ $category_name }}
|
{{ $categoryName }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
{{ $fieldsValuesMap := .FieldsValuesMap}}
|
{{ $fieldsValuesMap := .FieldsValuesMap}}
|
||||||
{{ range $.Fields}}
|
{{ range $.Fields}}
|
||||||
<td class="no-label" data-label="{{.Title}}">
|
<td class="no-label" data-label="{{.Title}}">
|
||||||
{{ $values_str := renderFieldValues (index $fieldsValuesMap .Type_field_id) .Widget }}
|
{{ $values_str := renderFieldValues (index $fieldsValuesMap .TypeFieldId) .Widget }}
|
||||||
{{ if gt (len $values_str) 0 }}
|
{{ if gt (len $values_str) 0 }}
|
||||||
<span class="field-label hide-medium hide-large">{{.Title}} : </span>{{ $values_str }}
|
<span class="field-label hide-medium hide-large">{{.Title}} : </span>{{ $values_str }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
<td data-label="" class="operations" nowrap="nowrap">
|
<td data-label="" class="operations" nowrap="nowrap">
|
||||||
|
|
||||||
{{ if eq .On_dashboard 1}}
|
{{ if eq .OnDashboard 1}}
|
||||||
{{ template "item:remove_from_dashboard" .Id }}
|
{{ template "item:remove_from_dashboard" .Id }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ template "item:add_to_dashboard" .Id }}
|
{{ template "item:add_to_dashboard" .Id }}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{{define "page:title"}}
|
{{define "page:title"}}
|
||||||
<div id="page-title-title"> <h5>Edit {{.item.Type_title}}</h5></div>
|
<div id="page-title-title"> <h5>Edit {{.item.TypeTitle}}</h5></div>
|
||||||
<div class="hide-large" id="top-toolbar">
|
<div class="hide-large" id="top-toolbar">
|
||||||
<a class="button" href="#" onclick="bm_toggle_quickbox(); return false;"><i class='bi bi-inbox-fill'></i></a>
|
<a class="button" href="#" onclick="bm_toggle_quickbox(); return false;"><i class='bi bi-inbox-fill'></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
{{define "page:content"}}
|
{{define "page:content"}}
|
||||||
<dialog id="dialog" class="view">
|
<dialog id="dialog" class="view">
|
||||||
<header>
|
<header>
|
||||||
<h5><i class="{{.item.Type_icon}}" title="{{.item.Type_title}}"></i> {{.item.Type_title}} : {{.item.Title}}</h5>
|
<h5><i class="{{.item.TypeIcon}}" title="{{.item.TypeTitle}}"></i> {{.item.TypeTitle}} : {{.item.Title}}</h5>
|
||||||
<span class="close-dialog button close"><i class='close-dialog bi bi-x-circle-fill'></i></span>
|
<span class="close-dialog button close"><i class='close-dialog bi bi-x-circle-fill'></i></span>
|
||||||
</header>
|
</header>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{{ if gt (len .item.Summary) 0}}
|
{{ if gt (len .item.Summary) 0}}
|
||||||
<span style="font-weight: bold;">Summary</span>
|
<span style="font-weight: bold;">Summary</span>
|
||||||
<div class="summary">
|
<div class="summary">
|
||||||
{{.item.Summary_rendered | safeHTML}}
|
{{.item.SummaryRendered | safeHTML}}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{.item.Description_rendered | safeHTML}}
|
{{.item.DescriptionRendered | safeHTML}}
|
||||||
|
|
||||||
{{ if gt (len .fields) 0}}
|
{{ if gt (len .fields) 0}}
|
||||||
<ul class="fields">
|
<ul class="fields">
|
||||||
|
@ -28,9 +28,9 @@
|
||||||
<div class="col half">
|
<div class="col half">
|
||||||
<strong>Categories</strong>
|
<strong>Categories</strong>
|
||||||
{{ range (stringToArray .item.Categories "|")}}
|
{{ range (stringToArray .item.Categories "|")}}
|
||||||
{{ $category_name := index $.categoriesMap .}}
|
{{ $categoryName := index $.categoriesMap .}}
|
||||||
<div class="tag" style="padding: 3px">
|
<div class="tag" style="padding: 3px">
|
||||||
<a hx-post="/items" hx-target="#page-content" hx-push-url="true" href="#" hx-vals="{category_id" : "{{ . }}"}">{{ $category_name }}</a>
|
<a hx-post="/items" hx-target="#page-content" hx-push-url="true" href="#" hx-vals="{category_id" : "{{ . }}"}">{{ $categoryName }}</a>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col l11 m11 s11">
|
<div class="col l11 m11 s11">
|
||||||
<h5>
|
<h5>
|
||||||
<a class="show-large" href="/item/view/{{.Id}}" hx-get="/item/view/{{.Id}}" hx-target="body" hx-swap="beforeend"><i class="{{.Type_icon}}" title="{{.Type_title}}"></i> {{.Title}}</a>
|
<a class="show-large" href="/item/view/{{.Id}}" hx-get="/item/view/{{.Id}}" hx-target="body" hx-swap="beforeend"><i class="{{.TypeIcon}}" title="{{.TypeTitle}}"></i> {{.Title}}</a>
|
||||||
<a class="hide-large" href="/item/read/{{.Id}}" hx-get="/item/read/{{.Id}}" hx-target="#page-content" hx-push-url="true"><i class="{{.Type_icon}}" title="{{.Type_title}}"></i> {{.Title}}</a>
|
<a class="hide-large" href="/item/read/{{.Id}}" hx-get="/item/read/{{.Id}}" hx-target="#page-content" hx-push-url="true"><i class="{{.TypeIcon}}" title="{{.TypeTitle}}"></i> {{.Title}}</a>
|
||||||
</h5>
|
</h5>
|
||||||
<div class="home-card-summary">{{.Summary | markdownfy | safeHTML}}</div>
|
<div class="home-card-summary">{{.Summary | markdownfy | safeHTML}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
<button class="button" hx-delete="/quickbox/delete/{{.quicknote.Id}}" hx-target="closest div.quickbox-row" hx-swap="outerHTML swap:1s" hx-trigger='confirmed' onClick="bm_show_confirm_delete(this, 'Quickbox', 'Delete this note ?')"><i class="bi bi-dash-square"></i></button>
|
<button class="button" hx-delete="/quickbox/delete/{{.quicknote.Id}}" hx-target="closest div.quickbox-row" hx-swap="outerHTML swap:1s" hx-trigger='confirmed' onClick="bm_show_confirm_delete(this, 'Quickbox', 'Delete this note ?')"><i class="bi bi-dash-square"></i></button>
|
||||||
<button class="button" hx-target="body" hx-swap="beforeend" hx-get="/quickbox/transform/{{.quicknote.Id}}"><i class='bi bi-arrow-up-left-circle-fill'></i></button>
|
<button class="button" hx-target="body" hx-swap="beforeend" hx-get="/quickbox/transform/{{.quicknote.Id}}"><i class='bi bi-arrow-up-left-circle-fill'></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div>{{.quicknote.Note_rendered | safeHTML}}</div>
|
<div>{{.quicknote.NoteRendered | safeHTML}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
|
@ -13,7 +13,7 @@ hx-get="/quickbox/all?offset={{ $offset }}" hx-trigger="intersect once" hx-swap=
|
||||||
<button class="button" hx-delete="/quickbox/delete/{{.Id}}" hx-target="closest div.quickbox-row" hx-swap="outerHTML swap:1s" hx-trigger='confirmed' onClick="bm_show_confirm_delete(this, 'Quickbox', 'Delete this note ?')"><i class="bi bi-dash-square"></i></button>
|
<button class="button" hx-delete="/quickbox/delete/{{.Id}}" hx-target="closest div.quickbox-row" hx-swap="outerHTML swap:1s" hx-trigger='confirmed' onClick="bm_show_confirm_delete(this, 'Quickbox', 'Delete this note ?')"><i class="bi bi-dash-square"></i></button>
|
||||||
<button class="button" hx-target="body" hx-swap="beforeend" hx-get="/quickbox/transform/{{.Id}}"><i class='bi bi-arrow-up-left-circle-fill'></i></button>
|
<button class="button" hx-target="body" hx-swap="beforeend" hx-get="/quickbox/transform/{{.Id}}"><i class='bi bi-arrow-up-left-circle-fill'></i></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="note">{{.Note_rendered | safeHTML}}</div>
|
<div class="note">{{.NoteRendered | safeHTML}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
|
@ -1,36 +1,36 @@
|
||||||
{{define "types:fields"}}
|
{{define "types:fields"}}
|
||||||
{{ range .fields }}
|
{{ range .fields }}
|
||||||
<div class="card" style="padding: 10px; margin-top: 10px">
|
<div class="card" style="padding: 10px; margin-top: 10px">
|
||||||
<div id="Field-{{.Type_field_id}}">
|
<div id="Field-{{.TypeFieldId}}">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col half">
|
<div class="col half">
|
||||||
{{ widget_select (print "Fields-" .Type_field_id "-Widget_id") "Widget" .Widget_id $.widgets `` }}
|
{{ widget_select (print "Fields-" .TypeFieldId "-Widget_id") "Widget" .WidgetId $.widgets `` }}
|
||||||
</div>
|
</div>
|
||||||
<div class="half">
|
<div class="half">
|
||||||
<label for="Fields-{{.Type_field_id}}-Title">Title</label>
|
<label for="Fields-{{.TypeFieldId}}-Title">Title</label>
|
||||||
<input type="text" id="Fields-{{.Type_field_id}}-Title" name="Fields-{{.Type_field_id}}-Title" value="{{.Title}}"/>
|
<input type="text" id="Fields-{{.TypeFieldId}}-Title" name="Fields-{{.TypeFieldId}}-Title" value="{{.Title}}"/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col half">
|
<div class="col half">
|
||||||
<label for="Fields-{{.Type_field_id}}-Valid_values">Valid values</label>
|
<label for="Fields-{{.TypeFieldId}}-Valid_values">Valid values</label>
|
||||||
<input type="text" id="Fields-{{.Type_field_id}}-Valid_values" name="Fields-{{.Type_field_id}}-Valid_values" value="{{.Valid_values}}"/>
|
<input type="text" id="Fields-{{.TypeFieldId}}-Valid_values" name="Fields-{{.TypeFieldId}}-Valid_values" value="{{.ValidValues}}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col half">
|
<div class="col half">
|
||||||
{{ widget_select (print "Fields-" .Type_field_id "-Ui_section") "Section" .Ui_section $.uisections `` }}
|
{{ widget_select (print "Fields-" .TypeFieldId "-Ui_section") "Section" .UiSection $.uisections `` }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>{{ widget_checkbox (print "Fields-" .Type_field_id "-Show_on_list") "Show on list" "1" .Show_on_list }}</p>
|
<p>{{ widget_checkbox (print "Fields-" .TypeFieldId "-Show_on_list") "Show on list" "1" .ShowOnList }}</p>
|
||||||
<p>{{ widget_checkbox (print "Fields-" .Type_field_id "-Show_on_view") "Show on view" "1" .Show_on_view }}</p>
|
<p>{{ widget_checkbox (print "Fields-" .TypeFieldId "-Show_on_view") "Show on view" "1" .ShowOnView }}</p>
|
||||||
<p>{{ widget_checkbox (print "Fields-" .Type_field_id "-Is_multiple") "Multiple" "1" .Is_multiple }}</p>
|
<p>{{ widget_checkbox (print "Fields-" .TypeFieldId "-Is_multiple") "Multiple" "1" .IsMultiple }}</p>
|
||||||
|
|
||||||
<input type="hidden" id="Fields-{{.Type_field_id}}-ToRemove" name="Fields-{{.Type_field_id}}-ToRemove" value=""/>
|
<input type="hidden" id="Fields-{{.TypeFieldId}}-ToRemove" name="Fields-{{.TypeFieldId}}-ToRemove" value=""/>
|
||||||
</div>
|
</div>
|
||||||
<div class="bar">
|
<div class="bar">
|
||||||
<button id="Delete-{{.Type_field_id}}" type="button" style="float:right; margin-right: 5px;" class="delete" onclick="bm_type_field_delete(this, '{{.Type_field_id}}')"><i class="bi bi-file-minus" title="Remove"></i><span class="hide-xsmall"> Remove</span></button>
|
<button id="Delete-{{.TypeFieldId}}" type="button" style="float:right; margin-right: 5px;" class="delete" onclick="bm_type_field_delete(this, '{{.TypeFieldId}}')"><i class="bi bi-file-minus" title="Remove"></i><span class="hide-xsmall"> Remove</span></button>
|
||||||
<button id="Undelete-{{.Type_field_id}}" style="float:right; margin-right: 5px;" hidden type="button" class="delete" onclick="bm_type_field_undelete(this, '{{.Type_field_id}}')"><i class="bi bi-arrow-counterclockwise" title="Undo"></i><span class="hide-xsmall"> Undo</span></button>
|
<button id="Undelete-{{.TypeFieldId}}" style="float:right; margin-right: 5px;" hidden type="button" class="delete" onclick="bm_type_field_undelete(this, '{{.TypeFieldId}}')"><i class="bi bi-arrow-counterclockwise" title="Undo"></i><span class="hide-xsmall"> Undo</span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -28,9 +28,9 @@
|
||||||
<textarea name="Description" id="type-description" rows="5">{{.type.Description}}</textarea>
|
<textarea name="Description" id="type-description" rows="5">{{.type.Description}}</textarea>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>{{ widget_checkbox "Show_summary" "Show summary" "1" .type.Show_summary }}</p>
|
<p>{{ widget_checkbox "Show_summary" "Show summary" "1" .type.ShowSummary }}</p>
|
||||||
|
|
||||||
<p>{{ widget_checkbox "Show_description" "Show description" "1" .type.Show_description }}</p>
|
<p>{{ widget_checkbox "Show_description" "Show description" "1" .type.ShowDescription }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="tab" id="fields" style="display: none">
|
<div class="tab" id="fields" style="display: none">
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (app *application) categories(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) categoryCreate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) categoryCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
var category_id int64
|
var categoryId int64
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/category/create"
|
data["formAction"] = "/category/create"
|
||||||
|
@ -137,17 +137,17 @@ func (app *application) categoryCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
Name: categoryFromForm.Name,
|
Name: categoryFromForm.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
category_id, err = categoryModel.Create(category)
|
categoryId, err = categoryModel.Create(category)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.badRequest(w, err)
|
app.badRequest(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["formAction"] = fmt.Sprint("/category/update/", category_id)
|
data["formAction"] = fmt.Sprint("/category/update/", categoryId)
|
||||||
data["formTarget"] = "#page-content"
|
data["formTarget"] = "#page-content"
|
||||||
|
|
||||||
data["category"] = categoryForm{
|
data["category"] = categoryForm{
|
||||||
Id: category_id,
|
Id: categoryId,
|
||||||
Name: category.Name,
|
Name: category.Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func (app *application) categoryCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("HX-Trigger-After-Settle", `{"showMessage":""}`)
|
w.Header().Add("HX-Trigger-After-Settle", `{"showMessage":""}`)
|
||||||
w.Header().Add("HX-Replace-Url", fmt.Sprint("/type/update/", category_id))
|
w.Header().Add("HX-Replace-Url", fmt.Sprint("/type/update/", categoryId))
|
||||||
fullBuf.WriteTo(w)
|
fullBuf.WriteTo(w)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
@ -179,12 +179,12 @@ func (app *application) categoryCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) categoryUpdate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) categoryUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
category_id_str := flow.Param(r.Context(), "category_id")
|
categoryIdStr := flow.Param(r.Context(), "category_id")
|
||||||
category_id, _ := strconv.Atoi(category_id_str)
|
categoryId, _ := strconv.Atoi(categoryIdStr)
|
||||||
category, _, _ := categoryModel.One(category_id)
|
category, _, _ := categoryModel.One(categoryId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/category/update/" + category_id_str
|
data["formAction"] = "/category/update/" + categoryIdStr
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
data["messageType"] = ""
|
data["messageType"] = ""
|
||||||
data["messageContent"] = ""
|
data["messageContent"] = ""
|
||||||
|
@ -266,10 +266,10 @@ func (app *application) categoryUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) categoryDelete(w http.ResponseWriter, r *http.Request) {
|
func (app *application) categoryDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
category_id_str := flow.Param(r.Context(), "category_id")
|
categoryIdStr := flow.Param(r.Context(), "category_id")
|
||||||
category_id, _ := strconv.Atoi(category_id_str)
|
categoryId, _ := strconv.Atoi(categoryIdStr)
|
||||||
|
|
||||||
_, err := categoryModel.Delete(category_id)
|
_, err := categoryModel.Delete(categoryId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||||||
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"]
|
||||||
params := r.URL.Query()
|
params := r.URL.Query()
|
||||||
|
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
|
@ -27,8 +27,8 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
current_notebook_id = r.PostForm.Get("current_notebook_id")
|
currentNotebookId = r.PostForm.Get("current_notebook_id")
|
||||||
session.Values["current_notebook_id"] = current_notebook_id
|
session.Values["current_notebook_id"] = currentNotebookId
|
||||||
session.Save(r, w)
|
session.Save(r, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,21 +37,21 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"On_dashboard": 1,
|
"On_dashboard": 1,
|
||||||
"notebook_id": notebook_id,
|
"notebook_id": notebookId,
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
items, _, _ := itemModel.Find(criteria, offset)
|
items, _, _ := itemModel.Find(criteria, offset)
|
||||||
data["items"] = items
|
data["items"] = items
|
||||||
|
|
|
@ -17,9 +17,9 @@ func (app *application) newTemplateData(r *http.Request) map[string]any {
|
||||||
|
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
|
|
||||||
current_notebook_id := app.getCurrentNotebok_id(r)
|
currentNotebookId := app.getCurrentNotebookId(r)
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"notebook_id": current_notebook_id,
|
"notebook_id": currentNotebookId,
|
||||||
}
|
}
|
||||||
|
|
||||||
types, _, _ := typeModel.Find(criteria)
|
types, _, _ := typeModel.Find(criteria)
|
||||||
|
@ -27,7 +27,7 @@ func (app *application) newTemplateData(r *http.Request) map[string]any {
|
||||||
|
|
||||||
notebookModel := &models.NotebookModel{DB: app.db}
|
notebookModel := &models.NotebookModel{DB: app.db}
|
||||||
data["notebooksList"] = notebookModel.AllAsOptions(true)
|
data["notebooksList"] = notebookModel.AllAsOptions(true)
|
||||||
data["current_notebook_id"] = current_notebook_id
|
data["current_notebook_id"] = currentNotebookId
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ func (app *application) itemsSearch(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := make(map[string]any)
|
criteria := make(map[string]any)
|
||||||
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
criteria["notebook_id"] = app.getCurrentNotebookId(r)
|
||||||
|
|
||||||
rows, _, _ := itemModel.Search(r.PostForm.Get("SearchText"), criteria)
|
rows, _, _ := itemModel.Search(r.PostForm.Get("SearchText"), criteria)
|
||||||
data["items"] = &rows
|
data["items"] = &rows
|
||||||
|
@ -176,7 +176,7 @@ func (app *application) itemsSearchForRelations(w http.ResponseWriter, r *http.R
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := make(map[string]any)
|
criteria := make(map[string]any)
|
||||||
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
criteria["notebook_id"] = app.getCurrentNotebookId(r)
|
||||||
|
|
||||||
rows, _, _ := itemModel.Search(r.Form.Get("SearchText"), criteria)
|
rows, _, _ := itemModel.Search(r.Form.Get("SearchText"), criteria)
|
||||||
data["items"] = &rows
|
data["items"] = &rows
|
||||||
|
@ -226,7 +226,7 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
||||||
app.removeSessionValue(w, r, criteriaName)
|
app.removeSessionValue(w, r, criteriaName)
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
criteria["notebook_id"] = app.getCurrentNotebookId(r)
|
||||||
|
|
||||||
rows, _, _ := itemModel.Find(criteria, offset)
|
rows, _, _ := itemModel.Find(criteria, offset)
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria["type_id"] = typeId
|
criteria["type_id"] = typeId
|
||||||
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
criteria["notebook_id"] = app.getCurrentNotebookId(r)
|
||||||
|
|
||||||
rows, _, _ := itemModel.Find(criteria, offset)
|
rows, _, _ := itemModel.Find(criteria, offset)
|
||||||
for i, row := range rows {
|
for i, row := range rows {
|
||||||
|
@ -434,7 +434,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||||
|
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"notebook_id": app.getCurrentNotebok_id(r),
|
"notebook_id": app.getCurrentNotebookId(r),
|
||||||
}
|
}
|
||||||
data["types"] = typeModel.FindAsOptions(criteria)
|
data["types"] = typeModel.FindAsOptions(criteria)
|
||||||
|
|
||||||
|
@ -448,13 +448,13 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
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:
|
||||||
notebooks := []string{strconv.FormatInt(app.getCurrentNotebok_id(r), 10)}
|
notebooks := []string{strconv.FormatInt(app.getCurrentNotebookId(r), 10)}
|
||||||
|
|
||||||
data["item"] = itemForm{
|
data["item"] = itemForm{
|
||||||
Title: "",
|
Title: "",
|
||||||
TypeId: typeId,
|
TypeId: typeId,
|
||||||
TypeShowSummary: aType.Show_summary,
|
TypeShowSummary: aType.ShowSummary,
|
||||||
TypeShowDescription: aType.Show_description,
|
TypeShowDescription: aType.ShowDescription,
|
||||||
Summary: "",
|
Summary: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Tags: "",
|
Tags: "",
|
||||||
|
@ -468,7 +468,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
|
|
||||||
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", "items/shares.tmpl"}, "page:content", data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
@ -481,7 +481,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add("HX-Trigger-After-Settle", `{"activateEasyMDE":"item-description"}`)
|
w.Header().Add("HX-Trigger-After-Settle", `{"activateEasyMDE":"item-description"}`)
|
||||||
fullBuf.WriteTo(w)
|
fullBuf.WriteTo(w)
|
||||||
} else {
|
} else {
|
||||||
err := response.Page(w, http.StatusOK, data, []string{"items/create_title.tmpl", "items/relations.tmpl", "items/form.tmpl", "items/fields.tmpl", "items/form_jscode.tmpl"})
|
err := response.Page(w, http.StatusOK, data, []string{"items/create_title.tmpl", "items/relations.tmpl", "items/form.tmpl", "items/fields.tmpl", "items/form_jscode.tmpl", "items/shares.tmpl"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
@ -501,12 +501,12 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
item := &models.Item{
|
item := &models.Item{
|
||||||
TypeId: itemFromForm.TypeId,
|
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.OnDashboard,
|
OnDashboard: itemFromForm.OnDashboard,
|
||||||
}
|
}
|
||||||
|
|
||||||
notebooksStr := strings.Join(itemFromForm.Notebooks, "|")
|
notebooksStr := strings.Join(itemFromForm.Notebooks, "|")
|
||||||
|
@ -515,11 +515,11 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
item.Notebooks = notebooksStr
|
item.Notebooks = notebooksStr
|
||||||
|
|
||||||
categories_str := strings.Join(itemFromForm.Categories, "|")
|
categoriesStr := strings.Join(itemFromForm.Categories, "|")
|
||||||
if len(categories_str) > 0 {
|
if len(categoriesStr) > 0 {
|
||||||
categories_str = "|" + categories_str + "|"
|
categoriesStr = "|" + categoriesStr + "|"
|
||||||
}
|
}
|
||||||
item.Categories = categories_str
|
item.Categories = categoriesStr
|
||||||
|
|
||||||
itemId, err = itemModel.Create(item)
|
itemId, err = itemModel.Create(item)
|
||||||
item.Id = itemId
|
item.Id = itemId
|
||||||
|
@ -530,35 +530,35 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
fieldsValues := make(map[int64]map[int]string)
|
fieldsValues := make(map[int64]map[int]string)
|
||||||
for name, values := range r.PostForm {
|
for name, values := range r.PostForm {
|
||||||
id_s, found := strings.CutPrefix(name, "FieldsValues-")
|
idS, found := strings.CutPrefix(name, "FieldsValues-")
|
||||||
if found {
|
if found {
|
||||||
parts := strings.Split(id_s, "-")
|
parts := strings.Split(idS, "-")
|
||||||
type_field_id, _ := strconv.ParseInt(parts[0], 10, 64)
|
typeFieldId, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||||
counter, _ := strconv.Atoi(parts[1])
|
counter, _ := strconv.Atoi(parts[1])
|
||||||
|
|
||||||
_, found_key := fieldsValues[type_field_id]
|
_, foundKey := fieldsValues[typeFieldId]
|
||||||
if !found_key {
|
if !foundKey {
|
||||||
fieldsValues[type_field_id] = make(map[int]string)
|
fieldsValues[typeFieldId] = make(map[int]string)
|
||||||
}
|
}
|
||||||
fieldsValues[type_field_id][counter] = values[0]
|
fieldsValues[typeFieldId][counter] = values[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
related_id_s, found := strings.CutPrefix(name, "ItemRelation-New-")
|
relatedIdS, found := strings.CutPrefix(name, "ItemRelation-New-")
|
||||||
if found && len(values) > 0 {
|
if found && len(values) > 0 {
|
||||||
related_item_id, _ := strconv.ParseInt(related_id_s, 10, 64)
|
relatedItemId, _ := strconv.ParseInt(relatedIdS, 10, 64)
|
||||||
itemModel.AddRelation(item.Id, related_item_id, values[0])
|
itemModel.AddRelation(item.Id, relatedItemId, values[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for type_field_id, values := range fieldsValues {
|
for typeFieldId, values := range fieldsValues {
|
||||||
fieldModel.SaveValues(item.Id, type_field_id, values)
|
fieldModel.SaveValues(item.Id, typeFieldId, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Type_title = aType.Title
|
item.TypeTitle = aType.Title
|
||||||
fields, _, _ := fieldModel.ByType(type_id)
|
fields, _, _ := fieldModel.ByType(typeId)
|
||||||
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
||||||
|
|
||||||
data["formAction"] = fmt.Sprint("/item/update/", item_id)
|
data["formAction"] = fmt.Sprint("/item/update/", itemId)
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
|
|
||||||
notebooks := strings.Split(strings.Trim(item.Notebooks, "|"), "|")
|
notebooks := strings.Split(strings.Trim(item.Notebooks, "|"), "|")
|
||||||
|
@ -567,16 +567,16 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
shares, _, _ := itemModel.GetShares(item.Id)
|
shares, _, _ := itemModel.GetShares(item.Id)
|
||||||
|
|
||||||
data["item"] = itemForm{
|
data["item"] = itemForm{
|
||||||
Id: item_id,
|
Id: itemId,
|
||||||
TypeId: type_id,
|
TypeId: typeId,
|
||||||
TypeShowSummary: aType.Show_summary,
|
TypeShowSummary: aType.ShowSummary,
|
||||||
TypeShowDescription: aType.Show_description,
|
TypeShowDescription: aType.ShowDescription,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Summary: item.Summary,
|
Summary: item.Summary,
|
||||||
Description: item.Description,
|
Description: item.Description,
|
||||||
Tags: item.Tags,
|
Tags: item.Tags,
|
||||||
TypeIcon: item.Type_icon,
|
TypeIcon: item.TypeIcon,
|
||||||
TypeTitle: item.Type_title,
|
TypeTitle: item.TypeTitle,
|
||||||
FieldsSection: fieldsSection,
|
FieldsSection: fieldsSection,
|
||||||
FieldsValues: fieldsValues,
|
FieldsValues: fieldsValues,
|
||||||
Notebooks: notebooks,
|
Notebooks: notebooks,
|
||||||
|
@ -604,7 +604,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("HX-Trigger-After-Settle", `{"activateEasyMDE":"item-description","showMessage":""}`)
|
w.Header().Add("HX-Trigger-After-Settle", `{"activateEasyMDE":"item-description","showMessage":""}`)
|
||||||
w.Header().Add("HX-Replace-Url", fmt.Sprint("/item/update/", item_id))
|
w.Header().Add("HX-Replace-Url", fmt.Sprint("/item/update/", itemId))
|
||||||
fullBuf.WriteTo(w)
|
fullBuf.WriteTo(w)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
@ -613,18 +613,18 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) itemRead(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemRead(w http.ResponseWriter, r *http.Request) {
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
itemId, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
relations, _, _ := itemModel.GetRelations(item_id)
|
relations, _, _ := itemModel.GetRelations(itemId)
|
||||||
|
|
||||||
item, _, _ := itemModel.One(item_id)
|
item, _, _ := itemModel.One(itemId)
|
||||||
|
|
||||||
data["item"] = &item
|
data["item"] = &item
|
||||||
data["relations"] = relations
|
data["relations"] = relations
|
||||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||||
data["fields"] = fieldModel.GetFieldsValues(item_id)
|
data["fields"] = fieldModel.GetFieldsValues(itemId)
|
||||||
|
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
@ -652,18 +652,18 @@ func (app *application) itemRead(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) itemView(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemView(w http.ResponseWriter, r *http.Request) {
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
itemId, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
categoryModel := &models.CategoryModel{DB: app.db}
|
categoryModel := &models.CategoryModel{DB: app.db}
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
|
|
||||||
item, _, _ := itemModel.One(item_id)
|
item, _, _ := itemModel.One(itemId)
|
||||||
relations, _, _ := itemModel.GetRelations(item_id)
|
relations, _, _ := itemModel.GetRelations(itemId)
|
||||||
|
|
||||||
data["item"] = &item
|
data["item"] = &item
|
||||||
data["relations"] = relations
|
data["relations"] = relations
|
||||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||||
data["fields"] = fieldModel.GetFieldsValues(item_id)
|
data["fields"] = fieldModel.GetFieldsValues(itemId)
|
||||||
|
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
@ -686,14 +686,14 @@ func (app *application) itemView(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
item_id_str := flow.Param(r.Context(), "item_id")
|
itemIdStr := flow.Param(r.Context(), "item_id")
|
||||||
item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
itemId, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
item, _, _ := itemModel.One(item_id)
|
item, _, _ := itemModel.One(itemId)
|
||||||
fieldsSection, _, _ := fieldModel.ByTypeSection(item.Type_id)
|
fieldsSection, _, _ := fieldModel.ByTypeSection(item.TypeId)
|
||||||
fieldsValues := fieldModel.GetFieldsValuesAsMap(item.Id)
|
fieldsValues := fieldModel.GetFieldsValuesAsMap(item.Id)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/item/update/" + item_id_str
|
data["formAction"] = "/item/update/" + itemIdStr
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
|
|
||||||
notebookModel := &models.NotebookModel{DB: app.db}
|
notebookModel := &models.NotebookModel{DB: app.db}
|
||||||
|
@ -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,
|
||||||
TypeId: item.Type_id,
|
TypeId: item.TypeId,
|
||||||
TypeShowSummary: item.Type_show_summary,
|
TypeShowSummary: item.TypeShowSummary,
|
||||||
TypeShowDescription: item.Type_show_description,
|
TypeShowDescription: item.TypeShowDescription,
|
||||||
Title: item.Title,
|
Title: item.Title,
|
||||||
Summary: item.Summary,
|
Summary: item.Summary,
|
||||||
Description: item.Description,
|
Description: item.Description,
|
||||||
Tags: item.Tags,
|
Tags: item.Tags,
|
||||||
OnDashboard: item.On_dashboard,
|
OnDashboard: item.OnDashboard,
|
||||||
TypeIcon: item.Type_icon,
|
TypeIcon: item.TypeIcon,
|
||||||
TypeTitle: item.Type_title,
|
TypeTitle: item.TypeTitle,
|
||||||
FieldsSection: fieldsSection,
|
FieldsSection: fieldsSection,
|
||||||
FieldsValues: fieldsValues,
|
FieldsValues: fieldsValues,
|
||||||
Categories: categories,
|
Categories: categories,
|
||||||
|
@ -736,7 +736,7 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
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),
|
||||||
}
|
}
|
||||||
data["types"] = typeModel.FindAsOptions(criteria)
|
data["types"] = typeModel.FindAsOptions(criteria)
|
||||||
|
|
||||||
|
@ -774,23 +774,23 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
item.Title = itemFromForm.Title
|
item.Title = itemFromForm.Title
|
||||||
item.Type_id = itemFromForm.TypeId
|
item.TypeId = 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.OnDashboard
|
item.OnDashboard = 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, "|")
|
categoriesStr := strings.Join(itemFromForm.Categories, "|")
|
||||||
if len(categories_str) > 0 {
|
if len(categoriesStr) > 0 {
|
||||||
categories_str = "|" + categories_str + "|"
|
categoriesStr = "|" + categoriesStr + "|"
|
||||||
}
|
}
|
||||||
item.Categories = categories_str
|
item.Categories = categoriesStr
|
||||||
|
|
||||||
err = itemModel.Update(item)
|
err = itemModel.Update(item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -800,37 +800,37 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
fieldsValues := make(map[int64]map[int]string)
|
fieldsValues := make(map[int64]map[int]string)
|
||||||
for name, values := range r.PostForm {
|
for name, values := range r.PostForm {
|
||||||
id_s, found := strings.CutPrefix(name, "FieldsValues-")
|
idS, found := strings.CutPrefix(name, "FieldsValues-")
|
||||||
if found {
|
if found {
|
||||||
parts := strings.Split(id_s, "-")
|
parts := strings.Split(idS, "-")
|
||||||
type_field_id, _ := strconv.ParseInt(parts[0], 10, 64)
|
typeFieldId, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||||
counter, _ := strconv.Atoi(parts[1])
|
counter, _ := strconv.Atoi(parts[1])
|
||||||
|
|
||||||
valuesRemove, isMapContainsKey := r.PostForm["FieldsValuesToRemove-"+id_s]
|
valuesRemove, isMapContainsKey := r.PostForm["FieldsValuesToRemove-"+idS]
|
||||||
if !isMapContainsKey || valuesRemove[0] == "0" {
|
if !isMapContainsKey || valuesRemove[0] == "0" {
|
||||||
_, found_key := fieldsValues[type_field_id]
|
_, foundKey := fieldsValues[typeFieldId]
|
||||||
if !found_key {
|
if !foundKey {
|
||||||
fieldsValues[type_field_id] = make(map[int]string)
|
fieldsValues[typeFieldId] = make(map[int]string)
|
||||||
}
|
}
|
||||||
fieldsValues[type_field_id][counter] = values[0]
|
fieldsValues[typeFieldId][counter] = values[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
related_id_s, found := strings.CutPrefix(name, "ItemRelation-New-")
|
relatedIdS, found := strings.CutPrefix(name, "ItemRelation-New-")
|
||||||
if found && len(values) > 0 {
|
if found && len(values) > 0 {
|
||||||
related_item_id, _ := strconv.ParseInt(related_id_s, 10, 64)
|
relatedItemId, _ := strconv.ParseInt(relatedIdS, 10, 64)
|
||||||
itemModel.AddRelation(item.Id, related_item_id, values[0])
|
itemModel.AddRelation(item.Id, relatedItemId, values[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
id_s, found = strings.CutPrefix(name, "ItemRelation-")
|
idS, found = strings.CutPrefix(name, "ItemRelation-")
|
||||||
if found && len(values) > 0 {
|
if found && len(values) > 0 {
|
||||||
ids := strings.Split(id_s, "-")
|
ids := strings.Split(idS, "-")
|
||||||
item_id, _ := strconv.ParseInt(ids[0], 10, 64)
|
itemId, _ := strconv.ParseInt(ids[0], 10, 64)
|
||||||
related_item_id, _ := strconv.ParseInt(ids[1], 10, 64)
|
relatedItemId, _ := strconv.ParseInt(ids[1], 10, 64)
|
||||||
valuesRemove, isMapContainsKey := r.PostForm["ItemRelation-ToRemove-"+id_s]
|
valuesRemove, isMapContainsKey := r.PostForm["ItemRelation-ToRemove-"+idS]
|
||||||
if isMapContainsKey && valuesRemove[0] == "1" {
|
if isMapContainsKey && valuesRemove[0] == "1" {
|
||||||
itemModel.DeleteRelation(item_id, related_item_id)
|
itemModel.DeleteRelation(itemId, relatedItemId)
|
||||||
} else {
|
} else {
|
||||||
itemModel.UpdateRelation(item_id, related_item_id, values[0])
|
itemModel.UpdateRelation(itemId, relatedItemId, values[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shareId, found := strings.CutPrefix(name, "ItemShare-ToRemove-")
|
shareId, found := strings.CutPrefix(name, "ItemShare-ToRemove-")
|
||||||
|
@ -843,11 +843,11 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for type_field_id, values := range fieldsValues {
|
for typeFieldId, values := range fieldsValues {
|
||||||
fieldModel.SaveValues(item.Id, type_field_id, values)
|
fieldModel.SaveValues(item.Id, typeFieldId, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
fields, _, _ := fieldModel.ByType(item.Type_id)
|
fields, _, _ := fieldModel.ByType(item.TypeId)
|
||||||
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
||||||
|
|
||||||
relations, _, _ := itemModel.GetRelations(item.Id)
|
relations, _, _ := itemModel.GetRelations(item.Id)
|
||||||
|
@ -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,
|
||||||
TypeIcon: item.Type_icon,
|
TypeIcon: item.TypeIcon,
|
||||||
TypeTitle: item.Type_title,
|
TypeTitle: item.TypeTitle,
|
||||||
Relations: relations,
|
Relations: relations,
|
||||||
Shares: shares,
|
Shares: shares,
|
||||||
}
|
}
|
||||||
|
@ -913,10 +913,10 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) itemDelete(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
itemModel := models.NewItemModel(app.db)
|
itemModel := models.NewItemModel(app.db)
|
||||||
item_id_str := flow.Param(r.Context(), "item_id")
|
itemIdStr := flow.Param(r.Context(), "item_id")
|
||||||
item_id, _ := strconv.Atoi(item_id_str)
|
itemId, _ := strconv.Atoi(itemIdStr)
|
||||||
|
|
||||||
_, err := itemModel.Delete(item_id)
|
_, err := itemModel.Delete(itemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
@ -924,8 +924,8 @@ func (app *application) itemDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) itemShare(w http.ResponseWriter, r *http.Request) {
|
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)
|
itemId, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
item, _, _ := itemModel.One(item_id)
|
item, _, _ := itemModel.One(itemId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["item"] = item
|
data["item"] = item
|
||||||
|
@ -957,7 +957,7 @@ func (app *application) itemShare(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
itemShare := &models.ItemShare{
|
itemShare := &models.ItemShare{
|
||||||
ItemId: item_id,
|
ItemId: itemId,
|
||||||
Token: itemShareFromForm.Token,
|
Token: itemShareFromForm.Token,
|
||||||
Password: itemShareFromForm.Password,
|
Password: itemShareFromForm.Password,
|
||||||
PermissionEdit: itemShareFromForm.PermissionEdit,
|
PermissionEdit: itemShareFromForm.PermissionEdit,
|
||||||
|
@ -990,16 +990,16 @@ func (app *application) itemShare(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) itemAddToDashboard(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemAddToDashboard(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)
|
itemId, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
|
|
||||||
err := itemModel.AddToDashboard(item_id)
|
err := itemModel.AddToDashboard(itemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
err = response.HXFragment(fullBuf, []string{"items/remove_from_dashboard.tmpl"}, "item:remove_from_dashboard", item_id)
|
err = response.HXFragment(fullBuf, []string{"items/remove_from_dashboard.tmpl"}, "item:remove_from_dashboard", itemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
@ -1009,9 +1009,9 @@ func (app *application) itemAddToDashboard(w http.ResponseWriter, r *http.Reques
|
||||||
|
|
||||||
func (app *application) itemRemoveFromDashboard(w http.ResponseWriter, r *http.Request) {
|
func (app *application) itemRemoveFromDashboard(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)
|
itemId, _ := strconv.ParseInt(flow.Param(r.Context(), "item_id"), 10, 64)
|
||||||
|
|
||||||
err := itemModel.RemoveFromDashboard(item_id)
|
err := itemModel.RemoveFromDashboard(itemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1019,7 @@ func (app *application) itemRemoveFromDashboard(w http.ResponseWriter, r *http.R
|
||||||
if r.Method == http.MethodPost {
|
if r.Method == http.MethodPost {
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
|
||||||
err := response.HXFragment(fullBuf, []string{"items/add_to_dashboard.tmpl"}, "item:add_to_dashboard", item_id)
|
err := response.HXFragment(fullBuf, []string{"items/add_to_dashboard.tmpl"}, "item:add_to_dashboard", itemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ func (app *application) notebooks(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) notebookCreate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) notebookCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
notebookModel := &models.NotebookModel{DB: app.db}
|
notebookModel := &models.NotebookModel{DB: app.db}
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
var notebook_id int64
|
var notebookId int64
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/notebook/create"
|
data["formAction"] = "/notebook/create"
|
||||||
|
@ -141,17 +141,17 @@ func (app *application) notebookCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
Description: notebookFromForm.Description,
|
Description: notebookFromForm.Description,
|
||||||
}
|
}
|
||||||
|
|
||||||
notebook_id, err = notebookModel.Create(notebook)
|
notebookId, err = notebookModel.Create(notebook)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.badRequest(w, err)
|
app.badRequest(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["formAction"] = fmt.Sprint("/notebook/update/", notebook_id)
|
data["formAction"] = fmt.Sprint("/notebook/update/", notebookId)
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
|
|
||||||
data["notebook"] = notebookForm{
|
data["notebook"] = notebookForm{
|
||||||
Id: notebook_id,
|
Id: notebookId,
|
||||||
Title: notebook.Title,
|
Title: notebook.Title,
|
||||||
Icon: notebook.Icon,
|
Icon: notebook.Icon,
|
||||||
Description: notebook.Description,
|
Description: notebook.Description,
|
||||||
|
@ -182,7 +182,7 @@ func (app *application) notebookCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("HX-Replace-Url", fmt.Sprint("/notebook/update/", notebook_id))
|
w.Header().Add("HX-Replace-Url", fmt.Sprint("/notebook/update/", notebookId))
|
||||||
fullBuf.WriteTo(w)
|
fullBuf.WriteTo(w)
|
||||||
|
|
||||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||||
|
@ -191,12 +191,12 @@ func (app *application) notebookCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) notebookUpdate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) notebookUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
notebookModel := &models.NotebookModel{DB: app.db}
|
notebookModel := &models.NotebookModel{DB: app.db}
|
||||||
notebook_id_str := flow.Param(r.Context(), "notebook_id")
|
notebookIdStr := flow.Param(r.Context(), "notebook_id")
|
||||||
notebook_id, _ := strconv.ParseInt(notebook_id_str, 10, 64)
|
notebookId, _ := strconv.ParseInt(notebookIdStr, 10, 64)
|
||||||
notebook, _, _ := notebookModel.One(notebook_id)
|
notebook, _, _ := notebookModel.One(notebookId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/notebook/update/" + notebook_id_str
|
data["formAction"] = "/notebook/update/" + notebookIdStr
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
|
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
|
@ -289,10 +289,10 @@ func (app *application) notebookUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) notebookDelete(w http.ResponseWriter, r *http.Request) {
|
func (app *application) notebookDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
notebookModel := &models.NotebookModel{DB: app.db}
|
notebookModel := &models.NotebookModel{DB: app.db}
|
||||||
notebook_id_str := flow.Param(r.Context(), "notebook_id")
|
notebookIdStr := flow.Param(r.Context(), "notebook_id")
|
||||||
notebook_id, _ := strconv.ParseInt(notebook_id_str, 10, 64)
|
notebookId, _ := strconv.ParseInt(notebookIdStr, 10, 64)
|
||||||
|
|
||||||
_, err := notebookModel.Delete(notebook_id)
|
_, err := notebookModel.Delete(notebookId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,20 +15,20 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type quicknoteForm struct {
|
type quicknoteForm struct {
|
||||||
Id int64 `form:"Id"`
|
Id int64 `form:"Id"`
|
||||||
Note string `form:"Note"`
|
Note string `form:"Note"`
|
||||||
Note_rendered string `form:"Note_rendered"`
|
NoteRendered string `form:"Note_rendered"`
|
||||||
Validator validator.Validator `form:"-"`
|
Validator validator.Validator `form:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type quicknoteTransformForm struct {
|
type quicknoteTransformForm struct {
|
||||||
Title string `form:"Title"`
|
Title string `form:"Title"`
|
||||||
Type_id int64 `form:"Type_id"`
|
TypeId int64 `form:"Type_id"`
|
||||||
Description string `form:"Description"`
|
Description string `form:"Description"`
|
||||||
Tags string `form:"Tags"`
|
Tags string `form:"Tags"`
|
||||||
Categories []string `form:"Categories"`
|
Categories []string `form:"Categories"`
|
||||||
Notebooks []string `form:"Notebooks"`
|
Notebooks []string `form:"Notebooks"`
|
||||||
Keep_in_quickbox int `form:"Keep_in_quickbox"`
|
KeepInQuickbox int `form:"Keep_in_quickbox"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *application) quickboxAll(w http.ResponseWriter, r *http.Request) {
|
func (app *application) quickboxAll(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -39,12 +39,12 @@ func (app *application) quickboxAll(w http.ResponseWriter, r *http.Request) {
|
||||||
quicknoteModel := &models.QuicknoteModel{BaseModel: &models.BaseModel{DB: app.db}}
|
quicknoteModel := &models.QuicknoteModel{BaseModel: &models.BaseModel{DB: app.db}}
|
||||||
|
|
||||||
params := r.URL.Query()
|
params := r.URL.Query()
|
||||||
offset_str := params.Get("offset")
|
offsetStr := params.Get("offset")
|
||||||
var offset int64 = 0
|
var offset int64 = 0
|
||||||
if len(offset_str) == 0 {
|
if len(offsetStr) == 0 {
|
||||||
offset = 0
|
offset = 0
|
||||||
} else {
|
} else {
|
||||||
offset, _ = strconv.ParseInt(offset_str, 10, 64)
|
offset, _ = strconv.ParseInt(offsetStr, 10, 64)
|
||||||
}
|
}
|
||||||
data["offset"] = offset
|
data["offset"] = offset
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ func (app *application) quickboxAll(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) quickboxAdd(w http.ResponseWriter, r *http.Request) {
|
func (app *application) quickboxAdd(w http.ResponseWriter, r *http.Request) {
|
||||||
quicknoteModel := models.NewQuicknoteModel(app.db)
|
quicknoteModel := models.NewQuicknoteModel(app.db)
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
var quicknote_id int64
|
var quicknoteId int64
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
|
|
||||||
var quicknoteFromForm quicknoteForm
|
var quicknoteFromForm quicknoteForm
|
||||||
|
@ -76,16 +76,16 @@ func (app *application) quickboxAdd(w http.ResponseWriter, r *http.Request) {
|
||||||
Note: quicknoteFromForm.Note,
|
Note: quicknoteFromForm.Note,
|
||||||
}
|
}
|
||||||
|
|
||||||
quicknote_id, err = quicknoteModel.Create(quicknote)
|
quicknoteId, err = quicknoteModel.Create(quicknote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.badRequest(w, err)
|
app.badRequest(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["quicknote"] = quicknoteForm{
|
data["quicknote"] = quicknoteForm{
|
||||||
Id: quicknote_id,
|
Id: quicknoteId,
|
||||||
Note: quicknote.Note,
|
Note: quicknote.Note,
|
||||||
Note_rendered: quicknote.Note_rendered,
|
NoteRendered: quicknote.NoteRendered,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = response.HXFragment(fullBuf, []string{"quickbox/add.tmpl"}, "quickbox:add", data)
|
err = response.HXFragment(fullBuf, []string{"quickbox/add.tmpl"}, "quickbox:add", data)
|
||||||
|
@ -102,9 +102,9 @@ func (app *application) quickboxAdd(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) quickboxTransform(w http.ResponseWriter, r *http.Request) {
|
func (app *application) quickboxTransform(w http.ResponseWriter, r *http.Request) {
|
||||||
quicknoteModel := models.NewQuicknoteModel(app.db)
|
quicknoteModel := models.NewQuicknoteModel(app.db)
|
||||||
quicknote_id_str := flow.Param(r.Context(), "quicknote_id")
|
quicknoteIdStr := flow.Param(r.Context(), "quicknote_id")
|
||||||
quicknote_id, _ := strconv.ParseInt(quicknote_id_str, 10, 64)
|
quicknoteId, _ := strconv.ParseInt(quicknoteIdStr, 10, 64)
|
||||||
quicknote, _, _ := quicknoteModel.One(quicknote_id)
|
quicknote, _, _ := quicknoteModel.One(quicknoteId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
|
|
||||||
|
@ -141,33 +141,33 @@ func (app *application) quickboxTransform(w http.ResponseWriter, r *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
item := &models.Item{
|
item := &models.Item{
|
||||||
Type_id: quicknoteTransformFromForm.Type_id,
|
TypeId: quicknoteTransformFromForm.TypeId,
|
||||||
Title: quicknoteTransformFromForm.Title,
|
Title: quicknoteTransformFromForm.Title,
|
||||||
Description: quicknoteTransformFromForm.Description,
|
Description: quicknoteTransformFromForm.Description,
|
||||||
Tags: quicknoteTransformFromForm.Tags,
|
Tags: quicknoteTransformFromForm.Tags,
|
||||||
}
|
}
|
||||||
|
|
||||||
notebooks_str := strings.Join(quicknoteTransformFromForm.Notebooks, "|")
|
notebookStr := strings.Join(quicknoteTransformFromForm.Notebooks, "|")
|
||||||
if len(notebooks_str) > 0 {
|
if len(notebookStr) > 0 {
|
||||||
notebooks_str = "|" + notebooks_str + "|"
|
notebookStr = "|" + notebookStr + "|"
|
||||||
}
|
}
|
||||||
item.Notebooks = notebooks_str
|
item.Notebooks = notebookStr
|
||||||
|
|
||||||
categories_str := strings.Join(quicknoteTransformFromForm.Categories, "|")
|
categoriesStr := strings.Join(quicknoteTransformFromForm.Categories, "|")
|
||||||
if len(categories_str) > 0 {
|
if len(categoriesStr) > 0 {
|
||||||
categories_str = "|" + categories_str + "|"
|
categoriesStr = "|" + categoriesStr + "|"
|
||||||
}
|
}
|
||||||
item.Categories = categories_str
|
item.Categories = categoriesStr
|
||||||
|
|
||||||
item_id, err := itemModel.Create(item)
|
itemId, err := itemModel.Create(item)
|
||||||
item.Id = item_id
|
item.Id = itemId
|
||||||
|
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
aType, _, _ := typeModel.One(item.Type_id)
|
aType, _, _ := typeModel.One(item.TypeId)
|
||||||
item.Type_title = aType.Title
|
item.TypeTitle = aType.Title
|
||||||
|
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
fields, _, _ := fieldModel.ByType(int64(item.Type_id))
|
var fields, _, _ = fieldModel.ByType(item.TypeId)
|
||||||
fieldsValues := make(map[int64]map[int]string)
|
fieldsValues := make(map[int64]map[int]string)
|
||||||
|
|
||||||
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
||||||
|
@ -184,7 +184,7 @@ func (app *application) quickboxTransform(w http.ResponseWriter, r *http.Request
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
triggerResponse := fmt.Sprintf(`{"closeQuickboxTransformModal":{"quickNoteId": "%d", "keepQuickNote": "%d"}}`, quicknote_id, quicknoteTransformFromForm.Keep_in_quickbox)
|
triggerResponse := fmt.Sprintf(`{"closeQuickboxTransformModal":{"quickNoteId": "%d", "keepQuickNote": "%d"}}`, quicknoteId, quicknoteTransformFromForm.KeepInQuickbox)
|
||||||
w.Header().Add("HX-Trigger-After-Settle", triggerResponse)
|
w.Header().Add("HX-Trigger-After-Settle", triggerResponse)
|
||||||
fullBuf.WriteTo(w)
|
fullBuf.WriteTo(w)
|
||||||
|
|
||||||
|
@ -194,12 +194,12 @@ func (app *application) quickboxTransform(w http.ResponseWriter, r *http.Request
|
||||||
|
|
||||||
func (app *application) quickboxUpdate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) quickboxUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
quicknoteModel := models.NewQuicknoteModel(app.db)
|
quicknoteModel := models.NewQuicknoteModel(app.db)
|
||||||
quicknote_id_str := flow.Param(r.Context(), "quicknote_id")
|
quicknoteIdStr := flow.Param(r.Context(), "quicknote_id")
|
||||||
quicknote_id, _ := strconv.ParseInt(quicknote_id_str, 10, 64)
|
quicknoteId, _ := strconv.ParseInt(quicknoteIdStr, 10, 64)
|
||||||
quicknote, _, _ := quicknoteModel.One(quicknote_id)
|
quicknote, _, _ := quicknoteModel.One(quicknoteId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/quicknote/update/" + quicknote_id_str
|
data["formAction"] = "/quicknote/update/" + quicknoteIdStr
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
data["messageType"] = ""
|
data["messageType"] = ""
|
||||||
data["messageContent"] = ""
|
data["messageContent"] = ""
|
||||||
|
@ -292,10 +292,10 @@ func (app *application) quickboxUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) quickboxDelete(w http.ResponseWriter, r *http.Request) {
|
func (app *application) quickboxDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
quicknoteModel := models.NewQuicknoteModel(app.db)
|
quicknoteModel := models.NewQuicknoteModel(app.db)
|
||||||
quicknote_id_str := flow.Param(r.Context(), "quicknote_id")
|
quicknoteIdStr := flow.Param(r.Context(), "quicknote_id")
|
||||||
quicknote_id, _ := strconv.ParseInt(quicknote_id_str, 10, 64)
|
quicknoteId, _ := strconv.ParseInt(quicknoteIdStr, 10, 64)
|
||||||
|
|
||||||
_, err := quicknoteModel.Delete(quicknote_id)
|
_, err := quicknoteModel.Delete(quicknoteId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,16 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type typeForm struct {
|
type typeForm struct {
|
||||||
Id int64 `form:"Id"`
|
Id int64 `form:"Id"`
|
||||||
Title string `form:"Title"`
|
Title string `form:"Title"`
|
||||||
Icon string `form:"Icon"`
|
Icon string `form:"Icon"`
|
||||||
Description string `form:"Description"`
|
Description string `form:"Description"`
|
||||||
Show_summary int `form:"Show_summary"`
|
ShowSummary int `form:"Show_summary"`
|
||||||
Show_description int `form:"Show_description"`
|
ShowDescription int `form:"Show_description"`
|
||||||
Notebooks []string `form:"Notebooks"`
|
Notebooks []string `form:"Notebooks"`
|
||||||
Fields []models.Field
|
Fields []models.Field
|
||||||
Widgets []models.Widget
|
Widgets []models.Widget
|
||||||
Validator validator.Validator `form:"-"`
|
Validator validator.Validator `form:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (form *typeForm) Validate(w http.ResponseWriter, r *http.Request, app *application, data map[string]any) bool {
|
func (form *typeForm) Validate(w http.ResponseWriter, r *http.Request, app *application, data map[string]any) bool {
|
||||||
|
@ -91,7 +91,7 @@ func (app *application) types(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
var fullBuf = new(bytes.Buffer)
|
var fullBuf = new(bytes.Buffer)
|
||||||
var type_id int64
|
var typeId int64
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/type/create"
|
data["formAction"] = "/type/create"
|
||||||
|
@ -107,15 +107,15 @@ func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodGet:
|
case http.MethodGet:
|
||||||
|
|
||||||
notebooks := []string{strconv.FormatInt(app.getCurrentNotebok_id(r), 10)}
|
notebooks := []string{strconv.FormatInt(app.getCurrentNotebookId(r), 10)}
|
||||||
|
|
||||||
data["type"] = typeForm{
|
data["type"] = typeForm{
|
||||||
Title: "",
|
Title: "",
|
||||||
Icon: "",
|
Icon: "",
|
||||||
Description: "",
|
Description: "",
|
||||||
Show_summary: 0,
|
ShowSummary: 0,
|
||||||
Show_description: 0,
|
ShowDescription: 0,
|
||||||
Notebooks: notebooks,
|
Notebooks: notebooks,
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
|
@ -150,41 +150,41 @@ func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
aType := &models.Type{
|
aType := &models.Type{
|
||||||
Title: typeFromForm.Title,
|
Title: typeFromForm.Title,
|
||||||
Icon: typeFromForm.Icon,
|
Icon: typeFromForm.Icon,
|
||||||
Description: typeFromForm.Description,
|
Description: typeFromForm.Description,
|
||||||
Show_summary: int(typeFromForm.Show_summary),
|
ShowSummary: typeFromForm.ShowSummary,
|
||||||
Show_description: int(typeFromForm.Show_description),
|
ShowDescription: typeFromForm.ShowDescription,
|
||||||
}
|
}
|
||||||
notebooks_str := strings.Join(typeFromForm.Notebooks, "|")
|
notebooksStr := strings.Join(typeFromForm.Notebooks, "|")
|
||||||
if len(notebooks_str) > 0 {
|
if len(notebooksStr) > 0 {
|
||||||
notebooks_str = "|" + notebooks_str + "|"
|
notebooksStr = "|" + notebooksStr + "|"
|
||||||
}
|
}
|
||||||
aType.Notebooks = notebooks_str
|
aType.Notebooks = notebooksStr
|
||||||
|
|
||||||
type_id, err = typeModel.Create(aType)
|
typeId, err = typeModel.Create(aType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.badRequest(w, err)
|
app.badRequest(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
typeModel.AddFields(type_id, r)
|
typeModel.AddFields(typeId, r)
|
||||||
|
|
||||||
data["formAction"] = fmt.Sprint("/type/update/", type_id)
|
data["formAction"] = fmt.Sprint("/type/update/", typeId)
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
|
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
fields, _, _ := fieldModel.ByType(type_id)
|
fields, _, _ := fieldModel.ByType(typeId)
|
||||||
|
|
||||||
data["type"] = typeForm{
|
data["type"] = typeForm{
|
||||||
Id: type_id,
|
Id: typeId,
|
||||||
Title: aType.Title,
|
Title: aType.Title,
|
||||||
Icon: aType.Icon,
|
Icon: aType.Icon,
|
||||||
Description: aType.Description,
|
Description: aType.Description,
|
||||||
Show_summary: aType.Show_summary,
|
ShowSummary: aType.ShowSummary,
|
||||||
Show_description: aType.Show_description,
|
ShowDescription: aType.ShowDescription,
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
Notebooks: typeFromForm.Notebooks,
|
Notebooks: typeFromForm.Notebooks,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = response.HXFragment(fullBuf, []string{"types/form.tmpl", "types/fields.tmpl"}, "page:content", data)
|
err = response.HXFragment(fullBuf, []string{"types/form.tmpl", "types/fields.tmpl"}, "page:content", data)
|
||||||
|
@ -198,7 +198,7 @@ func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
criteria := map[string]any{
|
criteria := map[string]any{
|
||||||
"notebook_id": app.getCurrentNotebok_id(r),
|
"notebook_id": app.getCurrentNotebookId(r),
|
||||||
}
|
}
|
||||||
types, _, _ := typeModel.Find(criteria)
|
types, _, _ := typeModel.Find(criteria)
|
||||||
data["typesList"] = types
|
data["typesList"] = types
|
||||||
|
@ -215,7 +215,7 @@ func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Add("HX-Replace-Url", fmt.Sprint("/type/update/", type_id))
|
w.Header().Add("HX-Replace-Url", fmt.Sprint("/type/update/", typeId))
|
||||||
w.Header().Add("HX-Trigger-After-Settle", `{"showMessage":""}`)
|
w.Header().Add("HX-Trigger-After-Settle", `{"showMessage":""}`)
|
||||||
|
|
||||||
fullBuf.WriteTo(w)
|
fullBuf.WriteTo(w)
|
||||||
|
@ -227,12 +227,12 @@ func (app *application) typeCreate(w http.ResponseWriter, r *http.Request) {
|
||||||
func (app *application) typeUpdate(w http.ResponseWriter, r *http.Request) {
|
func (app *application) typeUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
fieldModel := &models.FieldModel{DB: app.db}
|
fieldModel := &models.FieldModel{DB: app.db}
|
||||||
type_id_str := flow.Param(r.Context(), "type_id")
|
typeIdStr := flow.Param(r.Context(), "type_id")
|
||||||
type_id, _ := strconv.ParseInt(type_id_str, 10, 64)
|
typeId, _ := strconv.ParseInt(typeIdStr, 10, 64)
|
||||||
aType, _, _ := typeModel.One(type_id)
|
aType, _, _ := typeModel.One(typeId)
|
||||||
|
|
||||||
data := app.newTemplateData(r)
|
data := app.newTemplateData(r)
|
||||||
data["formAction"] = "/type/update/" + type_id_str
|
data["formAction"] = "/type/update/" + typeIdStr
|
||||||
data["formTarget"] = "#message"
|
data["formTarget"] = "#message"
|
||||||
data["messageType"] = ""
|
data["messageType"] = ""
|
||||||
data["messageContent"] = ""
|
data["messageContent"] = ""
|
||||||
|
@ -254,14 +254,14 @@ func (app *application) typeUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
notebooks := strings.Split(strings.Trim(aType.Notebooks, "|"), "|")
|
notebooks := strings.Split(strings.Trim(aType.Notebooks, "|"), "|")
|
||||||
|
|
||||||
data["type"] = typeForm{
|
data["type"] = typeForm{
|
||||||
Id: aType.Id,
|
Id: aType.Id,
|
||||||
Title: aType.Title,
|
Title: aType.Title,
|
||||||
Icon: aType.Icon,
|
Icon: aType.Icon,
|
||||||
Description: aType.Description,
|
Description: aType.Description,
|
||||||
Show_summary: aType.Show_summary,
|
ShowSummary: aType.ShowSummary,
|
||||||
Show_description: aType.Show_description,
|
ShowDescription: aType.ShowDescription,
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
Notebooks: notebooks,
|
Notebooks: notebooks,
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Header.Get("HX-Request") == "true" {
|
if r.Header.Get("HX-Request") == "true" {
|
||||||
|
@ -299,13 +299,13 @@ func (app *application) typeUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
aType.Title = typeFromForm.Title
|
aType.Title = typeFromForm.Title
|
||||||
aType.Description = typeFromForm.Description
|
aType.Description = typeFromForm.Description
|
||||||
aType.Icon = typeFromForm.Icon
|
aType.Icon = typeFromForm.Icon
|
||||||
aType.Show_summary = typeFromForm.Show_summary
|
aType.ShowSummary = typeFromForm.ShowSummary
|
||||||
aType.Show_description = typeFromForm.Show_description
|
aType.ShowDescription = typeFromForm.ShowDescription
|
||||||
notebooks_str := strings.Join(typeFromForm.Notebooks, "|")
|
notebooksStr := strings.Join(typeFromForm.Notebooks, "|")
|
||||||
if len(notebooks_str) > 0 {
|
if len(notebooksStr) > 0 {
|
||||||
notebooks_str = "|" + notebooks_str + "|"
|
notebooksStr = "|" + notebooksStr + "|"
|
||||||
}
|
}
|
||||||
aType.Notebooks = notebooks_str
|
aType.Notebooks = notebooksStr
|
||||||
|
|
||||||
err = typeModel.Update(aType)
|
err = typeModel.Update(aType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -319,35 +319,35 @@ func (app *application) typeUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
if found {
|
if found {
|
||||||
parts := strings.Split(s, "-")
|
parts := strings.Split(s, "-")
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
type_field_id, _ := strconv.ParseInt(parts[0], 10, 64)
|
typeFieldId, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||||
type_field_attribute := parts[1]
|
typeFieldAttribute := parts[1]
|
||||||
|
|
||||||
field, found := fieldsUpdate[type_field_id]
|
field, found := fieldsUpdate[typeFieldId]
|
||||||
if !found {
|
if !found {
|
||||||
field := &models.Field{Type_field_id: type_field_id}
|
field := &models.Field{TypeFieldId: typeFieldId}
|
||||||
fieldsUpdate[type_field_id] = *field
|
fieldsUpdate[typeFieldId] = *field
|
||||||
}
|
}
|
||||||
field = fieldsUpdate[type_field_id]
|
field = fieldsUpdate[typeFieldId]
|
||||||
|
|
||||||
switch type_field_attribute {
|
switch typeFieldAttribute {
|
||||||
case "Widget_id":
|
case "Widget_id":
|
||||||
field.Widget_id, _ = strconv.ParseInt(values[0], 10, 64)
|
field.WidgetId, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "Title":
|
case "Title":
|
||||||
field.Title = values[0]
|
field.Title = values[0]
|
||||||
case "Valid_values":
|
case "Valid_values":
|
||||||
field.Valid_values = values[0]
|
field.ValidValues = values[0]
|
||||||
case "Ui_section":
|
case "Ui_section":
|
||||||
field.Ui_section = values[0]
|
field.UiSection = values[0]
|
||||||
case "Show_on_list":
|
case "Show_on_list":
|
||||||
field.Show_on_list, _ = strconv.ParseInt(values[0], 10, 64)
|
field.ShowOnList, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "Show_on_view":
|
case "Show_on_view":
|
||||||
field.Show_on_view, _ = strconv.ParseInt(values[0], 10, 64)
|
field.ShowOnView, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "Is_multiple":
|
case "Is_multiple":
|
||||||
field.Is_multiple, _ = strconv.ParseInt(values[0], 10, 64)
|
field.IsMultiple, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "ToRemove":
|
case "ToRemove":
|
||||||
field.ToRemove, _ = strconv.ParseInt(values[0], 10, 64)
|
field.ToRemove, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
}
|
}
|
||||||
fieldsUpdate[type_field_id] = field
|
fieldsUpdate[typeFieldId] = field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,19 +356,19 @@ func (app *application) typeUpdate(w http.ResponseWriter, r *http.Request) {
|
||||||
if field.ToRemove > 0 {
|
if field.ToRemove > 0 {
|
||||||
typeModel.RemoveField(id)
|
typeModel.RemoveField(id)
|
||||||
} else {
|
} else {
|
||||||
typeModel.SaveField(id, &field)
|
typeModel.SaveField(&field)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typeModel.AddFields(type_id, r)
|
typeModel.AddFields(typeId, r)
|
||||||
|
|
||||||
data["type"] = typeForm{
|
data["type"] = typeForm{
|
||||||
Id: aType.Id,
|
Id: aType.Id,
|
||||||
Title: aType.Title,
|
Title: aType.Title,
|
||||||
Icon: aType.Icon,
|
Icon: aType.Icon,
|
||||||
Description: aType.Description,
|
Description: aType.Description,
|
||||||
Show_summary: aType.Show_summary,
|
ShowSummary: aType.ShowSummary,
|
||||||
Show_description: aType.Show_description,
|
ShowDescription: aType.ShowDescription,
|
||||||
}
|
}
|
||||||
|
|
||||||
dataMessage := make(map[string]string)
|
dataMessage := make(map[string]string)
|
||||||
|
@ -426,10 +426,10 @@ func (app *application) typeFieldNew(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func (app *application) typeDelete(w http.ResponseWriter, r *http.Request) {
|
func (app *application) typeDelete(w http.ResponseWriter, r *http.Request) {
|
||||||
typeModel := &models.TypeModel{DB: app.db}
|
typeModel := &models.TypeModel{DB: app.db}
|
||||||
item_id_str := flow.Param(r.Context(), "type_id")
|
itemIdStr := flow.Param(r.Context(), "type_id")
|
||||||
item_id, _ := strconv.Atoi(item_id_str)
|
itemId, _ := strconv.Atoi(itemIdStr)
|
||||||
|
|
||||||
_, err := typeModel.Delete(item_id)
|
_, err := typeModel.Delete(itemId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func (model *CategoryModel) Find(ids []int64) ([]Category, bool, error) {
|
||||||
|
|
||||||
var rows []Category
|
var rows []Category
|
||||||
|
|
||||||
err := model.DB.SelectContext(ctx, &rows, query, args)
|
err := model.DB.SelectContext(ctx, &rows, query, args...)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
@ -79,11 +79,11 @@ func (model *CategoryModel) AllAsOptions() []funcs.WidgetOption {
|
||||||
|
|
||||||
func (model *CategoryModel) AllAsMap() map[string]string {
|
func (model *CategoryModel) AllAsMap() map[string]string {
|
||||||
categories, _, _ := model.All()
|
categories, _, _ := model.All()
|
||||||
var categories_map = make(map[string]string)
|
var categoriesMap = make(map[string]string)
|
||||||
for _, category := range categories {
|
for _, category := range categories {
|
||||||
categories_map[strconv.FormatInt(category.Id, 10)] = category.Name
|
categoriesMap[strconv.FormatInt(category.Id, 10)] = category.Name
|
||||||
}
|
}
|
||||||
return categories_map
|
return categoriesMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *CategoryModel) Delete(id int) (bool, error) {
|
func (model *CategoryModel) Delete(id int) (bool, error) {
|
||||||
|
|
|
@ -12,30 +12,30 @@ type FieldModel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Field struct {
|
type Field struct {
|
||||||
Type_field_id int64 `db:"type_field_id"`
|
TypeFieldId int64 `db:"type_field_id"`
|
||||||
Widget_id int64 `db:"widget_id"`
|
WidgetId int64 `db:"widget_id"`
|
||||||
Type_id int64 `db:"type_id"`
|
TypeId int64 `db:"type_id"`
|
||||||
Widget string `db:"widget"`
|
Widget string `db:"widget"`
|
||||||
Title string `db:"title"`
|
Title string `db:"title"`
|
||||||
Position int `db:"position"`
|
Position int `db:"position"`
|
||||||
Show_on_list int64 `db:"show_on_list"`
|
ShowOnList int64 `db:"show_on_list"`
|
||||||
Show_on_view int64 `db:"show_on_view"`
|
ShowOnView int64 `db:"show_on_view"`
|
||||||
Valid_values string `db:"valid_values"`
|
ValidValues string `db:"valid_values"`
|
||||||
Ui_section string `db:"ui_section"`
|
UiSection string `db:"ui_section"`
|
||||||
Is_multiple int64 `db:"is_multiple"`
|
IsMultiple int64 `db:"is_multiple"`
|
||||||
ToRemove int64
|
ToRemove int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type FieldValue struct {
|
type FieldValue struct {
|
||||||
Type_field_id int64 `db:"type_field_id"`
|
TypeFieldId int64 `db:"type_field_id"`
|
||||||
Value string `db:"value"`
|
Value string `db:"value"`
|
||||||
Title string `db:"title"`
|
Title string `db:"title"`
|
||||||
Widget string `db:"widget"`
|
Widget string `db:"widget"`
|
||||||
Number int64 `db:"number"`
|
Number int64 `db:"number"`
|
||||||
Counter int `db:"counter"`
|
Counter int `db:"counter"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) ByTypeSection(type_id int64) (map[string][]Field, bool, error) {
|
func (model *FieldModel) ByTypeSection(typeId int64) (map[string][]Field, bool, error) {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -46,23 +46,23 @@ func (model *FieldModel) ByTypeSection(type_id int64) (map[string][]Field, bool,
|
||||||
var rows []Field
|
var rows []Field
|
||||||
rowsBySection := make(map[string][]Field)
|
rowsBySection := make(map[string][]Field)
|
||||||
|
|
||||||
err := model.DB.SelectContext(ctx, &rows, query, type_id)
|
err := model.DB.SelectContext(ctx, &rows, query, typeId)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, row := range rows {
|
for _, row := range rows {
|
||||||
if value, found := rowsBySection[row.Ui_section]; found {
|
if value, found := rowsBySection[row.UiSection]; found {
|
||||||
rowsBySection[row.Ui_section] = append(value, row)
|
rowsBySection[row.UiSection] = append(value, row)
|
||||||
} else {
|
} else {
|
||||||
rowsBySection[row.Ui_section] = []Field{row}
|
rowsBySection[row.UiSection] = []Field{row}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rowsBySection, true, err
|
return rowsBySection, true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) ByType(type_id int64) ([]Field, bool, error) {
|
func (model *FieldModel) ByType(typeId int64) ([]Field, bool, error) {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ func (model *FieldModel) ByType(type_id int64) ([]Field, bool, error) {
|
||||||
|
|
||||||
var rows []Field
|
var rows []Field
|
||||||
|
|
||||||
err := model.DB.SelectContext(ctx, &rows, query, type_id)
|
err := model.DB.SelectContext(ctx, &rows, query, typeId)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (model *FieldModel) ByType(type_id int64) ([]Field, bool, error) {
|
||||||
return rows, true, err
|
return rows, true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) ByTypeOnList(type_id int64) ([]Field, bool, error) {
|
func (model *FieldModel) ByTypeOnList(typeId int64) ([]Field, bool, error) {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ func (model *FieldModel) ByTypeOnList(type_id int64) ([]Field, bool, error) {
|
||||||
|
|
||||||
var rows []Field
|
var rows []Field
|
||||||
|
|
||||||
err := model.DB.SelectContext(ctx, &rows, query, type_id)
|
err := model.DB.SelectContext(ctx, &rows, query, typeId)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
|
@ -98,31 +98,31 @@ func (model *FieldModel) ByTypeOnList(type_id int64) ([]Field, bool, error) {
|
||||||
return rows, true, err
|
return rows, true, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) SaveValues(item_id int64, type_field_id int64, values map[int]string) bool {
|
func (model *FieldModel) SaveValues(itemId int64, typeFieldId int64, values map[int]string) bool {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
qy_delete := `DELETE FROM bm_item_fields WHERE item_id=? AND type_field_id=?`
|
qyDelete := `DELETE FROM bm_item_fields WHERE item_id=? AND type_field_id=?`
|
||||||
|
|
||||||
_, err := model.DB.ExecContext(ctx, qy_delete, item_id, type_field_id)
|
_, err := model.DB.ExecContext(ctx, qyDelete, itemId, typeFieldId)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
qy_insert := `INSERT INTO bm_item_fields (item_id, type_field_id, counter, value) VALUES(?, ?, ?, ?)`
|
qyInsert := `INSERT INTO bm_item_fields (item_id, type_field_id, counter, value) VALUES(?, ?, ?, ?)`
|
||||||
|
|
||||||
for counter, value := range values {
|
for counter, value := range values {
|
||||||
model.DB.MustExecContext(ctx, qy_insert, item_id, type_field_id, counter, value)
|
model.DB.MustExecContext(ctx, qyInsert, itemId, typeFieldId, counter, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) GetFieldValues(item_id int64, type_field_id int64) map[int]string {
|
func (model *FieldModel) GetFieldValues(itemId int64, typeFieldId int64) map[int]string {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
rows, _ := model.DB.QueryContext(ctx, "SELECT counter, value FROM bm_item_fields WHERE item_id=? AND type_field_id=?", item_id, type_field_id)
|
rows, _ := model.DB.QueryContext(ctx, "SELECT counter, value FROM bm_item_fields WHERE item_id=? AND type_field_id=?", itemId, typeFieldId)
|
||||||
|
|
||||||
values := make(map[int]string)
|
values := make(map[int]string)
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ func (model *FieldModel) GetFieldValues(item_id int64, type_field_id int64) map[
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) GetFieldsValues(item_id int64) []FieldValue {
|
func (model *FieldModel) GetFieldsValues(itemId int64) []FieldValue {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -146,23 +146,23 @@ func (model *FieldModel) GetFieldsValues(item_id int64) []FieldValue {
|
||||||
INNER JOIN bm_type_fields btf on btf.id=bif.type_field_id
|
INNER JOIN bm_type_fields btf on btf.id=bif.type_field_id
|
||||||
INNER JOIN bm_widgets bw on bw.id=btf.widget_id
|
INNER JOIN bm_widgets bw on bw.id=btf.widget_id
|
||||||
WHERE bif.item_id=$1`
|
WHERE bif.item_id=$1`
|
||||||
model.DB.SelectContext(ctx, &values, q, item_id)
|
model.DB.SelectContext(ctx, &values, q, itemId)
|
||||||
|
|
||||||
return values
|
return values
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *FieldModel) GetFieldsValuesAsMap(item_id int64) map[int64]map[int]string {
|
func (model *FieldModel) GetFieldsValuesAsMap(itemId int64) map[int64]map[int]string {
|
||||||
values := model.GetFieldsValues(item_id)
|
values := model.GetFieldsValues(itemId)
|
||||||
|
|
||||||
values_map := make(map[int64]map[int]string)
|
valuesMap := make(map[int64]map[int]string)
|
||||||
|
|
||||||
for _, item_value := range values {
|
for _, itemValue := range values {
|
||||||
_, found := values_map[item_value.Type_field_id]
|
_, found := valuesMap[itemValue.TypeFieldId]
|
||||||
if !found {
|
if !found {
|
||||||
values_map[item_value.Type_field_id] = make(map[int]string)
|
valuesMap[itemValue.TypeFieldId] = make(map[int]string)
|
||||||
}
|
}
|
||||||
values_map[item_value.Type_field_id][item_value.Counter] = item_value.Value
|
valuesMap[itemValue.TypeFieldId][itemValue.Counter] = itemValue.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
return values_map
|
return valuesMap
|
||||||
}
|
}
|
||||||
|
|
|
@ -374,7 +374,7 @@ func (model *ItemModel) SaveKeywords(Item *Item, fields *[]Field, fieldsValues m
|
||||||
|
|
||||||
for _, field := range *fields {
|
for _, field := range *fields {
|
||||||
if field.Widget != "url" {
|
if field.Widget != "url" {
|
||||||
values, found := fieldsValues[field.Type_field_id]
|
values, found := fieldsValues[field.TypeFieldId]
|
||||||
if found {
|
if found {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
keywords = append(keywords, value)
|
keywords = append(keywords, value)
|
||||||
|
|
|
@ -16,14 +16,14 @@ type TypeModel struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Type struct {
|
type Type struct {
|
||||||
Id int64 `db:"id"`
|
Id int64 `db:"id"`
|
||||||
Title string `db:"title"`
|
Title string `db:"title"`
|
||||||
Icon string `db:"icon"`
|
Icon string `db:"icon"`
|
||||||
Description string `db:"description"`
|
Description string `db:"description"`
|
||||||
Notebooks string `db:"notebooks"`
|
Notebooks string `db:"notebooks"`
|
||||||
Show_summary int `db:"show_summary"`
|
ShowSummary int `db:"show_summary"`
|
||||||
Show_description int `db:"show_description"`
|
ShowDescription int `db:"show_description"`
|
||||||
Sections string `db:"sections"`
|
Sections string `db:"sections"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *TypeModel) One(id int64) (*Type, bool, error) {
|
func (model *TypeModel) One(id int64) (*Type, bool, error) {
|
||||||
|
@ -148,7 +148,7 @@ func (model *TypeModel) Update(Type *Type) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *TypeModel) SaveField(type_field_id int64, field *Field) error {
|
func (model *TypeModel) SaveField(field *Field) error {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
@ -160,14 +160,14 @@ func (model *TypeModel) SaveField(type_field_id int64, field *Field) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (model *TypeModel) RemoveField(type_field_id int64) error {
|
func (model *TypeModel) RemoveField(typeFieldId int64) error {
|
||||||
ctx, cancel := database.GetContext()
|
ctx, cancel := database.GetContext()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
//Check here if it is used
|
//Check here if it is used
|
||||||
query := "DELETE FROM bm_type_fields WHERE id=$1"
|
query := "DELETE FROM bm_type_fields WHERE id=$1"
|
||||||
|
|
||||||
_, err := model.DB.ExecContext(ctx, query, type_field_id)
|
_, err := model.DB.ExecContext(ctx, query, typeFieldId)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -192,30 +192,30 @@ func (model *TypeModel) AddFields(TypeId int64, r *http.Request) {
|
||||||
parts := strings.Split(s, "-")
|
parts := strings.Split(s, "-")
|
||||||
if len(parts) == 2 {
|
if len(parts) == 2 {
|
||||||
counter, _ := strconv.ParseInt(parts[0], 10, 64)
|
counter, _ := strconv.ParseInt(parts[0], 10, 64)
|
||||||
type_field_attribute := parts[1]
|
typeFieldAttribute := parts[1]
|
||||||
|
|
||||||
field, found := fieldsNew[counter]
|
field, found := fieldsNew[counter]
|
||||||
if !found {
|
if !found {
|
||||||
field := &Field{Type_id: TypeId}
|
field := &Field{TypeId: TypeId}
|
||||||
fieldsNew[counter] = *field
|
fieldsNew[counter] = *field
|
||||||
}
|
}
|
||||||
field = fieldsNew[counter]
|
field = fieldsNew[counter]
|
||||||
|
|
||||||
switch type_field_attribute {
|
switch typeFieldAttribute {
|
||||||
case "Widget_id":
|
case "Widget_id":
|
||||||
field.Widget_id, _ = strconv.ParseInt(values[0], 10, 64)
|
field.WidgetId, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "Title":
|
case "Title":
|
||||||
field.Title = values[0]
|
field.Title = values[0]
|
||||||
case "Valid_values":
|
case "Valid_values":
|
||||||
field.Valid_values = values[0]
|
field.ValidValues = values[0]
|
||||||
case "Ui_section":
|
case "Ui_section":
|
||||||
field.Ui_section = values[0]
|
field.UiSection = values[0]
|
||||||
case "Is_multiple":
|
case "Is_multiple":
|
||||||
field.Is_multiple, _ = strconv.ParseInt(values[0], 10, 64)
|
field.IsMultiple, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "Show_on_list":
|
case "Show_on_list":
|
||||||
field.Show_on_list, _ = strconv.ParseInt(values[0], 10, 64)
|
field.ShowOnList, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
case "Show_on_view":
|
case "Show_on_view":
|
||||||
field.Show_on_view, _ = strconv.ParseInt(values[0], 10, 64)
|
field.ShowOnView, _ = strconv.ParseInt(values[0], 10, 64)
|
||||||
}
|
}
|
||||||
fieldsNew[counter] = field
|
fieldsNew[counter] = field
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue