2023-11-18 21:23:22 +03:00
|
|
|
//! A module that handles the engines tab for setting page view in the `websurfx` frontend.
|
2023-11-17 22:10:06 +03:00
|
|
|
|
2023-12-28 19:54:47 +03:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2023-11-17 22:10:06 +03:00
|
|
|
use maud::{html, Markup};
|
|
|
|
|
2023-11-18 21:23:22 +03:00
|
|
|
/// A functions that handles the html code for the engines tab for the settings page for the search page.
|
2023-11-17 22:10:06 +03:00
|
|
|
///
|
2023-11-18 21:23:22 +03:00
|
|
|
/// # Arguments
|
|
|
|
///
|
2023-12-28 19:54:47 +03:00
|
|
|
/// * `engine_names` - It takes the key value pair list of all available engine names and there corresponding
|
|
|
|
/// selected (enabled/disabled) value as an argument.
|
2023-11-18 21:23:22 +03:00
|
|
|
///
|
|
|
|
/// # Returns
|
|
|
|
///
|
|
|
|
/// It returns the compiled html markup code for the engines tab.
|
2023-12-28 19:54:47 +03:00
|
|
|
pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
|
2023-11-17 22:10:06 +03:00
|
|
|
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{
|
2023-12-28 19:54:47 +03:00
|
|
|
// 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.values().all(|selected| *selected == true){
|
|
|
|
.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"
|
|
|
|
}
|
2023-11-17 22:10:06 +03:00
|
|
|
}
|
|
|
|
hr;
|
2023-12-28 19:54:47 +03:00
|
|
|
@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 == true {
|
|
|
|
.toggle_btn{
|
|
|
|
label class="switch"{
|
|
|
|
input type="checkbox" class="engine" checked;
|
|
|
|
span class="slider round"{}
|
|
|
|
}
|
|
|
|
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@else {
|
|
|
|
.toggle_btn {
|
|
|
|
label class="switch"{
|
|
|
|
input type="checkbox" class="engine";
|
|
|
|
span class="slider round"{}
|
|
|
|
}
|
|
|
|
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
2023-11-17 22:10:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|