Spaces:
Runtime error
Runtime error
neon_arch
commited on
Commit
โข
b7a23f1
1
Parent(s):
3446820
๐ธ chore: add code to display saved settings from the config on the settings page (#461)
Browse files
src/templates/partials/settings_tabs/engines.rs
CHANGED
@@ -1,17 +1,20 @@
|
|
1 |
//! A module that handles the engines tab for setting page view in the `websurfx` frontend.
|
2 |
|
|
|
|
|
3 |
use maud::{html, Markup};
|
4 |
|
5 |
/// A functions that handles the html code for the engines tab for the settings page for the search page.
|
6 |
///
|
7 |
/// # Arguments
|
8 |
///
|
9 |
-
/// * `engine_names` - It takes the list of all available engine names
|
|
|
10 |
///
|
11 |
/// # Returns
|
12 |
///
|
13 |
/// It returns the compiled html markup code for the engines tab.
|
14 |
-
pub fn engines(engine_names: &
|
15 |
html!(
|
16 |
div class="engines tab"{
|
17 |
h1{"Engines"}
|
@@ -20,21 +23,49 @@ pub fn engines(engine_names: &[&String]) -> Markup {
|
|
20 |
"Select the search engines from the list of engines that you want results from"
|
21 |
}
|
22 |
.engine_selection{
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
hr;
|
31 |
-
@for engine_name in engine_names{
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
-
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
38 |
}
|
39 |
}
|
40 |
}
|
|
|
1 |
//! A module that handles the engines tab for setting page view in the `websurfx` frontend.
|
2 |
|
3 |
+
use std::collections::HashMap;
|
4 |
+
|
5 |
use maud::{html, Markup};
|
6 |
|
7 |
/// A functions that handles the html code for the engines tab for the settings page for the search page.
|
8 |
///
|
9 |
/// # Arguments
|
10 |
///
|
11 |
+
/// * `engine_names` - It takes the key value pair list of all available engine names and there corresponding
|
12 |
+
/// selected (enabled/disabled) value as an argument.
|
13 |
///
|
14 |
/// # Returns
|
15 |
///
|
16 |
/// It returns the compiled html markup code for the engines tab.
|
17 |
+
pub fn engines(engine_names: &HashMap<String, bool>) -> Markup {
|
18 |
html!(
|
19 |
div class="engines tab"{
|
20 |
h1{"Engines"}
|
|
|
23 |
"Select the search engines from the list of engines that you want results from"
|
24 |
}
|
25 |
.engine_selection{
|
26 |
+
// Checks whether all the engines are selected or not if they are then the
|
27 |
+
// checked `select_all` button is rendered otherwise the unchecked version
|
28 |
+
// is rendered.
|
29 |
+
@if engine_names.values().all(|selected| *selected == true){
|
30 |
+
.toggle_btn{
|
31 |
+
label class="switch"{
|
32 |
+
input type="checkbox" class="select_all" onchange="toggleAllSelection()" checked;
|
33 |
+
span class="slider round"{}
|
34 |
+
}
|
35 |
+
"Select All"
|
36 |
+
}
|
37 |
+
}
|
38 |
+
@else{
|
39 |
+
.toggle_btn {
|
40 |
+
label class="switch"{
|
41 |
+
input type="checkbox" class="select_all" onchange="toggleAllSelection()";
|
42 |
+
span class="slider round"{}
|
43 |
+
}
|
44 |
+
"Select All"
|
45 |
+
}
|
46 |
}
|
47 |
hr;
|
48 |
+
@for (engine_name, selected) in engine_names{
|
49 |
+
// Checks whether the `engine_name` is selected or not if they are then the
|
50 |
+
// checked `engine` button is rendered otherwise the unchecked version is
|
51 |
+
// rendered.
|
52 |
+
@if *selected == true {
|
53 |
+
.toggle_btn{
|
54 |
+
label class="switch"{
|
55 |
+
input type="checkbox" class="engine" checked;
|
56 |
+
span class="slider round"{}
|
57 |
+
}
|
58 |
+
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
59 |
+
}
|
60 |
+
}
|
61 |
+
@else {
|
62 |
+
.toggle_btn {
|
63 |
+
label class="switch"{
|
64 |
+
input type="checkbox" class="engine";
|
65 |
+
span class="slider round"{}
|
66 |
+
}
|
67 |
+
(format!("{}{}",engine_name[..1].to_uppercase().to_owned(), engine_name[1..].to_owned()))
|
68 |
}
|
|
|
69 |
}
|
70 |
}
|
71 |
}
|
src/templates/partials/settings_tabs/general.rs
CHANGED
@@ -7,10 +7,14 @@ const SAFE_SEARCH_LEVELS: [(u8, &str); 3] = [(0, "None"), (1, "Low"), (2, "Moder
|
|
7 |
|
8 |
/// A functions that handles the html code for the general tab for the settings page for the search page.
|
9 |
///
|
|
|
|
|
|
|
|
|
10 |
/// # Returns
|
11 |
///
|
12 |
/// It returns the compiled html markup code for the general tab.
|
13 |
-
pub fn general() -> Markup {
|
14 |
html!(
|
15 |
div class="general tab active"{
|
16 |
h1{"General"}
|
@@ -18,9 +22,19 @@ pub fn general() -> Markup {
|
|
18 |
p class="description"{
|
19 |
"Select a safe search level from the menu below to filter content based on the level."
|
20 |
}
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
}
|
26 |
}
|
|
|
7 |
|
8 |
/// A functions that handles the html code for the general tab for the settings page for the search page.
|
9 |
///
|
10 |
+
/// # Arguments
|
11 |
+
///
|
12 |
+
/// * `safe_search_level` - It takes the safe search level as an argument.
|
13 |
+
///
|
14 |
/// # Returns
|
15 |
///
|
16 |
/// It returns the compiled html markup code for the general tab.
|
17 |
+
pub fn general(safe_search_level: u8) -> Markup {
|
18 |
html!(
|
19 |
div class="general tab active"{
|
20 |
h1{"General"}
|
|
|
22 |
p class="description"{
|
23 |
"Select a safe search level from the menu below to filter content based on the level."
|
24 |
}
|
25 |
+
@if safe_search_level < 3 {
|
26 |
+
select name="safe_search_levels" {
|
27 |
+
// Sets the user selected safe_search_level name from the config file as the first option in the selection list.
|
28 |
+
option value=(safe_search_level){(SAFE_SEARCH_LEVELS.iter().filter(|level| level.0 == safe_search_level).next().unwrap().1)}
|
29 |
+
@for (k,v) in SAFE_SEARCH_LEVELS.iter().filter(|level| level.0 != safe_search_level){
|
30 |
+
option value=(k){(v)}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
}
|
34 |
+
@else {
|
35 |
+
p class="admin_warning" {"โ ๏ธ This setting is being managed by the server administrator."}
|
36 |
+
select name="safe_search_levels" disabled {
|
37 |
+
option value=(SAFE_SEARCH_LEVELS[2].0){(SAFE_SEARCH_LEVELS[2].1)}
|
38 |
}
|
39 |
}
|
40 |
}
|
src/templates/partials/settings_tabs/user_interface.rs
CHANGED
@@ -4,13 +4,16 @@ use crate::handler::{file_path, FileType};
|
|
4 |
use maud::{html, Markup};
|
5 |
use std::fs::read_dir;
|
6 |
|
7 |
-
/// A helper function that helps in building the list of all available colorscheme/theme
|
8 |
-
/// present in the colorschemes and themes folder respectively
|
|
|
9 |
///
|
10 |
/// # Arguments
|
11 |
///
|
12 |
/// * `style_type` - It takes the style type of the values `theme` and `colorscheme` as an
|
13 |
/// argument.
|
|
|
|
|
14 |
///
|
15 |
/// # Error
|
16 |
///
|
@@ -18,7 +21,8 @@ use std::fs::read_dir;
|
|
18 |
/// returns a standard error message.
|
19 |
fn style_option_list(
|
20 |
style_type: &str,
|
21 |
-
|
|
|
22 |
let mut style_option_names: Vec<(String, String)> = Vec::new();
|
23 |
for file in read_dir(format!(
|
24 |
"{}static/{}/",
|
@@ -26,7 +30,13 @@ fn style_option_list(
|
|
26 |
style_type,
|
27 |
))? {
|
28 |
let style_name = file?.file_name().to_str().unwrap().replace(".css", "");
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
}
|
31 |
|
32 |
Ok(style_option_names)
|
@@ -38,7 +48,11 @@ fn style_option_list(
|
|
38 |
///
|
39 |
/// It returns the compiled html markup code for the user interface tab on success otherwise
|
40 |
/// returns a standard error message.
|
41 |
-
pub fn user_interface(
|
|
|
|
|
|
|
|
|
42 |
Ok(html!(
|
43 |
div class="user_interface tab"{
|
44 |
h1{"User Interface"}
|
@@ -47,7 +61,9 @@ pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
|
|
47 |
"Select the theme from the available themes to be used in user interface"
|
48 |
}
|
49 |
select name="themes"{
|
50 |
-
|
|
|
|
|
51 |
option value=(k){(v)}
|
52 |
}
|
53 |
}
|
@@ -56,7 +72,9 @@ pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
|
|
56 |
"Select the color scheme for your theme to be used in user interface"
|
57 |
}
|
58 |
select name="colorschemes"{
|
59 |
-
|
|
|
|
|
60 |
option value=(k){(v)}
|
61 |
}
|
62 |
}
|
@@ -65,12 +83,12 @@ pub fn user_interface() -> Result<Markup, Box<dyn std::error::Error>> {
|
|
65 |
"Select the animation for your theme to be used in user interface"
|
66 |
}
|
67 |
select name="animations"{
|
68 |
-
option
|
69 |
-
|
|
|
70 |
option value=(k){(v)}
|
71 |
}
|
72 |
}
|
73 |
-
|
74 |
}
|
75 |
))
|
76 |
}
|
|
|
4 |
use maud::{html, Markup};
|
5 |
use std::fs::read_dir;
|
6 |
|
7 |
+
/// A helper function that helps in building the list of all available colorscheme/theme/animation
|
8 |
+
/// names present in the colorschemes, animations and themes folder respectively by excluding the
|
9 |
+
/// ones that have already been selected via the config file.
|
10 |
///
|
11 |
/// # Arguments
|
12 |
///
|
13 |
/// * `style_type` - It takes the style type of the values `theme` and `colorscheme` as an
|
14 |
/// argument.
|
15 |
+
/// * `selected_style` - It takes the currently selected style value provided via the config file
|
16 |
+
/// as an argument.
|
17 |
///
|
18 |
/// # Error
|
19 |
///
|
|
|
21 |
/// returns a standard error message.
|
22 |
fn style_option_list(
|
23 |
style_type: &str,
|
24 |
+
selected_style: &str,
|
25 |
+
) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> {
|
26 |
let mut style_option_names: Vec<(String, String)> = Vec::new();
|
27 |
for file in read_dir(format!(
|
28 |
"{}static/{}/",
|
|
|
30 |
style_type,
|
31 |
))? {
|
32 |
let style_name = file?.file_name().to_str().unwrap().replace(".css", "");
|
33 |
+
if selected_style != style_name {
|
34 |
+
style_option_names.push((style_name.clone(), style_name.replace('-', " ")));
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
if style_type == "animations" {
|
39 |
+
style_option_names.push(("".to_owned(), "none".to_owned()))
|
40 |
}
|
41 |
|
42 |
Ok(style_option_names)
|
|
|
48 |
///
|
49 |
/// It returns the compiled html markup code for the user interface tab on success otherwise
|
50 |
/// returns a standard error message.
|
51 |
+
pub fn user_interface(
|
52 |
+
theme: &str,
|
53 |
+
colorscheme: &str,
|
54 |
+
animation: &Option<String>,
|
55 |
+
) -> Result<Markup, Box<dyn std::error::Error>> {
|
56 |
Ok(html!(
|
57 |
div class="user_interface tab"{
|
58 |
h1{"User Interface"}
|
|
|
61 |
"Select the theme from the available themes to be used in user interface"
|
62 |
}
|
63 |
select name="themes"{
|
64 |
+
// Sets the user selected theme name from the config file as the first option in the selection list.
|
65 |
+
option value=(theme){(theme.replace('-', " "))}
|
66 |
+
@for (k,v) in style_option_list("themes", theme)?{
|
67 |
option value=(k){(v)}
|
68 |
}
|
69 |
}
|
|
|
72 |
"Select the color scheme for your theme to be used in user interface"
|
73 |
}
|
74 |
select name="colorschemes"{
|
75 |
+
// Sets the user selected colorscheme name from the config file as the first option in the selection list.
|
76 |
+
option value=(colorscheme){(colorscheme.replace('-', " "))}
|
77 |
+
@for (k,v) in style_option_list("colorschemes", colorscheme)?{
|
78 |
option value=(k){(v)}
|
79 |
}
|
80 |
}
|
|
|
83 |
"Select the animation for your theme to be used in user interface"
|
84 |
}
|
85 |
select name="animations"{
|
86 |
+
// Sets the user selected animation name from the config file as the first option in the selection list.
|
87 |
+
option value=(animation.as_ref().unwrap_or(&"".to_owned())){(animation.as_ref().unwrap_or(&"".to_owned()).replace('-'," "))}
|
88 |
+
@for (k,v) in style_option_list("animations", &animation.as_ref().unwrap_or(&"".to_owned()))?{
|
89 |
option value=(k){(v)}
|
90 |
}
|
91 |
}
|
|
|
92 |
}
|
93 |
))
|
94 |
}
|
src/templates/views/settings.rs
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
//! A module that handles the view for the settings page in the `websurfx` frontend.
|
2 |
|
|
|
|
|
3 |
use maud::{html, Markup};
|
4 |
|
5 |
use crate::templates::partials::{
|
@@ -14,8 +16,10 @@ use crate::templates::partials::{
|
|
14 |
///
|
15 |
/// # Arguments
|
16 |
///
|
|
|
17 |
/// * `colorscheme` - It takes the colorscheme name as an argument.
|
18 |
/// * `theme` - It takes the theme name as an argument.
|
|
|
19 |
/// * `engine_names` - It takes a list of engine names as an argument.
|
20 |
///
|
21 |
/// # Error
|
@@ -23,10 +27,11 @@ use crate::templates::partials::{
|
|
23 |
/// This function returns a compiled html markup code on success otherwise returns a standard error
|
24 |
/// message.
|
25 |
pub fn settings(
|
|
|
26 |
colorscheme: &str,
|
27 |
theme: &str,
|
28 |
animation: &Option<String>,
|
29 |
-
engine_names: &
|
30 |
) -> Result<Markup, Box<dyn std::error::Error>> {
|
31 |
Ok(html!(
|
32 |
(header(colorscheme, theme, animation))
|
@@ -41,8 +46,8 @@ pub fn settings(
|
|
41 |
.btn onclick="setActiveTab(this)"{"cookies"}
|
42 |
}
|
43 |
.main_container{
|
44 |
-
(general())
|
45 |
-
(user_interface()?)
|
46 |
(engines(engine_names))
|
47 |
(cookies())
|
48 |
p class="message"{}
|
|
|
1 |
//! A module that handles the view for the settings page in the `websurfx` frontend.
|
2 |
|
3 |
+
use std::collections::HashMap;
|
4 |
+
|
5 |
use maud::{html, Markup};
|
6 |
|
7 |
use crate::templates::partials::{
|
|
|
16 |
///
|
17 |
/// # Arguments
|
18 |
///
|
19 |
+
/// * `safe_search_level` - It takes the safe search level as an argument.
|
20 |
/// * `colorscheme` - It takes the colorscheme name as an argument.
|
21 |
/// * `theme` - It takes the theme name as an argument.
|
22 |
+
/// * `animation` - It takes the animation name as an argument.
|
23 |
/// * `engine_names` - It takes a list of engine names as an argument.
|
24 |
///
|
25 |
/// # Error
|
|
|
27 |
/// This function returns a compiled html markup code on success otherwise returns a standard error
|
28 |
/// message.
|
29 |
pub fn settings(
|
30 |
+
safe_search_level: u8,
|
31 |
colorscheme: &str,
|
32 |
theme: &str,
|
33 |
animation: &Option<String>,
|
34 |
+
engine_names: &HashMap<String, bool>,
|
35 |
) -> Result<Markup, Box<dyn std::error::Error>> {
|
36 |
Ok(html!(
|
37 |
(header(colorscheme, theme, animation))
|
|
|
46 |
.btn onclick="setActiveTab(this)"{"cookies"}
|
47 |
}
|
48 |
.main_container{
|
49 |
+
(general(safe_search_level))
|
50 |
+
(user_interface(theme, colorscheme, animation)?)
|
51 |
(engines(engine_names))
|
52 |
(cookies())
|
53 |
p class="message"{}
|