survey/src/pages/panel/campaigns/bench.rs

57 lines
1.4 KiB
Rust

// Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::cell::RefCell;
use actix_web::http::header::ContentType;
use actix_web::{web, HttpResponse, Responder};
use tera::Context;
use crate::AppData;
use crate::PAGES;
pub use super::*;
pub struct Bench {
ctx: RefCell<Context>,
}
pub const BENCH: TemplateFile = TemplateFile::new("new_bench", "bench/index.html");
impl CtxError for Bench {
fn with_error(&self, e: &ReadableError) -> String {
self.ctx.borrow_mut().insert(ERROR_KEY, e);
self.render()
}
}
impl Bench {
pub fn new(settings: &Settings) -> Self {
let ctx = RefCell::new(context(settings, "Benchmark"));
Self { ctx }
}
pub fn render(&self) -> String {
TEMPLATES.render(BENCH.name, &self.ctx.borrow()).unwrap()
}
}
#[actix_web_codegen_const_routes::get(
path = "PAGES.panel.campaigns.bench",
wrap = "crate::api::v1::bench::get_check_login()"
)]
pub async fn bench(
data: AppData,
_path: web::Path<uuid::Uuid>,
) -> PageResult<impl Responder, Bench> {
let bench = Bench::new(&data.settings).render();
let html = ContentType::html();
Ok(HttpResponse::Ok().content_type(html).body(bench))
}
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(bench);
}