Skip to content

Commit

Permalink
index.html improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cofob committed May 14, 2024
1 parent 94a621d commit 2adf049
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/crawler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ pub enum CrawledInstanceStatus {
Unknown,
}

impl CrawledInstanceStatus {
/// Used for sorting values in index.html template.
pub fn as_u8(&self) -> u8 {
match self {
Self::Ok(_) => 3,
Self::TimedOut => 2,
Self::Unknown => 1,
}
}
}

impl std::fmt::Display for CrawledInstanceStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
Expand Down
10 changes: 10 additions & 0 deletions src/routes/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ pub struct IndexTemplate<'a> {
pub services: &'a Vec<CrawledService>,
}

mod filters {
use crate::crawler::CrawledInstance;

pub fn sort_list(l: &[CrawledInstance]) -> ::askama::Result<Vec<CrawledInstance>> {
let mut new = l.to_owned();
new.sort_by(|a, b| b.status.as_u8().cmp(&a.status.as_u8()));
Ok(new)
}
}

#[get("/")]
async fn index(crawler: web::Data<Arc<Crawler>>) -> actix_web::Result<impl Responder> {
let data = crawler.read().await;
Expand Down
7 changes: 4 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ <h1>Fastside [<a href="https://github.com/cofob/fastside">GitHub</a>]</h1>
<ul>
{% for service in services %}
<li><a href="/{{ service.name }}/">{{ service.name }}</a> Aliases: [{% for alias in service.aliases
%}<code>{{ alias }}, </code>{% endfor %}]</li>
%}{% if loop.index != 1 %}, {% endif %}<code>{{ alias }}</code>{% endfor %}]</li>
<ul>
{% for instance in service.instances %}
{% let instances = service.instances|sort_list %}
{% for instance in instances %}
<li>
<a href="{{ instance.url }}">{{ instance.url }}</a> <span>Status:
<code>{{ instance.status }}</code></span>
Expand All @@ -73,4 +74,4 @@ <h1>Fastside [<a href="https://github.com/cofob/fastside">GitHub</a>]</h1>
</div>
</div>
</div>
</body>
</body>

0 comments on commit 2adf049

Please sign in to comment.