%v", hop.Errs))
+ return
+ }
+ http.Redirect(w, rq, "/page/"+hyphaName, http.StatusSeeOther)
}
func handlerRenameAsk(w http.ResponseWriter, rq *http.Request) {
diff --git a/http_readers.go b/http_readers.go
index 497a30f..939aef1 100644
--- a/http_readers.go
+++ b/http_readers.go
@@ -80,6 +80,7 @@ func handlerPage(w http.ResponseWriter, rq *http.Request) {
var (
hyphaName = HyphaNameFromRq(rq, "page")
data, hyphaExists = HyphaStorage[hyphaName]
+ hasAmnt = hyphaExists && data.binaryPath != ""
contents string
openGraph string
)
@@ -102,6 +103,7 @@ func handlerPage(w http.ResponseWriter, rq *http.Request) {
templates.PageHTML(rq, hyphaName,
naviTitle(hyphaName),
contents,
- treeHTML, prevHypha, nextHypha),
+ treeHTML, prevHypha, nextHypha,
+ hasAmnt),
openGraph))
}
diff --git a/hypha.go b/hypha.go
index c9f2612..64015e8 100644
--- a/hypha.go
+++ b/hypha.go
@@ -128,6 +128,29 @@ func (hd *HyphaData) DeleteHypha(hyphaName string, u *user.User) *history.Histor
return hop
}
+// UnattachHypha unattaches hypha and makes a history record about that.
+func (hd *HyphaData) UnattachHypha(hyphaName string, u *user.User) *history.HistoryOp {
+ hop := history.Operation(history.TypeUnattachHypha).
+ WithFilesRemoved(hd.binaryPath).
+ WithMsg(fmt.Sprintf("Unattach ā%sā", hyphaName)).
+ WithUser(u).
+ Apply()
+ if len(hop.Errs) == 0 {
+ hd, ok := HyphaStorage[hyphaName]
+ if ok {
+ if hd.binaryPath != "" {
+ hd.binaryPath = ""
+ }
+ // If nothing is left of the hypha
+ if hd.textPath == "" {
+ delete(HyphaStorage, hyphaName)
+ hyphae.DecrementCount()
+ }
+ }
+ }
+ return hop
+}
+
func findHyphaeToRename(hyphaName string, recursive bool) []string {
hyphae := []string{hyphaName}
if recursive {
diff --git a/main.go b/main.go
index ae1aa0f..6a4c26a 100644
--- a/main.go
+++ b/main.go
@@ -154,7 +154,7 @@ func main() {
history.Start(WikiDir)
// See http_readers.go for /page/, /text/, /binary/
- // See http_mutators.go for /upload-binary/, /upload-text/, /edit/, /delete-ask/, /delete-confirm/, /rename-ask/, /rename-confirm/
+ // See http_mutators.go for /upload-binary/, /upload-text/, /edit/, /delete-ask/, /delete-confirm/, /rename-ask/, /rename-confirm/, /unattach-ask/, /unattach-confirm/
// See http_auth.go for /login, /login-data, /logout, /logout-confirm
// See http_history.go for /history/, /recent-changes
http.HandleFunc("/list", handlerList)
diff --git a/templates/asset.qtpl.go b/templates/asset.qtpl.go
index abab4b6..36a8da9 100644
--- a/templates/asset.qtpl.go
+++ b/templates/asset.qtpl.go
@@ -72,6 +72,7 @@ article pre.codeblock { padding:.5rem; white-space: pre-wrap; border-radius: .25
.navi-title__separator { margin: 0 .25rem; }
.navi-title__colon { margin-right: .5rem; }
.upload-amnt { clear: both; padding: .5rem; border-radius: .25rem; }
+.upload-amnt__unattach { display: block; }
aside { clear: both; }
.img-gallery { text-align: center; margin-top: .25rem; margin-bottom: .25rem; }
diff --git a/templates/default.css b/templates/default.css
index ef42a50..192e2fe 100644
--- a/templates/default.css
+++ b/templates/default.css
@@ -47,6 +47,7 @@ article pre.codeblock { padding:.5rem; white-space: pre-wrap; border-radius: .25
.navi-title__separator { margin: 0 .25rem; }
.navi-title__colon { margin-right: .5rem; }
.upload-amnt { clear: both; padding: .5rem; border-radius: .25rem; }
+.upload-amnt__unattach { display: block; }
aside { clear: both; }
.img-gallery { text-align: center; margin-top: .25rem; margin-bottom: .25rem; }
diff --git a/templates/http_readers.qtpl b/templates/http_readers.qtpl
index cb63f5e..445df90 100644
--- a/templates/http_readers.qtpl
+++ b/templates/http_readers.qtpl
@@ -28,7 +28,7 @@
{% endfunc %}
If `contents` == "", a helpful message is shown instead.
-{% func PageHTML(rq *http.Request, hyphaName, naviTitle, contents, tree, prevHyphaName, nextHyphaName string) %}
+{% func PageHTML(rq *http.Request, hyphaName, naviTitle, contents, tree, prevHyphaName, nextHyphaName string, hasAmnt bool) %}
Do you really want to unattach hypha {%s hyphaName %}?
+ + +This hypha does not exist.
+ +Do you really want to unattach hypha `) +//line templates/unattach.qtpl:8 + qw422016.E().S(hyphaName) +//line templates/unattach.qtpl:8 + qw422016.N().S(`?
+ + +This hypha does not exist.
+ +