Add basic render of public act
This commit is contained in:
@ -2,9 +2,9 @@ APP_NAME = Gogs: Go Git Service
|
||||
RUN_USER = lunny
|
||||
|
||||
[repository]
|
||||
ROOT = /Users/lunny/git/gogs-repositories
|
||||
LANG_IGNS=Google Go|C
|
||||
LICENSES=Apache v2 License|BSD (3-Clause) License
|
||||
ROOT = /Users/%(RUN_USER)s/git/gogs-repositories
|
||||
LANG_IGNS=Google Go|C|Python
|
||||
LICENSES=Apache v2 License|GPL v2|BSD (3-Clause) License
|
||||
|
||||
[server]
|
||||
HTTP_ADDR =
|
||||
|
36
conf/gitignore/Python
Normal file
36
conf/gitignore/Python
Normal file
@ -0,0 +1,36 @@
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Packages
|
||||
*.egg
|
||||
*.egg-info
|
||||
dist
|
||||
build
|
||||
eggs
|
||||
parts
|
||||
bin
|
||||
var
|
||||
sdist
|
||||
develop-eggs
|
||||
.installed.cfg
|
||||
lib
|
||||
lib64
|
||||
__pycache__
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.coverage
|
||||
.tox
|
||||
nosetests.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
339
conf/license/GPL v2
Normal file
339
conf/license/GPL v2
Normal file
File diff suppressed because it is too large
Load Diff
2
gogs.go
2
gogs.go
@ -20,7 +20,7 @@ import (
|
||||
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
||||
const go11tag = true
|
||||
|
||||
const APP_VER = "0.0.7.0314"
|
||||
const APP_VER = "0.0.8.0315"
|
||||
|
||||
func init() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -21,20 +21,34 @@ const (
|
||||
// An Action represents
|
||||
type Action struct {
|
||||
Id int64
|
||||
UserId int64
|
||||
UserName string
|
||||
UserId int64 // Receiver user id.
|
||||
OpType int
|
||||
ActUserId int64 // Action user id.
|
||||
ActUserName string // Action user name.
|
||||
RepoId int64
|
||||
RepoName string
|
||||
Content string
|
||||
Created time.Time `xorm:"created"`
|
||||
}
|
||||
|
||||
func (a Action) GetOpType() int {
|
||||
return a.OpType
|
||||
}
|
||||
|
||||
func (a Action) GetActUserName() string {
|
||||
return a.ActUserName
|
||||
}
|
||||
|
||||
func (a Action) GetRepoName() string {
|
||||
return a.RepoName
|
||||
}
|
||||
|
||||
// NewRepoAction inserts action for create repository.
|
||||
func NewRepoAction(user *User, repo *Repository) error {
|
||||
_, err := orm.InsertOne(&Action{
|
||||
UserId: user.Id,
|
||||
UserName: user.Name,
|
||||
ActUserId: user.Id,
|
||||
ActUserName: user.Name,
|
||||
OpType: OP_CREATE_REPO,
|
||||
RepoId: repo.Id,
|
||||
RepoName: repo.Name,
|
||||
@ -42,8 +56,14 @@ func NewRepoAction(user *User, repo *Repository) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetFeeds(userid, offset int64) ([]Action, error) {
|
||||
func GetFeeds(userid, offset int64, isProfile bool) ([]Action, error) {
|
||||
actions := make([]Action, 0, 20)
|
||||
err := orm.Limit(20, int(offset)).Desc("id").Where("user_id=?", userid).Find(&actions)
|
||||
sess := orm.Limit(20, int(offset)).Desc("id").Where("user_id=?", userid)
|
||||
if isProfile {
|
||||
sess.And("act_user_id=?", userid)
|
||||
} else {
|
||||
sess.And("act_user_id!=?", userid)
|
||||
}
|
||||
err := sess.Find(&actions)
|
||||
return actions, err
|
||||
}
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b
|
||||
form.RepoName, form.Description, form.Language, form.License,
|
||||
form.Visibility == "private", form.InitReadme == "on"); err == nil {
|
||||
if err == nil {
|
||||
data["RepoName"] = user.Name + "/" + form.RepoName
|
||||
r.HTML(200, "repo/created", data)
|
||||
r.Redirect("/"+user.Name+"/"+form.RepoName, 200)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,12 @@ func Profile(params martini.Params, r render.Render, data base.TmplData, session
|
||||
}
|
||||
|
||||
data["Owner"] = user
|
||||
feeds, err := models.GetFeeds(user.Id, 0, true)
|
||||
if err != nil {
|
||||
log.Handle(200, "user.Profile", data, r, err)
|
||||
return
|
||||
}
|
||||
data["Feeds"] = feeds
|
||||
r.HTML(200, "user/profile", data)
|
||||
}
|
||||
|
||||
@ -156,7 +162,7 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r
|
||||
}
|
||||
|
||||
func Feeds(form auth.FeedsForm, r render.Render) {
|
||||
actions, err := models.GetFeeds(form.UserId, form.Offset)
|
||||
actions, err := models.GetFeeds(form.UserId, form.Offset, false)
|
||||
if err != nil {
|
||||
r.JSON(500, err)
|
||||
}
|
||||
|
@ -26,11 +26,15 @@
|
||||
<div id="gogs-user-activity" class="col-md-9">
|
||||
<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><a href="#activity" data-toggle="tab"><i class="fa fa-rss"></i>Activity</a></li>
|
||||
<li><a href="#activity" data-toggle="tab"><i class="fa fa-rss"></i>Public Activity</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane active" id="repo">repo</div>
|
||||
<div class="tab-pane" id="activity">activity</div>
|
||||
<div class="tab-pane" id="activity">
|
||||
{{range .Feeds}}<div>
|
||||
<i class="fa fa-{{ActionIcon .OpType}}"></i>{{ActionDesc . | str2html}} {{TimeSince .Created}}
|
||||
</div>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
3
web.go
3
web.go
@ -40,8 +40,11 @@ var AppHelpers template.FuncMap = map[string]interface{}{
|
||||
"AppVer": func() string {
|
||||
return APP_VER
|
||||
},
|
||||
"str2html": base.Str2html,
|
||||
"TimeSince": base.TimeSince,
|
||||
"Subtract": base.Subtract,
|
||||
"ActionIcon": base.ActionIcon,
|
||||
"ActionDesc": base.ActionDesc,
|
||||
}
|
||||
|
||||
func runWeb(*cli.Context) {
|
||||
|
Reference in New Issue
Block a user