-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
So far features were stored only in database. Show their names in topbar menu with link to the new features page. Features page will show all relevant features with their subfeatures.
- Loading branch information
Showing
10 changed files
with
248 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::db::types::Feature; | ||
use crate::{ | ||
db::Pool, | ||
impl_webpage, | ||
web::{page::WebPage, MetaData}, | ||
}; | ||
use iron::{IronResult, Request, Response}; | ||
use router::Router; | ||
use serde::Serialize; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)] | ||
struct FeaturesPage { | ||
metadata: MetaData, | ||
features: Option<Vec<Feature>>, | ||
feature_len: usize, | ||
default_feature_len: usize, | ||
} | ||
|
||
impl_webpage! { | ||
FeaturesPage = "crate/features.html", | ||
} | ||
|
||
pub fn build_features_handler(req: &mut Request) -> IronResult<Response> { | ||
let router = extension!(req, Router); | ||
let name = cexpect!(req, router.find("name")); | ||
let version = cexpect!(req, router.find("version")); | ||
|
||
let mut conn = extension!(req, Pool).get()?; | ||
|
||
let query = ctry!( | ||
req, | ||
conn.query( | ||
"SELECT crates.name, | ||
releases.features | ||
FROM builds | ||
INNER JOIN releases ON releases.id = builds.rid | ||
INNER JOIN crates ON releases.crate_id = crates.id | ||
WHERE crates.name = $1 AND releases.version = $2 | ||
ORDER BY releases.id DESC", | ||
&[&name, &version] | ||
) | ||
); | ||
let row = cexpect!(req, query.get(0)); | ||
let features = MetaData::parse_features(row.get("features")); | ||
let mut feature_len = 0; | ||
let mut default_feature_len = 0; | ||
if let Some(ref feature_list) = features { | ||
feature_len = feature_list.len(); | ||
if let Some(first) = feature_list.first() { | ||
if first.is_default() { | ||
default_feature_len = first.subfeature_len(); | ||
} | ||
} | ||
} | ||
|
||
FeaturesPage { | ||
metadata: cexpect!(req, MetaData::from_crate(&mut conn, &name, &version)), | ||
features, | ||
feature_len, | ||
default_feature_len, | ||
} | ||
.into_response(req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{%- extends "base.html" -%} | ||
{%- import "header/package_navigation.html" as navigation -%} | ||
|
||
{%- block title -%} | ||
{{ macros::doc_title(name=metadata.name, version=metadata.version) }} | ||
{%- endblock title -%} | ||
|
||
{%- block topbar -%} | ||
{%- set latest_version = "" -%} | ||
{%- set latest_path = "" -%} | ||
{%- set target = "" -%} | ||
{%- set inner_path = metadata.target_name ~ "/index.html" -%} | ||
{%- set is_latest_version = true -%} | ||
{%- set is_prerelease = false -%} | ||
{%- include "rustdoc/topbar.html" -%} | ||
{%- endblock topbar -%} | ||
|
||
{%- block header -%} | ||
{{ navigation::package_navigation(metadata=metadata, active_tab="features") }} | ||
{%- endblock header -%} | ||
|
||
{%- block body -%} | ||
<div class="container package-page-container"> | ||
<div class="pure-g"> | ||
<div class="pure-u-1 pure-u-sm-7-24 pure-u-md-5-24"> | ||
<div class="pure-menu package-menu"> | ||
<ul class="pure-menu-list"> | ||
<li class="pure-menu-heading">Feature flags</li> | ||
{%- if features -%} | ||
{%- for feature in features -%} | ||
<li class="pure-menu-item"> | ||
<a href="#{{ feature.name }}" class="pure-menu-link" style="text-align:center;"> | ||
{{ feature.name }} | ||
</a> | ||
</li> | ||
{%- endfor -%} | ||
{%- else -%} | ||
<li class="pure-menu-item"> | ||
<span style="font-size: 13px;">Feature flags are not available for this version.</span> | ||
</li> | ||
{%- endif -%} | ||
</ul> | ||
</div> | ||
</div> | ||
|
||
<div class="pure-u-1 pure-u-sm-17-24 pure-u-md-19-24 package-details" id="main"> | ||
<h1>{{ metadata.name }}</h1> | ||
{%- if features -%} | ||
<p>This version has <b>{{ feature_len }}</b> feature flags, <b>{{ default_feature_len }}</b> of them being enabled by <b>default</b>.</p> | ||
{%- for feature in features -%} | ||
<h3 id="{{ feature.name }}">{{ feature.name }}</h3> | ||
<ul class="pure-menu-list"> | ||
{%- if feature.subfeatures -%} | ||
{%- for subfeature in feature.subfeatures -%} | ||
<li class="pure-menu-item"> | ||
<span>{{ subfeature }}</span> | ||
</li> | ||
{%- endfor -%} | ||
{%- else -%} | ||
<p>This feature flag do not enable additional features.</p> | ||
{%- endif -%} | ||
</ul> | ||
{%- endfor -%} | ||
{%- else -%} | ||
<p>Feature flags are not available for this version.</p> | ||
{%- endif -%} | ||
</div> | ||
</div> | ||
</div> | ||
{%- endblock body -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.