forked from qor5/admin
/
helper.go
76 lines (65 loc) · 1.95 KB
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package note
import (
"fmt"
"github.com/anshiii/playground-admin/presets"
"github.com/anshiii/playground-admin/presets/actions"
"github.com/qor5/ui/vuetify"
. "github.com/qor5/ui/vuetify"
"github.com/qor5/web"
"github.com/qor5/x/i18n"
h "github.com/theplant/htmlgo"
"gorm.io/gorm"
)
type contextUserIDKey int
const (
UserIDKey contextUserIDKey = iota
UserKey
)
func getUserData(ctx *web.EventContext) (userID uint, creator string) {
if ctx.R.Context().Value(UserIDKey) != nil {
userID = ctx.R.Context().Value(UserIDKey).(uint)
}
if ctx.R.Context().Value(UserKey) != nil {
creator = ctx.R.Context().Value(UserKey).(string)
}
return
}
func getNotesTab(ctx *web.EventContext, db *gorm.DB, resourceType string, resourceId string) h.HTMLComponent {
msgr := i18n.MustGetModuleMessages(ctx.R, I18nNoteKey, Messages_en_US).(*Messages)
c := h.Div(
web.Scope(
VCardText(
h.Text(msgr.NewNote),
VRow(VCol(VTextField().Attr(web.VFieldName("Content")...).Clearable(true))),
),
VCardActions(h.Components(
VSpacer(),
VBtn(presets.MustGetMessages(ctx.R).Create).
Color("primary").
Attr("@click", web.Plaid().
EventFunc(createNoteEvent).
Query("resource_id", resourceId).
Query("resource_type", resourceType).
Go()+";"+web.Plaid().
EventFunc(actions.ReloadList).
Go(),
),
)),
).VSlot("{plaidForm}"),
)
var notes []QorNote
db.Where("resource_type = ? and resource_id = ?", resourceType, resourceId).
Order("id DESC").Find(¬es)
var panels []h.HTMLComponent
for _, note := range notes {
panels = append(panels, vuetify.VExpansionPanel(
vuetify.VExpansionPanelHeader(h.Span(fmt.Sprintf("%v - %v", note.Creator, note.CreatedAt.Format("2006-01-02 15:04:05 MST")))),
vuetify.VExpansionPanelContent(h.Text(note.Content)),
))
}
c.AppendChildren(vuetify.VExpansionPanels(panels...).Attr("style", "padding:10px;"))
return c
}
var AfterCreateFunc = func(db *gorm.DB) (err error) {
return
}