mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-01 05:36:19 +01:00
Add HomeLink and AvatarLink to User model. Please use .SignedUser in template.
This commit is contained in:
parent
e251b9bbca
commit
06deed820d
9 changed files with 147 additions and 24 deletions
|
@ -56,6 +56,14 @@ type User struct {
|
||||||
Updated time.Time `xorm:"updated"`
|
Updated time.Time `xorm:"updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) HomeLink() string {
|
||||||
|
return "/user/" + user.LowerName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (user *User) AvatarLink() string {
|
||||||
|
return "http://1.gravatar.com/avatar/" + user.Avatar
|
||||||
|
}
|
||||||
|
|
||||||
// A Follow represents
|
// A Follow represents
|
||||||
type Follow struct {
|
type Follow struct {
|
||||||
Id int64
|
Id int64
|
||||||
|
|
|
@ -74,10 +74,16 @@ func SignInRequire(redirect bool) martini.Handler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user := SignedInUser(session)
|
||||||
|
if user == nil {
|
||||||
|
r.Redirect("/")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
data["IsSigned"] = true
|
data["IsSigned"] = true
|
||||||
data["SignedUserId"] = SignedInId(session)
|
data["SignedUser"] = user
|
||||||
data["SignedUserName"] = SignedInName(session)
|
data["SignedUserId"] = user.Id
|
||||||
data["SignedAvatar"] = SignedInUser(session).Avatar
|
data["SignedUserName"] = user.LowerName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -134,6 +135,61 @@ func Subtract(left interface{}, right interface{}) interface{} {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DateFormat pattern rules.
|
||||||
|
var datePatterns = []string{
|
||||||
|
// year
|
||||||
|
"Y", "2006", // A full numeric representation of a year, 4 digits Examples: 1999 or 2003
|
||||||
|
"y", "06", //A two digit representation of a year Examples: 99 or 03
|
||||||
|
|
||||||
|
// month
|
||||||
|
"m", "01", // Numeric representation of a month, with leading zeros 01 through 12
|
||||||
|
"n", "1", // Numeric representation of a month, without leading zeros 1 through 12
|
||||||
|
"M", "Jan", // A short textual representation of a month, three letters Jan through Dec
|
||||||
|
"F", "January", // A full textual representation of a month, such as January or March January through December
|
||||||
|
|
||||||
|
// day
|
||||||
|
"d", "02", // Day of the month, 2 digits with leading zeros 01 to 31
|
||||||
|
"j", "2", // Day of the month without leading zeros 1 to 31
|
||||||
|
|
||||||
|
// week
|
||||||
|
"D", "Mon", // A textual representation of a day, three letters Mon through Sun
|
||||||
|
"l", "Monday", // A full textual representation of the day of the week Sunday through Saturday
|
||||||
|
|
||||||
|
// time
|
||||||
|
"g", "3", // 12-hour format of an hour without leading zeros 1 through 12
|
||||||
|
"G", "15", // 24-hour format of an hour without leading zeros 0 through 23
|
||||||
|
"h", "03", // 12-hour format of an hour with leading zeros 01 through 12
|
||||||
|
"H", "15", // 24-hour format of an hour with leading zeros 00 through 23
|
||||||
|
|
||||||
|
"a", "pm", // Lowercase Ante meridiem and Post meridiem am or pm
|
||||||
|
"A", "PM", // Uppercase Ante meridiem and Post meridiem AM or PM
|
||||||
|
|
||||||
|
"i", "04", // Minutes with leading zeros 00 to 59
|
||||||
|
"s", "05", // Seconds, with leading zeros 00 through 59
|
||||||
|
|
||||||
|
// time zone
|
||||||
|
"T", "MST",
|
||||||
|
"P", "-07:00",
|
||||||
|
"O", "-0700",
|
||||||
|
|
||||||
|
// RFC 2822
|
||||||
|
"r", time.RFC1123Z,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse Date use PHP time format.
|
||||||
|
func DateParse(dateString, format string) (time.Time, error) {
|
||||||
|
replacer := strings.NewReplacer(datePatterns...)
|
||||||
|
format = replacer.Replace(format)
|
||||||
|
return time.ParseInLocation(format, dateString, time.Local)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Date takes a PHP like date func to Go's time format.
|
||||||
|
func DateFormat(t time.Time, format string) string {
|
||||||
|
replacer := strings.NewReplacer(datePatterns...)
|
||||||
|
format = replacer.Replace(format)
|
||||||
|
return t.Format(format)
|
||||||
|
}
|
||||||
|
|
||||||
type Actioner interface {
|
type Actioner interface {
|
||||||
GetOpType() int
|
GetOpType() int
|
||||||
GetActUserName() string
|
GetActUserName() string
|
||||||
|
|
|
@ -520,4 +520,34 @@ body {
|
||||||
|
|
||||||
#gogs-source-table.table-hover > tbody > tr:hover > td {
|
#gogs-source-table.table-hover > tbody > tr:hover > td {
|
||||||
background-color: #FEFEFE;
|
background-color: #FEFEFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.activity-list {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activity-list .icon {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #aaa;
|
||||||
|
float: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activity-list .info {
|
||||||
|
float: left;
|
||||||
|
padding:0 0 0 10px;
|
||||||
|
line-height: 1.7em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activity-list .meta {
|
||||||
|
color: #aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activity-list li {
|
||||||
|
padding: 15px 0;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.activity-list li:first-child {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
|
||||||
r.HTML(200, "user/dashboard", data)
|
r.HTML(200, "user/dashboard", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Profile(params martini.Params, r render.Render, data base.TmplData, session sessions.Session) {
|
func Profile(params martini.Params, r render.Render, req *http.Request, data base.TmplData, session sessions.Session) {
|
||||||
data["Title"] = "Profile"
|
data["Title"] = "Profile"
|
||||||
|
|
||||||
// TODO: Need to check view self or others.
|
// TODO: Need to check view self or others.
|
||||||
|
@ -40,12 +40,23 @@ func Profile(params martini.Params, r render.Render, data base.TmplData, session
|
||||||
}
|
}
|
||||||
|
|
||||||
data["Owner"] = user
|
data["Owner"] = user
|
||||||
feeds, err := models.GetFeeds(user.Id, 0, true)
|
|
||||||
if err != nil {
|
req.ParseForm()
|
||||||
log.Handle(200, "user.Profile", data, r, err)
|
tab := req.Form.Get("tab")
|
||||||
return
|
data["TabName"] = tab
|
||||||
|
|
||||||
|
switch tab {
|
||||||
|
case "activity":
|
||||||
|
feeds, err := models.GetFeeds(user.Id, 0, true)
|
||||||
|
if err != nil {
|
||||||
|
log.Handle(200, "user.Profile", data, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data["Feeds"] = feeds
|
||||||
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
data["Feeds"] = feeds
|
|
||||||
r.HTML(200, "user/profile", data)
|
r.HTML(200, "user/profile", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<a class="gogs-nav-item" href="#">Explore</a>
|
<a class="gogs-nav-item" href="#">Explore</a>
|
||||||
<a class="gogs-nav-item" href="#">Help</a>{{if .IsSigned}}
|
<a class="gogs-nav-item" href="#">Help</a>{{if .IsSigned}}
|
||||||
<a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/logout/"><i class="fa fa-power-off fa-lg"></i></a>
|
<a id="gogs-nav-out" class="gogs-nav-item navbar-right navbar-btn btn btn-danger" href="/user/logout/"><i class="fa fa-power-off fa-lg"></i></a>
|
||||||
<a id="gogs-nav-avatar" class="gogs-nav-item navbar-right" href="/user/{{.SignedUserName}}" data-toggle="tooltip" data-placement="bottom" title="{{.SignedUserName}}">
|
<a id="gogs-nav-avatar" class="gogs-nav-item navbar-right" href="{{.SignedUser.HomeLink}}" data-toggle="tooltip" data-placement="bottom" title="{{.SignedUserName}}">
|
||||||
<img src="http://1.gravatar.com/avatar/{{.SignedAvatar}}?s=28" alt="user-avatar" title="username"/>
|
<img src="{{.SignedUser.AvatarLink}}?s=28" alt="user-avatar" title="username"/>
|
||||||
</a>
|
</a>
|
||||||
<a class="navbar-right gogs-nav-item" href="/repo/create" data-toggle="tooltip" data-placement="bottom" title="New Repository"><i class="fa fa-plus fa-lg"></i></a>
|
<a class="navbar-right gogs-nav-item" href="/repo/create" data-toggle="tooltip" data-placement="bottom" title="New Repository"><i class="fa fa-plus fa-lg"></i></a>
|
||||||
<a class="navbar-right gogs-nav-item{{if .PageIsUserSetting}} active{{end}}" href="/user/setting" data-toggle="tooltip" data-placement="bottom" title="Setting"><i class="fa fa-cogs fa-lg"></i></a>
|
<a class="navbar-right gogs-nav-item{{if .PageIsUserSetting}} active{{end}}" href="/user/setting" data-toggle="tooltip" data-placement="bottom" title="Setting"><i class="fa fa-cogs fa-lg"></i></a>
|
||||||
|
|
|
@ -37,6 +37,6 @@
|
||||||
<button type="button" class="btn btn-default"><i class="fa fa-code-fork"></i>Fork {{.Repository.NumForks}}</button>
|
<button type="button" class="btn btn-default"><i class="fa fa-code-fork"></i>Fork {{.Repository.NumForks}}</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h3><i class="fa fa-book fa-lg"></i><a href="/user/{{.Owner.Name}}">{{.Owner.Name}}</a> / {{.Repository.Name}}</h3>
|
<h3><i class="fa fa-book fa-lg"></i><a href="{{.Owner.HomeLink}}">{{.Owner.Name}}</a> / {{.Repository.Name}}</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
|
@ -3,10 +3,10 @@
|
||||||
<div id="gogs-body" class="container">
|
<div id="gogs-body" class="container">
|
||||||
<div id="gogs-user-profile" class="col-md-3">
|
<div id="gogs-user-profile" class="col-md-3">
|
||||||
<div class="profile-avatar text-center">
|
<div class="profile-avatar text-center">
|
||||||
<a href="#" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar">
|
<a href="{{.Owner.HomeLink}}" class="center-block" data-toggle="tooltip" data-placement="bottom" title="Change Avatar">
|
||||||
<img id="gogs-user-avatar" src="http://1.gravatar.com/avatar/{{.Owner.Avatar}}?s=200" alt="user-avatar" title="username"/>
|
<img id="gogs-user-avatar" src="{{.Owner.AvatarLink}}?s=200" alt="user-avatar" title="username"/>
|
||||||
</a>
|
</a>
|
||||||
<span id="gogs-user-name" class="center-block" href="#">{{.Owner.Name}}</span>
|
<span id="gogs-user-name" class="center-block">{{.Owner.Name}}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="profile-info">
|
<div class="profile-info">
|
||||||
<ul class="list-group">
|
<ul class="list-group">
|
||||||
|
@ -19,22 +19,33 @@
|
||||||
{{if .Owner.Website}}
|
{{if .Owner.Website}}
|
||||||
<li class="list-group-item"><i class="fa fa-link"></i><a target="_blank" href="{{.Owner.Website}}">{{.Owner.Website}}</a></li>
|
<li class="list-group-item"><i class="fa fa-link"></i><a target="_blank" href="{{.Owner.Website}}">{{.Owner.Website}}</a></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
<li class="list-group-item"><i class="fa fa-clock-o"></i>{{.Owner.Created}}</li>
|
<li class="list-group-item"><i class="fa fa-clock-o"></i>Joined on {{DateFormat .Owner.Created "M d, Y"}}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="gogs-user-activity" class="col-md-9">
|
<div id="gogs-user-activity" class="col-md-9">
|
||||||
<ul class="nav nav-tabs" id="gogs-user-act-tabs" data-init="tabs">
|
<ul class="nav nav-tabs" id="gogs-user-act-tabs" data-init="tabs">
|
||||||
<li class="active"><a href="#repo" data-toggle="tab"><i class="fa fa-gittip"></i>Repositories</a></li>
|
<li{{if not .TabName}} class="active"{{end}}><a href="{{.Owner.HomeLink}}"><i class="fa fa-gittip"></i>Repositories</a></li>
|
||||||
<li><a href="#activity" data-toggle="tab"><i class="fa fa-rss"></i>Public Activity</a></li>
|
<li{{if eq .TabName "activity"}} class="active"{{end}}><a href="{{.Owner.HomeLink}}?tab=activity"><i class="fa fa-rss"></i>Public Activity</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane active" id="repo">repo</div>
|
{{if eq .TabName "activity"}}
|
||||||
<div class="tab-pane" id="activity">
|
<div class="tab-pane active">
|
||||||
{{range .Feeds}}<div>
|
<ul class="list-unstyled activity-list">
|
||||||
<i class="fa fa-{{ActionIcon .OpType}}"></i>{{ActionDesc . | str2html}} {{TimeSince .Created}}
|
{{range .Feeds}}
|
||||||
</div>{{end}}
|
<li>
|
||||||
|
<i class="icon fa fa-{{ActionIcon .OpType}}"></i>
|
||||||
|
<div class="info"><span class="meta">{{TimeSince .Created}}</span><br>{{ActionDesc . | str2html}}</div>
|
||||||
|
<span class="clearfix"></span>
|
||||||
|
</li>
|
||||||
|
{{else}}
|
||||||
|
<li>Not found any activity</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="tab-pane active">repo</div>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
1
web.go
1
web.go
|
@ -45,6 +45,7 @@ var AppHelpers template.FuncMap = map[string]interface{}{
|
||||||
"Subtract": base.Subtract,
|
"Subtract": base.Subtract,
|
||||||
"ActionIcon": base.ActionIcon,
|
"ActionIcon": base.ActionIcon,
|
||||||
"ActionDesc": base.ActionDesc,
|
"ActionDesc": base.ActionDesc,
|
||||||
|
"DateFormat": base.DateFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runWeb(*cli.Context) {
|
func runWeb(*cli.Context) {
|
||||||
|
|
Loading…
Reference in a new issue