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 let len = path_str.len();
69 match len {
70 8 => {
71 match path_str.to_str() {
72 Some("./assets") => (),
73 Some(".\\assets") => (),
74 _ => vec.push(full_path),
75 }
76 }
77 _ => vec.push(full_path),
78 };
79 }
80 }
81 }
82 Ok(())
83}
84
85fn list_files(path: &Path) -> io::Result<Vec<PathBuf>> {
87 let mut vec = Vec::new();
88 _list_files(&mut vec,&path)?;
89 Ok(vec)
90}
91
92fn find_name_of_library() -> String {
96 let exe = env::current_exe().expect("Naw1");
97 exe.parent().expect("NawX").file_name().expect("Naw1").to_str().expect("Naw2").to_string()
98}
99
100fn find_all_process_folders(dir:&str) -> Vec<PathBuf> {
102 list_files(Path::new(dir)).expect("that's not a good path?")
103}
104
105pub fn generate_complete_webmenu(verbose:&bool) {
113
114 if *verbose { print!("\n[A] Attempting to edit WebMenu.html..."); }
116 let mut html_file = OpenOptions::new()
117 .read(true)
118 .write(true)
119 .create(true)
120 .truncate(true)
121 .open("./WebMenu.html")
122 .expect("cannot open file");
123 if *verbose { print!("success! WebMenu.html is open for editing.\n"); }
124
125 if *verbose { print!("[B] Attempting to create new Library struct..."); }
126 let mut new_library = Library::new();
127 if *verbose { print!("success! New Library struct created.\n"); }
128
129 if *verbose { print!("[C] Attempting to change the name of the Library to this folder's name...")}
130 new_library.set_name(&find_name_of_library().as_str());
131 if *verbose { print!("success! New name: {}\n",new_library.get_name()); }
132
133 if *verbose { print!("[D] Attempting list of all folders (excluding 'assets')..."); }
134 let list_of_process_folders = find_all_process_folders(".");
135 if *verbose { for folder in &list_of_process_folders { println!("{}",folder.file_name().expect("No bueno?").to_str().expect("Really bueno?").to_string());} }
136 if *verbose { print!("success! Folders found, now look for files to process:\n"); }
137 for folder in list_of_process_folders {
138 let folder_string = folder.file_name().expect("No bueno?").to_str().expect("Really bueno?").to_string();
139 if *verbose { print!("\t{}",&folder_string); }
140 let new_ebml_str = folder_string.clone() + "/" + &folder_string + ".ebml";
141 if *verbose { print!("\n\t\t-> {}",&new_ebml_str); }
142 let new_process = read_ebml(&("./".to_owned()+&new_ebml_str));
143 if *verbose { print!("\n\t\t-> processed "); }
144 new_library.add_process(new_process);
145 if *verbose { print!("\n\t\t-> added to Library\n"); }
146 }
147
148 if *verbose { print!("[E] Attempting to write the top of the HTML file..."); }
149 compose_top_of_webmenu(&mut html_file);
150 if *verbose { print!("success!\n"); }
151
152 if *verbose { print!("[F] Attempting to write the head of the HTML file, including all CSS and Javascript..."); }
153 compose_head_of_webmenu(&mut html_file,&new_library);
154 if *verbose { print!("success!\n"); }
155
156 if *verbose { print!("[G] Attempting to write the body of the HTML file, including everything that appears on screen..."); }
157 compose_body_of_webmenu(&mut html_file,&new_library);
158 if *verbose { print!("success!\n"); }
159
160
161 if *verbose { print!("[H] Attempting to write the bottom of the HTML file..."); }
162 compose_bottom_of_webmenu(&mut html_file);
163 if *verbose { print!("success!\n"); }
164
165 if *verbose { print!("\n\n"); new_library.display(); print!("\n\n"); }
166}
167
168fn compose_top_of_webmenu(f:&mut File) {
170 f.write(b"<!DOCTYPE html>\n").expect("write failed");
171 f.write(b"<html lang=\"en-US\">\n").expect("write failed");
172}
173
174fn compose_head_of_webmenu(f:&mut File, lib:&Library) {
180 f.write(b"\t<head>\n").expect("write failed");
181 f.write(b"\t\t<meta charset=\"utf-8\" />\n").expect("write failed");
182 f.write(b"\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=1\" />\n").expect("write failed");
183 f.write(b"\t\t<style>\n").expect("write failed");
184 f.write(b"\t\t\t
185 @media print { .no-print, .no-print * { display: none !important; } br { display:none !important; } table { font-size: 0.5em; } }
186 body { font-family: sans-serif; padding: 0px; margin: 0px;}
187 #pre-header { padding: 15px; border: 15px solid #BA6F47; background-color: #BEA465; color: #2F495A; text-align: center; font-size: 0.7em; }
188 header { z-index: 100; border-bottom: 3px solid black; background-color: #2F495A; color: white; position: sticky; top:0px;}
189 header, main { padding: 20px; margin:0px;}
190 table { margin-top: 20px; }
191
192 input + span { margin: 0px 5px 0px 5px; }
193
194 .doc-box { display:inline-block; padding: 1px; border: 1px solid black; margin: 2px; width: 25px; }
195 .doc-icon { width: 25px; height: 25px; overflow: hidden; position: relative; }
196 .doc-format img { position: absolute; height: 25px; left: 0px; }
197
198 input { z-index: 0; margin: 0px 5px 0px 5px; transform: scale(1.3);}
199
200 .doc-box { display:inline-block; padding: 1px; border: 1px solid black; margin: 2px; width: 25px; }
201 .doc-icon { width: 25px; height: 25px; overflow: hidden; position: relative; }
202 .doc-format img { position: absolute; height: 25px; left: 0px; }
203
204 .toggle-column-01:not(:checked) ~ table th:nth-child(1) { display: none; }
205 .toggle-column-01:not(:checked) ~ table td:nth-child(1) { display: none; }
206
207 .toggle-column-02:not(:checked) ~ table th:nth-child(2) { display: none; }
208 .toggle-column-02:not(:checked) ~ table td:nth-child(2) { display: none; }
209
210 .toggle-column-03:not(:checked) ~ table th:nth-child(3) { display: none; }
211 .toggle-column-03:not(:checked) ~ table td:nth-child(3) { display: none; }
212
213 .toggle-column-04:not(:checked) ~ table th:nth-child(4) { display: none; }
214 .toggle-column-04:not(:checked) ~ table td:nth-child(4) { display: none; }
215
216 .toggle-column-05:not(:checked) ~ table th:nth-child(5) { display: none; }
217 .toggle-column-05:not(:checked) ~ table td:nth-child(5) { display: none; }
218
219 .toggle-column-06:not(:checked) ~ table th:nth-child(6) { display: none; }
220 .toggle-column-06:not(:checked) ~ table td:nth-child(6) { display: none; }
221
222 .toggle-column-07:not(:checked) ~ table th:nth-child(7) { display: none; }
223 .toggle-column-07:not(:checked) ~ table td:nth-child(7) { display: none; }
224
225 .toggle-column-08:not(:checked) ~ table th:nth-child(8) { display: none; }
226 .toggle-column-08:not(:checked) ~ table td:nth-child(8) { display: none; }
227
228 .toggle-column-09:not(:checked) ~ table th:nth-child(9) { display: none; }
229 .toggle-column-09:not(:checked) ~ table td:nth-child(9) { display: none; }
230
231 .toggle-column-10:not(:checked) ~ table th:nth-child(10) { display: none; }
232 .toggle-column-10:not(:checked) ~ table td:nth-child(10) { display: none; }
233
234 .toggle-column-11:not(:checked) ~ table th:nth-child(11) { display: none; }
235 .toggle-column-11:not(:checked) ~ table td:nth-child(11) { display: none; }
236
237 .toggle-column-12:not(:checked) ~ table th:nth-child(12) { display: none; }
238 .toggle-column-12:not(:checked) ~ table td:nth-child(12) { display: none; }
239
240 .toggle-column-13:not(:checked) ~ table th:nth-child(13) { display: none; }
241 .toggle-column-13:not(:checked) ~ table td:nth-child(13) { display: none; }
242
243 .toggle-column-14:not(:checked) ~ table th:nth-child(14) { display: none; }
244 .toggle-column-14:not(:checked) ~ table td:nth-child(14) { display: none; }
245
246 .toggle-column-15:not(:checked) ~ table th:nth-child(15) { display: none; }
247 .toggle-column-15:not(:checked) ~ table td:nth-child(15) { display: none; }
248
249 .toggle-column-16:not(:checked) ~ table th:nth-child(16) { display: none; }
250 .toggle-column-16:not(:checked) ~ table td:nth-child(16) { display: none; }
251 \n").expect("write failed");
252 f.write(b"\t\t\ttable { border-collapse: collapse; }
253 \t\tth, td { padding: 0.4em; border: 1px solid black;}
254 \t\tth { background-color: black; color: white; }
255 \t\tth[role=columnheader]:not(.no-sort) { cursor: pointer; }
256 \t\tth[role=columnheader]:not(.no-sort):after {
257 \t\t content: '';
258 \t\t float: right;
259 \t\t margin-top: 7px;
260 \t\t margin-left: 5px;
261 \t\t border-width: 0 4px 4px;
262 \t\t border-style: solid;
263 \t\t border-color: white transparent;
264 \t\t visibility: hidden;
265 \t\t opacity: 0;
266 \t\t -ms-user-select: none;
267 \t\t -webkit-user-select: none;
268 \t\t -moz-user-select: none;
269 \t\t user-select: none;
270 \t\t}
271 \t\tth[aria-sort=ascending]:not(.no-sort):after { border-bottom: none; border-width: 4px 4px 0; }
272 \t\tth[aria-sort]:not(.no-sort):after { visibility: visible; opacity: 0.4; }
273 \t\tth[role=columnheader]:not(.no-sort):hover:after { visibility: visible; opacity: 1; }\n").expect("write failed");
274 f.write(b"\t\t</style>\n").expect("write failed");
275
276 f.write(b"\t\t<script>\n").expect("write failed");
278 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");
279 f.write(b"\t\t</script>\n").expect("write failed");
280
281 f.write(b"\t\t<script>\n").expect("write failed");
283 f.write(b"\t\t\tfunction onPageReady() {\n").expect("write failed");
284 f.write(b"\t\t\t\tnew Tablesort(document.getElementById('library'));\n").expect("write failed");
285 f.write(b"\t\t\t}\n").expect("write failed");
286 f.write(b"\t\t\tdocument.addEventListener('DOMContentLoaded', onPageReady, false);\n").expect("write failed");
287 f.write(b"\t\t</script>\n").expect("write failed");
288
289 f.write(b"\t\t<link rel=\"shortcut icon\" sizes=\"16x16 32x32 48x48\" type=\"image/png\" href=\"./assets/favicon.png\" />\n").expect("write failed");
290 f.write(b"\t\t<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"./assets/favicon.png\" />\n").expect("write failed");
291 f.write(b"\t\t<link rel=\"mask-icon\" href=\"./assets/favicon.svg\" color=\"#000000\" />\n").expect("write failed");
292 let temp_str = String::from("\t\t<title>📚 ") + &lib.get_name() + " 📚</title>\n";
293 f.write(temp_str.as_bytes()).expect("write failed");
294 f.write(b"\t</head>\n").expect("write failed");
295}
296
297fn compose_body_of_webmenu(f:&mut File, lib:&Library) {
302 f.write(b"\t<body>\n").expect("write failed");
303 compose_body_header(f,lib);
304 compose_body_table(f,lib);
305 compose_body_footer(f,lib);
306 f.write(b"\t</body>\n").expect("write failed");
307}
308
309fn compose_body_header(f:&mut File, lib:&Library) {
311 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");
312 f.write(b"\t\t<header>\n").expect("write failed");
313 let temp_str = String::from("\t\t\t<h1>") + &lib.get_name() + "</h1>\n";
314 f.write(temp_str.as_bytes()).expect("write failed");
315 let temp_str = String::from("\t\t\t<p>Process Library with ") + &lib.get_all_processes().len().to_string() + " processes.</p>\n";
316 f.write(temp_str.as_bytes()).expect("write failed");
317 f.write(b"\t\t</header>\n").expect("write failed");
318}
319
320fn compose_body_table(f:&mut File, lib:&Library) {
324 f.write(b"\t\t<main>\n").expect("write failed");
325 f.write(b"\t\t\t<h2 class=\"no-print\">Process metadata columns to show in the table below:</h2>\n").expect("write failed");
326 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");
327 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");
328 f.write(b"\t\t\t<input class=\"toggle-column-03 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Current Revision</span><br/>\n").expect("write failed");
329 f.write(b"\t\t\t<input class=\"toggle-column-04 no-print\" type=\"checkbox\" checked><span class=\"no-print\">Title</span><br/>\n").expect("write failed");
330 f.write(b"\t\t\t<input class=\"toggle-column-05 no-print\" type=\"checkbox\" ><span class=\"no-print\">Subject</span><br/>\n").expect("write failed");
331 f.write(b"\t\t\t<input class=\"toggle-column-06 no-print\" type=\"checkbox\" ><span class=\"no-print\">Author</span><br/>\n").expect("write failed");
332 f.write(b"\t\t\t<input class=\"toggle-column-07 no-print\" type=\"checkbox\" ><span class=\"no-print\">Reviewer</span><br/>\n").expect("write failed");
333 f.write(b"\t\t\t<input class=\"toggle-column-08 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Objectives</span><br/>\n").expect("write failed");
334 f.write(b"\t\t\t<input class=\"toggle-column-09 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Objectives</span><br/>\n").expect("write failed");
335 f.write(b"\t\t\t<input class=\"toggle-column-10 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Out of Scope Declarations</span><br/>\n").expect("write failed");
336 f.write(b"\t\t\t<input class=\"toggle-column-11 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Out of Scope Declarations</span><br/>\n").expect("write failed");
337 f.write(b"\t\t\t<input class=\"toggle-column-12 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Requirement Verifications</span><br/>\n").expect("write failed");
338 f.write(b"\t\t\t<input class=\"toggle-column-13 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Requirement Verifications</span><br/>\n").expect("write failed");
339 f.write(b"\t\t\t<input class=\"toggle-column-14 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Resources</span><br/>\n").expect("write failed");
340 f.write(b"\t\t\t<input class=\"toggle-column-15 no-print\" type=\"checkbox\" ><span class=\"no-print\">List of Resources</span><br/>\n").expect("write failed");
341 f.write(b"\t\t\t<input class=\"toggle-column-16 no-print\" type=\"checkbox\" ><span class=\"no-print\">Number of Command Lines</span><br/>\n").expect("write failed");
342 f.write(b"\t\t\t<h2 class=\"no-print\">Click on any column header to sort ascending/descending.</h2>\n").expect("write failed");
343
344 f.write(b"\t\t\t<table id=\"library\">\n").expect("write failed");
345 f.write(b"\t\t\t\t<thead>\n").expect("write failed");
346 f.write(b"\t\t\t\t\t<tr data-sort-method=\"none\">\n").expect("write failed");
347 f.write(b"\t\t\t\t\t\t<th class=\"col01 no-print\">Links</th>\n").expect("write failed");
348 f.write(b"\t\t\t\t\t\t<th class=\"col02\">Number</th>\n").expect("write failed");
349 f.write(b"\t\t\t\t\t\t<th class=\"col03\">Rev</th>\n").expect("write failed");
350 f.write(b"\t\t\t\t\t\t<th class=\"col04\">Title</th>\n").expect("write failed");
351 f.write(b"\t\t\t\t\t\t<th class=\"col05\">Subject</th>\n").expect("write failed");
352 f.write(b"\t\t\t\t\t\t<th class=\"col06\">Author</th>\n").expect("write failed");
353 f.write(b"\t\t\t\t\t\t<th class=\"col07\">Reviewer</th>\n").expect("write failed");
354 f.write(b"\t\t\t\t\t\t<th class=\"col08\">Obj</th>\n").expect("write failed");
355 f.write(b"\t\t\t\t\t\t<th class=\"col09\">List of Objectives</th>\n").expect("write failed");
356 f.write(b"\t\t\t\t\t\t<th class=\"col10\">OoS</th>\n").expect("write failed");
357 f.write(b"\t\t\t\t\t\t<th class=\"col11\">Out of Scope Declarations</th>\n").expect("write failed");
358 f.write(b"\t\t\t\t\t\t<th class=\"col12\">Ver</th>\n").expect("write failed");
359 f.write(b"\t\t\t\t\t\t<th class=\"col13\">List of Requirement Verifications</th>\n").expect("write failed");
360 f.write(b"\t\t\t\t\t\t<th class=\"col14\">Res</th>\n").expect("write failed");
361 f.write(b"\t\t\t\t\t\t<th class=\"col15\">List of Resources</th>\n").expect("write failed");
362 f.write(b"\t\t\t\t\t\t<th class=\"col16\">Cmd</th>\n").expect("write failed");
363 f.write(b"\t\t\t\t\t</tr>\n").expect("write failed");
364 f.write(b"\t\t\t\t</thead>\n").expect("write failed");
365 f.write(b"\t\t\t\t<tbody>\n").expect("write failed");
366 for proc in lib.get_all_processes() {
367 f.write(b"\t\t\t\t\t<tr>\n").expect("write failed");
368
369 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col01 no-print\">
371 <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>
372 <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>
373 <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>
374 </td>\n";
375 f.write(temp_str.as_bytes()).expect("write failed");
376
377 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col02\">") + proc.get_number() + "</td>\n";
378 f.write(temp_str.as_bytes()).expect("write failed");
379
380 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col03\">") + proc.get_revision() + "</td>\n";
381 f.write(temp_str.as_bytes()).expect("write failed");
382
383 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col04\">") + proc.get_title() + "</td>\n";
384 f.write(temp_str.as_bytes()).expect("write failed");
385
386 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col05\">") + proc.get_subject() + "</td>\n";
387 f.write(temp_str.as_bytes()).expect("write failed");
388
389 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col06\">") + proc.get_author() + "</td>\n";
390 f.write(temp_str.as_bytes()).expect("write failed");
391
392 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col07\">") + proc.get_reviewer() + "</td>\n";
393 f.write(temp_str.as_bytes()).expect("write failed");
394
395 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col08\">") + &format!("{:03}",&proc.get_all_objectives().len()) + "</td>\n";
396 f.write(temp_str.as_bytes()).expect("write failed");
397
398 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col09\"><ul>\n");
399 f.write(temp_str.as_bytes()).expect("write failed");
400 let all_objectives = proc.get_all_objectives();
401 if all_objectives.len() > 0 {
402 for objective in all_objectives {
403 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &objective.0 + "</li>\n";
404 f.write(temp_str.as_bytes()).expect("write failed");
405 }
406 }
407 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
408 f.write(temp_str.as_bytes()).expect("write failed");
409
410 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col10\">") + &format!("{:03}",&proc.get_all_out_of_scopes().len()) + "</td>\n";
411 f.write(temp_str.as_bytes()).expect("write failed");
412
413 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col11\"><ul>\n");
414 f.write(temp_str.as_bytes()).expect("write failed");
415 let all_out_of_scopes = proc.get_all_out_of_scopes();
416 if all_out_of_scopes.len() > 0 {
417 for out_of_scope in all_out_of_scopes {
418 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &out_of_scope.0 + "</li>\n";
419 f.write(temp_str.as_bytes()).expect("write failed");
420 }
421 }
422 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
423 f.write(temp_str.as_bytes()).expect("write failed");
424
425 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col12\">") + &format!("{:03}",&proc.get_all_verifications().len()) + "</td>\n";
426 f.write(temp_str.as_bytes()).expect("write failed");
427
428 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col13\"><ul>\n");
429 f.write(temp_str.as_bytes()).expect("write failed");
430 let all_verifications = proc.get_all_verifications();
431 if all_verifications.len() > 0 {
432 for verification in all_verifications {
433 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";
434 f.write(temp_str.as_bytes()).expect("write failed");
435 }
436 }
437 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
438 f.write(temp_str.as_bytes()).expect("write failed");
439
440 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col14\">") + &format!("{:03}",&proc.get_all_resources().len()) + "</td>\n";
441 f.write(temp_str.as_bytes()).expect("write failed");
442
443 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col15\"><ul>\n");
444 f.write(temp_str.as_bytes()).expect("write failed");
445 let all_resources = proc.get_all_resources();
446 if all_resources.len() > 0 {
447 for resource in all_resources {
448 let temp_str = String::from("\t\t\t\t\t\t\t<li>") + &resource.0.get_name() + "</li>\n";
449 f.write(temp_str.as_bytes()).expect("write failed");
450 }
451 }
452 let temp_str = String::from("\t\t\t\t\t\t</ul></td>\n");
453 f.write(temp_str.as_bytes()).expect("write failed");
454
455 let temp_str = String::from("\t\t\t\t\t\t<td class=\"col16\">") + &format!("{:03}",&proc.get_all_command_lines().len()) + "</td>\n";
456 f.write(temp_str.as_bytes()).expect("write failed");
457
458 f.write(b"\t\t\t\t\t</tr>\n").expect("write failed");
459
460 }
461 f.write(b"\t\t\t\t</tbody>\n").expect("write failed");
462 f.write(b"\t\t\t</table>\n").expect("write failed");
463 f.write(b"\t\t</main>\n").expect("write failed");
464}
465
466fn compose_body_footer(_f:&mut File, _lib:&Library) {}
468
469fn compose_bottom_of_webmenu(f:&mut File) {
471 f.write(b"</html>\n").expect("write failed");
472}
473
474impl Library {
488
489 pub fn new() -> Library {
491 Library {
492 name: "".to_string(),
493 all_processes: vec![],
494 }
495 }
496
497 pub fn get_name(&self) -> &String { &self.name }
499 pub fn get_all_processes(&self) -> &Vec<Process> { &self.all_processes }
501
502 pub fn set_name(&mut self, lib_name: &str) {
504 self.name = String::from(lib_name.trim());
505 }
506
507 pub fn add_process(&mut self, process: Process) {
509 self.all_processes.push(process);
510 }
511
512 pub fn display(&self) {
514 let name = self.get_name();
515 let all_processes = self.get_all_processes();
516 println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
517 println!("XX LIBRARY VISUALIZER XX");
518 println!("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
519 println!(" -> Name: {}",name);
520 println!(" -> Processes:");
521 for proc in all_processes {
522 println!(" -> {}",proc.get_number());
523 }
524 }
525}
526
527#[cfg(test)]
540mod tests {
541 use super::*;
543 #[test]
565 fn test_find_name_of_library() {
566 println!("result of find_name_of_library() -> {}",find_name_of_library());
567 }
568
569 #[test]
589 fn test_library_new() {
590 Library::new();
591 }
592
593 #[test]
594 fn test_library_get_functions() {
595
596 let lib:Library = Library::new();
597
598 assert_eq!(&lib.name,lib.get_name());
599 println!("struct Library / Result of get_name() -> {:?}",lib.get_name());
600
601 assert!(lib.all_processes.len()==0);
602 assert_eq!(lib.all_processes.len(),lib.get_all_processes().len());
603 let _is_right_type:&Vec<Process> = lib.get_all_processes();
604 println!("struct Library / Result of get_all_processes() -> [it's empty]");
605 }
606
607 #[test]
608 fn test_library_display() {
609 Library::new().display();
610 }
611
612 #[test]
613 fn test_library_set_functions() {
614 let mut lib:Library = Library::new();
615
616 lib.set_name("SET_LIBRARY_NAME");
617 assert_eq!(&lib.name,lib.get_name());
618
619 let proc = Process::new();
620 let number = &proc.get_number().clone();
621 lib.add_process(proc);
622 assert_eq!(lib.get_all_processes()[0].get_number(),number);
623
624 lib.display();
625 }
626
627
628}