inital no-js frontend
This commit is contained in:
parent
38f04320f0
commit
253de6ff13
17 changed files with 13 additions and 488 deletions
|
@ -86,7 +86,6 @@ async fn main() {
|
|||
.service(router::index) // index page
|
||||
.service(server::routes::search::search) // search page
|
||||
.service(router::about) // about page
|
||||
.service(router::settings) // settings page
|
||||
.default_service(web::route().to(router::not_found)) // error page
|
||||
})
|
||||
// Start server on 127.0.0.1 with the user provided port number. for example 127.0.0.1:8080.
|
||||
|
|
|
@ -2,11 +2,8 @@
|
|||
//! meta search engine website and provide appropriate response to each route/page
|
||||
//! when requested.
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
handler::{file_path, FileType},
|
||||
};
|
||||
use actix_web::{get, http::header::ContentType, web, HttpRequest, HttpResponse};
|
||||
use crate::handler::{file_path, FileType};
|
||||
use actix_web::{get, http::header::ContentType, HttpRequest, HttpResponse};
|
||||
use tokio::fs::read_to_string;
|
||||
|
||||
/// Handles the route of index page or main page of the `crabbysearch` meta search engine website.
|
||||
|
@ -42,21 +39,3 @@ pub async fn about() -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
|||
.content_type(ContentType::html())
|
||||
.body(crate::templates::views::about::about().0))
|
||||
}
|
||||
|
||||
/// Handles the route of settings page of the `crabbysearch` meta search engine website.
|
||||
#[get("/settings")]
|
||||
pub async fn settings(
|
||||
config: web::Data<Config>,
|
||||
) -> Result<HttpResponse, Box<dyn std::error::Error>> {
|
||||
Ok(HttpResponse::Ok().content_type(ContentType::html()).body(
|
||||
crate::templates::views::settings::settings(
|
||||
&config
|
||||
.upstream_search_engines
|
||||
.list()
|
||||
.iter()
|
||||
.map(|n| (*n, true))
|
||||
.collect(),
|
||||
)?
|
||||
.0,
|
||||
))
|
||||
}
|
||||
|
|
|
@ -14,10 +14,15 @@ use maud::{html, Markup, PreEscaped};
|
|||
/// It returns the compiled html code for the search bar as a result.
|
||||
pub fn bar(query: &str) -> Markup {
|
||||
html!(
|
||||
(PreEscaped("<div class=\"search_bar\">"))
|
||||
input type="search" name="search-box" value=(query) placeholder="Type to search";
|
||||
button type="submit" onclick="searchWeb()" {
|
||||
img src="./images/magnifying_glass.svg" alt="Info icon for error box";
|
||||
.search_container {
|
||||
(PreEscaped("<div class=\"search_bar\">"))
|
||||
form action="/search" method="get" {
|
||||
input type="search" name="query" value=(query) placeholder="Type to search";
|
||||
input type="hidden" name="page" value="0";
|
||||
button type="submit" {
|
||||
img src="./images/magnifying_glass.svg" alt="Info icon for error box";
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,5 +4,3 @@ pub mod bar;
|
|||
pub mod footer;
|
||||
pub mod header;
|
||||
pub mod navbar;
|
||||
pub mod search_bar;
|
||||
pub mod settings_tabs;
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
//! A module that handles `search bar` partial for the search page in the `crabbysearch` frontend.
|
||||
|
||||
use maud::{html, Markup, PreEscaped};
|
||||
|
||||
use crate::{models::aggregation_models::EngineErrorInfo, templates::partials::bar::bar};
|
||||
|
||||
/// A constant holding the named safe search level options for the corresponding values 0, 1 and 2.
|
||||
const SAFE_SEARCH_LEVELS_NAME: [&str; 3] = ["None", "Low", "Moderate"];
|
||||
|
||||
/// A functions that handles the html code for the search bar for the search page.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `engine_errors_info` - It takes the engine errors list containing errors for each upstream
|
||||
/// search engine which failed to provide results as an argument.
|
||||
/// * `safe_search_level` - It takes the safe search level with values from 0-2 as an argument.
|
||||
/// * `query` - It takes the current search query provided by user as an argument.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// It returns the compiled html code for the search bar as a result.
|
||||
pub fn search_bar(
|
||||
engine_errors_info: &[EngineErrorInfo],
|
||||
safe_search_level: u8,
|
||||
query: &str,
|
||||
) -> Markup {
|
||||
html!(
|
||||
.search_area{
|
||||
(bar(query))
|
||||
.error_box {
|
||||
@if !engine_errors_info.is_empty(){
|
||||
button onclick="toggleErrorBox()" class="error_box_toggle_button"{
|
||||
img src="./images/warning.svg" alt="Info icon for error box";
|
||||
}
|
||||
.dropdown_error_box{
|
||||
@for errors in engine_errors_info{
|
||||
.error_item{
|
||||
span class="engine_name"{(errors.engine)}
|
||||
span class="engine_name"{(errors.error)}
|
||||
span class="severity_color" style="background: {{{this.severity_color}}};"{}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@else {
|
||||
button onclick="toggleErrorBox()" class="error_box_toggle_button"{
|
||||
img src="./images/info.svg" alt="Warning icon for error box";
|
||||
}
|
||||
.dropdown_error_box {
|
||||
.no_errors{
|
||||
"Everything looks good 🙂!!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(PreEscaped("</div>"))
|
||||
.search_options {
|
||||
@if safe_search_level >= 3 {
|
||||
(PreEscaped("<select name=\"safe_search_levels\" disabled>"))
|
||||
}
|
||||
@else{
|
||||
(PreEscaped("<select name=\"safe_search_levels\">"))
|
||||
}
|
||||
@for (idx, name) in SAFE_SEARCH_LEVELS_NAME.iter().enumerate() {
|
||||
@if (safe_search_level as usize) == idx {
|
||||
option value=(idx) selected {(format!("SafeSearch: {name}"))}
|
||||
}
|
||||
@else{
|
||||
option value=(idx) {(format!("SafeSearch: {name}"))}
|
||||
}
|
||||
}
|
||||
(PreEscaped("</select>"))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
//! A module that handles the engines tab for setting page view in the `crabbysearch` frontend.
|
||||
|
||||
use maud::{html, Markup};
|
||||
|
||||
/// A functions that handles the html code for the cookies tab for the settings page for the search page.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// It returns the compiled html markup code for the cookies tab.
|
||||
pub fn cookies() -> Markup {
|
||||
html!(
|
||||
div class="cookies tab"{
|
||||
h1{"Cookies"}
|
||||
p class="description"{
|
||||
"This is the cookies are saved on your system and it contains the preferences
|
||||
you chose in the settings page"
|
||||
}
|
||||
input type="text" name="cookie_field" value="" readonly;
|
||||
p class="description"{
|
||||
"The cookies stored are not used by us for any malicious intend or for
|
||||
tracking you in any way."
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
//! A module that handles the engines tab for setting page view in the `crabbysearch` frontend.
|
||||
|
||||
use maud::{html, Markup};
|
||||
|
||||
/// A functions that handles the html code for the engines tab for the settings page for the search page.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `engine_names` - It takes the key value pair list of all available engine names and there corresponding
|
||||
/// selected (enabled/disabled) value as an argument.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// It returns the compiled html markup code for the engines tab.
|
||||
pub fn engines(engine_names: &Vec<(&str, bool)>) -> Markup {
|
||||
html!(
|
||||
div class="engines tab"{
|
||||
h1{"Engines"}
|
||||
h3{"select search engines"}
|
||||
p class="description"{
|
||||
"Select the search engines from the list of engines that you want results from"
|
||||
}
|
||||
.engine_selection{
|
||||
// Checks whether all the engines are selected or not if they are then the
|
||||
// checked `select_all` button is rendered otherwise the unchecked version
|
||||
// is rendered.
|
||||
@if engine_names.iter().all(|selected| selected.1){
|
||||
.toggle_btn{
|
||||
label class="switch"{
|
||||
input type="checkbox" class="select_all" onchange="toggleAllSelection()" checked;
|
||||
span class="slider round"{}
|
||||
}
|
||||
"Select All"
|
||||
}
|
||||
}
|
||||
@else{
|
||||
.toggle_btn {
|
||||
label class="switch"{
|
||||
input type="checkbox" class="select_all" onchange="toggleAllSelection()";
|
||||
span class="slider round"{}
|
||||
}
|
||||
"Select All"
|
||||
}
|
||||
}
|
||||
hr;
|
||||
@for (engine_name, selected) in engine_names{
|
||||
// Checks whether the `engine_name` is selected or not if they are then the
|
||||
// checked `engine` button is rendered otherwise the unchecked version is
|
||||
// rendered.
|
||||
@if *selected {
|
||||
.toggle_btn{
|
||||
label class="switch"{
|
||||
input type="checkbox" class="engine" checked;
|
||||
span class="slider round"{}
|
||||
}
|
||||
(format!("{}{}",&engine_name[..1].to_uppercase(), &engine_name[1..]))
|
||||
}
|
||||
}
|
||||
@else {
|
||||
.toggle_btn {
|
||||
label class="switch"{
|
||||
input type="checkbox" class="engine";
|
||||
span class="slider round"{}
|
||||
}
|
||||
(format!("{}{}",&engine_name[..1], &engine_name[1..]))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
//! This module provides other modules to handle the partials for the tabs for the settings page
|
||||
//! view in the `crabbysearch` frontend.
|
||||
|
||||
pub mod cookies;
|
||||
pub mod engines;
|
|
@ -5,4 +5,3 @@ pub mod about;
|
|||
pub mod index;
|
||||
pub mod not_found;
|
||||
pub mod search;
|
||||
pub mod settings;
|
||||
|
|
|
@ -4,7 +4,7 @@ use maud::{html, Markup, PreEscaped};
|
|||
|
||||
use crate::{
|
||||
models::aggregation_models::SearchResults,
|
||||
templates::partials::{footer::footer, header::header, search_bar::search_bar},
|
||||
templates::partials::{bar::bar, footer::footer, header::header},
|
||||
};
|
||||
|
||||
/// A function that handles the html code for the search page view in the search engine frontend.
|
||||
|
@ -23,7 +23,7 @@ pub fn search(query: &str, search_results: &SearchResults) -> Markup {
|
|||
html!(
|
||||
(header())
|
||||
main class="results"{
|
||||
(search_bar(&search_results.engine_errors_info, search_results.safe_search_level, query))
|
||||
(bar(query))
|
||||
.results_aggregated{
|
||||
@if !search_results.results.is_empty() {
|
||||
@for result in search_results.results.iter(){
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
//! A module that handles the view for the settings page in the `crabbysearch` frontend.
|
||||
|
||||
use maud::{html, Markup};
|
||||
|
||||
use crate::templates::partials::{
|
||||
footer::footer,
|
||||
header::header,
|
||||
settings_tabs::{cookies::cookies, engines::engines},
|
||||
};
|
||||
|
||||
/// A function that handles the html code for the settings page view in the search engine frontend.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `safe_search_level` - It takes the safe search level as an argument.
|
||||
/// * `colorscheme` - It takes the colorscheme name as an argument.
|
||||
/// * `theme` - It takes the theme name as an argument.
|
||||
/// * `animation` - It takes the animation name as an argument.
|
||||
/// * `engine_names` - It takes a list of engine names as an argument.
|
||||
///
|
||||
/// # Error
|
||||
///
|
||||
/// This function returns a compiled html markup code on success otherwise returns a standard error
|
||||
/// message.
|
||||
pub fn settings(
|
||||
engine_names: &Vec<(&'static str, bool)>,
|
||||
) -> Result<Markup, Box<dyn std::error::Error>> {
|
||||
Ok(html!(
|
||||
(header())
|
||||
main class="settings"{
|
||||
h1{"Settings"}
|
||||
hr;
|
||||
.settings_container{
|
||||
.sidebar{
|
||||
div class="btn active" onclick="setActiveTab(this)"{"general"}
|
||||
.btn onclick="setActiveTab(this)"{"user interface"}
|
||||
.btn onclick="setActiveTab(this)"{"engines"}
|
||||
.btn onclick="setActiveTab(this)"{"cookies"}
|
||||
}
|
||||
.main_container{
|
||||
(engines(&engine_names))
|
||||
(cookies())
|
||||
p class="message"{}
|
||||
button type="submit" onclick="setClientSettings()"{"Save"}
|
||||
}
|
||||
}
|
||||
}
|
||||
script src="static/settings.js"{}
|
||||
script src="static/cookies.js"{}
|
||||
(footer())
|
||||
))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue