Permalink
Browse files

Clyde feature complete

  • Loading branch information...
1 parent dc8c37b commit e90d108fa581874162acca2fe83ef656d621629f @lakshmivyas lakshmivyas committed Jan 21, 2010
View
@@ -11,7 +11,7 @@
from tornado.options import define, options
from django.conf import settings
-from hydeengine import setup_env
+from hydeengine import setup_env, Generator
from hydeengine.siteinfo import SiteInfo
from hydeengine.file_system import FileSystemEntity, File, Folder
@@ -28,7 +28,10 @@ def __init__(self):
(r"/site/([^/]+)/files", FilesJSONHandler),
(r"/site/([^/]+)/content", ContentHandler),
(r"/site/([^/]+)/content/save", SaveHandler),
- (r"/site/([^/]+)/publish", PublishHandler)
+ (r"/site/([^/]+)/publish", PublishHandler),
+ (r"/site/([^/]+)/rename", RenameHandler),
+ (r"/site/([^/]+)/delete", DeleteHandler),
+ (r"/site/([^/]+)/generate", GenerateHandler),
]
sites = yaml.load(File(options.sites).read_all())
@@ -41,7 +44,7 @@ def __init__(self):
class BaseHandler(tornado.web.RequestHandler):
- def init_site(self, site):
+ def init_site(self, site, force=False):
if not site in self.settings['sites']:
raise Exception("Site [%s] is not configured." % (site, ))
@@ -51,7 +54,7 @@ def init_site(self, site):
setup_env(self.site_path)
setattr(settings, 'siteinfo', {})
- if not site in settings.siteinfo:
+ if not site in settings.siteinfo or force:
self.siteinfo = SiteInfo(settings, self.site_path)
self.siteinfo.refresh()
settings.siteinfo[site] = self.siteinfo
@@ -91,7 +94,7 @@ def jsnode(node):
children.append([jsnode(child_node)
for child_node in node['nodes']])
return dict(
- attributes = dict(tooltip=node['path']),
+ attributes = dict(tooltip=node['path'], rel='folder'),
data = dict(
title=node['name'],attributes=dict()),
children=children
@@ -108,21 +111,59 @@ def doget(self, site):
path = self.get_argument("path", None)
if not path: return
f = File(self.siteinfo.folder.child(path))
+ if not f.exists: return
self.write(f.read_all())
class SiteHandler(tornado.web.RequestHandler):
def get(self, site):
self.render("clydeweb/templates/site.html", site=site)
-class NewFileHandler(BaseHandler):
+class GenerateHandler(BaseHandler):
+ def dopost(self, site):
+ Generator(self.site_path).generate()
+
+class RenameHandler(BaseHandler):
def dopost(self, site):
path = self.get_argument("path", None)
- if not path: return
- f = File(self.siteinfo.folder.child(path))
- f.write("")
+ original_path = self.get_argument("original_path", None)
+ type = self.get_argument('type', None)
+ repo = self.settings['sites'][site]['repo']
+ dvcs = DVCS.load_dvcs(self.siteinfo.folder.path, repo)
+ if type == "file":
+ f = File(self.siteinfo.folder.child(original_path))
+ newf = File(self.siteinfo.folder.child(path))
+ if not f.exists:
+ newf.write("")
+ dvcs.add_file(newf)
+ else:
+ f.move_to(newf)
+ dvcs.add_file(newf, message="Renamed " + path)
+
+ else:
+ f = Folder(self.siteinfo.folder.child(original_path))
+ newf = Folder(self.siteinfo.folder.child(path))
+ if not f.exists:
+ newf.make()
+ else:
+ f.move_to(newf)
+ dvcs.add_file(newf, message="Renamed " + path)
+ self.init_site(site, force=True)
+
+class DeleteHandler(BaseHandler):
+ def dopost(self, site):
+ path = self.get_argument("path", None)
+ type = self.get_argument('type', None)
repo = self.settings['sites'][site]['repo']
dvcs = DVCS.load_dvcs(self.siteinfo.folder.path, repo)
- dvcs.add_file(path)
+ f = None
+ if type == "file":
+ f = File(self.siteinfo.folder.child(path))
+ else:
+ f = Folder(self.siteinfo.folder.child(path))
+
+ f.delete()
+ dvcs.save_draft()
+ self.init_site(site, force=True)
class SaveHandler(BaseHandler):
def dopost(self, site):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -35,9 +35,12 @@
<h2>{{site}}</h2>
</hgroup>
<div class="buttonbar">
- <a id="new-file-button" class="button" href="/site/{{site}}/new-folder"><img title="New File" alt="New File" src="{{static_url("images/document--plus.png")}}"></a>
- <a id="new-folder-button" class="button" href="/site/{{site}}/new-file"><img title="New Folder" alt="New Folder" src="{{static_url("images/folder--plus.png")}}"></a>
- <a id="push-button" class="button" href="/site/{{site}}/publish"><img title="Publish" alt="Publish" src="{{static_url("images/network-cloud.png")}}"></a>
+ <a id="new-file-button" class="button" href="/site/{{site}}/new-file" title="New File"><img title="New File" alt="New File" src="{{static_url("images/document--plus.png")}}"></a>
+ <a id="new-folder-button" class="button" href="/site/{{site}}/new-folder" title="New Folder"><img title="New Folder" alt="New Folder" src="{{static_url("images/folder--plus.png")}}"></a>
+ <a id="rename-button" class="button" href="/site/{{site}}/rename" title="Rename"><img title="Rename" alt="Rename" src="{{static_url("images/drive-rename.png")}}"></a>
+ <a id="delete-button" class="button" href="/site/{{site}}/delete" title="Delete"><img title="Delete" alt="Delete" src="{{static_url("images/cross-button.png")}}"></a>
+ <a id="push-button" class="button" href="/site/{{site}}/publish" title="Publish"><img title="Publish" alt="Publish" src="{{static_url("images/network-cloud.png")}}"></a>
+ <a id="generate-button" class="button" href="/site/{{site}}/generate" title="Generate"><img title="Generate" alt="Generate" src="{{static_url("images/gear.png")}}"></a>
</div>
</div>
<div id="files"></div>
@@ -81,7 +84,28 @@
$(function(){
- $("#editor").markItUp(getHydeSet(save_draft));
+ $("#editor").markItUp(getHydeSet(save_draft));
+ $("#rename-button").unbind('click').bind('click', function(){
+ var t = $.tree.focused();
+ if (t.selected){
+ t.rename(t.selected);
+ }
+ return false;
+ });
+
+ $("#delete-button").unbind('click').bind('click', function(){
+ var t = $.tree.focused();
+ if (t.selected){
+ t.remove(t.selected);
+ }
+ return false;
+ });
+
+ $("#generate-button").unbind('click').bind('click', function(){
+ $.post('/site/{{site}}/generate');
+ return false;
+ });
+
$("#sites-button").unbind('click').bind('click', function(){
if (!sites){
$.getJSON('/sites', function(data){
@@ -114,7 +138,29 @@
$("#push-button").unbind('click').bind('click', function(){
$.post('/site/{{site}}/publish');
return false;
- });
+ });
+
+ function newFileOrFolder(fileOrFolder){
+ var t = $.tree.focused();
+ var name = fileOrFolder == "file" ? "new_file" : "new_folder/";
+ if(t.selected){
+ newNode = t.create({
+ attributes: {
+ rel:fileOrFolder,
+ tooltip:t.selected.attr("tooltip") + name
+ }}, t.selected, 'inside');
+ }
+ return false;
+ }
+
+ $("#new-folder-button").unbind('click').bind('click', function(){
+ return newFileOrFolder("folder");
+ });
+
+ $("#new-file-button").unbind('click').bind('click', function(){
+ return newFileOrFolder("file");
+ });
+
$("#files").tree({
ui : {
dots: false,
@@ -138,10 +184,42 @@
callback : {
onchange: function(node, tree){
current_path = node.attributes.tooltip.value;
- $("#crumbs h2").text("/" + current_path);
- $("#editor").load(
- '/site/{{site}}/content?path=' + encodeURIComponent(current_path));
- }
+ $("#crumbs h2").text("/" + current_path);
+ if (node.attributes.rel.value == 'file'){
+ $("#editor").show();
+ $("#editor").load(
+ '/site/{{site}}/content?path=' +
+ encodeURIComponent(current_path));
+ } else {
+ $("#editor").val("");
+ }
+
+ },
+ ondelete: function(node, tree, RB){
+ var path = node.attributes.tooltip.value;
+ var type = tree.get_type(node);
+ $.post('/site/{{site}}/delete?path='
+ + encodeURIComponent(path)
+ + "&type="
+ + type
+ );
+ },
+ onrename: function(node, tree, RB){
+ var originalPath = node.attributes.tooltip.value;
+ var path = tree.parent(node).attr('tooltip') + tree.get_text(node);
+ var type = tree.get_type(node);
+ if (type == "folder"){
+ path += "/";
+ }
+ $(node).attr("tooltip", path);
+ $.post('/site/{{site}}/rename?path='
+ + encodeURIComponent(path)
+ + "&original_path="
+ + encodeURIComponent(originalPath)
+ + "&type="
+ + type
+ );
+ }
}
});
@@ -420,9 +420,9 @@ def move_to(self, destination):
Moves this directory to the given destination. Returns a Folder object
that represents the moved directory.
- """
+ """
shutil.copytree(self.path, str(destination))
- shutil.rmtree(str(destination))
+ shutil.rmtree(self.path)
return self.__get_destination__(destination)
def copy_to(self, destination):
View
@@ -15,6 +15,7 @@ def add_file(self, path, message=None):
raise Exception(cmdresult)
self.commit(message or "Added file %s" % path)
+ self.push(self.draft_branch)
def publish(self):
self.switch(self.prod_branch)

0 comments on commit e90d108

Please sign in to comment.