Add basic render of public act
This commit is contained in:
@ -2,9 +2,9 @@ APP_NAME = Gogs: Go Git Service
|
|||||||
RUN_USER = lunny
|
RUN_USER = lunny
|
||||||
|
|
||||||
[repository]
|
[repository]
|
||||||
ROOT = /Users/lunny/git/gogs-repositories
|
ROOT = /Users/%(RUN_USER)s/git/gogs-repositories
|
||||||
LANG_IGNS=Google Go|C
|
LANG_IGNS=Google Go|C|Python
|
||||||
LICENSES=Apache v2 License|BSD (3-Clause) License
|
LICENSES=Apache v2 License|GPL v2|BSD (3-Clause) License
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
HTTP_ADDR =
|
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.
|
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
||||||
const go11tag = true
|
const go11tag = true
|
||||||
|
|
||||||
const APP_VER = "0.0.7.0314"
|
const APP_VER = "0.0.8.0315"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
@ -20,30 +20,50 @@ const (
|
|||||||
|
|
||||||
// An Action represents
|
// An Action represents
|
||||||
type Action struct {
|
type Action struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64
|
UserId int64 // Receiver user id.
|
||||||
UserName string
|
OpType int
|
||||||
OpType int
|
ActUserId int64 // Action user id.
|
||||||
RepoId int64
|
ActUserName string // Action user name.
|
||||||
RepoName string
|
RepoId int64
|
||||||
Content string
|
RepoName string
|
||||||
Created time.Time `xorm:"created"`
|
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.
|
// NewRepoAction inserts action for create repository.
|
||||||
func NewRepoAction(user *User, repo *Repository) error {
|
func NewRepoAction(user *User, repo *Repository) error {
|
||||||
_, err := orm.InsertOne(&Action{
|
_, err := orm.InsertOne(&Action{
|
||||||
UserId: user.Id,
|
UserId: user.Id,
|
||||||
UserName: user.Name,
|
ActUserId: user.Id,
|
||||||
OpType: OP_CREATE_REPO,
|
ActUserName: user.Name,
|
||||||
RepoId: repo.Id,
|
OpType: OP_CREATE_REPO,
|
||||||
RepoName: repo.Name,
|
RepoId: repo.Id,
|
||||||
|
RepoName: repo.Name,
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFeeds(userid, offset int64) ([]Action, error) {
|
func GetFeeds(userid, offset int64, isProfile bool) ([]Action, error) {
|
||||||
actions := make([]Action, 0, 20)
|
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
|
return actions, err
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,6 +29,10 @@ const (
|
|||||||
Year = 12 * Month
|
Year = 12 * Month
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Str2html(raw string) template.HTML {
|
||||||
|
return template.HTML(raw)
|
||||||
|
}
|
||||||
|
|
||||||
// TimeSince calculates the time interval and generate user-friendly string.
|
// TimeSince calculates the time interval and generate user-friendly string.
|
||||||
func TimeSince(then time.Time) string {
|
func TimeSince(then time.Time) string {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@ -128,3 +133,37 @@ func Subtract(left interface{}, right interface{}) interface{} {
|
|||||||
return fleft + float64(rleft) - (fright + float64(rright))
|
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.RepoName, form.Description, form.Language, form.License,
|
||||||
form.Visibility == "private", form.InitReadme == "on"); err == nil {
|
form.Visibility == "private", form.InitReadme == "on"); err == nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
data["RepoName"] = user.Name + "/" + form.RepoName
|
r.Redirect("/"+user.Name+"/"+form.RepoName, 200)
|
||||||
r.HTML(200, "repo/created", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,12 @@ 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 {
|
||||||
|
log.Handle(200, "user.Profile", data, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data["Feeds"] = feeds
|
||||||
r.HTML(200, "user/profile", data)
|
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) {
|
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 {
|
if err != nil {
|
||||||
r.JSON(500, err)
|
r.JSON(500, err)
|
||||||
}
|
}
|
||||||
|
@ -26,11 +26,15 @@
|
|||||||
<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 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>
|
</ul>
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-pane active" id="repo">repo</div>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
7
web.go
7
web.go
@ -40,8 +40,11 @@ var AppHelpers template.FuncMap = map[string]interface{}{
|
|||||||
"AppVer": func() string {
|
"AppVer": func() string {
|
||||||
return APP_VER
|
return APP_VER
|
||||||
},
|
},
|
||||||
"TimeSince": base.TimeSince,
|
"str2html": base.Str2html,
|
||||||
"Subtract": base.Subtract,
|
"TimeSince": base.TimeSince,
|
||||||
|
"Subtract": base.Subtract,
|
||||||
|
"ActionIcon": base.ActionIcon,
|
||||||
|
"ActionDesc": base.ActionDesc,
|
||||||
}
|
}
|
||||||
|
|
||||||
func runWeb(*cli.Context) {
|
func runWeb(*cli.Context) {
|
||||||
|
Reference in New Issue
Block a user