snapshot.go

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