forked from gitea/gitea
1
0
Fork 0

add repo list of dashboard

This commit is contained in:
Lunny Xiao 2014-03-11 14:17:05 +08:00
parent fdc4151ff3
commit b5cc4078a9
4 changed files with 24 additions and 5 deletions

View File

@ -223,6 +223,10 @@ func GetRepositories(user *User) ([]Repository, error) {
return repos, err return repos, err
} }
func GetRepositoryCount(user *User) (int64, error) {
return orm.Count(&Repository{OwnerId: user.Id})
}
func StarReposiory(user *User, repoName string) error { func StarReposiory(user *User, repoName string) error {
return nil return nil
} }

View File

@ -142,13 +142,15 @@ func UpdateUser(user *User) (err error) {
// DeleteUser completely deletes everything of the user. // DeleteUser completely deletes everything of the user.
func DeleteUser(user *User) error { func DeleteUser(user *User) error {
repos, err := GetRepositories(user) cnt, err := GetRepositoryCount(user)
if err != nil { if err != nil {
return errors.New("modesl.GetRepositories: " + err.Error()) return errors.New("modesl.GetRepositories: " + err.Error())
} else if len(repos) > 0 { } else if cnt > 0 {
return ErrUserOwnRepos return ErrUserOwnRepos
} }
// TODO: check issues, other repos' commits
_, err = orm.Delete(user) _, err = orm.Delete(user)
// TODO: delete and update follower information. // TODO: delete and update follower information.
return err return err

View File

@ -20,6 +20,14 @@ import (
func Dashboard(r render.Render, data base.TmplData, session sessions.Session) { func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
data["Title"] = "Dashboard" data["Title"] = "Dashboard"
data["PageIsUserDashboard"] = true data["PageIsUserDashboard"] = true
repos, err := models.GetRepositories(&models.User{Id: auth.SignedInId(session)})
if err != nil {
data["ErrorMsg"] = err
log.Error("dashboard: %v", err)
r.HTML(200, "base/error", data)
return
}
data["MyRepos"] = repos
r.HTML(200, "user/dashboard", data) r.HTML(200, "user/dashboard", data)
} }
@ -133,7 +141,7 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren
} }
// TODO: unfinished // TODO: unfinished
func Delete(data base.TmplData, req *http.Request, r render.Render) { func Delete(data base.TmplData, req *http.Request, session sessions.Session, r render.Render) {
data["Title"] = "Delete Account" data["Title"] = "Delete Account"
if req.Method == "GET" { if req.Method == "GET" {
@ -141,7 +149,8 @@ func Delete(data base.TmplData, req *http.Request, r render.Render) {
return return
} }
u := &models.User{} id := auth.SignedInId(session)
u := &models.User{Id: id}
err := models.DeleteUser(u) err := models.DeleteUser(u)
data["ErrorMsg"] = err data["ErrorMsg"] = err
log.Error("user.Delete: %v", data) log.Error("user.Delete: %v", data)

View File

@ -21,7 +21,11 @@
<a class="btn btn-success pull-right btn-sm" href="/repo/create/"><i class="fa fa-plus-square"></i>New Repo</a> <a class="btn btn-success pull-right btn-sm" href="/repo/create/"><i class="fa fa-plus-square"></i>New Repo</a>
</div> </div>
<div class="panel-body"> <div class="panel-body">
repo-list <ul>
{{range .MyRepos}}
<li><a href="#">{{.Name}}</a></li>
{{end}}
</ul>
</div> </div>
</div> </div>
</div> </div>