| package loop |
| |
| import ( |
| "fmt" |
| "strings" |
| "sync" |
| |
| "github.com/invopop/jsonschema" |
| ) |
| |
| type Comment struct { |
| Author string `json:"author" jsonschema:"title=author,description=author of the comment,required"` |
| Comment string `json:"comment" jsonschema:"title=comment,description=actual comment text,required"` |
| } |
| |
| func (c Comment) String() string { |
| return fmt.Sprintf("%s: %s", c.Author, c.Comment) |
| } |
| |
| type ToDo struct { |
| ID string `json:"id" jsonschema:"title=id,description=unique id of the TODO item,required"` |
| Title string `json:"title" jsonschema:"title=title,description=high level title of the TODO item,required"` |
| Description string `json:"description" jsonschema:"title=description,description=detailed description what this TODO item is about"` |
| Items []*ToDo `json:"items" jsonschema:"title=sub items,description=array of sub items current item consists of"` |
| Parallel bool `json:"parallel" jsonschema:"title=parallel,description=if true sub-items may be worked on in parallel and there is no depencency between them, otherwise they shall be worked on sequentially"` |
| Done bool `json:"done" jsonschema:"title=done,description=if true item shall be considered as done"` |
| AssignedTo string `json:"assignedTo" jsonschema:"title=assigned to,description=name of the person who shall work on this item"` |
| Discussion []Comment `json:"discussion" jsonschema:"title=discussion,description=comments related to current item"` |
| Summary string `json:"summary" jsonschem:"title=summary,description=detailed summary of current item and all of it's sub-item trees."` |
| lock sync.RWMutex |
| } |
| |
| func (t ToDo) String() string { |
| var ret []string |
| status := "IN PROGRESS" |
| if t.Done { |
| status = "DONE" |
| } |
| ret = append(ret, fmt.Sprintf("%s: %s - %s %s %t", t.ID, t.Title, status, t.AssignedTo, t.Parallel)) |
| if t.Description != "" { |
| ret = append(ret, t.Description) |
| } |
| if t.Summary != "" { |
| ret = append(ret, fmt.Sprintf("SUMMARY: %s", t.Summary)) |
| } |
| for _, c := range t.Discussion { |
| ret = append(ret, fmt.Sprintf("\t - %s", c.String())) |
| } |
| for _, i := range t.Items { |
| for _, k := range strings.Split(i.String(), "\n") { |
| ret = append(ret, fmt.Sprintf("\t%s", k)) |
| } |
| } |
| return strings.Join(ret, "\n") |
| } |
| |
| func (t *ToDo) LockRead() { |
| t.lock.RLock() |
| } |
| |
| func (t *ToDo) UnlockRead() { |
| t.lock.RUnlock() |
| } |
| |
| func (t *ToDo) Lock() { |
| t.lock.Lock() |
| } |
| |
| func (t *ToDo) Unlock() { |
| t.lock.Unlock() |
| } |
| |
| func ToDoJSONSchema() string { |
| reflector := jsonschema.Reflector{ |
| AllowAdditionalProperties: false, |
| RequiredFromJSONSchemaTags: true, |
| DoNotReference: false, |
| } |
| var v ToDo |
| s := reflector.Reflect(v) |
| b, err := s.MarshalJSON() |
| if err != nil { |
| panic(err) |
| } |
| return string(b) |
| } |