From 3cd7f84e1b58195d67f9797e98b7314cb9b7ea46 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 11 Feb 2016 09:26:02 -0500 Subject: [PATCH] Added total time to pages Issue #22 Former-commit-id: cafa73d9ad79299f3bb0049679d400479d655503 [formerly a49c91b6ed2187d40bba323e98b3f40373ecb855] [formerly 30ed4b6aedb03cff094e9a6ccd90f4e55ca8bff5 [formerly 71165300922812d6eb98203774d9bddcf119978e [formerly e6e5d701e60761dee87ef2f845e5e0561beba447]]] Former-commit-id: 9d4d1b049f4c253868704a377d7e813f0bff4adb [formerly 13817559a3e0c4e156cd85916d77d993ba61eda6] Former-commit-id: 15d127b0267745ebcbcc4fd2a15abdba78d8efb9 Former-commit-id: 45977e42ffc70eb2c2110a7fa8c3015320210d7d --- db.go | 10 ++++++---- install/awwkoala.init | 0 install/awwkoala.nginx | 0 routes.go | 33 +++++++++++++++++++-------------- static/img/awwkoala.png | Bin static/img/gomascot.png | Bin static/img/nginx.png | Bin static/img/raspberrypi.png | Bin templates/index.tmpl | 2 +- templates/view.tmpl | 2 +- utils.go | 9 ++++----- 11 files changed, 31 insertions(+), 25 deletions(-) mode change 100644 => 100755 install/awwkoala.init mode change 100644 => 100755 install/awwkoala.nginx mode change 100644 => 100755 static/img/awwkoala.png mode change 100644 => 100755 static/img/gomascot.png mode change 100644 => 100755 static/img/nginx.png mode change 100644 => 100755 static/img/raspberrypi.png diff --git a/db.go b/db.go index 604303e..af5cab1 100644 --- a/db.go +++ b/db.go @@ -77,13 +77,14 @@ func hasPassword(title string) (bool, error) { return hasPassword, nil } -func getCurrentText(title string, version int) (string, []versionsInfo, bool) { +func getCurrentText(title string, version int) (string, []versionsInfo, bool, time.Duration) { title = strings.ToLower(title) var vi []versionsInfo + totalTime := time.Now().Sub(time.Now()) isCurrent := true currentText := "" if !open { - return currentText, vi, isCurrent + return currentText, vi, isCurrent, totalTime } err := db.View(func(tx *bolt.Tx) error { var err error @@ -107,13 +108,14 @@ func getCurrentText(title string, version int) (string, []versionsInfo, bool) { currentText = rebuildTextsToDiffN(p, version) isCurrent = false } - vi = getImportantVersions(p) + vi, totalTime = getImportantVersions(p) + log.Println(totalTime) return nil }) if err != nil { fmt.Printf("Could not get WikiData: %s", err) } - return currentText, vi, isCurrent + return currentText, vi, isCurrent, totalTime } func (p *WikiData) load(title string) error { diff --git a/install/awwkoala.init b/install/awwkoala.init old mode 100644 new mode 100755 diff --git a/install/awwkoala.nginx b/install/awwkoala.nginx old mode 100644 new mode 100755 diff --git a/routes.go b/routes.go index ffc4b2f..27f5db1 100644 --- a/routes.go +++ b/routes.go @@ -8,6 +8,7 @@ import ( "regexp" "strconv" "strings" + "time" "github.com/boltdb/bolt" "github.com/gin-gonic/gin" @@ -35,7 +36,7 @@ func editNote(c *gin.Context) { } else { version := c.DefaultQuery("version", "-1") versionNum, _ := strconv.Atoi(version) - currentText, versions, currentVersion := getCurrentText(title, versionNum) + currentText, versions, currentVersion, totalTime := getCurrentText(title, versionNum) numRows := len(strings.Split(currentText, "\n")) + 10 if currentVersion { c.HTML(http.StatusOK, "index.tmpl", gin.H{ @@ -45,6 +46,7 @@ func editNote(c *gin.Context) { "CurrentText": currentText, "NumRows": numRows, "Versions": versions, + "TotalTime": totalTime, }) } else { c.HTML(http.StatusOK, "index.tmpl", gin.H{ @@ -54,6 +56,7 @@ func editNote(c *gin.Context) { "CurrentText": currentText, "NumRows": numRows, "Versions": versions, + "TotalTime": totalTime, "NoEdit": true, }) } @@ -71,10 +74,10 @@ func everythingElse(c *gin.Context) { if strings.ToLower(title) == "about" { versionNum = -1 } - currentText, versions, _ := getCurrentText(title, versionNum) - renderMarkdown(c, currentText, title, versions, "") + currentText, versions, _, totalTime := getCurrentText(title, versionNum) + renderMarkdown(c, currentText, title, versions, "", totalTime) } else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 { - renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey) + renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now())) } else if option == "/list" { renderList(c, title) } else if title == "static" { @@ -93,7 +96,7 @@ func serveStaticFile(c *gin.Context, option string) { } } -func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string) { +func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string, totalTime time.Duration) { r, _ := regexp.Compile("\\[\\[(.*?)\\]\\]") for _, s := range r.FindAllString(currentText, -1) { currentText = strings.Replace(currentText, s, "["+s[2:len(s)-2]+"](/"+s[2:len(s)-2]+"/view)", 1) @@ -125,18 +128,20 @@ func renderMarkdown(c *gin.Context, currentText string, title string, versions [ if AdminKey == "" { c.HTML(http.StatusOK, "view.tmpl", gin.H{ - "Title": title, - "WikiName": RuntimeArgs.WikiName, - "Body": template.HTML([]byte(html2)), - "Versions": versions, + "Title": title, + "WikiName": RuntimeArgs.WikiName, + "Body": template.HTML([]byte(html2)), + "TotalTime": totalTime.String(), + "Versions": versions, }) } else { c.HTML(http.StatusOK, "view.tmpl", gin.H{ - "Title": title, - "WikiName": RuntimeArgs.WikiName, - "Body": template.HTML([]byte(html2)), - "Versions": versions, - "AdminKey": AdminKey, + "Title": title, + "WikiName": RuntimeArgs.WikiName, + "Body": template.HTML([]byte(html2)), + "Versions": versions, + "TotalTime": totalTime.String(), + "AdminKey": AdminKey, }) } } diff --git a/static/img/awwkoala.png b/static/img/awwkoala.png old mode 100644 new mode 100755 diff --git a/static/img/gomascot.png b/static/img/gomascot.png old mode 100644 new mode 100755 diff --git a/static/img/nginx.png b/static/img/nginx.png old mode 100644 new mode 100755 diff --git a/static/img/raspberrypi.png b/static/img/raspberrypi.png old mode 100644 new mode 100755 diff --git a/templates/index.tmpl b/templates/index.tmpl index eb1f25e..da90a31 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -62,7 +62,7 @@