tweaks & download button

master
Michael Murtaugh 10 years ago
parent 0d51d2cd19
commit fef563f975

@ -0,0 +1,35 @@
#!/usr/bin/env python
import cgitb; cgitb.enable()
import os, sys, cgi
from project import Project
from zipfile import ZipFile
method = os.environ.get("REQUEST_METHOD", "")
fs = cgi.FieldStorage()
project = fs.getvalue("p", "")
paths = fs.getlist("f[]")
if paths:
proj = Project(project)
zippath = os.path.join(proj.fullpath, "{0}.zip".format(project))
with ZipFile(zippath, 'w') as zzip:
for p in paths:
fp = os.path.join(proj.fullpath, p)
# print >> sys.stderr, "*** rm", fp
_, base = os.path.split(fp)
zzip.write(fp, project+"/"+base)
# serve zippath
print "Content-type: application/zip"
print "Content-disposition: attachment; filename={0}.zip".format(project)
print "Content-length: {0}".format(os.path.getsize(zippath))
print
with open(zippath) as f:
while True:
data = f.read()
if data == "":
break
sys.stdout.write(data)
os.unlink(zippath)

@ -1,4 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
#
# (c) 2014 Michael Murtaugh and contributors to the Digital Publishing Toolkit
# License: GPL3
# This code has been developed as part of the [Digital Publishing Toolkit](http://digitalpublishingtoolkit.org).
# with the support of Institute for [Network Cultures](http://networkcultures.org)
# and [Creating 010](http://creating010.com).
import cgitb; cgitb.enable() import cgitb; cgitb.enable()
import os, sys, cgi, mimetypes import os, sys, cgi, mimetypes
@ -33,11 +41,13 @@ print """<!DOCTYPE html>
<div id="listing" class="left"> <div id="listing" class="left">
<div class="controls"> <div class="controls">
<span class="selection_functions"> <span class="selection_functions">
<button id="listing_download">download</button>
<button id="listing_rename">rename</button> <button id="listing_rename">rename</button>
<button id="listing_delete">delete</button> <button id="listing_delete">delete</button>
<button id="listing_cancel">cancel</button> <button id="listing_cancel">cancel</button>
</span> </span>
<span class="regular_functions"> <span class="regular_functions">
<button id="listing_select_all">select all</button>
<button id="listing_newfile">new file</button> <button id="listing_newfile">new file</button>
<button id="listing_newfolder">new folder</button> <button id="listing_newfolder">new folder</button>
<button id="listing_refresh" class="refresh">refresh</button> <button id="listing_refresh" class="refresh">refresh</button>

@ -101,6 +101,23 @@ a:hover {
width: auto; width: auto;
} }
#listing div.item a {
text-decoration: none;
}
#listing div.item.active a {
font-weight: bold;
}
#listing div.item.active a::after {
content: " \2192";
font-weight: bold;
}
#listing div.item a:hover {
text-decoration: underline;
}
#listing div.item a.normal { #listing div.item a.normal {
color: black; color: black;
} }
@ -126,6 +143,10 @@ a:hover {
display: none; display: none;
} }
#listing button, #listing select {
margin-right: 2px;
}
/* *** */ /* *** */
#editor { #editor {
@ -158,6 +179,10 @@ a:hover {
font-size: 12px; font-size: 12px;
} }
.editorfoot button, .editorfoot select {
margin-right: 6px;
}
#editor .preview { #editor .preview {
position: absolute; position: absolute;
left: 0; right: 0; left: 0; right: 0;

@ -1,3 +1,16 @@
/*
(c) 2014 Michael Murtaugh and contributors to the Digital Publishing Toolkit
License: GPL3
This code has been developed as part of the [Digital Publishing Toolkit](http://digitalpublishingtoolkit.org).
with the support of Institute for [Network Cultures](http://networkcultures.org)
and [Creating 010](http://creating010.com).
*/
var editor_factory = aa_aceeditor(window.ace), var editor_factory = aa_aceeditor(window.ace),
editor = editor_factory.get_editor(), editor = editor_factory.get_editor(),
editor_elt = d3.select(editor.elt), editor_elt = d3.select(editor.elt),
@ -21,6 +34,7 @@ var editor_factory = aa_aceeditor(window.ace),
.append("div") .append("div")
.attr("class", "gear"); .attr("class", "gear");
function url_for (script) { function url_for (script) {
return cgi_url+script+"?p=" + encodeURIComponent(project); return cgi_url+script+"?p=" + encodeURIComponent(project);
} }
@ -92,17 +106,30 @@ aa_frames(document.getElementById("split"));
document.getElementById("editor").appendChild(editor.elt); document.getElementById("editor").appendChild(editor.elt);
function edit (url) { var activeURL;
editor.href(url);
function updateActiveItem () {
var item = d3.selectAll("#listing div.item")
.classed("active", function (d) {
return d.url == activeURL;
});
}
function edit (url, done, forceReload) {
activeURL = url;
editor.href(url, done, forceReload);
editor.aceeditor.focus();
editor_elt editor_elt
.style("display", "block"); .style("display", "block");
preview_div preview_div
.style("display", "none"); .style("display", "none");
close_make(); close_make();
updateActiveItem();
// make_div.style("display", "none"); // make_div.style("display", "none");
} }
function preview (url) { function preview (url) {
activeURL = url;
preview_div preview_div
.style("display", "block"); .style("display", "block");
editor_elt editor_elt
@ -110,6 +137,7 @@ function preview (url) {
preview_iframe preview_iframe
.attr("src", url); .attr("src", url);
close_make(); close_make();
updateActiveItem();
// make_div.style("display", "none"); // make_div.style("display", "none");
} }
@ -143,18 +171,11 @@ function make (path, done) {
function make_busy (val) { function make_busy (val) {
make_div.classed("busy", val); make_div.classed("busy", val);
} }
/*
function select_all () { function select_all () {
var checkboxes = d3.selectAll(".itemcheckbox"), d3.selectAll("#listing div.item").each(item_select);
checked = d3.selectAll(".itemcheckbox:checked");
if (checkboxes.size() == checked.size()) {
checkboxes.property("checked", false);
} else {
checkboxes.property("checked", true);
}
update_selection(); update_selection();
} }
*/
function delete_selection () { function delete_selection () {
var items_selected = d3.selectAll("#listing div.selected"), var items_selected = d3.selectAll("#listing div.selected"),
@ -181,6 +202,25 @@ function delete_selection () {
} }
} }
function download_selection () {
var items_selected = d3.selectAll("#listing div.selected"),
num_selected = items_selected.size(),
paths = items_selected.data().map(function (d) { return d.path });
if (num_selected == 0) return;
var ok = true; //confirm("Download "+num_selected+" selected file"+((num_selected==1)?"":"s") + "?");
if (ok) {
var url = url_for("download.cgi");
url += paths.map(function(x) { return "&f[]="+encodeURIComponent(x); }).join("");
// console.log("download", url);
preview_iframe
.attr("src", url);
items_selected.each(item_deselect);
update_selection();
}
}
var longclick_begin; var longclick_begin;
function item_select (d) { function item_select (d) {
@ -256,7 +296,7 @@ function rename () {
$("#listing .listing_rename_buttons").hide(); $("#listing .listing_rename_buttons").hide();
return; return;
} }
var ok = confirm("Rename "+ss.size()+" file"+((ss==1)?"":"s") + "?"); var ok = true; // confirm("Rename "+ss.size()+" file"+((ss==1)?"":"s") + "?");
if (ok) { if (ok) {
ss.each(function (d) { ss.each(function (d) {
var newpath = d3.select(this.parentNode).select("input.rename").property("value"); var newpath = d3.select(this.parentNode).select("input.rename").property("value");
@ -320,12 +360,16 @@ function refresh_listing(done) {
} }
if (d.remake) { if (d.remake) {
// alert("make"); // alert("make");
activeURL = d.url;
updateActiveItem();
make(d.path, function () { make(d.path, function () {
// re-get the d in case of change! // re-get the d in case of change!
var d = d3.select(that).datum(); var d = d3.select(that).datum();
// console.log("d", d, d.binary, d.url); // console.log("d", d, d.binary, d.url);
if (!d.binary) { if (!d.binary) {
edit(d.url); // force reload!
console.log("force reload")
edit(d.url, null, true);
} else { } else {
preview(d.url); preview(d.url);
} }
@ -364,8 +408,10 @@ refresh_listing();
$("#listing .body").niceScroll({cursorcolor:"#0F0"}); $("#listing .body").niceScroll({cursorcolor:"#0F0"});
$("#editor .make .body").niceScroll({cursorcolor:"#0F0"}); $("#editor .make .body").niceScroll({cursorcolor:"#0F0"});
$("#listing_select_all").click(select_all);
$("#listing_refresh").click(refresh_listing); $("#listing_refresh").click(refresh_listing);
$("#listing_delete").click(delete_selection); $("#listing_delete").click(delete_selection);
$("#listing_download").click(download_selection);
$("#listing_rename").click(rename); $("#listing_rename").click(rename);
$("#listing_cancel").click(listing_cancel); $("#listing_cancel").click(listing_cancel);
// $("#listing_select_all").click(select_all); // $("#listing_select_all").click(select_all);

@ -26,7 +26,7 @@ function aa_aceeditor (ace) {
current_href, current_href,
highlightLineStart, highlightLineStart,
highlightLineEnd, highlightLineEnd,
_save; _save, _reload;
editor.elt = document.createElement("div"); editor.elt = document.createElement("div");
@ -42,6 +42,9 @@ function aa_aceeditor (ace) {
editor.save = function (callback) { editor.save = function (callback) {
_save = callback; _save = callback;
} }
editor.reload = function (callback) {
_reload = callback;
}
// a bit of a brutal solution but... // a bit of a brutal solution but...
$(document).bind("resize", function (e) { $(document).bind("resize", function (e) {
@ -79,6 +82,24 @@ function aa_aceeditor (ace) {
} }
}); });
var reload = foot
.append("button")
.text("reload")
.on("click", function () {
var text;
if (_reload) {
text = editor.aceeditor.getValue();
_reload.call(editor, {
text: text,
href: current_href
});
} else {
editor.href(current_href, null, true);
aceeditor.focus();
}
});
function highlight(s, e) { function highlight(s, e) {
var session = editor.aceeditor.getSession(); var session = editor.aceeditor.getSession();
if (highlightLineStart) { if (highlightLineStart) {
@ -111,9 +132,9 @@ function aa_aceeditor (ace) {
if (session == "loading") { if (session == "loading") {
return false; return false;
} }
/*
todo, improve this.. now commented out to force reload // todo, improve this.. now commented out to force reload
if (session != undefined) { if (!forceReload && (session != undefined)) {
if (done) { if (done) {
window.setTimeout(function () { window.setTimeout(function () {
done.call(session); done.call(session);
@ -128,7 +149,6 @@ function aa_aceeditor (ace) {
return true; return true;
} }
*/
sessionsByHref[href.nofrag] = "loading"; sessionsByHref[href.nofrag] = "loading";
$.ajax({ $.ajax({
url: href.nofrag, url: href.nofrag,

Loading…
Cancel
Save