@@ -3,10 +3,11 @@ package component
import (
"fmt"
"time"
"dmitri.shuralyov.com/app/changes/common"
"dmitri.shuralyov.com/html/belt"
"dmitri.shuralyov.com/service/change"
"dmitri.shuralyov.com/state"
"github.com/dustin/go-humanize"
"github.com/shurcooL/htmlg"
@@ -18,10 +19,14 @@ import (
)
// Event is an event component.
type Event struct {
Event change.TimelineItem
// State must have BaseURI and ChangeID fields populated.
// They are used while rendering change.CommitEvent events.
State common.State
}
func (e Event) Render() []*html.Node {
// TODO: Make this much nicer.
// <div class="list-entry event event-{{.Type}}">
@@ -59,10 +64,12 @@ func (e Event) icon() *html.Node {
case change.ReopenedEvent:
icon = octicon.PrimitiveDot()
color, backgroundColor = "#fff", "#6cc644"
case change.RenamedEvent:
icon = octicon.Pencil()
case change.CommitEvent:
icon = octicon.GitCommit()
case change.LabeledEvent, change.UnlabeledEvent:
icon = octicon.Tag()
case change.ReviewRequestedEvent:
icon = octicon.Eye()
case change.ReviewRequestRemovedEvent:
@@ -125,10 +132,22 @@ func (e Event) text() []*html.Node {
Attr: []html.Attribute{{Key: atom.Style.String(), Val: "font-weight: bold;"}},
FirstChild: htmlg.Text(p.From),
}
to := htmlg.Strong(p.To)
return []*html.Node{htmlg.Text("changed the title "), from, htmlg.Text(" "), to}
case change.CommitEvent:
return []*html.Node{
htmlg.Text("uploaded "),
{
Type: html.ElementNode, Data: atom.A.String(),
Attr: []html.Attribute{
{Key: atom.Class.String(), Val: "black"},
{Key: atom.Href.String(), Val: fmt.Sprintf("%s/%d/files/%s", e.State.BaseURI, e.State.ChangeID, p.SHA)},
},
FirstChild: htmlg.Text(p.Subject),
},
}
case change.LabeledEvent:
var ns []*html.Node
ns = append(ns, htmlg.Text("added the "))
ns = append(ns, issuescomponent.Label{Label: p.Label}.Render()...)
ns = append(ns, htmlg.Text(" label"))