1use crate::read_ebml::read_ebml;
11use crate::read_ebml::Process;
12use crate::write_ebml::get_process_folder_name;
13
14use std::fs::File;
15use std::path::{PathBuf,Path};
16use std::fs::{self,OpenOptions,metadata};
17use std::io::{self,Write};
18use std::env;
19
20pub struct Library {
36
37 name: String,
39
40 all_processes: Vec<Process>,
42}
43
44fn _list_files(vec: &mut Vec<PathBuf>, path: &Path) -> io::Result<()> {
62 if metadata(&path)?.is_dir() {
63 let paths = fs::read_dir(&path)?;
64 for path_result in paths {
65 let full_path = path_result?.path();
66 if metadata(&full_path)?.is_dir() {
67 let path_str = &full_path.as_os_str();
68 match path_str.to_str() {
69 Some("./assets") => (),
70 Some(".\\assets") => (),
71 Some("./assets-old") => (),
72 Some(".\\assets-old") => (),
73 Some("./assets-organizations") => (),
74 Some(".\\assets-organizations") => (),
75 _ => vec.push(full_path),
76 }
77 }
78 }
79 }
80 Ok(())
81}
82
83fn list_files(path: &Path) -> io::Result<Vec<PathBuf>> {
85 let mut vec = Vec::new();
86 _list_files(&mut vec,&path)?;
87 Ok(vec)
88}
89
90fn find_name_of_library() -> String {
94 let exe = env::current_exe().expect("Naw1");
95 exe.parent().expect("NawX").file_name().expect("Naw1").to_str().expect("Naw2").to_string()
96}
97
98pub fn find_all_process_folders(dir:&str) -> Vec<PathBuf> {
100 list_files(Path::new(dir)).expect("that's not a good path?")
101}
102
103pub fn generate_complete_webmenu(verbose:&bool) {
111
112 if *verbose { print!("\n[A] Attempting to edit WebMenu.html..."); }
114 let mut html_file = OpenOptions::new()
115 .read(true)
116 .write(true)
117 .create(true)
118 .truncate(true)
119 .open("./WebMenu.html")
120 .expect("cannot open file");
121 if *verbose { print!("success! WebMenu.html is open for editing.\n"); }
122
123 if *verbose { print!("[B] Attempting to create new Library struct..."); }
124 let mut new_library = Library::new();
125 if *verbose { print!("success! New Library struct created.\n"); }
126
127 if *verbose { print!("[C] Attempting to change the name of the Library to this folder's name...")}
128 new_library.set_name(&find_name_of_library().as_str());
129 if *verbose { print!("success! New name: {}\n",new_library.get_name()); }
130
131 if *verbose { print!("[D] Attempting list of all folders (excluding 'assets')..."); }
132 let list_of_process_folders = find_all_process_folders(".");
133 if *verbose { for folder in &list_of_process_folders { println!("{}",folder.file_name().expect("No bueno?").to_str().expect("Really bueno?").to_string());} }
134 if *verbose { print!("success! Folders found, now look for files to process:\n"); }
135 for folder in list_of_process_folders {
136 let folder_string = folder.file_name().expect("No bueno?").to_str().expect("Really bueno?").to_string();
137 if *verbose { print!("\t{}",&folder_string); }
138 let new_ebml_str = folder_string.clone() + "/" + &folder_string + ".ebml";
139 if *verbose { print!("\n\t\t-> {}",&new_ebml_str); }
140 let new_process = read_ebml(&("./".to_owned()+&new_ebml_str));
141 if *verbose { print!("\n\t\t-> processed "); }
142 new_library.add_process(new_process);
143 if *verbose { print!("\n\t\t-> added to Library\n"); }
144 }
145
146 if *verbose { print!("[E] Attempting to write the top of the HTML file..."); }
147 compose_top_of_webmenu(&mut html_file);
148 if *verbose { print!("success!\n"); }
149
150 if *verbose { print!("[F] Attempting to write the head of the HTML file, including all CSS and Javascript..."); }
151 compose_head_of_webmenu(&mut html_file,&new_library);
152 if *verbose { print!("success!\n"); }
153
154 if *verbose { print!("[G] Attempting to write the body of the HTML file, including everything that appears on screen..."); }
155 compose_body_of_webmenu(&mut html_file,&new_library);
156 if *verbose { print!("success!\n"); }
157
158
159 if *verbose { print!("[H] Attempting to write the bottom of the HTML file..."); }
160 compose_bottom_of_webmenu(&mut html_file);
161 if *verbose { print!("success!\n"); }
162
163 if *verbose { print!("\n\n"); new_library.display(); print!("\n\n"); }
164}
165
166fn compose_top_of_webmenu(f:&mut File) {
168 f.write(b"<!DOCTYPE html>\n").expect("write failed");
169 f.write(b"<html lang=\"en-US\">\n").expect("write failed");
170}
171
172fn compose_head_of_webmenu(f:&mut File, lib:&Library) {
178 f.write(b"\t<head>\n").expect("write failed");
179 f.write(b"\t\t<meta charset=\"utf-8\" />\n").expect("write failed");
180 f.write(b"\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=1\" />\n").expect("write failed");
181 f.write(b"\t\t<style>\n").expect("write failed");
182 f.write(b"\t\t\t
183 @media print { .no-print, .no-print * { display: none !important; } br { display:none !important; } table { font-size: 0.5em; } }
184 body { font-family: sans-serif; padding: 0px; margin: 0px;}
185 #pre-header { padding: 15px; border: 15px solid #BA6F47; background-color: #BEA465; color: #2F495A; text-align: center; font-size: 0.7em; }
186 header { z-index: 100; border-bottom: 3px solid black; background-color: #2F495A; color: white; position: sticky; top:0px;}
187 header, main { padding: 20px; margin:0px;}
188 table { margin-top: 20px; }
189
190 input + span { margin: 0px 5px 0px 5px; }
191
192 .doc-box { display:inline-block; padding: 1px; border: 1px solid black; margin: 2px; width: 25px; }
193 .doc-icon { width: 25px; height: 25px; overflow: hidden; position: relative; }
194 .doc-format img { position: absolute; height: 25px; left: 0px; }
195
196 input { z-index: 0; margin: 0px 5px 0px 5px; transform: scale(1.3);}
197
198 .doc-box { display:inline-block; padding: 1px; border: 1px solid black; margin: 2px; width: 25px; }
199 .doc-icon { width: 25px; height: 25px; overflow: hidden; position: relative; }
200 .doc-format img { position: absolute; height: 25px; left: 0px; }
201
202 .toggle-column-01:not(:checked) ~ table th:nth-child(1) { display: none; }
203 .toggle-column-01:not(:checked) ~ table td:nth-child(1) { display: none; }
204
205 .toggle-column-02:not(:checked) ~ table th:nth-child(2) { display: none; }
206 .toggle-column-02:not(:checked) ~ table td:nth-child(2) { display: none; }
207
208 .toggle-column-03:not(:checked) ~ table th:nth-child(3) { display: none; }
209 .toggle-column-03:not(:checked) ~ table td:nth-child(3) { display: none; }
210
211 .toggle-column-04:not(:checked) ~ table th:nth-child(4) { display: none; }
212 .toggle-column-04:not(:checked) ~ table td:nth-child(4) { display: none; }
213
214 .toggle-column-05:not(:checked) ~ table th:nth-child(5) { display: none; }
215 .toggle-column-05:not(:checked) ~ table td:nth-child(5) { display: none; }
216
217 .toggle-column-06:not(:checked) ~ table th:nth-child(6) { display: none; }
218 .toggle-column-06:not(:checked) ~ table td:nth-child(6) { display: none; }
219
220 .toggle-column-07:not(:checked) ~ table th:nth-child(7) { display: none; }
221 .toggle-column-07:not(:checked) ~ table td:nth-child(7) { display: none; }
222
223 .toggle-column-08:not(:checked) ~ table th:nth-child(8) { display: none; }
224 .toggle-column-08:not(:checked) ~ table td:nth-child(8) { display: none; }
225
226 .toggle-column-09:not(:checked) ~ table th:nth-child(9) { display: none; }
227 .toggle-column-09:not(:checked) ~ table td:nth-child(9) { display: none; }
228
229 .toggle-column-10:not(:checked) ~ table th:nth-child(10) { display: none; }
230 .toggle-column-10:not(:checked) ~ table td:nth-child(10) { display: none; }
231
232 .toggle-column-11:not(:checked) ~ table th:nth-child(11) { display: none; }
233 .toggle-column-11:not(:checked) ~ table td:nth-child(11) { display: none; }
234
235 .toggle-column-12:not(:checked) ~ table th:nth-child(12) { display: none; }
236 .toggle-column-12:not(:checked) ~ table td:nth-child(12) { display: none; }
237
238 .toggle-column-13:not(:checked) ~ table th:nth-child(13) { display: none; }
239 .toggle-column-13:not(:checked) ~ table td:nth-child(13) { display: none; }
240
241 .toggle-column-14:not(:checked) ~ table th:nth-child(14) { display: none; }
242 .toggle-column-14:not(:checked) ~ table td:nth-child(14) { display: none; }
243
244 .toggle-column-15:not(:checked) ~ table th:nth-child(15) { display: none; }
245 .toggle-column-15:not(:checked) ~ table td:nth-child(15) { display: none; }
246
247 .toggle-column-16:not(:checked) ~ table th:nth-child(16) { display: none; }
248 .toggle-column-16:not(:checked) ~ table td:nth-child(16) { display: none; }
249
250 .toggle-column-17:not(:checked) ~ table th:nth-child(17) { display: none; }
251 .toggle-column-17:not(:checked) ~ table td:nth-child(17) { display: none; }
252
253 .toggle-column-18:not(:checked) ~ table th:nth-child(18) { display: none; }
254 .toggle-column-18:not(:checked) ~ table td:nth-child(18) { display: none; }
255
256 .toggle-column-19:not(:checked) ~ table th:nth-child(19) { display: none; }
257 .toggle-column-19:not(:checked) ~ table td:nth-child(19) { display: none; }
258
259 .toggle-column-20:not(:checked) ~ table th:nth-child(20) { display: none; }
260 .toggle-column-20:not(:checked) ~ table td:nth-child(20) { display: none; }
261
262 .toggle-column-21:not(:checked) ~ table th:nth-child(21) { display: none; }
263 .toggle-column-21:not(:checked) ~ table td:nth-child(21) { display: none; }
264
265 .toggle-column-22:not(:checked) ~ table th:nth-child(22) { display: none; }
266 .toggle-column-22:not(:checked) ~ table td:nth-child(22) { display: none; }
267
268 .toggle-column-23:not(:checked) ~ table th:nth-child(23) { display: none; }
269 .toggle-column-23:not(:checked) ~ table td:nth-child(23) { display: none; }
270
271 .toggle-column-24:not(:checked) ~ table th:nth-child(24) { display: none; }
272 .toggle-column-24:not(:checked) ~ table td:nth-child(24) { display: none; }
273
274 .toggle-column-25:not(:checked) ~ table th:nth-child(25) { display: none; }
275 .toggle-column-25:not(:checked) ~ table td:nth-child(25) { display: none; }
276
277 .toggle-column-26:not(:checked) ~ table th:nth-child(26) { display: none; }
278 .toggle-column-26:not(:checked) ~ table td:nth-child(26) { display: none; }
279
280 .toggle-column-27:not(:checked) ~ table th:nth-child(27) { display: none; }
281 .toggle-column-27:not(:checked) ~ table td:nth-child(27) { display: none; }
282
283 .toggle-column-28:not(:checked) ~ table th:nth-child(28) { display: none; }
284 .toggle-column-28:not(:checked) ~ table td:nth-child(28) { display: none; }
285
286 .toggle-column-29:not(:checked) ~ table th:nth-child(29) { display: none; }
287 .toggle-column-29:not(:checked) ~ table td:nth-child(29) { display: none; }
288 \n").expect("write failed");
289 f.write(b"\t\t\ttable { border-collapse: collapse; }
290 \t\tth, td { padding: 0.4em; border: 1px solid black;}
291 \t\tth { background-color: black; color: white; }
292 \t\tth[role=columnheader]:not(.no-sort) { cursor: pointer; }
293 \t\tth[role=columnheader]:not(.no-sort):after {
294 \t\t content: '';
295 \t\t float: right;
296 \t\t margin-top: 7px;
297 \t\t margin-left: 5px;
298 \t\t border-width: 0 4px 4px;
299 \t\t border-style: solid;
300 \t\t border-color: white transparent;
301 \t\t visibility: hidden;
302 \t\t opacity: 0;
303 \t\t -ms-user-select: none;
304 \t\t -webkit-user-select: none;
305 \t\t -moz-user-select: none;
306 \t\t user-select: none;
307 \t\t}
308 \t\tth[aria-sort=ascending]:not(.no-sort):after { border-bottom: none; border-width: 4px 4px 0; }
309 \t\tth[aria-sort]:not(.no-sort):after { visibility: visible; opacity: 0.4; }
310 \t\tth[role=columnheader]:not(.no-sort):hover:after { visibility: visible; opacity: 1; }\n").expect("write failed");
311 f.write(b"\t\t</style>\n").expect("write failed");
312
313 f.write(b"\t\t<script>\n").expect("write failed");
315 f.write(b"\t\t\t!function(){function a(b,c){if(!(this instanceof a))return new a(b,c);if(!b||\"TABLE\"!==b.tagName)throw new Error(\"Element must be a table\");this.init(b,c||{})}var b=[],c=function(a){var b;return window.CustomEvent&&\"function\"==typeof window.CustomEvent?b=new CustomEvent(a):(b=document.createEvent(\"CustomEvent\"),b.initCustomEvent(a,!1,!1,void 0)),b},d=function(a){return a.getAttribute(\"data-sort\")||a.textContent||a.innerText||\"\"},e=function(a,b){return a=a.trim().toLowerCase(),b=b.trim().toLowerCase(),a===b?0:a<b?1:-1},f=function(a,b){return function(c,d){var e=a(c.td,d.td);return 0===e?b?d.index-c.index:c.index-d.index:e}};a.extend=function(a,c,d){if(\"function\"!=typeof c||\"function\"!=typeof d)throw new Error(\"Pattern and sort must be a function\");b.push({name:a,pattern:c,sort:d})},a.prototype={init:function(a,b){var c,d,e,f,g=this;if(g.table=a,g.thead=!1,g.options=b,a.rows&&a.rows.length>0)if(a.tHead&&a.tHead.rows.length>0){for(e=0;e<a.tHead.rows.length;e++)if(\"thead\"===a.tHead.rows[e].getAttribute(\"data-sort-method\")){c=a.tHead.rows[e];break}c||(c=a.tHead.rows[a.tHead.rows.length-1]),g.thead=!0}else c=a.rows[0];if(c){var h=function(){g.current&&g.current!==this&&g.current.removeAttribute(\"aria-sort\"),g.current=this,g.sortTable(this)};for(e=0;e<c.cells.length;e++)f=c.cells[e],f.setAttribute(\"role\",\"columnheader\"),\"none\"!==f.getAttribute(\"data-sort-method\")&&(f.tabindex=0,f.addEventListener(\"click\",h,!1),null!==f.getAttribute(\"data-sort-default\")&&(d=f));d&&(g.current=d,g.sortTable(d))}},sortTable:function(a,g){var h=this,i=a.cellIndex,j=e,k=\"\",l=[],m=h.thead?0:1,n=a.getAttribute(\"data-sort-method\"),o=a.getAttribute(\"aria-sort\");if(h.table.dispatchEvent(c(\"beforeSort\")),g||(o=\"ascending\"===o?\"descending\":\"descending\"===o?\"ascending\":h.options.descending?\"descending\":\"ascending\",a.setAttribute(\"aria-sort\",o)),!(h.table.rows.length<2)){if(!n){for(;l.length<3&&m<h.table.tBodies[0].rows.length;)k=d(h.table.tBodies[0].rows[m].cells[i]),k=k.trim(),k.length>0&&l.push(k),m++;if(!l)return}for(m=0;m<b.length;m++)if(k=b[m],n){if(k.name===n){j=k.sort;break}}else if(l.every(k.pattern)){j=k.sort;break}for(h.col=i,m=0;m<h.table.tBodies.length;m++){var p,q=[],r={},s=0,t=0;if(!(h.table.tBodies[m].rows.length<2)){for(p=0;p<h.table.tBodies[m].rows.length;p++)k=h.table.tBodies[m].rows[p],\"none\"===k.getAttribute(\"data-sort-method\")?r[s]=k:q.push({tr:k,td:d(k.cells[h.col]),index:s}),s++;for(\"descending\"===o?q.sort(f(j,!0)):(q.sort(f(j,!1)),q.reverse()),p=0;p<s;p++)r[p]?(k=r[p],t++):k=q[p-t].tr,h.table.tBodies[m].appendChild(k)}}h.table.dispatchEvent(c(\"afterSort\"))}},refresh:function(){void 0!==this.current&&this.sortTable(this.current,!0)}},\"undefined\"!=typeof module&&module.exports?module.exports=a:window.Tablesort=a}();\n").expect("write failed");
316 f.write(b"\t\t</script>\n").expect("write failed");
317
318 f.write(b"\t\t<script>\n").expect("write failed");
320 f.write(b"\t\t\tfunction onPageReady() {\n").expect("write failed");
321 f.write(b"\t\t\t\tnew Tablesort(document.getElementById('library'));\n").expect("write failed");
322 f.write(b"\t\t\t}\n").expect("write failed");
323 f.write(b"\t\t\tdocument.addEventListener('DOMContentLoaded', onPageReady, false);\n").expect("write failed");
324 f.write(b"\t\t</script>\n").expect("write failed");
325
326 f.write(b"\t\t<link rel=\"shortcut icon\" sizes=\"16x16 32x32 48x48\" type=\"image/png\" href=\"./assets/favicon.png\" />\n").expect("write failed");
327 f.write(b"\t\t<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"./assets/favicon.png\" />\n").expect("write failed");
328 f.write(b"\t\t<link rel=\"mask-icon\" href=\"./assets/favicon.svg\" color=\"#000000\" />\n").expect("write failed");
329 let temp_str = String::from("\t\t<title>📚 ") + &lib.get_name() + " 📚</title>\n";
330 f.write(temp_str.as_bytes()).expect("write failed");
331 f.write(b"\t</head>\n").expect("write failed");
332}
333
334fn compose_body_of_webmenu(f:&mut File, lib:&Library) {
339 f.write(b"\t<body>\n").expect("write failed");
340 compose_body_header(f,lib);
341 compose_body_table(f,lib);
342 compose_body_footer(f,lib);
343 f.write(b"\t</body>\n").expect("write failed");
344}
345
346fn compose_body_header(f:&mut File, lib:&Library) {
348 f.write(b"\t\t<div id=\"pre-header\" class=\"no-print\"><h1>Contact Strativus Group for help of any kind! For example:</h1><h2>📚 Help with your Process Library 📚</h2><h2>📊 Help with Project Management 📊</h2><h2>👥 Help with People-Focused Leadership 👥</h2><h2><span style=\"background-color: #2F495A; color: #BEA465; padding: 10px;\">contact@strativusgroup.com</span></h2></div>\n").expect("write failed");
349 f.write(b"\t\t<header>\n").expect("write failed");
350 let temp_str = String::from("\t\t\t<h1>") + &lib.get_name() + "</h1>\n";
351 f.write(temp_str.as_bytes()).expect("write failed");
352 let temp_str = String::from("\t\t\t<p>Process Library with ") + &lib.get_all_processes().len().to_string() + " processes.</p>\n";
353 f.write(temp_str.as_bytes()).expect("write failed");
354 f.write(b"\t\t</header>\n").expect("write failed");
355}
356
357fn compose_body_table(f:&mut File, lib:&Library) {
361 f.write(b"\t\t<main>\n").expect("write failed");
362 f.write(b"\t\t\t<h2 class=\"no-print\">Process metadata columns to show in the table below:</h2>\n").expect("write failed");
363 f.write(b"\t\t\t<input class=\"toggle-column-01 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Links</span><br/>\n").expect("write failed");
364 f.write(b"\t\t\t<input class=\"toggle-column-02 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Document Number</span><br/>\n").expect("write failed");
365 f.write(b"\t\t\t<input class=\"toggle-column-03 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Templates</span><br/>\n").expect("write failed");
366 f.write(b"\t\t\t<input class=\"toggle-column-04 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Templates</span><br/>\n").expect("write failed");
367 f.write(b"\t\t\t<input class=\"toggle-column-05 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Current Revision</span><br/>\n").expect("write failed");
368 f.write(b"\t\t\t<input class=\"toggle-column-06 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Title</span><br/>\n").expect("write failed");
369 f.write(b"\t\t\t<input class=\"toggle-column-07 no-print\" type=\"checkbox\" ><span class=\"no-print\">Subject</span><br/>\n").expect("write failed");
370 f.write(b"\t\t\t<input class=\"toggle-column-08 no-print\" type=\"checkbox\" ><span class=\"no-print\">Product</span><br/>\n").expect("write failed");
371 f.write(b"\t\t\t<input class=\"toggle-column-09 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Author</span><br/>\n").expect("write failed");
372 f.write(b"\t\t\t<input class=\"toggle-column-10 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Reviewer</span><br/>\n").expect("write failed");
373 f.write(b"\t\t\t<input class=\"toggle-column-11 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Number of Objectives</span><br/>\n").expect("write failed");
374 f.write(b"\t\t\t<input class=\"toggle-column-12 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Objectives</span><br/>\n").expect("write failed");
375 f.write(b"\t\t\t<input class=\"toggle-column-13 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Out of Scope Declarations</span><br/>\n").expect("write failed");
376 f.write(b"\t\t\t<input class=\"toggle-column-14 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Out of Scope Declarations</span><br/>\n").expect("write failed");
377 f.write(b"\t\t\t<input class=\"toggle-column-15 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Sections</span><br/>\n").expect("write failed");
378 f.write(b"\t\t\t<input class=\"toggle-column-16 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Section References</span><br/>\n").expect("write failed");
379 f.write(b"\t\t\t<input class=\"toggle-column-17 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Steps</span><br/>\n").expect("write failed");
380 f.write(b"\t\t\t<input class=\"toggle-column-18 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Requirement Verifications</span><br/>\n").expect("write failed");
381 f.write(b"\t\t\t<input class=\"toggle-column-19 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Requirement Verifications</span><br/>\n").expect("write failed");
382 f.write(b"\t\t\t<input class=\"toggle-column-20 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Resources</span><br/>\n").expect("write failed");
383 f.write(b"\t\t\t<input class=\"toggle-column-21 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Resources</span><br/>\n").expect("write failed");
384 f.write(b"\t\t\t<input class=\"toggle-column-22 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Calibrated Resources</span><br/>\n").expect("write failed");
385 f.write(b"\t\t\t<input class=\"toggle-column-23 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Calibrated Resources</span><br/>\n").expect("write failed");
386 f.write(b"\t\t\t<input class=\"toggle-column-24 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Context/Comment Lines</span><br/>\n").expect("write failed");
387 f.write(b"\t\t\t<input class=\"toggle-column-25 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Command Lines</span><br/>\n").expect("write failed");
388 f.write(b"\t\t\t<input class=\"toggle-column-26 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Number of Unique Images</span><br/>\n").expect("write failed");
389 f.write(b"\t\t\t<input class=\"toggle-column-27 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Images</span><br/>\n").expect("write failed");
390 f.write(b"\t\t\t<input class=\"toggle-column-28 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Number of Missing Images</span><br/>\n").expect("write failed");
391 f.write(b"\t\t\t<input class=\"toggle-column-29 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Missing Images</span><br/>\n").expect("write failed");
392
393 f.write(b"\t\t\t<h2 class=\"no-print\">Click on any column header to sort ascending/descending.</h2>\n").expect("write failed");
394
395 f.write(b"\t\t\t<table id=\"library\">\n").expect("write failed");
396 f.write(b"\t\t\t\t<thead>\n").expect("write failed");
397 f.write(b"\t\t\t\t\t<tr data-sort-method=\"none\">\n").expect("write failed");
398 f.write(b"\t\t\t\t\t\t<th class=\"col01 no-print\">Links</th>\n").expect("write failed");
399 f.write(b"\t\t\t\t\t\t<th class=\"col02\">Number</th>\n").expect("write failed");
400 f.write(b"\t\t\t\t\t\t<th class=\"col03\">CSS</th>\n").expect("write failed");
401 f.write(b"\t\t\t\t\t\t<th class=\"col04\">Templates</th>\n").expect("write failed");
402 f.write(b"\t\t\t\t\t\t<th class=\"col05\">Rev</th>\n").expect("write failed");
403 f.write(b"\t\t\t\t\t\t<th class=\"col06\">Title</th>\n").expect("write failed");
404 f.write(b"\t\t\t\t\t\t<th class=\"col07\">Subject</th>\n").expect("write failed");
405 f.write(b"\t\t\t\t\t\t<th class=\"col08\">Product</th>\n").expect("write failed");
406 f.write(b"\t\t\t\t\t\t<th class=\"col09\">Author</th>\n").expect("write failed");
407 f.write(b"\t\t\t\t\t\t<th class=\"col10\">Reviewer</th>\n").expect("write failed");
408 f.write(b"\t\t\t\t\t\t<th class=\"col11\">OBJ</th>\n").expect("write failed");
409 f.write(b"\t\t\t\t\t\t<th class=\"col12\">Objectives</th>\n").expect("write failed");
410 f.write(b"\t\t\t\t\t\t<th class=\"col13\">OOS</th>\n").expect("write failed");
411 f.write(b"\t\t\t\t\t\t<th class=\"col14\">Out of Scope Declarations</th>\n").expect("write failed");
412 f.write(b"\t\t\t\t\t\t<th class=\"col15\">SEC</th>\n").expect("write failed");
413 f.write(b"\t\t\t\t\t\t<th class=\"col16\">SECREF</th>\n").expect("write failed");
414 f.write(b"\t\t\t\t\t\t<th class=\"col17\">STP</th>\n").expect("write failed");
415 f.write(b"\t\t\t\t\t\t<th class=\"col18\">VER</th>\n").expect("write failed");
416 f.write(b"\t\t\t\t\t\t<th class=\"col19\">Requirement Verifications</th>\n").expect("write failed");
417 f.write(b"\t\t\t\t\t\t<th class=\"col20\">RES</th>\n").expect("write failed");
418 f.write(b"\t\t\t\t\t\t<th class=\"col21\">Resources</th>\n").expect("write failed");
419 f.write(b"\t\t\t\t\t\t<th class=\"col22\">CAL</th>\n").expect("write failed");
420 f.write(b"\t\t\t\t\t\t<th class=\"col23\">Calibrated Resources</th>\n").expect("write failed");
421 f.write(b"\t\t\t\t\t\t<th class=\"col24\">TXT</th>\n").expect("write failed");
422 f.write(b"\t\t\t\t\t\t<th class=\"col25\">CMD</th>\n").expect("write failed");
423 f.write(b"\t\t\t\t\t\t<th class=\"col26\">IMG</th>\n").expect("write failed");
424 f.write(b"\t\t\t\t\t\t<th class=\"col27\">All Images</th>\n").expect("write failed");
425 f.write(b"\t\t\t\t\t\t<th class=\"col28\">IMG?</th>\n").expect("write failed");
426 f.write(b"\t\t\t\t\t\t<th class=\"col29\">Missing Images</th>\n").expect("write failed");
427 f.write(b"\t\t\t\t\t</tr>\n").expect("write failed");
428 f.write(b"\t\t\t\t</thead>\n").expect("write failed");
429 f.write(b"\t\t\t\t<tbody>\n").expect("write failed");
430 for proc in lib.get_all_processes() {
431 f.write(b"\t\t\t\t\t<tr>\n").expect("write failed");
432
433 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col01 no-print\">
435 <a href=\"") + &get_process_folder_name(&proc) + "/" + &get_process_folder_name(&proc) + ".ebml\"><div class=\"doc-box\" style=\"background-color: #DDD;\"><div class=\"doc-icon\"><div class=\"doc-format\"><img src=\"./assets/EBML.png\" alt=\"EBML\"/></div></div></div></a>
436 <a href=\"" + &get_process_folder_name(&proc) + "/" + &get_process_folder_name(&proc) + ".html\"><div class=\"doc-box\" style=\"background-color: #DDD;\"><div class=\"doc-icon\"><div class=\"doc-format\"><img src=\"./assets/html.png\" alt=\"HTML\"/></div></div></div></a>
437 <a href=\"" + &get_process_folder_name(&proc) + "/" + &get_process_folder_name(&proc) + ".pdf\"><div class=\"doc-box\" style=\"background-color: #DDD;\"><div class=\"doc-icon\"><div class=\"doc-format\"><img src=\"./assets/pdf.png\" alt=\"PDF\"/></div></div></div></a>
438 </td>\n";
439 f.write(temp_str.as_bytes()).expect("write failed");
440
441 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col02\">") + proc.get_number() + "</td>\n";
442 f.write(temp_str.as_bytes()).expect("write failed");
443
444 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col03\">") + &format!("{:03}",&proc.get_all_templates().len()) + "</td>\n";
445 f.write(temp_str.as_bytes()).expect("write failed");
446
447 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col04\"><ul>\n");
448 f.write(temp_str.as_bytes()).expect("write failed");
449 let all_templates = proc.get_all_templates();
450 if all_templates.len() > 0 {
451 for template in all_templates {
452 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &template + "</li>\n";
453 f.write(temp_str.as_bytes()).expect("write failed");
454 }
455 }
456 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
457 f.write(temp_str.as_bytes()).expect("write failed");
458
459 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col05\">") + proc.get_revision() + "</td>\n";
460 f.write(temp_str.as_bytes()).expect("write failed");
461
462 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col06\">") + proc.get_title() + "</td>\n";
463 f.write(temp_str.as_bytes()).expect("write failed");
464
465 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col07\">") + proc.get_subject() + "</td>\n";
466 f.write(temp_str.as_bytes()).expect("write failed");
467
468 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col08\">") + proc.get_product() + "</td>\n";
469 f.write(temp_str.as_bytes()).expect("write failed");
470
471 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col09\">") + proc.get_author() + "</td>\n";
472 f.write(temp_str.as_bytes()).expect("write failed");
473
474 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col10\">") + proc.get_reviewer() + "</td>\n";
475 f.write(temp_str.as_bytes()).expect("write failed");
476
477 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col11\">") + &format!("{:03}",&proc.get_all_objectives().len()) + "</td>\n";
478 f.write(temp_str.as_bytes()).expect("write failed");
479
480 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col12\"><ul>\n");
481 f.write(temp_str.as_bytes()).expect("write failed");
482 let all_objectives = proc.get_all_objectives();
483 if all_objectives.len() > 0 {
484 for objective in all_objectives {
485 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &objective.0 + "</li>\n";
486 f.write(temp_str.as_bytes()).expect("write failed");
487 }
488 }
489 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
490 f.write(temp_str.as_bytes()).expect("write failed");
491
492 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col13\">") + &format!("{:03}",&proc.get_all_out_of_scopes().len()) + "</td>\n";
493 f.write(temp_str.as_bytes()).expect("write failed");
494
495 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col14\"><ul>\n");
496 f.write(temp_str.as_bytes()).expect("write failed");
497 let all_out_of_scopes = proc.get_all_out_of_scopes();
498 if all_out_of_scopes.len() > 0 {
499 for out_of_scope in all_out_of_scopes {
500 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &out_of_scope.0 + "</li>\n";
501 f.write(temp_str.as_bytes()).expect("write failed");
502 }
503 }
504 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
505 f.write(temp_str.as_bytes()).expect("write failed");
506
507 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col15\">") + &format!("{:03}",&proc.get_all_sections().len()) + "</td>\n";
508 f.write(temp_str.as_bytes()).expect("write failed");
509
510 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col16\">") + &format!("{:03}",&proc.get_section_reference_count()) + "</td>\n";
511 f.write(temp_str.as_bytes()).expect("write failed");
512
513 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col17\">") + &format!("{:03}",&proc.get_step_count()) + "</td>\n";
514 f.write(temp_str.as_bytes()).expect("write failed");
515
516 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col18\">") + &format!("{:03}",&proc.get_all_verifications().len()) + "</td>\n";
517 f.write(temp_str.as_bytes()).expect("write failed");
518
519 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col19\"><ul>\n");
520 f.write(temp_str.as_bytes()).expect("write failed");
521 let all_verifications = proc.get_all_verifications();
522 if all_verifications.len() > 0 {
523 for verification in all_verifications {
524 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &verification.0.get_id() + " (" + &((verification.0.get_method()).chars().nth(0).expect("How does this work?").to_string()) + ")</li>\n";
525 f.write(temp_str.as_bytes()).expect("write failed");
526 }
527 }
528 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
529 f.write(temp_str.as_bytes()).expect("write failed");
530
531 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col20\">") + &format!("{:03}",&proc.get_all_resources().len()) + "</td>\n";
532 f.write(temp_str.as_bytes()).expect("write failed");
533
534 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col21\"><ul>\n");
535 f.write(temp_str.as_bytes()).expect("write failed");
536 let all_resources = proc.get_all_resources();
537 if all_resources.len() > 0 {
538 for resource in all_resources {
539 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &resource.0.get_name() + "</li>\n";
540 f.write(temp_str.as_bytes()).expect("write failed");
541 }
542 }
543 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
544 f.write(temp_str.as_bytes()).expect("write failed");
545
546 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col22\">") + &format!("{:03}",&proc.get_all_calibrated_resources().len()) + "</td>\n";
547 f.write(temp_str.as_bytes()).expect("write failed");
548
549 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col23\"><ul>\n");
550 f.write(temp_str.as_bytes()).expect("write failed");
551 let all_calibrated_resources = proc.get_all_calibrated_resources();
552 if all_calibrated_resources.len() > 0 {
553 for calibrated_resource in all_calibrated_resources {
554 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &calibrated_resource.get_name() + "</li>\n";
555 f.write(temp_str.as_bytes()).expect("write failed");
556 }
557 }
558 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
559 f.write(temp_str.as_bytes()).expect("write failed");
560
561 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col24\">") + &format!("{:03}",&proc.get_all_context_lines().len()) + "</td>\n";
562 f.write(temp_str.as_bytes()).expect("write failed");
563
564 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col25\">") + &format!("{:03}",&proc.get_all_command_lines().len()) + "</td>\n";
565 f.write(temp_str.as_bytes()).expect("write failed");
566
567 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col26\">") + &format!("{:03}",&proc.get_unique_image_count()) + "</td>\n";
568 f.write(temp_str.as_bytes()).expect("write failed");
569
570 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col27\"><ul>\n");
571 f.write(temp_str.as_bytes()).expect("write failed");
572 let all_images = proc.get_all_images();
573 if all_images.len() > 0 {
574 for image in all_images {
575 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &image.0 + "</li>\n";
576 f.write(temp_str.as_bytes()).expect("write failed");
577 }
578 }
579 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
580 f.write(temp_str.as_bytes()).expect("write failed");
581
582 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col28\">") + &format!("{:03}",&proc.get_missing_image_count()) + "</td>\n";
583 f.write(temp_str.as_bytes()).expect("write failed");
584
585 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col29\"><ul>\n");
586 f.write(temp_str.as_bytes()).expect("write failed");
587 let all_missing_images = proc.get_missing_images();
588 if all_missing_images.len() > 0 {
589 for missing_image in all_missing_images {
590 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &missing_image + "</li>\n";
591 f.write(temp_str.as_bytes()).expect("write failed");
592 }
593 }
594 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
595 f.write(temp_str.as_bytes()).expect("write failed");
596
597 f.write(b"\t\t\t\t\t</tr>\n").expect("write failed");
605
606 }
607 f.write(b"\t\t\t\t</tbody>\n").expect("write failed");
608 f.write(b"\t\t\t</table>\n").expect("write failed");
609 f.write(b"\t\t</main>\n").expect("write failed");
610}
611
612fn compose_body_footer(_f:&mut File, _lib:&Library) {}
614
615fn compose_bottom_of_webmenu(f:&mut File) {
617 f.write(b"</html>\n").expect("write failed");
618}
619
620impl Library {
634
635 pub fn new() -> Library {
637 Library {
638 name: "".to_string(),
639 all_processes: vec![],
640 }
641 }
642
643 pub fn get_name(&self) -> &String { &self.name }
645 pub fn get_all_processes(&self) -> &Vec<Process> { &self.all_processes }
647
648 pub fn set_name(&mut self, lib_name: &str) {
650 self.name = String::from(lib_name.trim());
651 }
652
653 pub fn add_process(&mut self, process: Process) {
655 self.all_processes.push(process);
656 }
657
658 pub fn display(&self) {
660 let name = self.get_name();
661 let all_processes = self.get_all_processes();
662 println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
663 println!("XX LIBRARY VISUALIZER XX");
664 println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
665 println!(" -> Name: {}",name);
666 println!(" -> Processes:");
667 for proc in all_processes {
668 println!(" -> {}",proc.get_number());
669 }
670 }
671}
672
673#[cfg(test)]
686mod tests {
687 use super::*;
689 #[test]
711 fn test_find_name_of_library() {
712 println!("result of find_name_of_library() -> {}",find_name_of_library());
713 }
714
715 #[test]
735 fn test_library_new() {
736 Library::new();
737 }
738
739 #[test]
740 fn test_library_get_functions() {
741
742 let lib:Library = Library::new();
743
744 assert_eq!(&lib.name,lib.get_name());
745 println!("struct Library / Result of get_name() -> {:?}",lib.get_name());
746
747 assert!(lib.all_processes.len()==0);
748 assert_eq!(lib.all_processes.len(),lib.get_all_processes().len());
749 let _is_right_type:&Vec<Process> = lib.get_all_processes();
750 println!("struct Library / Result of get_all_processes() -> [it's empty]");
751 }
752
753 #[test]
754 fn test_library_display() {
755 Library::new().display();
756 }
757
758 #[test]
759 fn test_library_set_functions() {
760 let mut lib:Library = Library::new();
761
762 lib.set_name("SET_LIBRARY_NAME");
763 assert_eq!(&lib.name,lib.get_name());
764
765 let proc = Process::new();
766 let number = &proc.get_number().clone();
767 lib.add_process(proc);
768 assert_eq!(lib.get_all_processes()[0].get_number(),number);
769
770 lib.display();
771 }
772
773
774}