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:
parent
ea241506f5
commit
6987950b78
3
main.go
3
main.go
@ -11,6 +11,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/gin-gonic/contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
@ -125,6 +126,8 @@ Options:`)
|
||||
|
||||
r := gin.Default()
|
||||
r.LoadHTMLGlob(path.Join(RuntimeArgs.SourcePath, "templates/*"))
|
||||
store := sessions.NewCookieStore([]byte("secret"))
|
||||
r.Use(sessions.Sessions("mysession", store))
|
||||
r.GET("/", newNote)
|
||||
r.HEAD("/", func(c *gin.Context) { c.Status(200) })
|
||||
r.GET("/:title", editNote)
|
||||
|
35
routes.go
35
routes.go
@ -16,6 +16,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/gin-gonic/contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/russross/blackfriday"
|
||||
@ -225,6 +226,29 @@ func getCodeType(title string) string {
|
||||
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) {
|
||||
title := c.Param("title")
|
||||
if title == "ws" {
|
||||
@ -261,6 +285,7 @@ func editNote(c *gin.Context) {
|
||||
splitStrings := strings.Split(title, ".")
|
||||
suffix := splitStrings[len(splitStrings)-1]
|
||||
CodeType := getCodeType(title)
|
||||
|
||||
c.HTML(http.StatusOK, "index.tmpl", gin.H{
|
||||
"Title": title,
|
||||
"WikiName": RuntimeArgs.WikiName,
|
||||
@ -275,6 +300,7 @@ func editNote(c *gin.Context) {
|
||||
"Coding": len(CodeType) > 0,
|
||||
"CodeType": CodeType,
|
||||
"Suffix": suffix,
|
||||
"RecentlyEdited": getRecentlyEdited(title, c),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -296,7 +322,8 @@ func everythingElse(c *gin.Context) {
|
||||
p := WikiData{strings.ToLower(title), "", []string{}, []string{}, false, ""}
|
||||
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" {
|
||||
version := c.DefaultQuery("version", "-1")
|
||||
versionNum, _ := strconv.Atoi(version)
|
||||
@ -312,7 +339,7 @@ func everythingElse(c *gin.Context) {
|
||||
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
c.Data(200, contentType(title), []byte(currentText))
|
||||
} 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" {
|
||||
renderList(c, title)
|
||||
} 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
|
||||
CodeType := getCodeType(title)
|
||||
if CodeType == "markdown" {
|
||||
@ -386,6 +413,7 @@ func renderMarkdown(c *gin.Context, currentText string, title string, versions [
|
||||
"LockedOrEncrypted": locked || encrypted,
|
||||
"Coding": len(CodeType) > 0,
|
||||
"CodeType": CodeType,
|
||||
"RecentlyEdited": recentlyEdited,
|
||||
})
|
||||
|
||||
}
|
||||
@ -472,6 +500,7 @@ func renderList(c *gin.Context, title string) {
|
||||
"Title": title,
|
||||
"WikiName": RuntimeArgs.WikiName,
|
||||
"ListItems": listItems,
|
||||
"RecentlyEdited": getRecentlyEdited(title, c),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> -->
|
||||
<style>
|
||||
|
||||
.navbar-header-menu {
|
||||
float: left;
|
||||
.dropdown-menu>li
|
||||
{ position:relative;
|
||||
-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;
|
||||
}
|
||||
|
||||
.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 {
|
||||
.dropdown-menu .sub-menu {
|
||||
left: 100%;
|
||||
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;
|
||||
top: 0;
|
||||
display:none;
|
||||
margin-top: -1px;
|
||||
border-top-left-radius:0;
|
||||
border-bottom-left-radius:0;
|
||||
border-left-color:#fff;
|
||||
box-shadow:none;
|
||||
}
|
||||
|
||||
.navbar-header-menu > .navbar-form > .form-group {
|
||||
.right-caret:after,.left-caret:after
|
||||
{ content:"";
|
||||
border-bottom: 5px solid transparent;
|
||||
border-top: 5px solid transparent;
|
||||
display: inline-block;
|
||||
margin-bottom: 0;
|
||||
height: 0;
|
||||
vertical-align: middle;
|
||||
width: 0;
|
||||
margin-left:5px;
|
||||
}
|
||||
|
||||
.navbar-header-menu > .navbar-left {
|
||||
float: left;
|
||||
.right-caret:after
|
||||
{ border-left: 5px solid #000000;
|
||||
}
|
||||
|
||||
.navbar-header-menu > .navbar-right {
|
||||
float: right !important;
|
||||
}
|
||||
|
||||
.navbar-header-menu > *.navbar-right:last-child {
|
||||
margin-right: -15px !important;
|
||||
.left-caret:after
|
||||
{ border-right: 5px solid #000000;
|
||||
}
|
||||
</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}}
|
||||
|
@ -126,8 +126,16 @@
|
||||
<li><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li>
|
||||
|
||||
<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 <span class="caret"></span></a>
|
||||
<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="/PrivacyPolicy/view"> Privacy Policy</a></li>
|
||||
</ul>
|
||||
|
@ -37,8 +37,16 @@ span { cursor: pointer; }
|
||||
<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="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 <span class="caret"></span></a>
|
||||
<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="/PrivacyPolicy/view"> Privacy Policy</a></li>
|
||||
</ul>
|
||||
|
@ -105,8 +105,16 @@ body {
|
||||
</li>
|
||||
<li><a href="/{{ .Title }}/list"><span class="glyphicon glyphicon-align-left" aria-hidden="true"></span> List</a></li>
|
||||
<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 <span class="caret"></span></a>
|
||||
<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="/PrivacyPolicy/view"> Privacy Policy</a></li>
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user