Skip to content

Commit

Permalink
Merge pull request #174 from danielperna84/devel
Browse files Browse the repository at this point in the history
0.3.7
  • Loading branch information
danielperna84 authored Nov 23, 2019
2 parents 6fa5e10 + 33cf9fe commit 503576b
Show file tree
Hide file tree
Showing 6 changed files with 426 additions and 39 deletions.
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
Version 0.3.7 ()
- Rename files via UI (Issue #162)
- Disable browser-autocomplete on searchbox @ProLoser
- Fix documentation @adebree
- Add file history button (Issue #169)
- Update Ace Editor

Version 0.3.6 (2019-10-08)
- Update Ace Editor @emontnemery & @danielperna84
- Update js-yaml
Expand Down
134 changes: 123 additions & 11 deletions configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
IGNORE_PATTERN = []
# if DIRSFIRST is set to `true`, directories will be displayed at the top
DIRSFIRST = False
# Don't display hidden files (starting with .)
HIDEHIDDEN = False
# Sesame token. Browse to the configurator URL + /secrettoken to unban your
# client IP and add it to the list of allowed IPs.
HIDEHIDDEN = False
# Don't display hidden files (starting with .)
SESAME = None
# Instead of a static SESAME token you may also use a TOTP based token that
# changes every 30 seconds. The value needs to be a base 32 encoded string.
Expand Down Expand Up @@ -111,7 +111,7 @@
logging.Formatter('%(levelname)s:%(asctime)s:%(name)s:%(message)s'))
LOG.addHandler(SO)
RELEASEURL = "https://api.github.com/repos/danielperna84/hass-configurator/releases/latest"
VERSION = "0.3.6"
VERSION = "0.3.7"
BASEDIR = "."
DEV = False
LISTENPORT = None
Expand Down Expand Up @@ -320,7 +320,7 @@
color: #fff;
}
#dropdown_menu, #dropdown_menu_mobile {
#file_history, #dropdown_menu, #dropdown_menu_mobile {
min-width: 235px;
}
Expand Down Expand Up @@ -615,9 +615,9 @@
height: auto;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-modelist.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.6/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.7/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.7/ext-modelist.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.7/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="preloader-background">
Expand Down Expand Up @@ -674,7 +674,9 @@
<div class="nav-wrapper">
<ul class="left">
<li><a class="waves-effect waves-light tooltipped files-collapse hide-on-small-only" data-activates="slide-out" data-position="bottom" data-delay="500" data-tooltip="Browse Filesystem" style="padding-left: 25px; padding-right: 25px;"><i class="material-icons">folder</i></a></li>
<li><a class="waves-effect waves-light tooltipped dropdown-button hide-on-small-only" data-activates="file_history" data-beloworigin="true" data-delay="500" data-tooltip="File History" style="padding-left: 25px; padding-right: 25px;"><i class="material-icons">history</i></a></li>
<li><a class="waves-effect waves-light files-collapse hide-on-med-and-up" data-activates="slide-out" style="padding-left: 25px; padding-right: 25px;"><i class="material-icons">folder</i></a></li>
<li><a class="waves-effect waves-light dropdown-button hide-on-med-and-up" data-activates="file_history" data-beloworigin="true" style="padding-left: 25px; padding-right: 25px;"><i class="material-icons">history</i></a></li>
</ul>
<ul class="right">
<li><a class="waves-effect waves-light tooltipped hide-on-small-only markdirty hidesave" data-position="bottom" data-delay="500" data-tooltip="Save" onclick="save_check()"><i class="material-icons">save</i></a></li>
Expand All @@ -691,6 +693,7 @@
</div>
</header>
<main>
<ul id="file_history" class="dropdown-content z-depth-4"></ul>
<ul id="dropdown_menu" class="dropdown-content z-depth-4">
<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>
Expand Down Expand Up @@ -1370,6 +1373,17 @@
<a onclick="closefile()" class="modal-action modal-close waves-effect waves-green btn-flat light-blue-text">Yes</a>
</div>
</div>
<div id="modal_rename" class="modal">
<div class="modal-content">
<h4 class="grey-text text-darken-3">Rename</h4>
<p>Please enter a new name for <span class="fb_currentfile"></span>.</p>
<input type="text" id="rename_name_new" />
</div>
<div class="modal-footer">
<a class=" modal-action modal-close waves-effect waves-red btn-flat light-blue-text">Cancel</a>
<a onclick="rename_file()" class="modal-action modal-close waves-effect waves-green btn-flat light-blue-text">Apply</a>
</div>
</div>
<div id="modal_delete" class="modal">
<div class="modal-content">
<h4 class="grey-text text-darken-3">Delete</h4>
Expand Down Expand Up @@ -1725,7 +1739,7 @@
<label>Events</label>
</div>
<div class="input-field col s12">
<input type="text" id="entities-search" class="autocomplete" placeholder="sensor.example">
<input type="text" id="entities-search" class="autocomplete" autocomplete="off" placeholder="sensor.example">
<label>Search entity</label>
</div>
<div class="input-field col s12">
Expand Down Expand Up @@ -2168,7 +2182,7 @@
<label class="active" for="wrap_limit">Wrap Limit</label>
</div>
<a class="waves-effect waves-light btn light-blue" onclick="save_ace_settings()">Save Settings Locally</a>
<p class="center col s12"> Ace Editor 1.4.6 </p>
<p class="center col s12"> Ace Editor 1.4.7 </p>
</div>
</ul>
</div>
Expand Down Expand Up @@ -2615,6 +2629,16 @@
dd_download.appendChild(dd_download_a);
dropdown.appendChild(dd_download);
// Rename button
var dd_rename = document.createElement('li');
var dd_rename_a = document.createElement('a');
dd_rename_a.classList.add("waves-effect", "fb_dd");
dd_rename_a.setAttribute('href', "#modal_rename");
dd_rename_a.classList.add("modal-trigger");
dd_rename_a.innerHTML = "Rename";
dd_rename.appendChild(dd_rename_a);
dropdown.appendChild(dd_rename);
// Delete button
var dd_delete = document.createElement('li');
var dd_delete_a = document.createElement('a');
Expand Down Expand Up @@ -2774,6 +2798,36 @@
current_filename: global_current_filename}
localStorage.setItem('current_file', JSON.stringify(current_file));
check_lint();
if (localStorage.getItem("filehistory") === null) {
localStorage.setItem("filehistory", JSON.stringify([filepath]));
var filehistory = JSON.parse(localStorage.getItem("filehistory"));
}
else {
var filehistory = JSON.parse(localStorage.getItem("filehistory"));
if (filehistory[filehistory.length -1] != filepath) {
filehistory.push(filepath);
filehistory = filehistory.reduce(function(a,b){if(a.indexOf(b)<0)a.push(b);return a;},[]);
while (filehistory.length > 10) {
filehistory.shift();
}
localStorage.setItem("filehistory", JSON.stringify(filehistory));
}
}
var history_ul = document.getElementById("file_history");
while (history_ul.firstChild) {
history_ul.removeChild(history_ul.firstChild);
}
filehistory.reverse();
for (i = 0; i < filehistory.length; i++) {
var li = document.createElement('li');
var item = document.createElement('span');
var parts = decodeURI(filehistory[i]).split(separator);
var filename = parts[parts.length - 1];
item.innerHTML = "..." + decodeURI(filehistory[i].slice(filehistory[i].length - 25));
item.setAttribute("onclick", "loadfile('" + filehistory[i] + "', '" + filename + "')");
li.appendChild(item);
history_ul.appendChild(li);
}
});
}
}
Expand Down Expand Up @@ -3062,11 +3116,35 @@
window.open("api/download?filename="+encodeURI(filepath));
}
function rename_file() {
var src = document.getElementById("fb_currentfile").value;
var dstfilename = document.getElementById("rename_name_new").value;
if (src.length > 0 && dstfilename.length > 0) {
data = new Object();
data.src = src;
data.dstfilename = dstfilename;
$.post("api/rename", data).done(function(resp) {
if (resp.error) {
var $toastContent = $("<div><pre>" + resp.message + "\n" + resp.path + "</pre></div>");
Materialize.toast($toastContent, 5000);
}
else {
var $toastContent = $("<div><pre>" + resp.message + "</pre></div>");
Materialize.toast($toastContent, 2000);
listdir(document.getElementById('fbheader').innerHTML)
//document.getElementById('currentfile').value='';
//editor.setValue('');
document.getElementById("rename_name_new").value = "";
}
})
}
}
function delete_file() {
var path = document.getElementById('currentfile').value;
if (path.length > 0) {
data = new Object();
data.path= path;
data.path = path;
$.post("api/delete", data).done(function(resp) {
if (resp.error) {
var $toastContent = $("<div><pre>" + resp.message + "\n" + resp.path + "</pre></div>");
Expand Down Expand Up @@ -3574,7 +3652,7 @@ def load_settings(args):
GIT = settings.get("GIT", GIT)
if GIT:
try:
# pylint: disable=redefined-outer-name
# pylint: disable=redefined-outer-name,import-outside-toplevel
from git import Repo as REPO
except ImportError:
LOG.warning("Unable to import Git module")
Expand Down Expand Up @@ -4345,6 +4423,40 @@ def do_POST(self):
response['message'] = "Upload successful"
self.wfile.write(bytes(json.dumps(response), "utf8"))
return
elif req.path.endswith('/api/rename'):
try:
postvars = parse_qs(self.rfile.read(length).decode('utf-8'),
keep_blank_values=1)
except Exception as err:
LOG.warning(err)
response['message'] = "%s" % (str(err))
postvars = {}
if 'src' in postvars.keys() and 'dstfilename' in postvars.keys():
if postvars['src'] and postvars['dstfilename']:
try:
src = unquote(postvars['src'][0])
dstfilename = unquote(postvars['dstfilename'][0])
renamepath = src[:src.index(os.path.basename(src))] + dstfilename
response['path'] = renamepath
try:
os.rename(src, renamepath)
self.send_response(200)
self.send_header('Content-type', 'text/json')
self.end_headers()
response['error'] = False
response['message'] = "Rename successful"
self.wfile.write(bytes(json.dumps(response), "utf8"))
return
except Exception as err:
LOG.warning(err)
response['error'] = True
response['message'] = str(err)

except Exception as err:
response['message'] = "%s" % (str(err))
LOG.warning(err)
else:
response['message'] = "Missing filename or text"
elif req.path.endswith('/api/delete'):
try:
postvars = parse_qs(self.rfile.read(length).decode('utf-8'),
Expand Down
Loading

0 comments on commit 503576b

Please sign in to comment.