1package board
2
3import (
4 "time"
5
6 "github.com/MichaelMure/git-bug/entities/identity"
7 "github.com/MichaelMure/git-bug/entity"
8 "github.com/MichaelMure/git-bug/entity/dag"
9)
10
11type Column struct {
12 Id entity.Id
13 Name string
14 Items []Item
15}
16
17type Item interface {
18 CombinedId() entity.CombinedId
19 // Status() common.Status
20}
21
22var _ dag.Snapshot = &Snapshot{}
23
24type Snapshot struct {
25 id entity.Id
26
27 Title string
28 Description string
29 Columns []*Column
30 Actors []identity.Interface
31
32 CreateTime time.Time
33 Operations []dag.Operation
34}
35
36// Id returns the Board identifier
37func (snap *Snapshot) Id() entity.Id {
38 if snap.id == "" {
39 // simply panic as it would be a coding error (no id provided at construction)
40 panic("no id")
41 }
42 return snap.id
43}
44
45func (snap *Snapshot) AllOperations() []dag.Operation {
46 return snap.Operations
47}
48
49func (snap *Snapshot) AppendOperation(op dag.Operation) {
50 snap.Operations = append(snap.Operations, op)
51}
52
53// EditTime returns the last time the board was modified
54func (snap *Snapshot) EditTime() time.Time {
55 if len(snap.Operations) == 0 {
56 return time.Unix(0, 0)
57 }
58
59 return snap.Operations[len(snap.Operations)-1].Time()
60}
61
62// append the operation author to the actors list
63func (snap *Snapshot) addActor(actor identity.Interface) {
64 for _, a := range snap.Actors {
65 if actor.Id() == a.Id() {
66 return
67 }
68 }
69
70 snap.Actors = append(snap.Actors, actor)
71}
72
73// HasActor return true if the id is a actor
74func (snap *Snapshot) HasActor(id entity.Id) bool {
75 for _, p := range snap.Actors {
76 if p.Id() == id {
77 return true
78 }
79 }
80 return false
81}
82
83// HasAnyActor return true if one of the ids is a actor
84func (snap *Snapshot) HasAnyActor(ids ...entity.Id) bool {
85 for _, id := range ids {
86 if snap.HasActor(id) {
87 return true
88 }
89 }
90 return false
91}
92
93func (snap *Snapshot) ItemCount() int {
94 var count int
95 for _, column := range snap.Columns {
96 count += len(column.Items)
97 }
98 return count
99}
100
101// IsAuthored is a sign post method for gqlgen
102func (snap *Snapshot) IsAuthored() {}