1
0
Fork 0

Get week range from server

This commit is contained in:
Gregory Eremin 2015-03-22 20:23:18 +07:00
parent b172e131e0
commit fc4a95545d
7 changed files with 48 additions and 18 deletions

View File

@ -29,6 +29,7 @@
<script src="/jsx/build/charts/chart_data_mixin.js"></script>
<script src="/jsx/build/charts/chart_animation_mixin.js"></script>
<script src="/jsx/build/charts/selector.js"></script>
<script src="/jsx/build/charts/week_interval_selector.js"></script>
<script src="/jsx/build/charts/bc/bar_chart.js"></script>
<script src="/jsx/build/charts/bc/bar.js"></script>
<script src="/jsx/build/charts/sac/stacked_area_chart.js"></script>
@ -39,6 +40,5 @@
<script src="/jsx/build/app/menu.js"></script>
<script src="/jsx/build/app/dashboard.js"></script>
<script src="/jsx/build/app/info_block.js"></script>
<script src="/jsx/build/app/week_interval_selector.js"></script>
<script src="/jsx/build/start.js"></script>
</html>

View File

@ -143,7 +143,7 @@ var BarChart = React.createClass({
return (
<div className="barchart-container">
<div className="whatsgoingon">
This bar chart shows <em>{words.values[this.state.sort]}</em> {words.actions[this.state.item +'-'+ this.state.sort]} <em>{words.items[this.state.item]}</em> {words.whatHappened[this.state.item +'-'+ target]} <em>{subject}</em> {words.targetSuffix[target]}<br /><WeekIntervalSelector />
This bar chart shows <em>{words.values[this.state.sort]}</em> {words.actions[this.state.item +'-'+ this.state.sort]} <em>{words.items[this.state.item]}</em> {words.whatHappened[this.state.item +'-'+ target]} <em>{subject}</em> {words.targetSuffix[target]}<br /><WeekIntervalSelector org={this.getParams().org} />
</div>
<div className="filters">
<Selector thing="sort"

View File

@ -301,7 +301,7 @@ var StackedAreaChart = React.createClass({
return (
<div ref="container" className="sac">
<div className="whatsgoingon">
This stacked area chart shows <em>the number of commits</em> {words.actions[this.state.item]} <em>{words.items[this.state.item]}</em> {words.whatHappened[this.state.item +'-'+ target]} <em>{subject}</em> {words.targetSuffix[target]}<br /><WeekIntervalSelector />
This stacked area chart shows <em>the number of commits</em> {words.actions[this.state.item]} <em>{words.items[this.state.item]}</em> {words.whatHappened[this.state.item +'-'+ target]} <em>{subject}</em> {words.targetSuffix[target]}<br /><WeekIntervalSelector org={this.getParams().org} />
</div>
<div className="filters">
<Selector thing="sort"

View File

@ -2,31 +2,39 @@ var WeekIntervalSelector = React.createClass({
mixins: [ReactRouter.Navigation, ReactRouter.State],
getInitialState: function() {
var ms = 1000,
daySeconds = 86400,
weekSeconds = daySeconds*7,
today = new Date(),
sunday = new Date(today - daySeconds*ms*today.getDay()),
perfectSunday = new Date(Date.UTC(sunday.getFullYear(), sunday.getMonth(), sunday.getDate())),
lastWeek = perfectSunday.setHours(0)/ms,
firstWeek = lastWeek - 51*weekSeconds;
var weeks = [];
for (var i = lastWeek; i >= firstWeek; i -= weekSeconds) {
weeks.push(i);
};
return {
weeks: weeks.sort()
weeks: []
};
},
componentDidMount: function() {
this.loadWeekRange(this.props.org);
},
componentWillReceiveProps: function(newProps) {
this.loadWeekRange(newProps.org);
},
handleChange: function(thing, e) {
var params = this.getQuery();
params[thing.slice(0, 1)] = e.target.value/100;
this.transitionTo(document.location.pathname, null, params);
},
loadWeekRange: function(org) {
getURL("/api/weeks", {org: org}, function(res){
var weeks = [],
min = res[0],
max = res[1];
for (var i = min; i <= max; i += 86400*7) {
weeks.push(i);
};
this.setState({
weeks: weeks
});
}.bind(this));
},
render: function() {
var daySeconds = 86400,
weekSeconds = daySeconds*7,

View File

@ -36,3 +36,18 @@ func UserOrgs(login string) (orgs []*Org) {
`, login)
return
}
func OrgWeekRange(login string) (min int, max int) {
row := db.QueryRow(`
select
min(c.week) as min,
max(c.week) as max
from contribs c
join orgs o on o.id = c.org_id
where o.login = ?
`, login)
if err := row.Scan(&min, &max); err != nil {
panic(err)
}
return
}

View File

@ -29,3 +29,9 @@ func apiReposHandler(w http.ResponseWriter, r *http.Request) {
repos := db.OrgRepos(stat.Org)
req.respondWith(repos)
}
func apiOrgWeekRangeHandler(w http.ResponseWriter, r *http.Request) {
req, stat := parseRequest(w, r)
min, max := db.OrgWeekRange(stat.Org)
req.respondWith([]int{min, max})
}

View File

@ -26,6 +26,7 @@ func init() {
http.HandleFunc("/api/teams", apiTeamsHandler)
http.HandleFunc("/api/users", apiUsersHandler)
http.HandleFunc("/api/repos", apiReposHandler)
http.HandleFunc("/api/weeks", apiOrgWeekRangeHandler)
http.HandleFunc("/api/stat/orgs/top", statOrgTopHandler)
http.HandleFunc("/api/stat/orgs/activity", statOrgActivityHandler)