From f43cc908411a62c9252eb42484e5096810272369 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 11 Jan 2016 20:41:43 +0800 Subject: [PATCH] #2287 Truncate repository name if too long --- README.md | 2 +- gogs.go | 2 +- models/action.go | 40 ++++++++++++++++--------- models/user.go | 7 +---- modules/base/tool.go | 9 ++++++ public/css/gogs.css | 15 ++++++++++ public/less/_dashboard.less | 18 +++++++++++ public/less/_explore.less | 5 ++++ templates/.VERSION | 2 +- templates/explore/repo_list.tmpl | 2 +- templates/user/dashboard/dashboard.tmpl | 18 ++++++----- templates/user/dashboard/feeds.tmpl | 2 +- 12 files changed, 89 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 3c6aa419ae..d7177b5b59 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) -##### Current version: 0.8.19 +##### Current version: 0.8.20 | Web | UI | Preview | |:-------------:|:-------:|:-------:| diff --git a/gogs.go b/gogs.go index 38f949d36c..76f89f6746 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.8.19.0111" +const APP_VER = "0.8.20.0111" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/action.go b/models/action.go index 9ecf67b4b6..4e5f461a36 100644 --- a/models/action.go +++ b/models/action.go @@ -90,54 +90,66 @@ func (a *Action) AfterSet(colName string, _ xorm.Cell) { } } -func (a Action) GetOpType() int { +func (a *Action) GetOpType() int { return int(a.OpType) } -func (a Action) GetActUserName() string { +func (a *Action) GetActUserName() string { return a.ActUserName } -func (a Action) GetActEmail() string { +func (a *Action) ShortActUserName() string { + return base.EllipsisString(a.ActUserName, 20) +} + +func (a *Action) GetActEmail() string { return a.ActEmail } -func (a Action) GetRepoUserName() string { +func (a *Action) GetRepoUserName() string { return a.RepoUserName } -func (a Action) GetRepoName() string { +func (a *Action) ShortRepoUserName() string { + return base.EllipsisString(a.RepoUserName, 20) +} + +func (a *Action) GetRepoName() string { return a.RepoName } -func (a Action) GetRepoPath() string { - return path.Join(a.RepoUserName, a.RepoName) +func (a *Action) ShortRepoName() string { + return base.EllipsisString(a.RepoName, 33) } -func (a Action) GetRepoLink() string { +func (a *Action) GetRepoPath() string { + return path.Join(a.ShortRepoUserName(), a.ShortRepoName()) +} + +func (a *Action) GetRepoLink() string { if len(setting.AppSubUrl) > 0 { return path.Join(setting.AppSubUrl, a.GetRepoPath()) } return "/" + a.GetRepoPath() } -func (a Action) GetBranch() string { +func (a *Action) GetBranch() string { return a.RefName } -func (a Action) GetContent() string { +func (a *Action) GetContent() string { return a.Content } -func (a Action) GetCreate() time.Time { +func (a *Action) GetCreate() time.Time { return a.Created } -func (a Action) GetIssueInfos() []string { +func (a *Action) GetIssueInfos() []string { return strings.SplitN(a.Content, "|", 2) } -func (a Action) GetIssueTitle() string { +func (a *Action) GetIssueTitle() string { index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { @@ -147,7 +159,7 @@ func (a Action) GetIssueTitle() string { return issue.Name } -func (a Action) GetIssueContent() string { +func (a *Action) GetIssueContent() string { index := com.StrTo(a.GetIssueInfos()[0]).MustInt64() issue, err := GetIssueByIndex(a.RepoID, index) if err != nil { diff --git a/models/user.go b/models/user.go index f648a8abcf..5c43a23a2f 100644 --- a/models/user.go +++ b/models/user.go @@ -429,13 +429,8 @@ func (u *User) DisplayName() string { return u.Name } -// ShortName returns shorted user name with given maximum length, -// it adds "..." at the end if user name has more length than maximum. func (u *User) ShortName(length int) string { - if len(u.Name) < length { - return u.Name - } - return u.Name[:length] + "..." + return base.EllipsisString(u.Name, length) } // IsUserExist checks if given user name exist, diff --git a/modules/base/tool.go b/modules/base/tool.go index 255c34ef5a..6bfd912d32 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -453,6 +453,15 @@ func Subtract(left interface{}, right interface{}) interface{} { } } +// EllipsisString returns a truncated short string, +// it appends '...' in the end of the length of string is too large. +func EllipsisString(str string, length int) string { + if len(str) < length { + return str + } + return str[:length-3] + "..." +} + // StringsToInt64s converts a slice of string to a slice of int64. func StringsToInt64s(strs []string) []int64 { ints := make([]int64, len(strs)) diff --git a/public/css/gogs.css b/public/css/gogs.css index b6d2616586..452d4a19a5 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -3057,6 +3057,18 @@ footer .container .links > *:first-child { margin-right: 6px; color: #888; } +.feeds .list .repo-owner-name-list .item-name { + max-width: 70%; + margin-bottom: -4px; +} +.feeds .list #collaborative-repo-list .owner-and-repo { + max-width: 80%; + margin-bottom: -5px; +} +.feeds .list #collaborative-repo-list .owner-name { + max-width: 120px; + margin-bottom: -5px; +} .admin { padding-top: 15px; padding-bottom: 80px; @@ -3117,6 +3129,9 @@ footer .container .links > *:first-child { font-size: 1.5rem; padding-bottom: 10px; } +.ui.repository.list .item .ui.header .name { + word-break: break-all; +} .ui.repository.list .item .ui.header .metas { color: #888; font-size: 13px; diff --git a/public/less/_dashboard.less b/public/less/_dashboard.less index 6f4fbb196b..f194dc1282 100644 --- a/public/less/_dashboard.less +++ b/public/less/_dashboard.less @@ -123,5 +123,23 @@ } } } + + .repo-owner-name-list { + .item-name { + max-width: 70%; + margin-bottom: -4px; + } + } + + #collaborative-repo-list { + .owner-and-repo { + max-width: 80%; + margin-bottom: -5px; + } + .owner-name { + max-width: 120px; + margin-bottom: -5px; + } + } } } diff --git a/public/less/_explore.less b/public/less/_explore.less index 53a6b5a46c..5141d49928 100644 --- a/public/less/_explore.less +++ b/public/less/_explore.less @@ -15,6 +15,11 @@ .ui.header { font-size: 1.5rem; padding-bottom: 10px; + + .name { + word-break: break-all; + } + .metas { color: #888; font-size: 13px; diff --git a/templates/.VERSION b/templates/.VERSION index f1eb383c3e..4295f9db1e 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.8.19.0111 \ No newline at end of file +0.8.20.0111 \ No newline at end of file diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index a674bcc90a..f8dff62869 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -2,7 +2,7 @@ {{range .Repos}}
- {{if $.PageIsExplore}}{{.Owner.Name}} / {{end}}{{.Name}} + {{if $.PageIsExplore}}{{.Owner.Name}} / {{end}}{{.Name}} {{if .IsPrivate}} {{else if .IsFork}} diff --git a/templates/user/dashboard/dashboard.tmpl b/templates/user/dashboard/dashboard.tmpl index 86936efa68..109b0bbe7d 100644 --- a/templates/user/dashboard/dashboard.tmpl +++ b/templates/user/dashboard/dashboard.tmpl @@ -22,12 +22,12 @@