feat: port benchmark page to tera
This commit is contained in:
parent
82d293a159
commit
e5bf7feebe
2 changed files with 165 additions and 154 deletions
|
@ -14,46 +14,55 @@
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
use std::str::FromStr;
|
use std::cell::RefCell;
|
||||||
|
|
||||||
|
use actix_web::http::header::ContentType;
|
||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
use lazy_static::lazy_static;
|
use tera::Context;
|
||||||
use my_codegen::get;
|
|
||||||
use sailfish::TemplateOnce;
|
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::errors::*;
|
use crate::AppData;
|
||||||
use crate::pages::errors::ErrorPage;
|
|
||||||
use crate::PAGES;
|
use crate::PAGES;
|
||||||
|
|
||||||
#[derive(TemplateOnce)]
|
pub use super::*;
|
||||||
#[template(path = "bench/index.html")]
|
|
||||||
struct Bench<'a> {
|
|
||||||
error: Option<ErrorPage<'a>>,
|
|
||||||
}
|
|
||||||
const PAGE: &str = "Survey";
|
|
||||||
|
|
||||||
impl<'a> Default for Bench<'a> {
|
pub struct Bench {
|
||||||
fn default() -> Self {
|
ctx: RefCell<Context>,
|
||||||
Bench { error: None }
|
}
|
||||||
|
|
||||||
|
pub const BENCH: TemplateFile = TemplateFile::new("new_campaign", "bench/index.html");
|
||||||
|
|
||||||
|
impl CtxError for Bench {
|
||||||
|
fn with_error(&self, e: &ReadableError) -> String {
|
||||||
|
self.ctx.borrow_mut().insert(ERROR_KEY, e);
|
||||||
|
self.render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
impl Bench {
|
||||||
static ref BENCH: String = Bench::default().render_once().unwrap();
|
pub fn new(settings: &Settings) -> Self {
|
||||||
|
let ctx = RefCell::new(context(settings, "Login"));
|
||||||
|
Self { ctx }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn render(&self) -> String {
|
||||||
|
TEMPLATES.render(BENCH.name, &self.ctx.borrow()).unwrap()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
#[actix_web_codegen_const_routes::get(
|
||||||
path = "PAGES.panel.campaigns.bench",
|
path = "PAGES.panel.campaigns.bench",
|
||||||
wrap = "crate::api::v1::bench::get_check_login()"
|
wrap = "crate::api::v1::bench::get_check_login()"
|
||||||
)]
|
)]
|
||||||
pub async fn bench(path: web::Path<String>) -> PageResult<impl Responder> {
|
pub async fn bench(
|
||||||
let path = path.into_inner();
|
data: AppData,
|
||||||
|
_path: web::Path<Uuid>,
|
||||||
match Uuid::from_str(&path) {
|
) -> PageResult<impl Responder, Bench> {
|
||||||
Err(_) => Err(PageError::PageDoesntExist),
|
let bench = Bench::new(&data.settings).render();
|
||||||
Ok(_) => Ok(HttpResponse::Ok()
|
let html = ContentType::html();
|
||||||
.content_type("text/html; charset=utf-8")
|
Ok(HttpResponse::Ok().content_type(html).body(bench))
|
||||||
.body(&*BENCH.as_str())),
|
}
|
||||||
}
|
|
||||||
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
cfg.service(bench);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
<. include!("../components/base/top.html"); .>
|
{% extends 'base' %}
|
||||||
<body class="survey__body">
|
{% block body %}
|
||||||
|
<body class="survey__body">
|
||||||
<main class="survey__container">
|
<main class="survey__container">
|
||||||
<. include!("../components/error/index.html"); .>
|
{% include "error_comp" %}
|
||||||
|
|
||||||
<div id="pre-bench">
|
<div id="pre-bench">
|
||||||
<h1>Click to Start Benchmark</h1>
|
<h1>Click to Start Benchmark</h1>
|
||||||
<form class="new-campaign__form" accept-charset="utf-8">
|
<form class="new-campaign__form" accept-charset="utf-8">
|
||||||
|
@ -61,9 +63,8 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<. include!("../components/footer/index.html"); .>
|
</body>
|
||||||
</body>
|
<style>
|
||||||
<style>
|
|
||||||
body {
|
body {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -138,6 +139,7 @@
|
||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
font-family: monospace, monospace;
|
font-family: monospace, monospace;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="<.= &*crate::GLUE .>"></script>
|
|
||||||
<. include!("../components/base/bottom.html"); .>
|
<script src="{{ assets.glue }}"></script>
|
||||||
|
{% endblock body %}
|
||||||
|
|
Loading…
Reference in a new issue