1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Added Recent to see recently edited/viewed things

This commit is contained in:
Zack Scholl 2016-04-10 09:50:18 -04:00
parent ea241506f5
commit 6987950b78
6 changed files with 123 additions and 69 deletions

View File

@ -11,6 +11,7 @@ import (
"path/filepath" "path/filepath"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -125,6 +126,8 @@ Options:`)
r := gin.Default() r := gin.Default()
r.LoadHTMLGlob(path.Join(RuntimeArgs.SourcePath, "templates/*")) r.LoadHTMLGlob(path.Join(RuntimeArgs.SourcePath, "templates/*"))
store := sessions.NewCookieStore([]byte("secret"))
r.Use(sessions.Sessions("mysession", store))
r.GET("/", newNote) r.GET("/", newNote)
r.HEAD("/", func(c *gin.Context) { c.Status(200) }) r.HEAD("/", func(c *gin.Context) { c.Status(200) })
r.GET("/:title", editNote) r.GET("/:title", editNote)

View File

@ -16,6 +16,7 @@ import (
"time" "time"
"github.com/boltdb/bolt" "github.com/boltdb/bolt"
"github.com/gin-gonic/contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/microcosm-cc/bluemonday" "github.com/microcosm-cc/bluemonday"
"github.com/russross/blackfriday" "github.com/russross/blackfriday"
@ -225,6 +226,29 @@ func getCodeType(title string) string {
return "" return ""
} }
func getRecentlyEdited(title string, c *gin.Context) []string {
session := sessions.Default(c)
var recentlyEdited string
v := session.Get("recentlyEdited")
editedThings := []string{}
if v == nil {
recentlyEdited = title
} else {
editedThings = strings.Split(v.(string), "|||")
fmt.Println(editedThings)
fmt.Println(v.(string))
fmt.Println(title)
if !stringInSlice(title, editedThings) {
recentlyEdited = v.(string) + "|||" + title
} else {
recentlyEdited = v.(string)
}
}
session.Set("recentlyEdited", recentlyEdited)
session.Save()
return editedThings
}
func editNote(c *gin.Context) { func editNote(c *gin.Context) {
title := c.Param("title") title := c.Param("title")
if title == "ws" { if title == "ws" {
@ -261,6 +285,7 @@ func editNote(c *gin.Context) {
splitStrings := strings.Split(title, ".") splitStrings := strings.Split(title, ".")
suffix := splitStrings[len(splitStrings)-1] suffix := splitStrings[len(splitStrings)-1]
CodeType := getCodeType(title) CodeType := getCodeType(title)
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Title": title, "Title": title,
"WikiName": RuntimeArgs.WikiName, "WikiName": RuntimeArgs.WikiName,
@ -275,6 +300,7 @@ func editNote(c *gin.Context) {
"Coding": len(CodeType) > 0, "Coding": len(CodeType) > 0,
"CodeType": CodeType, "CodeType": CodeType,
"Suffix": suffix, "Suffix": suffix,
"RecentlyEdited": getRecentlyEdited(title, c),
}) })
} }
} }
@ -296,7 +322,8 @@ func everythingElse(c *gin.Context) {
p := WikiData{strings.ToLower(title), "", []string{}, []string{}, false, ""} p := WikiData{strings.ToLower(title), "", []string{}, []string{}, false, ""}
p.save("") p.save("")
} }
renderMarkdown(c, currentText, title, versions, "", totalTime, encrypted, noprompt == "-1", len(locked) > 0)
renderMarkdown(c, currentText, title, versions, "", totalTime, encrypted, noprompt == "-1", len(locked) > 0, getRecentlyEdited(title, c))
} else if option == "/raw" { } else if option == "/raw" {
version := c.DefaultQuery("version", "-1") version := c.DefaultQuery("version", "-1")
versionNum, _ := strconv.Atoi(version) versionNum, _ := strconv.Atoi(version)
@ -312,7 +339,7 @@ func everythingElse(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true") c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Data(200, contentType(title), []byte(currentText)) c.Data(200, contentType(title), []byte(currentText))
} else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 { } else if title == "ls" && option == "/"+RuntimeArgs.AdminKey && len(RuntimeArgs.AdminKey) > 1 {
renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now()), false, false, false) renderMarkdown(c, listEverything(), "ls", nil, RuntimeArgs.AdminKey, time.Now().Sub(time.Now()), false, false, false, []string{})
} else if option == "/list" { } else if option == "/list" {
renderList(c, title) renderList(c, title)
} else if title == "static" { } else if title == "static" {
@ -331,7 +358,7 @@ func serveStaticFile(c *gin.Context, option string) {
} }
} }
func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string, totalTime time.Duration, encrypted bool, noprompt bool, locked bool) { func renderMarkdown(c *gin.Context, currentText string, title string, versions []versionsInfo, AdminKey string, totalTime time.Duration, encrypted bool, noprompt bool, locked bool, recentlyEdited []string) {
originalText := currentText originalText := currentText
CodeType := getCodeType(title) CodeType := getCodeType(title)
if CodeType == "markdown" { if CodeType == "markdown" {
@ -386,6 +413,7 @@ func renderMarkdown(c *gin.Context, currentText string, title string, versions [
"LockedOrEncrypted": locked || encrypted, "LockedOrEncrypted": locked || encrypted,
"Coding": len(CodeType) > 0, "Coding": len(CodeType) > 0,
"CodeType": CodeType, "CodeType": CodeType,
"RecentlyEdited": recentlyEdited,
}) })
} }
@ -469,9 +497,10 @@ func renderList(c *gin.Context, title string) {
listItems[i] = template.HTML([]byte(newHTML)) listItems[i] = template.HTML([]byte(newHTML))
} }
c.HTML(http.StatusOK, "list.tmpl", gin.H{ c.HTML(http.StatusOK, "list.tmpl", gin.H{
"Title": title, "Title": title,
"WikiName": RuntimeArgs.WikiName, "WikiName": RuntimeArgs.WikiName,
"ListItems": listItems, "ListItems": listItems,
"RecentlyEdited": getRecentlyEdited(title, c),
}) })
} }

View File

@ -26,66 +26,64 @@
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A==" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A==" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> -->
<style> <style>
.dropdown-menu>li
.navbar-header-menu { { position:relative;
float: left; -webkit-user-select: none; /* Chrome/Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+ */
/* Rules below not implemented in browsers yet */
-o-user-select: none;
user-select: none;
cursor:pointer;
}
.dropdown-menu .sub-menu {
left: 100%;
position: absolute;
top: 0;
display:none;
margin-top: -1px;
border-top-left-radius:0;
border-bottom-left-radius:0;
border-left-color:#fff;
box-shadow:none;
}
.right-caret:after,.left-caret:after
{ content:"";
border-bottom: 5px solid transparent;
border-top: 5px solid transparent;
display: inline-block;
height: 0;
vertical-align: middle;
width: 0;
margin-left:5px;
}
.right-caret:after
{ border-left: 5px solid #000000;
}
.left-caret:after
{ border-right: 5px solid #000000;
} }
.navbar-header-menu > .navbar-nav {
float: left;
margin: 0;
}
.navbar-header-menu > .navbar-nav > li {
float: left;
}
.navbar-header-menu > .navbar-nav > li > a {
padding-top: 15px;
padding-bottom: 15px;
}
.navbar-header-menu > .navbar-nav .open .dropdown-menu {
position: absolute;
float: left;
width: auto;
margin-top: 0;
background-color: #fff;
border: 1px solid #ccc;
border: 1px solid rgba(0,0,0,.15);
-webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
box-shadow: 0 6px 12px rgba(0,0,0,.175);
}
.navbar-header-menu > .navbar-form {
float: left;
width: auto;
padding-top: 0;
padding-bottom: 0;
margin-right: 0;
margin-left: 0;
border: 0;
-webkit-box-shadow: none;
box-shadow: none;
}
.navbar-header-menu > .navbar-form > .form-group {
display: inline-block;
margin-bottom: 0;
vertical-align: middle;
}
.navbar-header-menu > .navbar-left {
float: left;
}
.navbar-header-menu > .navbar-right {
float: right !important;
}
.navbar-header-menu > *.navbar-right:last-child {
margin-right: -15px !important;
}
</style> </style>
<script>
$(function(){
$(".dropdown-menu > li > a.trigger").on("click",function(e){
var current=$(this).next();
var grandparent=$(this).parent().parent();
if($(this).hasClass('left-caret')||$(this).hasClass('right-caret'))
$(this).toggleClass('right-caret left-caret');
grandparent.find('.left-caret').not(this).toggleClass('right-caret left-caret');
grandparent.find(".sub-menu:visible").not(current).hide();
current.toggle();
e.stopPropagation();
});
$(".dropdown-menu > li > a:not(.trigger)").on("click",function(){
var root=$(this).closest('.dropdown');
root.find('.left-caret').toggleClass('right-caret left-caret');
root.find('.sub-menu:visible').hide();
});
});
</script>
{{end}} {{end}}

View File

@ -126,8 +126,16 @@
<li><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li> <li><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> Help <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span> More &nbsp; <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li>
<a class="trigger right-caret">Recent</a>
<ul class="dropdown-menu sub-menu">
{{ range .RecentlyEdited}}
<li><a href="/{{.}}/view"> {{.}}</a></li>
{{ end }}
</ul>
</li>
<li><a href="/Help/view"> Help</a></li> <li><a href="/Help/view"> Help</a></li>
<li><a href="/PrivacyPolicy/view"> Privacy Policy</a></li> <li><a href="/PrivacyPolicy/view"> Privacy Policy</a></li>
</ul> </ul>

View File

@ -37,12 +37,20 @@ span { cursor: pointer; }
<li><a href="/{{ .Title }}/view"><span class="glyphicon glyphicon-sunglasses" aria-hidden="true"></span> View</a></li> <li><a href="/{{ .Title }}/view"><span class="glyphicon glyphicon-sunglasses" aria-hidden="true"></span> View</a></li>
<li class="active"><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li> <li class="active"><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> Help <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span> More &nbsp; <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li>
<a class="trigger right-caret">Recent</a>
<ul class="dropdown-menu sub-menu">
{{ range .RecentlyEdited}}
<li><a href="/{{.}}/view"> {{.}}</a></li>
{{ end }}
</ul>
</li>
<li><a href="/Help/view"> Help</a></li> <li><a href="/Help/view"> Help</a></li>
<li><a href="/PrivacyPolicy/view"> Privacy Policy</a></li> <li><a href="/PrivacyPolicy/view"> Privacy Policy</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
</div> </div>
<!--/.nav-collapse --> <!--/.nav-collapse -->

View File

@ -105,8 +105,16 @@ body {
</li> </li>
<li><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li> <li><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span> Help <span class="caret"></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" class="active"><span class="glyphicon glyphicon-globe" aria-hidden="true"></span> More &nbsp; <span class="caret"></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li>
<a class="trigger right-caret">Recent</a>
<ul class="dropdown-menu sub-menu">
{{ range .RecentlyEdited}}
<li><a href="/{{.}}/view"> {{.}}</a></li>
{{ end }}
</ul>
</li>
<li><a href="/Help/view"> Help</a></li> <li><a href="/Help/view"> Help</a></li>
<li><a href="/PrivacyPolicy/view"> Privacy Policy</a></li> <li><a href="/PrivacyPolicy/view"> Privacy Policy</a></li>
</ul> </ul>