Skip to content

Commit

Permalink
Show download count info in release list
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Feb 3, 2020
1 parent 29151b9 commit 9003512
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions modules/base/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,28 @@ func FileSize(s int64) string {
return humanateBytes(uint64(s), 1024, sizes)
}

// PrettyNumber formats a number string representation with thousand separator as spaces.
func PrettyNumber(i int64) string {
s := strconv.FormatInt(i, 10)
r1 := ""
idx := 0

for p := len(s) - 1; p >= 0; p-- {
idx++
if idx == 4 {
idx = 1
r1 += ","
}
r1 += string(s[p])
}

r2 := ""
for p := len(r1) - 1; p >= 0; p-- {
r2 += string(r1[p])
}
return r2
}

// Subtract deals with subtraction of all types of number.
func Subtract(left interface{}, right interface{}) interface{} {
var rleft, rright int64
Expand Down
1 change: 1 addition & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func NewFuncMap() []template.FuncMap {
"TimeSinceUnix": timeutil.TimeSinceUnix,
"RawTimeSince": timeutil.RawTimeSince,
"FileSize": base.FileSize,
"PrettyNumber": base.PrettyNumber,
"Subtract": base.Subtract,
"EntryIcon": base.EntryIcon,
"MigrationIcon": MigrationIcon,
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,7 @@ release.deletion_success = The release has been deleted.
release.tag_name_already_exist = A release with this tag name already exists.
release.tag_name_invalid = The tag name is not valid.
release.downloads = Downloads
release.download_count = Downloads: %s

branch.name = Branch Name
branch.search = Search branches
Expand Down
1 change: 1 addition & 0 deletions templates/repo/release/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
{{if .Attachments}}
{{range .Attachments}}
<li>
<span class="ui text right" data-tooltip="{{$.i18n.Tr "repo.release.download_count" (.DownloadCount | PrettyNumber)}}" data-position="bottom right"><i class="ui octicon octicon-info"></i></span>
<a target="_blank" rel="noopener noreferrer" href="{{.DownloadURL}}">
<strong><span class="ui image octicon octicon-package" title='{{.Name}}'></span> {{.Name}}</strong>
<span class="ui text grey right">{{.Size | FileSize}}</span>
Expand Down
4 changes: 4 additions & 0 deletions web_src/less/_repository.less
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,10 @@
padding-top: 8px;
padding-bottom: 8px;
border-bottom: 1px solid #eeeeee;

a > .text.right {
margin-right: 5px;
}
}
}
}
Expand Down

0 comments on commit 9003512

Please sign in to comment.