Skip to content

Commit d1bc23b

Browse files
KixironJoshua Nelson
authored and
Joshua Nelson
committed
Release Activity
1 parent 0fc0f21 commit d1bc23b

File tree

3 files changed

+74
-49
lines changed

3 files changed

+74
-49
lines changed

src/web/releases.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use postgres::Connection;
2222
use router::Router;
2323
use serde::Serialize;
2424
use serde_json::Value;
25+
use std::borrow::Cow;
2526

2627
/// Number of release in home page
2728
const RELEASES_IN_HOME: i64 = 15;
@@ -661,9 +662,19 @@ pub fn search_handler(req: &mut Request) -> IronResult<Response> {
661662
}
662663
}
663664

665+
#[derive(Debug, Clone, PartialEq, Serialize)]
666+
struct ReleaseActivity {
667+
description: Cow<'static, str>,
668+
activity_data: Value,
669+
}
670+
671+
impl_webpage! {
672+
ReleaseActivity = "releases/activity.html",
673+
}
674+
664675
pub fn activity_handler(req: &mut Request) -> IronResult<Response> {
665676
let conn = extension!(req, Pool).get()?;
666-
let release_activity_data: Value = ctry!(
677+
let activity_data: Value = ctry!(
667678
req,
668679
conn.query(
669680
"SELECT value FROM config WHERE name = 'release_activity'",
@@ -674,13 +685,11 @@ pub fn activity_handler(req: &mut Request) -> IronResult<Response> {
674685
.next()
675686
.map_or(Value::Null, |row| row.get("value"));
676687

677-
Page::new(release_activity_data)
678-
.title("Releases")
679-
.set("description", "Monthly release activity")
680-
.set_true("show_releases_navigation")
681-
.set_true("releases_navigation_activity_tab")
682-
.set_true("javascript_highchartjs")
683-
.to_resp("releases_activity")
688+
ReleaseActivity {
689+
description: Cow::Borrowed("Monthly release activity"),
690+
activity_data,
691+
}
692+
.into_response(req)
684693
}
685694

686695
pub fn build_queue_handler(req: &mut Request) -> IronResult<Response> {

templates/releases_activity.hbs

Lines changed: 0 additions & 41 deletions
This file was deleted.

tera-templates/releases/activity.html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{%- extends "base.html" -%}
2+
{%- import "releases/header.html" as release_macros -%}
3+
4+
{%- block title -%}Releases - Docs.rs{%- endblock title -%}
5+
6+
{%- block header -%}
7+
{{ release_macros::header(title="Releases", description=description, tab="activity") }}
8+
{%- endblock header -%}
9+
10+
{%- block body -%}
11+
<div class="container">
12+
<div id="releases-activity-chart"></div>
13+
</div>
14+
{%- endblock body -%}
15+
16+
{# TODO: Do this with tera alone #}
17+
{%- block javascript -%}
18+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.2.5/highcharts.js" type="text/javascript"
19+
charset="utf-8"></script>
20+
21+
<script type="text/javascript" charset="utf-8">
22+
new Highcharts.Chart({
23+
chart: {
24+
renderTo: 'releases-activity-chart',
25+
type: 'line'
26+
},
27+
title: {
28+
text: 'Monthly release activity',
29+
x: -20 //center
30+
},
31+
xAxis: {
32+
categories: [
33+
{% for date in activity_data.dates %}
34+
{{ "'" ~ date ~ "'," }}
35+
{% endfor %}
36+
]
37+
},
38+
yAxis: {
39+
title: {
40+
text: 'Crates'
41+
},
42+
plotLines: [{
43+
value: 0,
44+
width: 1,
45+
color: '#808080'
46+
}]
47+
},
48+
series: [{
49+
name: 'Releases',
50+
data: [{{ activity_data.counts | join(sep=", ") }}]
51+
}, {
52+
name: 'Build Failures',
53+
data: [{{ activity_data.failures | join(sep=", ") }}]
54+
}]
55+
});
56+
</script>
57+
{%- endblock javascript -%}

0 commit comments

Comments
 (0)