diff --git a/src/docs.rs b/src/docs.rs index d25fbf53..8374cf6b 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -34,7 +34,7 @@ pub mod routes { impl Docs { pub const fn new() -> Self { Docs { - home: "/docs", + home: "/docs/", spec: "/docs/openapi.json", assets: "/docs/{_:.*}", } diff --git a/src/pages/panel/sitekey/add.rs b/src/pages/panel/sitekey/add.rs index f7abf022..d7b93fe4 100644 --- a/src/pages/panel/sitekey/add.rs +++ b/src/pages/panel/sitekey/add.rs @@ -28,6 +28,7 @@ pub struct IndexPage<'a> { pub levels: usize, pub form_title: &'a str, pub form_description: &'a str, + pub form_duration: usize, } const COMPONENT: &str = "Add Site Key"; @@ -40,6 +41,7 @@ impl<'a> Default for IndexPage<'a> { levels: 1, form_description: "", form_title: "Add Site Key", + form_duration: 30, } } } diff --git a/templates/panel/add-site-key/form.html b/templates/panel/add-site-key/form.html index 0792c5c8..2409b5ea 100644 --- a/templates/panel/add-site-key/form.html +++ b/templates/panel/add-site-key/form.html @@ -14,6 +14,20 @@ /> + + + <. for level in 1..=levels { .> <. if level == levels { .> <. include!("./add-level.html"); .> diff --git a/templates/panel/add-site-key/form.ts b/templates/panel/add-site-key/form.ts index dc923c82..beb69a2a 100644 --- a/templates/panel/add-site-key/form.ts +++ b/templates/panel/add-site-key/form.ts @@ -15,12 +15,12 @@ * along with this program. If not, see . */ -import CONST from './const'; -import getNumLevels from './levels/getNumLevels'; +import {LEVELS} from './levels'; + import isBlankString from '../../utils/isBlankString'; import getFormUrl from '../../utils/getFormUrl'; import genJsonPayload from '../../utils/genJsonPayload'; -import {LEVELS} from './levels'; +import isNumber from '../../utils/isNumber'; import VIEWS from '../../views/v1/routes'; @@ -55,11 +55,24 @@ const validateDescription = (e: Event) => { isBlankString(val, filed, e); }; +const validateDuration = (e: Event) => { + const duartionElement = document.getElementById('duration'); + const duration = parseInt(duartionElement.value); + if (!isNumber(duration) || Number.isNaN(duration)) { + throw new Error('duration can contain nubers only'); + } + + if (duration <= 0) { + throw new Error('duration must be greater than zero'); + } + return duration; +}; + const submit = async (e: Event) => { e.preventDefault(); validateDescription(e); -// validateLevels(e); + const duration = validateDuration(e); const formUrl = getFormUrl(FORM); @@ -68,6 +81,7 @@ const submit = async (e: Event) => { const payload = { levels: levels, + duration, }; console.debug(`[form submition] json payload: ${JSON.stringify(payload)}`); diff --git a/templates/panel/add-site-key/levels/getLevelFields.ts b/templates/panel/add-site-key/levels/getLevelFields.ts index 21b24ab1..a0153005 100644 --- a/templates/panel/add-site-key/levels/getLevelFields.ts +++ b/templates/panel/add-site-key/levels/getLevelFields.ts @@ -34,11 +34,11 @@ const getLevelFields = (id: number) => { const visitor_threshold = parseInt(visitorElement.value); const difficulty_factor = parseInt(difficultyElement.value); - if (!isNumber(visitor_threshold) || Number.isNaN(visitor_threshold)) { + if (Number.isNaN(visitor_threshold)) { throw new Error('visitor can contain nubers only'); } - if (!isNumber(difficulty_factor) || Number.isNaN(difficulty_factor)) { + if (Number.isNaN(difficulty_factor)) { throw new Error('difficulty can contain nubers only'); } diff --git a/templates/panel/add-site-key/levels/index.ts b/templates/panel/add-site-key/levels/index.ts index c886efee..81ece72a 100644 --- a/templates/panel/add-site-key/levels/index.ts +++ b/templates/panel/add-site-key/levels/index.ts @@ -98,6 +98,7 @@ export const LEVELS = (function() { } return true; } catch (e) { + console.log(e); return false; } },