Skip to content

Commit

Permalink
Release Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kixiron authored and Joshua Nelson committed Jul 13, 2020
1 parent 658d5c0 commit 3d3b7cd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 49 deletions.
25 changes: 17 additions & 8 deletions src/web/releases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use postgres::Connection;
use router::Router;
use serde::Serialize;
use serde_json::Value;
use std::borrow::Cow;

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

#[derive(Debug, Clone, PartialEq, Serialize)]
struct ReleaseActivity {
description: Cow<'static, str>,
activity_data: Value,
}

impl_webpage! {
ReleaseActivity = "releases/activity.html",
}

pub fn activity_handler(req: &mut Request) -> IronResult<Response> {
let conn = extension!(req, Pool).get()?;
let release_activity_data: Value = ctry!(
let activity_data: Value = ctry!(
req,
conn.query(
"SELECT value FROM config WHERE name = 'release_activity'",
Expand All @@ -674,13 +685,11 @@ pub fn activity_handler(req: &mut Request) -> IronResult<Response> {
.next()
.map_or(Value::Null, |row| row.get("value"));

Page::new(release_activity_data)
.title("Releases")
.set("description", "Monthly release activity")
.set_true("show_releases_navigation")
.set_true("releases_navigation_activity_tab")
.set_true("javascript_highchartjs")
.to_resp("releases_activity")
ReleaseActivity {
description: Cow::Borrowed("Monthly release activity"),
activity_data,
}
.into_response(req)
}

pub fn build_queue_handler(req: &mut Request) -> IronResult<Response> {
Expand Down
41 changes: 0 additions & 41 deletions templates/releases_activity.hbs

This file was deleted.

57 changes: 57 additions & 0 deletions tera-templates/releases/activity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{%- extends "base.html" -%}
{%- import "releases/header.html" as release_macros -%}

{%- block title -%}Releases - Docs.rs{%- endblock title -%}

{%- block header -%}
{{ release_macros::header(title="Releases", description=description, tab="activity") }}
{%- endblock header -%}

{%- block body -%}
<div class="container">
<div id="releases-activity-chart"></div>
</div>
{%- endblock body -%}

{# TODO: Do this with tera alone #}
{%- block javascript -%}
<script src="https://cdnjs.cloudflare.com/ajax/libs/highcharts/4.2.5/highcharts.js" type="text/javascript"
charset="utf-8"></script>

<script type="text/javascript" charset="utf-8">
new Highcharts.Chart({
chart: {
renderTo: 'releases-activity-chart',
type: 'line'
},
title: {
text: 'Monthly release activity',
x: -20 //center
},
xAxis: {
categories: [
{% for date in activity_data.dates %}
{{ "'" ~ date ~ "'," }}
{% endfor %}
]
},
yAxis: {
title: {
text: 'Crates'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
series: [{
name: 'Releases',
data: [{{ activity_data.counts | join(sep=", ") }}]
}, {
name: 'Build Failures',
data: [{{ activity_data.failures | join(sep=", ") }}]
}]
});
</script>
{%- endblock javascript -%}

0 comments on commit 3d3b7cd

Please sign in to comment.