Skip to content

Commit

Permalink
Show diff links in page history
Browse files Browse the repository at this point in the history
Closes #55
  • Loading branch information
csmith committed Apr 9, 2021
1 parent d885368 commit 1c0ab08
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
21 changes: 20 additions & 1 deletion handlers_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,26 @@ func PageHistoryHandler(t *Templates, pp HistoryProvider) http.HandlerFunc {
number = len(history.Entries) + 1
}

t.RenderHistory(w, r, pageTitle, history.Entries[:number-1], next)
var entries []*HistoryEntry
for i := range history.Entries[:number-1] {
e := history.Entries[i]

var previousChange = ""
if i+1 < len(history.Entries) {
previousChange = history.Entries[i+1].ChangeId
}

entries = append(entries, &HistoryEntry{
Latest: start == "" && i == 0,
ChangeId: e.ChangeId,
PreviousChangeId: previousChange,
User: e.User,
Time: e.Time,
Message: e.Message,
})
}

t.RenderHistory(w, r, pageTitle, entries, next)
}
}

Expand Down
8 changes: 7 additions & 1 deletion resources/templates/history.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
</td>
<td>
<a href="/view/{{$.Common.PageTitle}}?rev={{.ChangeId}}">view</a>
<a href="/revert/{{$.Common.PageTitle}}?rev={{.ChangeId}}">revert to this version</a>
{{ if not .Latest }}
| <a href="/revert/{{$.Common.PageTitle}}?rev={{.ChangeId}}">revert to this version</a>
| <a href="/diff/{{$.Common.PageTitle}}?startrev={{.ChangeId}}&amp;endrev=HEAD">compare to latest</a>
{{ end }}
{{if .PreviousChangeId}}
| <a href="/diff/{{$.Common.PageTitle}}?startrev={{.PreviousChangeId}}&amp;endrev={{.ChangeId}}">compare to previous</a>
{{end}}
</td>
</tr>
{{end}}
Expand Down
15 changes: 12 additions & 3 deletions templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,20 @@ func (t *Templates) RenderUploadForm(w http.ResponseWriter, r *http.Request) {

type HistoryPageArgs struct {
Common CommonArgs
History []*LogEntry
History []*HistoryEntry
Next string
}

func (t *Templates) RenderHistory(w http.ResponseWriter, r *http.Request, title string, entries []*LogEntry, next string) {
type HistoryEntry struct {
ChangeId string
PreviousChangeId string
Latest bool
User string
Time time.Time
Message string
}

func (t *Templates) RenderHistory(w http.ResponseWriter, r *http.Request, title string, entries []*HistoryEntry, next string) {
t.render("history.gohtml", http.StatusOK, w, &HistoryPageArgs{
Common: t.populateArgs(w, r, CommonArgs{
PageTitle: title,
Expand Down Expand Up @@ -340,7 +349,7 @@ func (t *Templates) RenderSearch(w http.ResponseWriter, r *http.Request, pattern

type DiffPageArgs struct {
Common CommonArgs
Diff []diffmatchpatch.Diff
Diff []diffmatchpatch.Diff
}

func (t *Templates) RenderDiff(w http.ResponseWriter, r *http.Request, diff []diffmatchpatch.Diff) {
Expand Down

0 comments on commit 1c0ab08

Please sign in to comment.