mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
BlockDataviewViewUpdate updates only simple fields
This commit is contained in:
parent
fb9ad220c2
commit
4f3fbc3e18
3 changed files with 40 additions and 28 deletions
|
@ -176,7 +176,7 @@ func (s *Service) GetAggregatedRelations(
|
|||
|
||||
func (s *Service) UpdateDataviewView(ctx *session.Context, req pb.RpcBlockDataviewViewUpdateRequest) error {
|
||||
return s.DoDataview(req.ContextId, func(b dataview.Dataview) error {
|
||||
return b.UpdateView(ctx, req.BlockId, req.ViewId, *req.View, true)
|
||||
return b.UpdateView(ctx, req.BlockId, req.ViewId, req.View, true)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ type Dataview interface {
|
|||
SetViewPosition(ctx *session.Context, blockId string, viewId string, position uint32) error
|
||||
AddRelations(ctx *session.Context, blockId string, relationIds []string, showEvent bool) error
|
||||
DeleteRelations(ctx *session.Context, blockId string, relationIds []string, showEvent bool) error
|
||||
UpdateView(ctx *session.Context, blockId string, viewId string, view model.BlockContentDataviewView, showEvent bool) error
|
||||
UpdateView(ctx *session.Context, blockId string, viewId string, view *model.BlockContentDataviewView, showEvent bool) error
|
||||
UpdateViewGroupOrder(ctx *session.Context, blockId string, order *model.BlockContentDataviewGroupOrder) error
|
||||
UpdateViewObjectOrder(ctx *session.Context, blockId string, orders []*model.BlockContentDataviewObjectOrder) error
|
||||
|
||||
|
@ -209,14 +209,14 @@ func (d *sdataview) DeleteView(ctx *session.Context, blockId string, viewId stri
|
|||
return d.Apply(s, smartblock.NoEvent)
|
||||
}
|
||||
|
||||
func (d *sdataview) UpdateView(ctx *session.Context, blockId string, viewId string, view model.BlockContentDataviewView, showEvent bool) error {
|
||||
func (d *sdataview) UpdateView(ctx *session.Context, blockId string, viewId string, view *model.BlockContentDataviewView, showEvent bool) error {
|
||||
s := d.NewStateCtx(ctx)
|
||||
dvBlock, err := getDataviewBlock(s, blockId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = dvBlock.SetView(viewId, view); err != nil {
|
||||
if err = dvBlock.SetViewFields(viewId, view); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ type Block interface {
|
|||
simple.Block
|
||||
GetView(viewID string) (*model.BlockContentDataviewView, error)
|
||||
SetView(viewID string, view model.BlockContentDataviewView) error
|
||||
SetViewFields(viewID string, view *model.BlockContentDataviewView) error
|
||||
AddView(view model.BlockContentDataviewView)
|
||||
DeleteView(viewID string) error
|
||||
SetViewOrder(ids []string)
|
||||
|
@ -330,36 +331,47 @@ func (s *Dataview) DeleteView(viewID string) error {
|
|||
}
|
||||
|
||||
func (s *Dataview) SetView(viewID string, view model.BlockContentDataviewView) error {
|
||||
var found bool
|
||||
for _, v := range s.content.Views {
|
||||
if v.Id == viewID {
|
||||
found = true
|
||||
v, err := s.GetView(viewID)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
v.Relations = view.Relations
|
||||
v.Sorts = view.Sorts
|
||||
v.Filters = view.Filters
|
||||
for _, f := range v.Filters {
|
||||
if f.Id == "" {
|
||||
f.Id = bson.NewObjectId().Hex()
|
||||
}
|
||||
}
|
||||
v.Name = view.Name
|
||||
v.Type = view.Type
|
||||
v.CoverRelationKey = view.CoverRelationKey
|
||||
v.HideIcon = view.HideIcon
|
||||
v.CoverFit = view.CoverFit
|
||||
v.CardSize = view.CardSize
|
||||
v.GroupRelationKey = view.GroupRelationKey
|
||||
v.GroupBackgroundColors = view.GroupBackgroundColors
|
||||
|
||||
break
|
||||
v.Relations = view.Relations
|
||||
v.Sorts = view.Sorts
|
||||
v.Filters = view.Filters
|
||||
for _, f := range v.Filters {
|
||||
if f.Id == "" {
|
||||
f.Id = bson.NewObjectId().Hex()
|
||||
}
|
||||
}
|
||||
v.Name = view.Name
|
||||
v.Type = view.Type
|
||||
v.CoverRelationKey = view.CoverRelationKey
|
||||
v.HideIcon = view.HideIcon
|
||||
v.CoverFit = view.CoverFit
|
||||
v.CardSize = view.CardSize
|
||||
v.GroupRelationKey = view.GroupRelationKey
|
||||
v.GroupBackgroundColors = view.GroupBackgroundColors
|
||||
|
||||
if !found {
|
||||
return ErrViewNotFound
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetViewFields updates only simple fields of a view. It doesn't update filters, relations, sorts.
|
||||
func (s *Dataview) SetViewFields(viewID string, view *model.BlockContentDataviewView) error {
|
||||
v, err := s.GetView(viewID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v.Name = view.Name
|
||||
v.Type = view.Type
|
||||
v.CoverRelationKey = view.CoverRelationKey
|
||||
v.HideIcon = view.HideIcon
|
||||
v.CoverFit = view.CoverFit
|
||||
v.CardSize = view.CardSize
|
||||
v.GroupRelationKey = view.GroupRelationKey
|
||||
v.GroupBackgroundColors = view.GroupBackgroundColors
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue