~bigbes/sr-ht-spec

ref: 3cb1c03d8078d5748cc13a2e9bd7ba7d078e1b37 sr-ht-spec/web/templates/_threads.html -rw-r--r-- 4.5 KiB
3cb1c03d — Eugene Blikh go.mod: take the shared libraries' current heads 2 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
{{/*
  The review-thread markup, defined once and parsed into every page set.

  The diff renderer (web/diff.go) executes "blockthreads" into the HTML it
  builds for one block, and the proposal page renders "thread" directly for the
  comments whose anchor no longer names a block. Both go through html/template
  rather than string building because a comment body is prose someone else
  wrote: contextual auto-escaping is what keeps it text.
*/}}

{{define "thread"}}
<article class="ph-thread{{if .Resolved}} ph-thread-resolved{{end}}" id="thread-{{.ID}}">
  <header class="ph-thread-head">
    <span class="ph-author">{{.Author}}</span>
    {{if .Agent}}<span class="badge badge-secondary">agent</span>{{end}}
    <span class="ph-when">{{.When}}</span>
    {{if .Resolved}}<span class="badge badge-success">resolved</span>{{end}}
    {{if .Note}}<span class="badge badge-warning" title="{{.NoteWhy}}">{{.Note}}</span>{{end}}
    {{if .DocPath}}<code class="ph-when">{{.DocPath}}</code>{{end}}
    {{/*
      What this thread is attached to, spelled out. The reviewer selected lines;
      the comment stores a block under a heading path, and by the time anyone
      reads the thread the heading is usually off screen.

      It comes last and behind a separator because the badge in front of it is a
      warning about fit while this is a locator. Run together they read as one
      sentence, and "block edited since Storage › Goals" is a phrase the reader
      has to un-parse before noticing it is two unrelated facts.
    */}}
    {{if .AnchorPath}}<span class="ph-when">·</span>
    <code class="ph-anchor-path" title="the block this comment anchors to">{{.AnchorPath}}{{.AnchorIndex}}</code>{{end}}
  </header>
  <div class="ph-comment-body">{{.Body}}</div>

  {{range .Replies}}
  <div class="ph-reply">
    <header class="ph-thread-head">
      <span class="ph-author">{{.Author}}</span>
      {{if .Agent}}<span class="badge badge-secondary">agent</span>{{end}}
      <span class="ph-when">{{.When}}</span>
    </header>
    <div class="ph-comment-body">{{.Body}}</div>
  </div>
  {{end}}

  <div class="ph-thread-actions">
    {{if .CanReply}}
    <details class="ph-form">
      <summary>Reply</summary>
      <form method="POST" action="{{.ActionBase}}/reply">
        <input type="hidden" name="thread" value="{{.ID}}">
        <textarea class="form-control" name="body" rows="3" required
                  placeholder="Answer the critique"></textarea>
        <button type="submit" class="btn btn-sm btn-primary">Reply</button>
      </form>
    </details>
    {{end}}
    {{if .CanResolve}}
    <form method="POST" action="{{.ActionBase}}/resolve" class="ph-form">
      <input type="hidden" name="thread" value="{{.ID}}">
      <input type="hidden" name="resolved" value="{{if .Resolved}}0{{else}}1{{end}}">
      <button type="submit" class="btn btn-sm btn-outline-secondary">
        {{if .Resolved}}Reopen{{else}}Resolve{{end}}
      </button>
    </form>
    {{end}}
  </div>
</article>
{{end}}

{{define "blockthreads"}}
{{if .Threads}}
<div class="ph-threads">
  {{range .Threads}}{{template "thread" .}}{{end}}
</div>
{{end}}
{{if .Compose}}
<details class="ph-form ph-compose">
  <summary>Comment on this block</summary>
  {{/*
    Selection is by line, anchoring is by block, so the composer states which
    block it will anchor to before anything is typed. It is rendered here, on the
    server, rather than filled in by the selection script: with JavaScript off
    there is no selection and this sentence is the whole truth about where the
    comment lands. The script prefixes the selected line range onto it as its own
    element and removes that element again on Escape, so there is nothing here to
    repeat as a plain-text copy for restoring: writing such a copy back would
    have to go through textContent, which would flatten the code element below.
  */}}
  <p class="ph-anchor-note">Anchors to <code>{{.Compose.AnchorPath}}</code>{{.Compose.AnchorIndex}}</p>
  <form method="POST" action="{{.Compose.ActionBase}}/comment">
    <input type="hidden" name="doc" value="{{.Compose.DocPath}}">
    <input type="hidden" name="block" value="{{.Compose.Ordinal}}">
    <input type="hidden" name="side" value="{{.Compose.Side}}">
    <input type="hidden" name="hash" value="{{.Compose.Hash}}">
    <textarea class="form-control" name="body" rows="3" required
              placeholder="What is wrong with this block?"></textarea>
    <button type="submit" class="btn btn-sm btn-primary">Comment</button>
  </form>
</details>
{{end}}
{{end}}