forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview: pages: show tags against commits

anirudh.fi f5f258b2 2f49ac9b

verified
Changed files
+73 -22
appview
pages
templates
state
+1
appview/pages/pages.go
···
type RepoLogParams struct {
LoggedInUser *auth.User
RepoInfo RepoInfo
+
TagMap map[string][]string
types.RepoLogResponse
Active string
EmailToDidOrHandle map[string]string
+5 -6
appview/pages/templates/repo/index.html
···
<div id="commit-log" class="md:col-span-1 px-2 pb-4">
<div class="flex justify-between items-center">
<a href="/{{ .RepoInfo.FullName }}/commits/{{ .Ref | urlquery }}" class="flex text-black dark:text-white items-center gap-4 pb-2 no-underline hover:no-underline group">
-
<div class="flex gap-2 items-center">
-
{{ i "git-commit-horizontal" "w-4 h-4" }} commits
+
<div class="flex gap-2 items-center font-bold">
+
{{ i "logs" "w-4 h-4" }} commits
</div>
<span class="hidden group-hover:flex gap-2 items-center text-sm text-gray-500 dark:text-gray-400 ">
view {{ .TotalCommits }} commits {{ i "chevron-right" "w-4 h-4" }}
···
{{ if gt (len .BranchesTrunc) 0 }}
<div id="branches" class="md:col-span-1 px-2 py-4 border-t border-gray-200 dark:border-gray-700">
<a href="/{{ .RepoInfo.FullName }}/branches" class="flex text-black dark:text-white items-center gap-4 pb-2 no-underline hover:no-underline group">
-
<div class="flex gap-2 items-center">
-
<!-- git-branch icon is seemingly bigger than others at 4x4 -->
-
{{ i "git-branch" "w-3 h-3" }} branches
+
<div class="flex gap-2 items-center font-bold">
+
{{ i "git-branch" "w-4 h-4" }} branches
</div>
<span class="hidden group-hover:flex gap-2 items-center text-sm text-gray-500 dark:text-gray-400 ">
view {{ len .Branches }} branches {{ i "chevron-right" "w-4 h-4" }}
···
<div id="tags" class="md:col-span-1 px-2 py-4 border-t border-gray-200 dark:border-gray-700">
<div class="flex justify-between items-center">
<a href="/{{ .RepoInfo.FullName }}/tags" class="flex text-black dark:text-white items-center gap-4 pb-2 no-underline hover:no-underline group">
-
<div class="flex gap-2 items-center">
+
<div class="flex gap-2 items-center font-bold">
{{ i "tags" "w-4 h-4" }} tags
</div>
<span class="hidden group-hover:flex gap-2 items-center text-sm text-gray-500 dark:text-gray-400 ">
+41 -16
appview/pages/templates/repo/log.html
···
</td>
<td class=" py-3 align-top">
<div>
-
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}" class="dark:text-white no-underline hover:underline">{{ index $messageParts 0 }}</a>
-
{{ if gt (len $messageParts) 1 }}
-
<button class="ml-2 py-1/2 px-1 bg-gray-200 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-600 rounded" hx-on:click="this.nextElementSibling.classList.toggle('hidden')">{{ i "ellipsis" "w-3 h-3" }}</button>
+
<div class="flex items-center justify-start">
+
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}" class="dark:text-white no-underline hover:underline">{{ index $messageParts 0 }}</a>
+
{{ if gt (len $messageParts) 1 }}
+
<button class="ml-2 py-1/2 px-1 bg-gray-200 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-600 rounded" hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')">{{ i "ellipsis" "w-3 h-3" }}</button>
+
{{ end }}
+
+
+
{{ if index $.TagMap $commit.Hash.String }}
+
{{ range $tag := index $.TagMap $commit.Hash.String }}
+
<span class="ml-2 text-xs rounded bg-gray-100 dark:bg-gray-700 text-black dark:text-white font-mono px-2 inline-flex items-center">
+
{{ $tag }}
+
</span>
+
{{ end }}
+
{{ end }}
+
+
</div>
+
+
{{ if gt (len $messageParts) 1 }}
<p class="hidden mt-1 text-sm text-gray-600 dark:text-gray-400">{{ nl2br (index $messageParts 1) }}</p>
{{ end }}
-
</div>
</td>
<td class=" py-3 align-top text-gray-500 dark:text-gray-400">{{ timeFmt $commit.Author.When }}</td>
</tr>
-
{{ end }}
+
{{ end }}
</tbody>
</table>
···
<div>
<div class="flex items-center justify-between">
<div class="flex-1">
-
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}"
-
class="inline no-underline hover:underline dark:text-white">
-
{{ index $messageParts 0 }}
-
</a>
-
{{ if gt (len $messageParts) 1 }}
-
<button
-
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600"
-
hx-on:click="this.nextElementSibling.classList.toggle('hidden')">
-
{{ i "ellipsis" "w-3 h-3" }}
-
</button>
-
{{ end }}
+
<div class="flex items-center">
+
<a href="/{{ $.RepoInfo.FullName }}/commit/{{ $commit.Hash.String }}"
+
class="inline no-underline hover:underline dark:text-white">
+
{{ index $messageParts 0 }}
+
</a>
+
{{ if gt (len $messageParts) 1 }}
+
<button
+
class="py-1/2 px-1 bg-gray-200 hover:bg-gray-400 rounded dark:bg-gray-700 dark:hover:bg-gray-600 ml-2"
+
hx-on:click="this.parentElement.nextElementSibling.classList.toggle('hidden')">
+
{{ i "ellipsis" "w-3 h-3" }}
+
</button>
+
{{ end }}
+
+
{{ if index $.TagMap $commit.Hash.String }}
+
{{ range $tag := index $.TagMap $commit.Hash.String }}
+
<span class="ml-2 text-xs rounded bg-gray-100 dark:bg-gray-700 text-black dark:text-white font-mono px-2 inline-flex items-center">
+
{{ $tag }}
+
</span>
+
{{ end }}
+
{{ end }}
+
</div>
+
{{ if gt (len $messageParts) 1 }}
<p class="hidden mt-1 text-sm cursor-text pb-2 dark:text-gray-300">
{{ nl2br (index $messageParts 1) }}
+26
appview/state/repo.go
···
return
}
+
resp, err = us.Tags(f.OwnerDid(), f.RepoName)
+
if err != nil {
+
log.Println("failed to reach knotserver", err)
+
return
+
}
+
+
body, err = io.ReadAll(resp.Body)
+
if err != nil {
+
log.Printf("error reading response body: %v", err)
+
return
+
}
+
+
var result types.RepoTagsResponse
+
err = json.Unmarshal(body, &result)
+
if err != nil {
+
log.Printf("Error unmarshalling response body: %v", err)
+
return
+
}
+
+
tagMap := make(map[string][]string)
+
for _, tag := range result.Tags {
+
hash := tag.Hash
+
tagMap[hash] = append(tagMap[hash], tag.Name)
+
}
+
user := s.auth.GetUser(r)
s.pages.RepoLog(w, pages.RepoLogParams{
LoggedInUser: user,
+
TagMap: tagMap,
RepoInfo: f.RepoInfo(s, user),
RepoLogResponse: repolog,
EmailToDidOrHandle: EmailToDidOrHandle(s, uniqueEmails(repolog.Commits)),