Skip to content

Commit

Permalink
feat: show username in navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Apr 14, 2023
1 parent d7f7580 commit 1bac13f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 49 deletions.
117 changes: 68 additions & 49 deletions common/public/nav.html
Original file line number Diff line number Diff line change
@@ -1,58 +1,77 @@
{{define "nav"}}
<nav class="navbar nav-shadow" role="navigation" aria-label="main navigation" id="nav">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item is-size-5" href="/" style="font-weight: bold">
{{.option.WebsiteName}}
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false"
data-target="mainNavbar">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
<nav class="navbar nav-shadow" role="navigation" aria-label="main navigation" id="nav">
<div class="container">
<div class="navbar-brand">
<a class="navbar-item is-size-5" href="/" style="font-weight: bold">
{{.option.WebsiteName}}
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false"
data-target="mainNavbar">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="mainNavbar" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="/"> 首页 </a>
<a class="navbar-item" href="/explorer"> 文件 </a>
<a class="navbar-item" href="/image"> 图床 </a>
<a class="navbar-item" href="/video"> 视频 </a>
<a class="navbar-item" href="/help"> 帮助 </a>
</div>
<div id="mainNavbar" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="/"> 首页 </a>
<a class="navbar-item" href="/explorer"> 文件 </a>
<a class="navbar-item" href="/image"> 图床 </a>
<a class="navbar-item" href="/video"> 视频 </a>
<a class="navbar-item" href="/manage"> 管理 </a>
<a class="navbar-item" href="/help"> 帮助 </a>
</div>
<div class="navbar-end">
<div class="navbar-item">
<p class="control is-expanded is-light">
<input class="input" type="search" id="searchInput" autocomplete="nope"
autofocus="" style="cursor: text;" placeholder="搜索文件..."/>
</p>
<script>
const input = document.getElementById("searchInput");
input.addEventListener("keyup", function (event) {
if (event.key === 'Enter') {
let value = input.value.trim();
value = encodeURIComponent(value);
if (value === "") {
location.href = "/";
}else {
location.href = "/?query="+value;
}
<div class="navbar-end">
<div class="navbar-item" >
<p class="control is-expanded is-light flex-grow">
<input class="input flex-grow" type="search" id="searchInput" autocomplete="nope"
autofocus="" style="cursor: text;" placeholder="搜索文件..."/>
</p>
<script>
const input = document.getElementById("searchInput");
input.addEventListener("keyup", function (event) {
if (event.key === 'Enter') {
let value = input.value.trim();
value = encodeURIComponent(value);
if (value === "") {
location.href = "/";
} else {
location.href = "/?query=" + value;
}
});
</script>
}
});
</script>
</div>
<div class="navbar-item">
<div class="buttons">
<a class="button is-light" onclick="showUploadModal()">上传</a>
{{if not $.username}}
<a class="button is-light" href="/login">登录</a>
{{end}}
</div>
<div class="navbar-item">
<div class="buttons">
<a class="button is-light" onclick="showUploadModal()">上传</a>
<!-- <a class="button is-light" href="/logout">注销</a>-->
</div>
</div>
{{if $.username}}
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
{{$.username}}
</a>
<div class="navbar-dropdown">
<a class="navbar-item" href="/manage">
系统管理
</a>
<a class="navbar-item" href="https://github.com/songquanpeng/go-file#readme" target="_blank">
项目地址
</a>
<hr class="navbar-divider">
<a class="navbar-item" href="/logout">
退出登录
</a>
</div>
</div>
{{end}}
</div>
</div>
</nav>
</div>
</nav>
{{end}}
1 change: 1 addition & 0 deletions controller/page-explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func GetExplorerPageOrFile(c *gin.Context) {
c.HTML(http.StatusOK, "explorer.html", gin.H{
"message": "",
"option": common.OptionMap,
"username": c.GetString("username"),
"files": localFilesPtr,
"readmeFileLink": readmeFileLink,
})
Expand Down
1 change: 1 addition & 0 deletions controller/page-video.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func GetVideoPage(c *gin.Context) {
c.HTML(http.StatusOK, "video.html", gin.H{
"message": "",
"option": common.OptionMap,
"username": c.GetString("username"),
"files": localFiles,
"videoPath": videoPath,
})
Expand Down
1 change: 1 addition & 0 deletions controller/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func GetManagePage(c *gin.Context) {
c.HTML(http.StatusOK, "manage.html", gin.H{
"message": "",
"option": common.OptionMap,
"username": c.GetString("username"),
"memory": fmt.Sprintf("%d MB", m.Sys/1024/1024),
"uptime": common.Seconds2Time(int(uptime.Seconds())),
"userNum": model.CountTable("users"),
Expand Down

0 comments on commit 1bac13f

Please sign in to comment.