Show user info
This commit is contained in:
parent
954e140dfd
commit
ed49a23b94
|
@ -15,8 +15,9 @@ var Storage = {
|
||||||
var App = React.createClass({
|
var App = React.createClass({
|
||||||
mixins: [Router.Navigation, Router.State],
|
mixins: [Router.Navigation, Router.State],
|
||||||
|
|
||||||
orgsURL: "/api/orgs",
|
orgsURL: '/api/orgs',
|
||||||
teamsURL: "/api/teams?org=",
|
teamsURL: '/api/teams?org=',
|
||||||
|
usersURL: '/api/users?org=',
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
|
@ -30,6 +31,7 @@ var App = React.createClass({
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
this.loadOrgs();
|
this.loadOrgs();
|
||||||
this.loadTeams();
|
this.loadTeams();
|
||||||
|
this.loadUsers();
|
||||||
},
|
},
|
||||||
|
|
||||||
loadOrgs: function() {
|
loadOrgs: function() {
|
||||||
|
@ -46,7 +48,7 @@ var App = React.createClass({
|
||||||
|
|
||||||
loadTeams: function() {
|
loadTeams: function() {
|
||||||
$.get(this.teamsURL + this.getParams().org, function(res){
|
$.get(this.teamsURL + this.getParams().org, function(res){
|
||||||
this.setState({teams: res})
|
this.setState({teams: res});
|
||||||
if (res !== null) {
|
if (res !== null) {
|
||||||
for (var i = 0; i < res.length; i++) {
|
for (var i = 0; i < res.length; i++) {
|
||||||
var team = res[i];
|
var team = res[i];
|
||||||
|
@ -56,6 +58,18 @@ var App = React.createClass({
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
loadUsers: function() {
|
||||||
|
$.get(this.usersURL + this.getParams().org, function(res){
|
||||||
|
this.setState({users: res});
|
||||||
|
if (res !== null) {
|
||||||
|
for (var i = 0; i < res.length; i++) {
|
||||||
|
var user = res[i];
|
||||||
|
Storage.set('user', user.login, user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
render: function(){
|
render: function(){
|
||||||
return (
|
return (
|
||||||
<section className="app">
|
<section className="app">
|
||||||
|
@ -133,7 +147,9 @@ var Dashboard = React.createClass({
|
||||||
sacApi = '/api/stat/teams/activity';
|
sacApi = '/api/stat/teams/activity';
|
||||||
sacItems = ['user', 'repo'];
|
sacItems = ['user', 'repo'];
|
||||||
} else if (p.user) {
|
} else if (p.user) {
|
||||||
infoTitle = p.user;
|
var info = Storage.get('user', p.user);
|
||||||
|
infoImage = info ? info.avatar_url : null;
|
||||||
|
infoTitle = info && info.name ? info.name : p.user;
|
||||||
bcApi = '/api/stat/users/top';
|
bcApi = '/api/stat/users/top';
|
||||||
bcItems = ['repo'],
|
bcItems = ['repo'],
|
||||||
sacApi = '/api/stat/users/activity';
|
sacApi = '/api/stat/users/activity';
|
||||||
|
|
16
db/user.go
16
db/user.go
|
@ -9,6 +9,16 @@ type User struct {
|
||||||
AvatarURL string `json:"avatar_url" db:"avatar_url"`
|
AvatarURL string `json:"avatar_url" db:"avatar_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const orgUsersQuery = `
|
||||||
|
select
|
||||||
|
u.*
|
||||||
|
from members m
|
||||||
|
join teams t on
|
||||||
|
m.team_id = t.id
|
||||||
|
join users u on
|
||||||
|
m.user = u.login
|
||||||
|
where m.org = ?`
|
||||||
|
|
||||||
const saveUserQuery = `
|
const saveUserQuery = `
|
||||||
insert into users (login, name, id, avatar_url)
|
insert into users (login, name, id, avatar_url)
|
||||||
values (:login, :name, :id, :avatar_url)
|
values (:login, :name, :id, :avatar_url)
|
||||||
|
@ -19,3 +29,9 @@ func (u *User) Save() {
|
||||||
defer measure("SaveUser", time.Now())
|
defer measure("SaveUser", time.Now())
|
||||||
mustExecN(saveUserQuery, u)
|
mustExecN(saveUserQuery, u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OrgUsers(login string) (users []*User) {
|
||||||
|
defer measure("OrgUsers", time.Now())
|
||||||
|
mustSelect(&users, orgUsersQuery, login)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -18,6 +18,12 @@ func apiTeamsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
req.respondWith(teams)
|
req.respondWith(teams)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func apiUsersHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
req, stat := parseRequest(w, r)
|
||||||
|
users := db.OrgUsers(stat.Org)
|
||||||
|
req.respondWith(users)
|
||||||
|
}
|
||||||
|
|
||||||
func apiReposHandler(w http.ResponseWriter, r *http.Request) {
|
func apiReposHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
req, stat := parseRequest(w, r)
|
req, stat := parseRequest(w, r)
|
||||||
repos := db.OrgRepos(stat.Org)
|
repos := db.OrgRepos(stat.Org)
|
||||||
|
|
|
@ -22,6 +22,7 @@ func init() {
|
||||||
http.HandleFunc("/api/", authHandler)
|
http.HandleFunc("/api/", authHandler)
|
||||||
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
http.HandleFunc("/api/orgs", apiOrgsHandler)
|
||||||
http.HandleFunc("/api/teams", apiTeamsHandler)
|
http.HandleFunc("/api/teams", apiTeamsHandler)
|
||||||
|
http.HandleFunc("/api/users", apiUsersHandler)
|
||||||
http.HandleFunc("/api/repos", apiReposHandler)
|
http.HandleFunc("/api/repos", apiReposHandler)
|
||||||
|
|
||||||
http.HandleFunc("/api/stat/orgs/top", statOrgTopHandler)
|
http.HandleFunc("/api/stat/orgs/top", statOrgTopHandler)
|
||||||
|
|
Loading…
Reference in New Issue