@ -5,6 +5,7 @@
package user
package user
import (
import (
"fmt"
"net/http"
"net/http"
"github.com/codegangsta/martini"
"github.com/codegangsta/martini"
@ -26,10 +27,17 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
return
return
}
}
data [ "MyRepos" ] = repos
data [ "MyRepos" ] = repos
feeds , err := models . GetFeeds ( auth . SignedInId ( session ) , 0 , false )
if err != nil {
log . Handle ( 200 , "user.Dashboard" , data , r , err )
return
}
data [ "Feeds" ] = feeds
r . HTML ( 200 , "user/dashboard" , data )
r . HTML ( 200 , "user/dashboard" , data )
}
}
func Profile ( params martini . Params , r render . Render , req * http . Request , data base . TmplData , session sessions . Session ) {
func Profile ( params martini . Params , req * http . Request , r render . Render , data base . TmplData , session sessions . Session ) {
data [ "Title" ] = "Profile"
data [ "Title" ] = "Profile"
// TODO: Need to check view self or others.
// TODO: Need to check view self or others.
@ -40,23 +48,13 @@ func Profile(params martini.Params, r render.Render, req *http.Request, data bas
}
}
data [ "Owner" ] = user
data [ "Owner" ] = user
data [ "TabName" ] = req . FormValue ( "tab" )
req . ParseForm ( )
tab := req . Form . Get ( "tab" )
data [ "TabName" ] = tab
switch tab {
case "activity" :
feeds , err := models . GetFeeds ( user . Id , 0 , true )
feeds , err := models . GetFeeds ( user . Id , 0 , true )
if err != nil {
if err != nil {
log . Handle ( 200 , "user.Profile" , data , r , err )
log . Handle ( 200 , "user.Profile" , data , r , err )
return
return
}
}
data [ "Feeds" ] = feeds
data [ "Feeds" ] = feeds
default :
}
r . HTML ( 200 , "user/profile" , data )
r . HTML ( 200 , "user/profile" , data )
}
}
@ -172,10 +170,21 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r
r . HTML ( 200 , "user/delete" , data )
r . HTML ( 200 , "user/delete" , data )
}
}
const (
feedTpl = ` < i class = "icon fa fa-%s" > < / i >
< div class = "info" > < span class = "meta" > % s < / span > < br > % s < / div > `
)
func Feeds ( form auth . FeedsForm , r render . Render ) {
func Feeds ( form auth . FeedsForm , r render . Render ) {
actions , err := models . GetFeeds ( form . UserId , form . Offset , false )
actions , err := models . GetFeeds ( form . UserId , form . Page * 20 , false )
if err != nil {
if err != nil {
r . JSON ( 500 , err )
r . JSON ( 500 , err )
}
}
r . JSON ( 200 , actions )
feeds := make ( [ ] string , len ( actions ) )
for i := range actions {
feeds [ i ] = fmt . Sprintf ( feedTpl , base . ActionIcon ( actions [ i ] . OpType ) ,
base . TimeSince ( actions [ i ] . Created ) , base . ActionDesc ( actions [ i ] ) )
}
r . JSON ( 200 , & feeds )
}
}