mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-10 18:10:49 +09:00
Changes for fields
This commit is contained in:
parent
2b3b3f4c61
commit
b31e74214b
5 changed files with 2563 additions and 328 deletions
|
@ -216,56 +216,42 @@ func (d *Dataview) Diff(b simple.Block) (msgs []simple.EventMessage, err error)
|
|||
// @TODO: rewrite for optimised compare
|
||||
for _, view2 := range dv.content.Views {
|
||||
var found bool
|
||||
var changed bool
|
||||
var (
|
||||
viewFilterChanges []*pb.EventBlockDataviewViewUpdateFilter
|
||||
viewRelationChanges []*pb.EventBlockDataviewViewUpdateRelation
|
||||
viewSortChanges []*pb.EventBlockDataviewViewUpdateSort
|
||||
viewFieldsChange *pb.EventBlockDataviewViewUpdateFields
|
||||
)
|
||||
|
||||
for _, view1 := range d.content.Views {
|
||||
if view1.Id == view2.Id {
|
||||
found = true
|
||||
changed = !proto.Equal(view1, view2)
|
||||
|
||||
viewFieldsChange = diffViewFields(view1, view2)
|
||||
viewFilterChanges = diffViewFilters(view1, view2)
|
||||
viewRelationChanges = diffViewRelations(view1, view2)
|
||||
|
||||
// {
|
||||
//
|
||||
// calcID := func(s *model.BlockContentDataviewSort) string {
|
||||
// // TODO temp
|
||||
// return s.RelationKey
|
||||
// }
|
||||
// res := slice.Diff(wrapWithIDs(view1.Sorts, calcID), wrapWithIDs(view2.Sorts, calcID), func(a, b withID[*model.BlockContentDataviewSort]) bool {
|
||||
// return a.item.RelationKey == b.item.RelationKey
|
||||
// })
|
||||
// if len(res) > 0 {
|
||||
// fmt.Println("sorts")
|
||||
// }
|
||||
// for _, x := range res {
|
||||
// fmt.Printf("%s\n", x)
|
||||
// }
|
||||
// }
|
||||
viewSortChanges = diffViewSorts(view1, view2)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if len(viewFilterChanges) > 0 || len(viewRelationChanges) > 0 {
|
||||
if len(viewFilterChanges) > 0 || len(viewRelationChanges) > 0 || len(viewSortChanges) > 0 || viewFieldsChange != nil {
|
||||
msgs = append(msgs,
|
||||
simple.EventMessage{
|
||||
Msg: &pb.EventMessage{Value: &pb.EventMessageValueOfBlockDataviewViewUpdate{
|
||||
&pb.EventBlockDataviewViewUpdate{
|
||||
Id: dv.Id,
|
||||
ViewId: view2.Id,
|
||||
Fields: viewFieldsChange,
|
||||
Filter: viewFilterChanges,
|
||||
Relation: viewRelationChanges,
|
||||
Sort: viewSortChanges,
|
||||
},
|
||||
}}})
|
||||
}
|
||||
|
||||
if !found || changed {
|
||||
if !found {
|
||||
msgs = append(msgs,
|
||||
simple.EventMessage{
|
||||
Msg: &pb.EventMessage{Value: &pb.EventMessageValueOfBlockDataviewViewSet{
|
||||
|
@ -628,16 +614,80 @@ func (l *Dataview) ApplyViewUpdate(upd *pb.EventBlockDataviewViewUpdate) {
|
|||
return
|
||||
}
|
||||
|
||||
var changes []slice.Change[*model.BlockContentDataviewRelation]
|
||||
for _, r := range upd.Relation {
|
||||
if v := r.GetUpdate(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeReplace(v.Item, v.Id))
|
||||
if f := upd.Fields; f != nil {
|
||||
fmt.Println("apply fields", f)
|
||||
view.Type = f.Type
|
||||
view.Name = f.Name
|
||||
view.CoverRelationKey = f.CoverRelationKey
|
||||
view.HideIcon = f.HideIcon
|
||||
view.CardSize = f.CardSize
|
||||
view.CoverFit = f.CoverFit
|
||||
view.GroupRelationKey = f.GroupRelationKey
|
||||
view.GroupBackgroundColors = f.GroupBackgroundColors
|
||||
}
|
||||
|
||||
{
|
||||
var changes []slice.Change[*model.BlockContentDataviewRelation]
|
||||
for _, r := range upd.Relation {
|
||||
if v := r.GetUpdate(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeReplace(v.Item, v.Id))
|
||||
} else if v := r.GetAdd(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeAdd(v.Items, v.AfterId))
|
||||
} else if v := r.GetRemove(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeRemove[*model.BlockContentDataviewRelation](v.Ids))
|
||||
} else if v := r.GetMove(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeMove[*model.BlockContentDataviewRelation](v.Ids, v.AfterId))
|
||||
}
|
||||
}
|
||||
if len(changes) > 0 {
|
||||
fmt.Println("apply relation changes")
|
||||
for _, ch := range changes {
|
||||
fmt.Println(" ", ch)
|
||||
}
|
||||
}
|
||||
view.Relations = slice.ApplyChanges(view.Relations, changes, getViewRelationID)
|
||||
}
|
||||
{
|
||||
var changes []slice.Change[*model.BlockContentDataviewFilter]
|
||||
for _, r := range upd.Filter {
|
||||
if v := r.GetUpdate(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeReplace(v.Item, v.Id))
|
||||
} else if v := r.GetAdd(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeAdd(v.Items, v.AfterId))
|
||||
} else if v := r.GetRemove(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeRemove[*model.BlockContentDataviewFilter](v.Ids))
|
||||
} else if v := r.GetMove(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeMove[*model.BlockContentDataviewFilter](v.Ids, v.AfterId))
|
||||
}
|
||||
}
|
||||
if len(changes) > 0 {
|
||||
fmt.Println("apply filters changes")
|
||||
for _, ch := range changes {
|
||||
fmt.Println(" ", ch)
|
||||
}
|
||||
}
|
||||
view.Filters = slice.ApplyChanges(view.Filters, changes, getViewFilterID)
|
||||
}
|
||||
{
|
||||
var changes []slice.Change[*model.BlockContentDataviewSort]
|
||||
for _, r := range upd.Sort {
|
||||
if v := r.GetUpdate(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeReplace(v.Item, v.Id))
|
||||
} else if v := r.GetAdd(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeAdd(v.Items, v.AfterId))
|
||||
} else if v := r.GetRemove(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeRemove[*model.BlockContentDataviewSort](v.Ids))
|
||||
} else if v := r.GetMove(); v != nil {
|
||||
changes = append(changes, slice.MakeChangeMove[*model.BlockContentDataviewSort](v.Ids, v.AfterId))
|
||||
}
|
||||
}
|
||||
if len(changes) > 0 {
|
||||
fmt.Println("apply sorts changes")
|
||||
for _, ch := range changes {
|
||||
fmt.Println(" ", ch)
|
||||
}
|
||||
}
|
||||
view.Sorts = slice.ApplyChanges(view.Sorts, changes, getViewSortID)
|
||||
}
|
||||
|
||||
for _, ch := range changes {
|
||||
fmt.Println(" ", ch)
|
||||
}
|
||||
|
||||
view.Relations = slice.ApplyChanges(view.Relations, changes, getViewRelationID)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,31 @@ import (
|
|||
"github.com/anytypeio/go-anytype-middleware/util/slice"
|
||||
)
|
||||
|
||||
func diffViewFields(a, b *model.BlockContentDataviewView) *pb.EventBlockDataviewViewUpdateFields {
|
||||
isEqual := a.Type == b.Type &&
|
||||
a.Name == b.Name &&
|
||||
a.CoverRelationKey == b.CoverRelationKey &&
|
||||
a.HideIcon == b.HideIcon &&
|
||||
a.CardSize == b.CardSize &&
|
||||
a.CoverFit == b.CoverFit &&
|
||||
a.GroupRelationKey == b.GroupRelationKey &&
|
||||
a.GroupBackgroundColors == b.GroupBackgroundColors
|
||||
|
||||
if isEqual {
|
||||
return nil
|
||||
}
|
||||
return &pb.EventBlockDataviewViewUpdateFields{
|
||||
Type: b.Type,
|
||||
Name: b.Name,
|
||||
CoverRelationKey: b.CoverRelationKey,
|
||||
HideIcon: b.HideIcon,
|
||||
CardSize: b.CardSize,
|
||||
CoverFit: b.CoverFit,
|
||||
GroupRelationKey: b.GroupRelationKey,
|
||||
GroupBackgroundColors: b.GroupBackgroundColors,
|
||||
}
|
||||
}
|
||||
|
||||
func getViewFilterID(f *model.BlockContentDataviewFilter) string {
|
||||
// TODO temp
|
||||
return f.RelationKey
|
||||
|
@ -133,3 +158,67 @@ func diffViewRelations(a, b *model.BlockContentDataviewView) []*pb.EventBlockDat
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func getViewSortID(f *model.BlockContentDataviewSort) string {
|
||||
// TODO temp
|
||||
return f.RelationKey
|
||||
}
|
||||
|
||||
func isViewSortsEqual(a, b *model.BlockContentDataviewSort) bool {
|
||||
if a.RelationKey != b.RelationKey {
|
||||
return false
|
||||
}
|
||||
if a.Type != b.Type {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func diffViewSorts(a, b *model.BlockContentDataviewView) []*pb.EventBlockDataviewViewUpdateSort {
|
||||
diff := slice.Diff(a.Sorts, b.Sorts, getViewSortID, isViewSortsEqual)
|
||||
if len(diff) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return unwrapChanges(
|
||||
diff,
|
||||
func(afterID string, items []*model.BlockContentDataviewSort) *pb.EventBlockDataviewViewUpdateSort {
|
||||
return &pb.EventBlockDataviewViewUpdateSort{
|
||||
Operation: &pb.EventBlockDataviewViewUpdateSortOperationOfAdd{
|
||||
Add: &pb.EventBlockDataviewViewUpdateSortAdd{
|
||||
AfterId: afterID,
|
||||
Items: items,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
func(ids []string) *pb.EventBlockDataviewViewUpdateSort {
|
||||
return &pb.EventBlockDataviewViewUpdateSort{
|
||||
Operation: &pb.EventBlockDataviewViewUpdateSortOperationOfRemove{
|
||||
Remove: &pb.EventBlockDataviewViewUpdateSortRemove{
|
||||
Ids: ids,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
func(afterID string, ids []string) *pb.EventBlockDataviewViewUpdateSort {
|
||||
return &pb.EventBlockDataviewViewUpdateSort{
|
||||
Operation: &pb.EventBlockDataviewViewUpdateSortOperationOfMove{
|
||||
Move: &pb.EventBlockDataviewViewUpdateSortMove{
|
||||
AfterId: afterID,
|
||||
Ids: ids,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
func(id string, item *model.BlockContentDataviewSort) *pb.EventBlockDataviewViewUpdateSort {
|
||||
return &pb.EventBlockDataviewViewUpdateSort{
|
||||
Operation: &pb.EventBlockDataviewViewUpdateSortOperationOfUpdate{
|
||||
Update: &pb.EventBlockDataviewViewUpdateSortUpdate{
|
||||
Id: id,
|
||||
Item: item,
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
111
docs/proto.md
111
docs/proto.md
|
@ -997,6 +997,7 @@
|
|||
- [Event.Block.Dataview.ViewOrder](#anytype-Event-Block-Dataview-ViewOrder)
|
||||
- [Event.Block.Dataview.ViewSet](#anytype-Event-Block-Dataview-ViewSet)
|
||||
- [Event.Block.Dataview.ViewUpdate](#anytype-Event-Block-Dataview-ViewUpdate)
|
||||
- [Event.Block.Dataview.ViewUpdate.Fields](#anytype-Event-Block-Dataview-ViewUpdate-Fields)
|
||||
- [Event.Block.Dataview.ViewUpdate.Filter](#anytype-Event-Block-Dataview-ViewUpdate-Filter)
|
||||
- [Event.Block.Dataview.ViewUpdate.Filter.Add](#anytype-Event-Block-Dataview-ViewUpdate-Filter-Add)
|
||||
- [Event.Block.Dataview.ViewUpdate.Filter.Move](#anytype-Event-Block-Dataview-ViewUpdate-Filter-Move)
|
||||
|
@ -1007,6 +1008,11 @@
|
|||
- [Event.Block.Dataview.ViewUpdate.Relation.Move](#anytype-Event-Block-Dataview-ViewUpdate-Relation-Move)
|
||||
- [Event.Block.Dataview.ViewUpdate.Relation.Remove](#anytype-Event-Block-Dataview-ViewUpdate-Relation-Remove)
|
||||
- [Event.Block.Dataview.ViewUpdate.Relation.Update](#anytype-Event-Block-Dataview-ViewUpdate-Relation-Update)
|
||||
- [Event.Block.Dataview.ViewUpdate.Sort](#anytype-Event-Block-Dataview-ViewUpdate-Sort)
|
||||
- [Event.Block.Dataview.ViewUpdate.Sort.Add](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Add)
|
||||
- [Event.Block.Dataview.ViewUpdate.Sort.Move](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Move)
|
||||
- [Event.Block.Dataview.ViewUpdate.Sort.Remove](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Remove)
|
||||
- [Event.Block.Dataview.ViewUpdate.Sort.Update](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Update)
|
||||
- [Event.Block.Delete](#anytype-Event-Block-Delete)
|
||||
- [Event.Block.FilesUpload](#anytype-Event-Block-FilesUpload)
|
||||
- [Event.Block.Fill](#anytype-Event-Block-Fill)
|
||||
|
@ -15666,6 +15672,30 @@ sent when the view have been changed or added
|
|||
| viewId | [string](#string) | | |
|
||||
| filter | [Event.Block.Dataview.ViewUpdate.Filter](#anytype-Event-Block-Dataview-ViewUpdate-Filter) | repeated | |
|
||||
| relation | [Event.Block.Dataview.ViewUpdate.Relation](#anytype-Event-Block-Dataview-ViewUpdate-Relation) | repeated | |
|
||||
| sort | [Event.Block.Dataview.ViewUpdate.Sort](#anytype-Event-Block-Dataview-ViewUpdate-Sort) | repeated | |
|
||||
| fields | [Event.Block.Dataview.ViewUpdate.Fields](#anytype-Event-Block-Dataview-ViewUpdate-Fields) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Dataview-ViewUpdate-Fields"></a>
|
||||
|
||||
### Event.Block.Dataview.ViewUpdate.Fields
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| type | [model.Block.Content.Dataview.View.Type](#anytype-model-Block-Content-Dataview-View-Type) | | |
|
||||
| name | [string](#string) | | |
|
||||
| coverRelationKey | [string](#string) | | Relation used for cover in gallery |
|
||||
| hideIcon | [bool](#bool) | | Hide icon near name |
|
||||
| cardSize | [model.Block.Content.Dataview.View.Size](#anytype-model-Block-Content-Dataview-View-Size) | | Gallery card size |
|
||||
| coverFit | [bool](#bool) | | Image fits container |
|
||||
| groupRelationKey | [string](#string) | | Group view by this relationKey |
|
||||
| groupBackgroundColors | [bool](#bool) | | Enable backgrounds in groups |
|
||||
|
||||
|
||||
|
||||
|
@ -15834,6 +15864,87 @@ sent when the view have been changed or added
|
|||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Dataview-ViewUpdate-Sort"></a>
|
||||
|
||||
### Event.Block.Dataview.ViewUpdate.Sort
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| add | [Event.Block.Dataview.ViewUpdate.Sort.Add](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Add) | | |
|
||||
| remove | [Event.Block.Dataview.ViewUpdate.Sort.Remove](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Remove) | | |
|
||||
| update | [Event.Block.Dataview.ViewUpdate.Sort.Update](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Update) | | |
|
||||
| move | [Event.Block.Dataview.ViewUpdate.Sort.Move](#anytype-Event-Block-Dataview-ViewUpdate-Sort-Move) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Dataview-ViewUpdate-Sort-Add"></a>
|
||||
|
||||
### Event.Block.Dataview.ViewUpdate.Sort.Add
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| afterId | [string](#string) | | |
|
||||
| items | [model.Block.Content.Dataview.Sort](#anytype-model-Block-Content-Dataview-Sort) | repeated | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Dataview-ViewUpdate-Sort-Move"></a>
|
||||
|
||||
### Event.Block.Dataview.ViewUpdate.Sort.Move
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| afterId | [string](#string) | | |
|
||||
| ids | [string](#string) | repeated | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Dataview-ViewUpdate-Sort-Remove"></a>
|
||||
|
||||
### Event.Block.Dataview.ViewUpdate.Sort.Remove
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| ids | [string](#string) | repeated | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Dataview-ViewUpdate-Sort-Update"></a>
|
||||
|
||||
### Event.Block.Dataview.ViewUpdate.Sort.Update
|
||||
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| id | [string](#string) | | |
|
||||
| item | [model.Block.Content.Dataview.Sort](#anytype-model-Block-Content-Dataview-Sort) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="anytype-Event-Block-Delete"></a>
|
||||
|
||||
### Event.Block.Delete
|
||||
|
|
2541
pb/events.pb.go
2541
pb/events.pb.go
File diff suppressed because it is too large
Load diff
|
@ -688,6 +688,19 @@ message Event {
|
|||
string viewId = 2;
|
||||
repeated Filter filter = 3;
|
||||
repeated Relation relation = 4;
|
||||
repeated Sort sort = 5;
|
||||
Fields fields = 6;
|
||||
|
||||
message Fields {
|
||||
anytype.model.Block.Content.Dataview.View.Type type = 1;
|
||||
string name = 2;
|
||||
string coverRelationKey = 3; // Relation used for cover in gallery
|
||||
bool hideIcon = 4; // Hide icon near name
|
||||
anytype.model.Block.Content.Dataview.View.Size cardSize = 5; // Gallery card size
|
||||
bool coverFit = 6; // Image fits container
|
||||
string groupRelationKey = 7; // Group view by this relationKey
|
||||
bool groupBackgroundColors = 8; // Enable backgrounds in groups
|
||||
}
|
||||
|
||||
message Filter {
|
||||
oneof operation {
|
||||
|
@ -738,6 +751,31 @@ message Event {
|
|||
repeated string ids = 2;
|
||||
}
|
||||
}
|
||||
|
||||
message Sort {
|
||||
oneof operation {
|
||||
Add add = 1;
|
||||
Remove remove = 2;
|
||||
Update update = 3;
|
||||
Move move = 4;
|
||||
}
|
||||
|
||||
message Add {
|
||||
string afterId = 1;
|
||||
repeated anytype.model.Block.Content.Dataview.Sort items = 2;
|
||||
}
|
||||
message Remove {
|
||||
repeated string ids = 1;
|
||||
}
|
||||
message Update {
|
||||
string id = 1;
|
||||
anytype.model.Block.Content.Dataview.Sort item = 2;
|
||||
}
|
||||
message Move {
|
||||
string afterId = 1;
|
||||
repeated string ids = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message ViewDelete {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue