1
0
Fork 0

Don't extract all the router module

This commit is contained in:
Gregory Eremin 2015-03-08 15:42:40 +07:00
parent b39941aa7c
commit 6ebab740b7
3 changed files with 21 additions and 149 deletions

View File

@ -1,131 +0,0 @@
var Router = ReactRouter,
Route = Router.Route,
Link = Router.Link,
RouteHandler = Router.RouteHandler,
DefaultRoute = Router.DefaultRoute,
NotFoundRoute = Router.NotFoundRoute;
var App = React.createClass({displayName: "App",
mixins: [Router.Navigation],
render: function(){
return (
React.createElement("section", {className: "app"},
React.createElement(Menu, null),
React.createElement(RouteHandler, null)
)
);
}
});
var Menu = React.createClass({displayName: "Menu",
mixins: [Router.Navigation, 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() {
var renderTeam = function(team) {
return (
React.createElement("li", {key: team.slug, className: "nav team"},
React.createElement(Link, {to: "team", params: {org: team.owner, team: team.slug}}, team.name)
)
)
};
return (
React.createElement("section", {className: "menu"},
React.createElement("ul", null,
React.createElement("li", {key: "empact", className: "nav empact"},
React.createElement(Link, {to: "dashboard", params: {org: this.getParams().org}}, "Empact")
),
React.createElement("li", {key: "dash", className: "nav dash"},
React.createElement(Link, {to: "dashboard", params: {org: this.getParams().org}}, "Dashboard")
),
React.createElement("li", {key: "teams-header", className: "nav header"}, "Teams:"),
this.state.teams.map(renderTeam)
)
)
);
}
});
var Dashboard = React.createClass({displayName: "Dashboard",
render: function(){
return (
React.createElement(RouteHandler, null)
);
}
});
var OrgStats = React.createClass({displayName: "OrgStats",
mixins: [Router.Navigation, Router.State],
render: function(){
return (
React.createElement("section", {className: "content"}, "Org stats for ", this.getParams().org)
);
}
});
var TeamStats = React.createClass({displayName: "TeamStats",
mixins: [Router.Navigation, Router.State],
render: function(){
var url = "/api/stat/teams/top?org="+ this.getParams().org +"&from=1417878086&to=1425654067";
return (
React.createElement("section", {className: "content"},
React.createElement("div", {className: "left"},
React.createElement(BarChart, {url: url})
)
)
);
}
});
var UserStats = React.createClass({displayName: "UserStats",
render: function(){
return (
React.createElement("section", {className: "content"}, "User stats!")
);
}
});
var RepoStats = React.createClass({displayName: "RepoStats",
render: function(){
return (
React.createElement("section", {className: "content"}, "Repo Stats!")
);
}
});
var NotFound = React.createClass({displayName: "NotFound",
render: function(){
return (
React.createElement("section", {className: "content"}, "NOT FOUND :(")
);
}
});
var routes = [
React.createElement(Route, {name: "root", path: "/app/", handler: App},
React.createElement(Route, {name: "dashboard", path: ":org", handler: Dashboard},
React.createElement(DefaultRoute, {handler: OrgStats}),
React.createElement(Route, {name: "team", path: "teams/:team", handler: TeamStats}),
React.createElement(Route, {name: "user", path: "users/:user", handler: UserStats}),
React.createElement(Route, {name: "repo", path: "repos/:repo", handler: RepoStats})
),
React.createElement(NotFoundRoute, {handler: NotFound})
)
];
Router.run(routes, Router.HistoryLocation, function(Handler) {
React.render(React.createElement(Handler, null), document.body);
});

View File

@ -1,9 +1,5 @@
var Router = ReactRouter,
Route = Router.Route,
Link = Router.Link,
RouteHandler = Router.RouteHandler,
DefaultRoute = Router.DefaultRoute,
NotFoundRoute = Router.NotFoundRoute;
Link = Router.Link;
var App = React.createClass({
mixins: [Router.Navigation],
@ -11,7 +7,7 @@ var App = React.createClass({
return (
<section className="app">
<Menu/>
<RouteHandler/>
<Router.RouteHandler/>
</section>
);
}
@ -63,7 +59,7 @@ var Menu = React.createClass({
var Dashboard = React.createClass({
render: function(){
return (
<RouteHandler/>
<Router.RouteHandler/>
);
}
});
@ -71,8 +67,11 @@ var Dashboard = React.createClass({
var OrgStats = React.createClass({
mixins: [Router.Navigation, Router.State],
render: function(){
var topTeams = "/api/stat/teams/top?org="+ this.getParams().org;
return (
<section className="content">Org stats for {this.getParams().org}</section>
<section className="content">
<BarChart url={topTeams} />
</section>
);
}
});
@ -80,7 +79,7 @@ var OrgStats = React.createClass({
var TeamStats = React.createClass({
mixins: [Router.Navigation, Router.State],
render: function(){
var url = "/api/stat/teams/top?org="+ this.getParams().org +"&from=1417878086&to=1425654067";
var url = "/api/stat/teams/top?org="+ this.getParams().org;
return (
<section className="content">
<div className="left">
@ -116,15 +115,15 @@ var NotFound = React.createClass({
});
var routes = [
<Route name="root" path="/app/" handler={App}>
<Route name="dashboard" path=":org" handler={Dashboard}>
<DefaultRoute handler={OrgStats} />
<Route name="team" path="teams/:team" handler={TeamStats} />
<Route name="user" path="users/:user" handler={UserStats} />
<Route name="repo" path="repos/:repo" handler={RepoStats} />
</Route>
<NotFoundRoute handler={NotFound}/>
</Route>
<Router.Route name="root" path="/app/" handler={App}>
<Router.Route name="dashboard" path=":org" handler={Dashboard}>
<Router.DefaultRoute handler={OrgStats} />
<Router.Route name="team" path="teams/:team" handler={TeamStats} />
<Router.Route name="user" path="users/:user" handler={UserStats} />
<Router.Route name="repo" path="repos/:repo" handler={RepoStats} />
</Router.Route>
<Router.NotFoundRoute handler={NotFound}/>
</Router.Route>
];
Router.run(routes, Router.HistoryLocation, function(Handler) {
React.render(<Handler/>, document.body);

View File

@ -61,11 +61,15 @@ func parseStatRequest(r *http.Request) *statRequest {
if from, err = strconv.ParseInt(r.FormValue("from"), 10, 64); err != nil {
panic(err)
}
} else {
from = 0
}
if r.FormValue("to") != "" {
if to, err = strconv.ParseInt(r.FormValue("to"), 10, 64); err != nil {
panic(err)
}
} else {
to = time.Now().Unix()
}
return &statRequest{
org: r.FormValue("org"),