XFFXFF commited on
Commit
7f371bf
β€’
2 Parent(s): 11ba09a 2f1fa00

Merge pull request #189 from neon-mmd/feat-error-box-for-engine-errors

Browse files

✨ Error box UI to show which engines failed with several UI improvements

public/images/info.svg ADDED
public/images/no_results.gif ADDED
public/images/warning.svg ADDED
public/static/error_box.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ /**
2
+ * This function provides the ability for the button to toggle the dropdown error-box
3
+ * in the search page.
4
+ */
5
+ function toggleErrorBox() {
6
+ document.querySelector('.dropdown_error_box').classList.toggle('show')
7
+ }
public/static/themes/simple.css CHANGED
@@ -70,15 +70,90 @@ body {
70
  filter: brightness(1.2);
71
  }
72
 
73
- /* styles for the footer and header */
 
 
 
 
 
74
 
75
- header {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  background: var(--background-color);
77
- width: 100%;
 
 
 
 
 
 
 
 
 
78
  display: flex;
79
- justify-content: right;
80
  align-items: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  padding: 1rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  }
83
 
84
  header ul,
@@ -121,13 +196,8 @@ footer div {
121
  }
122
 
123
  footer {
124
- background: var(--background-color);
125
- width: 100%;
126
- padding: 1rem;
127
- display: flex;
128
  flex-direction: column;
129
  justify-content: center;
130
- align-items: center;
131
  }
132
 
133
  /* Styles for the search page */
 
70
  filter: brightness(1.2);
71
  }
72
 
73
+ .result_not_found {
74
+ display: flex;
75
+ flex-direction: column;
76
+ font-size: 1.5rem;
77
+ color: var(--foreground-color);
78
+ }
79
 
80
+ .result_not_found p {
81
+ margin: 1rem 0;
82
+ }
83
+
84
+ .result_not_found ul {
85
+ margin: 1rem 0;
86
+ }
87
+
88
+ .result_not_found img {
89
+ width: 40rem;
90
+ }
91
+
92
+ /* styles for the error box */
93
+ .error_box .error_box_toggle_button {
94
+ background: var(--foreground-color);
95
+ }
96
+
97
+ .error_box .dropdown_error_box {
98
+ position: absolute;
99
+ display: none;
100
+ flex-direction: column;
101
  background: var(--background-color);
102
+ border-radius: 0;
103
+ margin-left: 2rem;
104
+ min-height: 20rem;
105
+ min-width: 22rem;
106
+ }
107
+ .error_box .dropdown_error_box.show {
108
+ display: flex;
109
+ }
110
+ .error_box .dropdown_error_box .error_item,
111
+ .error_box .dropdown_error_box .no_errors {
112
  display: flex;
 
113
  align-items: center;
114
+ color: var(--foreground-color);
115
+ letter-spacing: 0.1rem;
116
+ padding: 1rem;
117
+ font-size: 1.2rem;
118
+ }
119
+ .error_box .dropdown_error_box .error_item {
120
+ justify-content: space-between;
121
+ }
122
+ .error_box .dropdown_error_box .no_errors {
123
+ min-height: 18rem;
124
+ justify-content: center;
125
+ }
126
+
127
+ .error_box .dropdown_error_box .error_item:hover {
128
+ box-shadow: inset 0 0 100px 100px rgba(255, 255, 255, 0.1);
129
+ }
130
+
131
+ .error_box .error_item .severity_color {
132
+ width: 1.2rem;
133
+ height: 1.2rem;
134
+ }
135
+
136
+ /* styles for the footer and header */
137
+
138
+ header,
139
+ footer {
140
+ width: 100%;
141
+ background: var(--background-color);
142
+ display: flex;
143
  padding: 1rem;
144
+ align-items: center;
145
+ }
146
+
147
+ header {
148
+ justify-content: space-between;
149
+ }
150
+
151
+ header h1 a {
152
+ text-transform: capitalize;
153
+ text-decoration: none;
154
+ color: var(--foreground-color);
155
+ letter-spacing: 0.1rem;
156
+ margin-left: 1rem;
157
  }
158
 
159
  header ul,
 
196
  }
197
 
198
  footer {
 
 
 
 
199
  flex-direction: column;
200
  justify-content: center;
 
201
  }
202
 
203
  /* Styles for the search page */
public/templates/bar.html ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ <div class="search_bar">
2
+ <input type="search" name="search-box" value="{{this.pageQuery}}" placeholder="Type to search" />
3
+ <button type="submit" onclick="searchWeb()">search</button>
public/templates/header.html CHANGED
@@ -1,4 +1,4 @@
1
- <!DOCTYPE html>
2
  <html lang="en">
3
 
4
  <head>
@@ -10,5 +10,7 @@
10
  </head>
11
 
12
  <body onload="getClientSettings()">
13
- <header>{{>navbar}}</header>
14
-
 
 
 
1
+ <!doctype html>
2
  <html lang="en">
3
 
4
  <head>
 
10
  </head>
11
 
12
  <body onload="getClientSettings()">
13
+ <header>
14
+ <h1><a href="/">Websurfx</a></h1>
15
+ {{>navbar}}
16
+ </header>
public/templates/index.html CHANGED
@@ -1,7 +1,8 @@
1
  {{>header this}}
2
  <main class="search-container">
3
  <img src="../images/websurfx_logo.png" alt="Websurfx meta-search engine logo" />
4
- {{>search_bar}}
 
5
  </main>
6
  <script src="static/index.js"></script>
7
  {{>footer}}
 
1
  {{>header this}}
2
  <main class="search-container">
3
  <img src="../images/websurfx_logo.png" alt="Websurfx meta-search engine logo" />
4
+ {{>bar}}
5
+ </div>
6
  </main>
7
  <script src="static/index.js"></script>
8
  {{>footer}}
public/templates/search.html CHANGED
@@ -1,8 +1,8 @@
1
  {{>header this.style}}
2
  <main class="results">
3
- {{>search_bar}}
4
  <div class="results_aggregated">
5
- {{#each results}}
6
  <div class="result">
7
  <h1><a href="{{{this.url}}}">{{{this.title}}}</a></h1>
8
  <small>{{{this.url}}}</small>
@@ -13,13 +13,27 @@
13
  {{/each}}
14
  </div>
15
  </div>
16
- {{/each}}
 
 
 
 
 
 
 
 
 
 
 
17
  </div>
18
  <div class="page_navigation">
19
- <button type="button" onclick="navigate_backward()">&#8592; previous</button>
 
 
20
  <button type="button" onclick="navigate_forward()">next &#8594;</button>
21
  </div>
22
  </main>
23
  <script src="static/index.js"></script>
24
  <script src="static/pagination.js"></script>
 
25
  {{>footer}}
 
1
  {{>header this.style}}
2
  <main class="results">
3
+ {{>search_bar this}}
4
  <div class="results_aggregated">
5
+ {{#if results}} {{#each results}}
6
  <div class="result">
7
  <h1><a href="{{{this.url}}}">{{{this.title}}}</a></h1>
8
  <small>{{{this.url}}}</small>
 
13
  {{/each}}
14
  </div>
15
  </div>
16
+ {{/each}} {{else}}
17
+ <div class="result_not_found">
18
+ <p>Your search - {{{this.pageQuery}}} - did not match any documents.</p>
19
+ <p class="suggestions">Suggestions:</p>
20
+ <ul>
21
+ <li>Make sure that all words are spelled correctly.</li>
22
+ <li>Try different keywords.</li>
23
+ <li>Try more general keywords.</li>
24
+ </ul>
25
+ <img src="./images/no_results.gif" alt="Man fishing gif" />
26
+ </div>
27
+ {{/if}}
28
  </div>
29
  <div class="page_navigation">
30
+ <button type="button" onclick="navigate_backward()">
31
+ &#8592; previous
32
+ </button>
33
  <button type="button" onclick="navigate_forward()">next &#8594;</button>
34
  </div>
35
  </main>
36
  <script src="static/index.js"></script>
37
  <script src="static/pagination.js"></script>
38
+ <script src="static/error_box.js"></script>
39
  {{>footer}}
public/templates/search_bar.html CHANGED
@@ -1,9 +1,27 @@
1
- <div class="search_bar">
2
- <input
3
- type="search"
4
- name="search-box"
5
- value="{{this.pageQuery}}"
6
- placeholder="Type to search"
7
- />
8
- <button type="submit" onclick="searchWeb()">search</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  </div>
 
1
+ {{>bar this}}
2
+ <div class="error_box">
3
+ {{#if engineErrorsInfo}}
4
+ <button onclick="toggleErrorBox()" class="error_box_toggle_button">
5
+ <img src="./images/warning.svg" alt="Info icon for error box" />
6
+ </button>
7
+ <div class="dropdown_error_box">
8
+ {{#each engineErrorsInfo}}
9
+ <div class="error_item">
10
+ <span class="engine_name">{{{this.engine}}}</span>
11
+ <span class="engine_name">{{{this.error}}}</span>
12
+ <span class="severity_color" style="background: {{{this.severity_color}}};"></span>
13
+ </div>
14
+ {{/each}}
15
+ </div>
16
+ {{else}}
17
+ <button onclick="toggleErrorBox()" class="error_box_toggle_button">
18
+ <img src="./images/info.svg" alt="Warning icon for error box" />
19
+ </button>
20
+ <div class="dropdown_error_box">
21
+ <div class="no_errors">
22
+ Everything looks good πŸ™‚!!
23
+ </div>
24
+ </div>
25
+ {{/if}}
26
+ </div>
27
  </div>
src/results/aggregation_models.rs CHANGED
@@ -63,10 +63,12 @@ impl SearchResult {
63
  }
64
  }
65
 
 
66
  #[derive(Serialize, Deserialize)]
67
  pub struct EngineErrorInfo {
68
  pub error: String,
69
  pub engine: String,
 
70
  }
71
 
72
  impl EngineErrorInfo {
@@ -78,6 +80,11 @@ impl EngineErrorInfo {
78
  EngineError::UnexpectedError => String::from("UnexpectedError"),
79
  },
80
  engine,
 
 
 
 
 
81
  }
82
  }
83
  }
 
63
  }
64
  }
65
 
66
+ ///
67
  #[derive(Serialize, Deserialize)]
68
  pub struct EngineErrorInfo {
69
  pub error: String,
70
  pub engine: String,
71
+ pub severity_color: String,
72
  }
73
 
74
  impl EngineErrorInfo {
 
80
  EngineError::UnexpectedError => String::from("UnexpectedError"),
81
  },
82
  engine,
83
+ severity_color: match error {
84
+ EngineError::RequestError => String::from("green"),
85
+ EngineError::EmptyResultSet => String::from("blue"),
86
+ EngineError::UnexpectedError => String::from("red"),
87
+ },
88
  }
89
  }
90
  }