mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-25 12:00:01 +02:00
Add basic render of public act
This commit is contained in:
parent
2289ff20bf
commit
adb17791bd
10 changed files with 472 additions and 26 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -28,6 +29,10 @@ const (
|
|||
Year = 12 * Month
|
||||
)
|
||||
|
||||
func Str2html(raw string) template.HTML {
|
||||
return template.HTML(raw)
|
||||
}
|
||||
|
||||
// TimeSince calculates the time interval and generate user-friendly string.
|
||||
func TimeSince(then time.Time) string {
|
||||
now := time.Now()
|
||||
|
@ -128,3 +133,37 @@ func Subtract(left interface{}, right interface{}) interface{} {
|
|||
return fleft + float64(rleft) - (fright + float64(rright))
|
||||
}
|
||||
}
|
||||
|
||||
type Actioner interface {
|
||||
GetOpType() int
|
||||
GetActUserName() string
|
||||
GetRepoName() string
|
||||
}
|
||||
|
||||
// ActionIcon accepts a int that represents action operation type
|
||||
// and returns a icon class name.
|
||||
func ActionIcon(opType int) string {
|
||||
switch opType {
|
||||
case 1: // Create repository.
|
||||
return "plus-circle"
|
||||
default:
|
||||
return "invalid type"
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
CreateRepoTpl = `<a href="/user/%s">%s</a> created repository <a href="/%s/%s">%s</a>`
|
||||
)
|
||||
|
||||
// ActionDesc accepts int that represents action operation type
|
||||
// and returns the description.
|
||||
func ActionDesc(act Actioner) string {
|
||||
actUserName := act.GetActUserName()
|
||||
repoName := act.GetRepoName()
|
||||
switch act.GetOpType() {
|
||||
case 1: // Create repository.
|
||||
return fmt.Sprintf(CreateRepoTpl, actUserName, actUserName, actUserName, repoName, repoName)
|
||||
default:
|
||||
return "invalid type"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue