mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
🎨 Support doc/snapshot history for database table view https://github.com/siyuan-note/siyuan/issues/9567
This commit is contained in:
parent
ad23d018a8
commit
9b831b967a
3 changed files with 85 additions and 0 deletions
|
|
@ -26,6 +26,46 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func renderSnapshotAttributeView(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
index := arg["snapshot"].(string)
|
||||
id := arg["id"].(string)
|
||||
view, attrView, err := model.RenderRepoSnapshotAttributeView(index, id)
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
var views []map[string]interface{}
|
||||
for _, v := range attrView.Views {
|
||||
view := map[string]interface{}{
|
||||
"id": v.ID,
|
||||
"name": v.Name,
|
||||
"type": v.LayoutType,
|
||||
}
|
||||
|
||||
views = append(views, view)
|
||||
}
|
||||
|
||||
ret.Data = map[string]interface{}{
|
||||
"name": attrView.Name,
|
||||
"id": attrView.ID,
|
||||
"viewType": view.GetType(),
|
||||
"viewID": view.GetID(),
|
||||
"views": views,
|
||||
"view": view,
|
||||
"isMirror": av.IsMirror(attrView.ID),
|
||||
}
|
||||
}
|
||||
|
||||
func renderHistoryAttributeView(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -376,6 +376,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
|
||||
ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView)
|
||||
ginServer.Handle("POST", "/api/av/renderHistoryAttributeView", model.CheckAuth, renderHistoryAttributeView)
|
||||
ginServer.Handle("POST", "/api/av/renderSnapshotAttributeView", model.CheckAuth, renderSnapshotAttributeView)
|
||||
ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys)
|
||||
ginServer.Handle("POST", "/api/av/setAttributeViewBlockAttr", model.CheckAuth, model.CheckReadonly, setAttributeViewBlockAttr)
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
"github.com/siyuan-note/dejavu/entity"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/av"
|
||||
|
|
@ -184,6 +185,49 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) {
|
|||
return
|
||||
}
|
||||
|
||||
func RenderRepoSnapshotAttributeView(indexID, avID string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
index, err := repo.GetIndex(indexID)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
files, err := repo.GetFiles(index)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
var avFile *entity.File
|
||||
for _, f := range files {
|
||||
if "/storage/av/"+avID+".json" == f.Path {
|
||||
avFile = f
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if nil == avFile {
|
||||
return
|
||||
}
|
||||
|
||||
data, readErr := repo.OpenFile(avFile)
|
||||
if nil != readErr {
|
||||
logging.LogErrorf("read attribute view [%s] failed: %s", avID, readErr)
|
||||
return
|
||||
}
|
||||
|
||||
attrView = &av.AttributeView{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, attrView); nil != err {
|
||||
logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
viewable, err = renderAttributeView(attrView)
|
||||
return
|
||||
}
|
||||
|
||||
func RenderHistoryAttributeView(avID, created string) (viewable av.Viewable, attrView *av.AttributeView, err error) {
|
||||
createdUnix, parseErr := strconv.ParseInt(created, 10, 64)
|
||||
if nil != parseErr {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue