Open file by URL (fixes #95)

This commit is contained in:
Daniel Perna 2018-06-19 00:23:22 +02:00
parent a3d5aaa847
commit c0c0b77bb6
2 changed files with 40 additions and 20 deletions

View file

@ -652,7 +652,7 @@ INDEX = Template(r"""<!DOCTYPE html>
</header> </header>
<main> <main>
<ul id="dropdown_menu" class="dropdown-content z-depth-4"> <ul id="dropdown_menu" class="dropdown-content z-depth-4">
<li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.href, '_blank');">New tab</a></li> <li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.origin+window.location.pathname, '_blank');">New tab</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li> <li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li>
<li><a target="_blank" href="https://materialdesignicons.com/">Material Icons</a></li> <li><a target="_blank" href="https://materialdesignicons.com/">Material Icons</a></li>
@ -671,7 +671,7 @@ INDEX = Template(r"""<!DOCTYPE html>
<li><a class="modal-trigger" href="#modal_exec_command">Execute shell command</a></li> <li><a class="modal-trigger" href="#modal_exec_command">Execute shell command</a></li>
</ul> </ul>
<ul id="dropdown_menu_mobile" class="dropdown-content z-depth-4"> <ul id="dropdown_menu_mobile" class="dropdown-content z-depth-4">
<li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.href, '_blank');">New tab</a></li> <li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.origin+window.location.pathname, '_blank');">New tab</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a target="_blank" href="https://home-assistant.io/help/">Help</a></li> <li><a target="_blank" href="https://home-assistant.io/help/">Help</a></li>
<li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li> <li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li>
@ -2157,6 +2157,7 @@ INDEX = Template(r"""<!DOCTYPE html>
} }
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
var init_loadfile = $loadfile;
var global_current_filepath = null; var global_current_filepath = null;
var global_current_filename = null; var global_current_filename = null;
@ -2264,6 +2265,11 @@ INDEX = Template(r"""<!DOCTYPE html>
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
$('.preloader-background').delay(800).fadeOut('slow'); $('.preloader-background').delay(800).fadeOut('slow');
$('.preloader-wrapper').delay(800).fadeOut('slow'); $('.preloader-wrapper').delay(800).fadeOut('slow');
if (init_loadfile) {
init_loadfile_name = init_loadfile.split('/').pop();
loadfile(init_loadfile, init_loadfile_name);
}
else {
if (!localStorage.getItem("new_tab")) { if (!localStorage.getItem("new_tab")) {
var old_file = localStorage.getItem("current_file"); var old_file = localStorage.getItem("current_file");
if (old_file) { if (old_file) {
@ -2275,6 +2281,7 @@ INDEX = Template(r"""<!DOCTYPE html>
localStorage.removeItem("current_file"); localStorage.removeItem("current_file");
} }
localStorage.removeItem("new_tab"); localStorage.removeItem("new_tab");
}
}); });
</script> </script>
<script> <script>
@ -3697,6 +3704,11 @@ class RequestHandler(BaseHTTPRequestHandler):
self.send_header('Content-type', 'text/html') self.send_header('Content-type', 'text/html')
self.end_headers() self.end_headers()
loadfile = query.get('loadfile', [None])[0]
if loadfile is None:
loadfile = 'null'
else:
loadfile = "'%s'" % loadfile
services = "[]" services = "[]"
events = "[]" events = "[]"
states = "[]" states = "[]"
@ -3741,6 +3753,7 @@ class RequestHandler(BaseHTTPRequestHandler):
html = get_html().safe_substitute(services=services, html = get_html().safe_substitute(services=services,
events=events, events=events,
states=states, states=states,
loadfile=loadfile,
current=VERSION, current=VERSION,
versionclass=color, versionclass=color,
separator="\%s" % os.sep if os.sep == "\\" else os.sep, separator="\%s" % os.sep if os.sep == "\\" else os.sep,

View file

@ -565,7 +565,7 @@
</header> </header>
<main> <main>
<ul id="dropdown_menu" class="dropdown-content z-depth-4"> <ul id="dropdown_menu" class="dropdown-content z-depth-4">
<li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.href, '_blank');">New tab</a></li> <li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.origin+window.location.pathname, '_blank');">New tab</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li> <li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li>
<li><a target="_blank" href="https://materialdesignicons.com/">Material Icons</a></li> <li><a target="_blank" href="https://materialdesignicons.com/">Material Icons</a></li>
@ -584,7 +584,7 @@
<li><a class="modal-trigger" href="#modal_exec_command">Execute shell command</a></li> <li><a class="modal-trigger" href="#modal_exec_command">Execute shell command</a></li>
</ul> </ul>
<ul id="dropdown_menu_mobile" class="dropdown-content z-depth-4"> <ul id="dropdown_menu_mobile" class="dropdown-content z-depth-4">
<li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.href, '_blank');">New tab</a></li> <li><a onclick="localStorage.setItem('new_tab', true);window.open(window.location.origin+window.location.pathname, '_blank');">New tab</a></li>
<li class="divider"></li> <li class="divider"></li>
<li><a target="_blank" href="https://home-assistant.io/help/">Help</a></li> <li><a target="_blank" href="https://home-assistant.io/help/">Help</a></li>
<li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li> <li><a target="_blank" href="https://home-assistant.io/components/">Components</a></li>
@ -2070,6 +2070,7 @@
} }
</script> </script>
<script type="text/javascript"> <script type="text/javascript">
var init_loadfile = $loadfile;
var global_current_filepath = null; var global_current_filepath = null;
var global_current_filename = null; var global_current_filename = null;
@ -2177,6 +2178,11 @@
document.addEventListener("DOMContentLoaded", function() { document.addEventListener("DOMContentLoaded", function() {
$('.preloader-background').delay(800).fadeOut('slow'); $('.preloader-background').delay(800).fadeOut('slow');
$('.preloader-wrapper').delay(800).fadeOut('slow'); $('.preloader-wrapper').delay(800).fadeOut('slow');
if (init_loadfile) {
init_loadfile_name = init_loadfile.split('/').pop();
loadfile(init_loadfile, init_loadfile_name);
}
else {
if (!localStorage.getItem("new_tab")) { if (!localStorage.getItem("new_tab")) {
var old_file = localStorage.getItem("current_file"); var old_file = localStorage.getItem("current_file");
if (old_file) { if (old_file) {
@ -2188,6 +2194,7 @@
localStorage.removeItem("current_file"); localStorage.removeItem("current_file");
} }
localStorage.removeItem("new_tab"); localStorage.removeItem("new_tab");
}
}); });
</script> </script>
<script> <script>