1
0
Fork 0

Correct menu teams and info blocks everywhere

This commit is contained in:
Gregory Eremin 2015-03-10 16:58:12 +07:00
parent 5f5ee4125e
commit a794366109
2 changed files with 101 additions and 38 deletions

View File

@ -1,12 +1,65 @@
var Router = ReactRouter, var Router = ReactRouter,
Link = Router.Link; Link = Router.Link;
var Storage = {
set: function(category, key, value) {
window.localStorage.setItem(category +'-'+ key, JSON.stringify(value));
},
get: function(category, key) {
var val = window.localStorage.getItem(category +'-'+ key);
return val === null ? null : JSON.parse(val);
}
};
var App = React.createClass({ var App = React.createClass({
mixins: [Router.Navigation], mixins: [Router.Navigation, Router.State],
orgsURL: "/api/orgs",
teamsURL: "/api/teams?org=",
getInitialState: function() {
return {
orgs: [],
org: null,
teams: [],
team: null
};
},
componentDidMount: function() {
this.loadOrgs();
this.loadTeams();
},
loadOrgs: function() {
$.get(this.orgsURL, function(res){
this.setState({orgs: res});
if (res !== null) {
for (var i = 0; i < res.length; i++) {
var org = res[i];
Storage.set('org', org.login, org);
}
}
}.bind(this));
},
loadTeams: function() {
$.get(this.teamsURL + this.getParams().org, function(res){
this.setState({teams: res})
if (res !== null) {
for (var i = 0; i < res.length; i++) {
var team = res[i];
Storage.set('team', team.name, team);
}
}
}.bind(this));
},
render: function(){ render: function(){
return ( return (
<section className="app"> <section className="app">
<Menu/> <Menu orgs={this.state.orgs} teams={this.state.teams} />
<Router.RouteHandler /> <Router.RouteHandler />
</section> </section>
); );
@ -15,26 +68,18 @@ var App = React.createClass({
var Menu = React.createClass({ var Menu = React.createClass({
mixins: [Router.State], mixins: [Router.State],
api_url: "/api/teams?org=",
getInitialState: function() {
return {teams: []};
},
componentDidMount: function() {
this.loadTeams();
},
loadTeams: function() {
$.get(this.api_url + this.getParams().org, function(res){
this.setState({teams: res})
}.bind(this));
},
render: function() { render: function() {
var renderOrg = function(org) {
return (
<li key={'org-'+ org.login} className="nav org">
<Link to="org" params={{org: org.login}}>{org.login}</Link>
</li>
)
};
var renderTeam = function(team) { var renderTeam = function(team) {
return ( return (
<li key={team.name} className="nav team"> <li key={'team-'+ team.name} className="nav team">
<Link to="team" params={{org: team.owner, team: team.name}}>{team.name}</Link> <Link to="team" params={{org: team.owner, team: team.name}}>{team.name}</Link>
</li> </li>
) )
@ -43,13 +88,12 @@ var Menu = React.createClass({
<section className="menu"> <section className="menu">
<ul> <ul>
<li key="empact" className="nav empact"> <li key="empact" className="nav empact">
<Link to="org" params={{org: this.getParams().org}}>Empact</Link> <Link to="org" params={this.getParams()}>Empact</Link>
</li>
<li key="dash" className="nav dash">
<Link to="org" params={{org: this.getParams().org}}>{this.getParams().org}</Link>
</li> </li>
<li key="orgs-header" className="nav header">Organizations:</li>
{this.props.orgs.map(renderOrg)}
<li key="teams-header" className="nav header">Teams:</li> <li key="teams-header" className="nav header">Teams:</li>
{this.state.teams.map(renderTeam)} {this.props.teams.map(renderTeam)}
</ul> </ul>
</section> </section>
); );
@ -66,9 +110,12 @@ var Org = React.createClass({
var OrgStats = React.createClass({ var OrgStats = React.createClass({
mixins: [Router.State], mixins: [Router.State],
render: function(){ render: function(){
var org = Storage.get('org', this.getParams().org);
return ( return (
<section className="content"> <section className="content">
<InfoBlock image={org.avatar_url} title={org.login} text={org.descr} />
<BarChart key={this.getParams().team} api="/api/stat/orgs/top" <BarChart key={this.getParams().team} api="/api/stat/orgs/top"
params={this.getParams()} items={["repo", "team", "user"]} /> params={this.getParams()} items={["repo", "team", "user"]} />
</section> </section>
@ -78,6 +125,7 @@ var OrgStats = React.createClass({
var TeamStats = React.createClass({ var TeamStats = React.createClass({
mixins: [Router.State], mixins: [Router.State],
render: function(){ render: function(){
return ( return (
<section className="content"> <section className="content">
@ -85,7 +133,7 @@ var TeamStats = React.createClass({
image="https://media.licdn.com/mpr/mpr/p/8/005/058/14b/0088c48.jpg" image="https://media.licdn.com/mpr/mpr/p/8/005/058/14b/0088c48.jpg"
title={this.getParams().team} title={this.getParams().team}
text={"The most awesome team in "+ this.getParams().org} /> text={"The most awesome team in "+ this.getParams().org} />
<BarChart key={"bar-chart"+ this.getParams().team} api="/api/stat/teams/top" <BarChart key={'bar-chart-'+ this.getParams().team} api="/api/stat/teams/top"
params={this.getParams()} items={["repo", "user"]} /> params={this.getParams()} items={["repo", "user"]} />
</section> </section>
); );
@ -97,7 +145,8 @@ var UserStats = React.createClass({
render: function(){ render: function(){
return ( return (
<section className="content"> <section className="content">
<BarChart key={this.getParams().team} api="/api/stat/users/top" <InfoBlock title={this.getParams().user} />
<BarChart key={'bar-chart-'+ this.getParams().user} api="/api/stat/users/top"
params={this.getParams()} items={["repo"]} /> params={this.getParams()} items={["repo"]} />
</section> </section>
); );
@ -109,6 +158,7 @@ var RepoStats = React.createClass({
render: function(){ render: function(){
return ( return (
<section className="content"> <section className="content">
<InfoBlock title={this.getParams().repo} />
<BarChart key={this.getParams().team} api="/api/stat/repos/top" <BarChart key={this.getParams().team} api="/api/stat/repos/top"
params={this.getParams()} items={["user", "team"]} /> params={this.getParams()} items={["user", "team"]} />
</section> </section>
@ -124,6 +174,14 @@ var NotFound = React.createClass({
} }
}); });
var SelectOrg = React.createClass({
render: function(){
return (
<section className="content">Please select organization from the menu!</section>
);
}
});
var InfoBlock = React.createClass({ var InfoBlock = React.createClass({
render: function() { render: function() {
var img = <div className="img" style={{backgroundImage: "url("+ this.props.image +")"}} />; var img = <div className="img" style={{backgroundImage: "url("+ this.props.image +")"}} />;
@ -139,13 +197,14 @@ var InfoBlock = React.createClass({
var routes = [ var routes = [
<Router.Route name="root" path="/app/" handler={App}> <Router.Route name="root" path="/app/" handler={App}>
<Router.DefaultRoute handler={SelectOrg} />
<Router.NotFoundRoute handler={NotFound} />
<Router.Route name="org" path=":org" handler={Org}> <Router.Route name="org" path=":org" handler={Org}>
<Router.DefaultRoute handler={OrgStats} /> <Router.DefaultRoute handler={OrgStats} />
<Router.Route name="team" path="teams/:team" handler={TeamStats} /> <Router.Route name="team" path="teams/:team" handler={TeamStats} />
<Router.Route name="user" path="users/:user" handler={UserStats} /> <Router.Route name="user" path="users/:user" handler={UserStats} />
<Router.Route name="repo" path="repos/:repo" handler={RepoStats} /> <Router.Route name="repo" path="repos/:repo" handler={RepoStats} />
</Router.Route> </Router.Route>
<Router.NotFoundRoute handler={NotFound}/>
</Router.Route> </Router.Route>
]; ];
Router.run(routes, Router.HistoryLocation, function(Handler) { Router.run(routes, Router.HistoryLocation, function(Handler) {

View File

@ -8,6 +8,7 @@ section {
.menu { .menu {
width: 13em; width: 13em;
margin-top: 20px;
} }
.menu ul { .menu ul {
margin: 0; margin: 0;
@ -28,8 +29,8 @@ li.nav {
} }
.content { .content {
margin-top: 15px;
width: calc(100% - 13em); width: calc(100% - 13em);
margin-top: 20px;
} }
.content .left, .content .right { .content .left, .content .right {
float: left; float: left;
@ -52,6 +53,9 @@ li.nav {
} }
.info-block h1 { .info-block h1 {
font-size: 32px;
line-height: 32px;
margin: 0;
font-weight: 400; font-weight: 400;
} }