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

appview: add page for single workflow

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 798f1a3a 372731c8

verified
Changed files
+116
appview
pages
templates
repo
pipelines
pipelines
+13
appview/pages/pages.go
···
return p.executeRepo("repo/pipelines/pipelines", w, params)
}
+
type WorkflowParams struct {
+
LoggedInUser *oauth.User
+
RepoInfo repoinfo.RepoInfo
+
Pipeline db.Pipeline
+
Workflow string
+
Active string
+
}
+
+
func (p *Pages) Workflow(w io.Writer, params WorkflowParams) error {
+
params.Active = "pipelines"
+
return p.executeRepo("repo/pipelines/workflow", w, params)
+
}
+
func (p *Pages) Static() http.Handler {
if p.dev {
return http.StripPrefix("/static/", http.FileServer(http.Dir("appview/pages/static")))
+52
appview/pages/templates/repo/pipelines/workflow.html
···
+
{{ define "title" }} {{ .Workflow }} &middot; pipeline {{ .Pipeline.Id }} &middot; {{ .RepoInfo.FullName }}{{ end }}
+
+
{{ define "extrameta" }}
+
{{ $title := "pipelines"}}
+
{{ $url := printf "https://tangled.sh/%s/pipelines" .RepoInfo.FullName }}
+
{{ template "repo/fragments/og" (dict "RepoInfo" .RepoInfo "Title" $title "Url" $url) }}
+
{{ end }}
+
+
{{ define "repoContent" }}
+
<section class="w-full grid grid-cols-1 md:grid-cols-4 gap-2 mt-2">
+
<div class="col-span-1">
+
{{ block "sidebar" . }} {{ end }}
+
</div>
+
<div class="col-span-1 md:col-span-3">
+
{{ block "logs" . }} {{ end }}
+
</div>
+
</section>
+
{{ end }}
+
+
{{ define "repoAfter" }}
+
{{ end }}
+
+
{{ define "sidebar" }}
+
{{ $active := .Workflow }}
+
{{ with .Pipeline }}
+
<div class="rounded border border-gray-200 dark:border-gray-700">
+
{{ range $name, $all := .Statuses }}
+
<div class="flex items-center justify-between p-2 border-b border-gray-200 dark:border-gray-700 {{if eq $name $active}}bg-gray-100/50 dark:bg-gray-700/50{{end}}">
+
{{ $lastStatus := $all.Latest }}
+
{{ $kind := $lastStatus.Status.String }}
+
+
{{ $t := .TimeTaken }}
+
{{ $time := "" }}
+
{{ if $t }}
+
{{ $time = durationFmt $t }}
+
{{ else }}
+
{{ $time = printf "%s ago" (shortTimeFmt $.Created) }}
+
{{ end }}
+
+
<div id="left" class="flex items-center gap-2 flex-shrink-0">
+
{{ template "repo/pipelines/fragments/workflowSymbol" $all }}
+
{{ $name }}
+
</div>
+
<div id="right" class="flex items-center gap-2 flex-shrink-0">
+
<span class="font-bold">{{ $kind }}</span>
+
<time>{{ $time }}</time>
+
</div>
+
</div>
+
{{ end }}
+
</div>
+
{{ end }}
+
{{ end }}
+51
appview/pipelines/pipelines.go
···
Pipelines: ps,
})
}
+
+
func (p *Pipelines) Workflow(w http.ResponseWriter, r *http.Request) {
+
user := p.oauth.GetUser(r)
+
l := p.Logger.With("handler", "Workflow")
+
+
f, err := p.repoResolver.Resolve(r)
+
if err != nil {
+
l.Error("failed to get repo and knot", "err", err)
+
return
+
}
+
+
repoInfo := f.RepoInfo(user)
+
+
pipelineId := chi.URLParam(r, "pipeline")
+
if pipelineId == "" {
+
l.Error("empty pipeline ID")
+
return
+
}
+
+
workflow := chi.URLParam(r, "workflow")
+
if pipelineId == "" {
+
l.Error("empty workflow name")
+
return
+
}
+
+
ps, err := db.GetPipelineStatuses(
+
p.db,
+
db.FilterEq("repo_owner", repoInfo.OwnerDid),
+
db.FilterEq("repo_name", repoInfo.Name),
+
db.FilterEq("knot", repoInfo.Knot),
+
db.FilterEq("id", pipelineId),
+
)
+
if err != nil {
+
l.Error("failed to query db", "err", err)
+
return
+
}
+
+
if len(ps) != 1 {
+
l.Error("invalid number of pipelines", "len", len(ps))
+
return
+
}
+
+
singlePipeline := ps[0]
+
+
p.pages.Workflow(w, pages.WorkflowParams{
+
LoggedInUser: user,
+
RepoInfo: repoInfo,
+
Pipeline: singlePipeline,
+
Workflow: workflow,
+
})
+
}