Browse Source

Fixed error display CSS and added dynamic deletion javascript file

feature/embedded-resources-and-css
root 5 months ago
parent
commit
f07aa88663
  1. 15
      static/homepage.js
  2. 19
      static/style.css
  3. 2
      templates/edit-repository.html
  4. 22
      templates/homepage.html
  5. 22
      web.go

15
static/homepage.js

@ -0,0 +1,15 @@
"use strict";
function confirmDeletion(ev) {
const name = ev.target.parentElement.parentElement.querySelector('a.name-link').innerHTML;
if (confirm("Are you sure you want to delete " + name + " ?")) {
ev.target.href += "&confirm=auto";
} else {
ev.preventDefault();
}
}
document.querySelectorAll('a.delete.button').forEach(btn => {
btn.addEventListener('click', confirmDeletion);
});

19
static/style.css

@ -70,3 +70,22 @@ fieldset {
aside {
margin-bottom: 1rem;
}
section.message {
border: 3px solid;
margin: 1rem 0;
padding: .2rem 1rem;
}
section.message:not(.error) {
border-color: #8181ff;
background-color: #e3e3ff;
}
section.message.error {
border-color: #ff4545;
background-color: #f8dada;
}
section.message * {
margin-top: .5rem;
margin-bottom: 0;
}

2
templates/edit-repository.html

@ -6,7 +6,7 @@
<link rel="stylesheet" href="/static/style.css">
<main>
<h1>Editing {{.Repo.Name}}</h1>
<a href="{{"/"|url}}">go back to project list</a>
<a class="button" href="{{"/"|url}}">go back to project list</a>
{{with .Errors}}
<h2>Errors:</h2>
<ul>

22
templates/homepage.html

@ -4,21 +4,29 @@
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Repositories</title>
<link rel="stylesheet" href="/static/style.css">
<script defer src="/static/homepage.js"></script>
<h1>Repositories</h1>
<aside>
<form method="post">
<label for="name">Create repository <input id="name" name="name" placeholder="Repository name"></label>
<label for="mirror">from mirror <input id="mirror" name="mirror" placeholder="Upstream URL"></label>
<label for="mirror">
from mirror (if any)
<input id="mirror" name="mirror" placeholder="Upstream URL (optional)">
</label>
<input type="submit" name="action" value="Create">
</form>
{{if .RepoInitLog|empty}}{{else}}
<section class="message {{if .HasRepoInitFailed}}error{{end}}">
{{if .HasRepoInitFailed}}
<h2>Error during repository creation</h2>
{{else}}
<h2>Created repository "{{.NewRepoName}}"</h2>
{{end}}
{{end}}
{{if .RepoInitLog|empty}}{{else}}
<p>{{if .HasRepoInitFailed}}<strong>error during repository creation</strong>: {{end}}{{.RepoInitLog}}</p>
<p>{{.RepoInitLog}}</p>
</section>
{{end}}
</aside>
@ -35,7 +43,7 @@
{{if $cat}}<tr class="category_header"><th colspan="4">{{$cat}}</th></tr>{{end}}
{{range $repos}}
<tr>
<td><a href="{{public_url .Name}}">{{.Name}}</a></td>
<td><a class="name-link" href="{{public_url .Name}}">{{.Name}}</a></td>
<td title="{{.Description}}">{{.Description|trim}}</td>
<td>{{if .IsExported}}public{{else}}private{{end}}</td>
<td>
@ -43,7 +51,7 @@
|
<a class="button" href="{{"/edit?repository="|url}}{{.Name}}">edit</a>
|
<a class="button" href="{{"/delete?repository="|url}}{{.Name}}">delete</a>
<a class="delete button" href="{{"/delete?repository="|url}}{{.Name}}">delete</a>
</td>
</tr>
{{end}}

22
web.go

@ -68,26 +68,28 @@ func (h *Handlers) HandleHomepage(w http.ResponseWriter, req *http.Request) {
// Handle repository creation
hasErrored := false
repoInitLog := ""
newRepoName := ""
action := req.FormValue("action")
if action == "Create" {
name, mirror, head := req.FormValue("name"), req.FormValue("mirror"), DefaultHead
if len(mirror) != 0 && len(name) == 0 {
name = path.Base(mirror)
newRepoName = req.FormValue("name")
mirror, head := req.FormValue("mirror"), DefaultHead
if len(mirror) != 0 && len(newRepoName) == 0 {
newRepoName = path.Base(mirror)
}
if len(name) == 0 {
if len(newRepoName) == 0 {
hasErrored = true
repoInitLog = emptyNameError.Error()
} else {
if len(mirror) == 0 {
h.log("initializing repository %s", name)
hasErrored, repoInitLog = h.gitStore.InitRepo(name, head)
h.log("initializing repository %s", newRepoName)
hasErrored, repoInitLog = h.gitStore.InitRepo(newRepoName, head)
} else {
h.log("cloning repository %s into %s", mirror, name)
hasErrored, repoInitLog = h.gitStore.MirrorRepo(name, mirror)
h.log("cloning repository %s into %s", mirror, newRepoName)
hasErrored, repoInitLog = h.gitStore.MirrorRepo(newRepoName, mirror)
if !hasErrored {
err := h.gitStore.GetRepo(name).UpdateMetadata(
err := h.gitStore.GetRepo(newRepoName).UpdateMetadata(
fmt.Sprintf("Mirror of %s", mirror),
"Repository mirrors",
head,
@ -111,10 +113,12 @@ func (h *Handlers) HandleHomepage(w http.ResponseWriter, req *http.Request) {
Repos map[string]RepoList
HasRepoInitFailed bool
RepoInitLog string
NewRepoName string
}{
Repos: byCategory,
HasRepoInitFailed: hasErrored,
RepoInitLog: repoInitLog,
NewRepoName: newRepoName,
})
}

Loading…
Cancel
Save