From f0f265f59e3b8917444df8bc4785a4ba1a31cf41 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Thu, 14 Oct 2021 21:25:19 +0530 Subject: [PATCH] submit benchmark --- src/middleware/auth.rs | 28 +++------ src/pages/panel/campaigns/bench.rs | 13 +++- templates/api/v1/routes.ts | 1 + templates/bench/index.html | 23 +++++-- templates/bench/index.ts | 62 ++++++++++++++++--- templates/bench/service-worker.ts | 8 +-- templates/bench/types.ts | 19 ++++-- templates/components/error/error.test.ts | 54 +++++++++++++++++ templates/components/error/index.html | 12 ++-- templates/components/error/index.ts | 77 ++++++++++++++++++++++++ templates/components/error/main.scss | 42 ++++++++----- templates/components/error/setUpTests.ts | 25 ++++++++ templates/main.scss | 1 + templates/utils/genJsonPayload.test.ts | 36 +++++++++++ templates/utils/genJsonPayload.ts | 29 +++++++++ templates/utils/isBlankString.test.ts | 36 +++++++++++ templates/utils/isBlankString.ts | 32 ++++++++++ 17 files changed, 437 insertions(+), 61 deletions(-) create mode 100644 templates/components/error/error.test.ts create mode 100644 templates/components/error/index.ts create mode 100644 templates/components/error/setUpTests.ts create mode 100644 templates/utils/genJsonPayload.test.ts create mode 100644 templates/utils/genJsonPayload.ts create mode 100644 templates/utils/isBlankString.test.ts create mode 100644 templates/utils/isBlankString.ts diff --git a/src/middleware/auth.rs b/src/middleware/auth.rs index 392fae4..742aae6 100644 --- a/src/middleware/auth.rs +++ b/src/middleware/auth.rs @@ -94,27 +94,19 @@ where fn call(&self, req: ServiceRequest) -> Self::Future { let (r, mut pl) = req.into_parts(); let mut is_authenticated = || match self.session_type { - AuthenticatedSession::ActixSession => { - if let Ok(Ok(Some(_))) = Session::from_request(&r, &mut pl) + AuthenticatedSession::ActixSession => matches!( + Session::from_request(&r, &mut pl) .into_inner() - .map(|x| x.get::(SURVEY_USER_ID)) - { - true - } else { - false - } - } + .map(|x| x.get::(SURVEY_USER_ID)), + Ok(Ok(Some(_))) + ), - AuthenticatedSession::ActixIdentity => { - if let Ok(Some(_)) = Identity::from_request(&r, &mut pl) + AuthenticatedSession::ActixIdentity => matches!( + Identity::from_request(&r, &mut pl) .into_inner() - .map(|x| x.identity()) - { - true - } else { - false - } - } + .map(|x| x.identity()), + Ok(Some(_)) + ), }; if is_authenticated() { let req = ServiceRequest::from_parts(r, pl); diff --git a/src/pages/panel/campaigns/bench.rs b/src/pages/panel/campaigns/bench.rs index 62557a6..7726310 100644 --- a/src/pages/panel/campaigns/bench.rs +++ b/src/pages/panel/campaigns/bench.rs @@ -23,13 +23,22 @@ use sailfish::TemplateOnce; use uuid::Uuid; use crate::errors::*; +use crate::pages::errors::ErrorPage; use crate::PAGES; -#[derive(TemplateOnce, Default)] +#[derive(TemplateOnce)] #[template(path = "bench/index.html")] -struct Bench; +struct Bench<'a> { + error: Option>, +} const PAGE: &str = "Survey"; +impl<'a> Default for Bench<'a> { + fn default() -> Self { + Bench { error: None } + } +} + lazy_static! { static ref BENCH: String = Bench::default().render_once().unwrap(); } diff --git a/templates/api/v1/routes.ts b/templates/api/v1/routes.ts index 9e4f4bf..8789e5e 100644 --- a/templates/api/v1/routes.ts +++ b/templates/api/v1/routes.ts @@ -17,6 +17,7 @@ const ROUTES = { register: "/survey/api/v1/benches/register", + submitBench: (key: string): string => `/survey/api/v1/benches/${key}/submit`, }; export default ROUTES; diff --git a/templates/bench/index.html b/templates/bench/index.html index 30860c2..320cf51 100644 --- a/templates/bench/index.html +++ b/templates/bench/index.html @@ -1,10 +1,26 @@ <. include!("../components/base/top.html"); .>
+<. include!("../components/error/index.html"); .>

Click to Start Benchmark

+
+ - + + +