# TODO: assumes unique basenames. Check?
return os.path.join(*([self.tag_dir] + tag + target[-1:]))
+ def new_tag(self, tag):
+ for i in range(len(tag)):
+ os.mkdir(os.path.join(self.tag_dir, *tag[:i+1]))
+
def add_tag(self, target, tag):
tag_path = self.tag_path(target, tag)
target_path = os.path.abspath(os.path.join(*([self.raw_dir]+target)))
"""Initialize the bug repository for this web interface."""
self.dirtag = dirtag
self.env = Environment(loader=FileSystemLoader(template_dir))
- self.repository_name = repository_name
+ self.repository_name = repository_name
self.rdf_root = 'http://dirtag.com/'
-
+
@cherrypy.expose
def index(self):
template = self.env.get_template('dirtag.xul')
"""
return len([x for x,y in zip(a,b) if x==y]) == len(a)
- #raise cherrypy.HTTPRedirect('/static/dirtag.xul', status=302)
-
+ @cherrypy.expose
+ def new_tag(self, tag):
+ self.dirtag.new_tag(tag.split('/'))
+ return '<p>New tag %s added</p>' % tag
+
+ @cherrypy.expose
+ def add_tag(self, path, tag):
+ self.dirtag.add_tag(path.split('/'), tag.split('/'))
+ return '<p>Added tag %s to %s</p>' % (tag, path)
+
+ @cherrypy.expose
+ def remove_tag(self, path, tag):
+ self.dirtag.remove_tag(path.split('/'), tag.split('/'))
+ return '<p>Removed tag %s from %s</p>' % (tag, path)
+
+
if __name__ == '__main__':
parser = OptionParser('%prog [options]', epilog=WebInterface.__doc__)
parser.add_option('-r', '--raw-dir', dest='raw_dir', metavar='DIR',
/* Functions driving the CherryPy backend */
-function new_tag(path) {
- alert('Adding tag: '+path.toString());
+function reload_rdf(e) {
/* https://developer.mozilla.org/en/RDF_in_Mozilla_FAQ */
+ if (e.readyState == 4) { /* 4: request finished and response is ready */
+ if(e.status != 200) {
+ alert("Error loading page\n\n"+e.responseText);
+ return;
+ }
+ // Get the RDF service
+ var RDF =
+ Components
+ .classes['@mozilla.org/rdf/rdf-service;1']
+ .getService(Components.interfaces.nsIRDFService);
+ // Get the datasources and refresh them
+ RDF.GetDataSource('raw.rdf').Refresh('non-blocking');
+ RDF.GetDataSource('tag.rdf').Refresh('non-blocking');
+ }
+}
+
+function push_data(url) {
+ /* https://developer.mozilla.org/en/using_xmlhttprequest */
+ xmlDoc = new XMLHttpRequest();
+ xmlDoc.open('GET', url, true);
+ xmlDoc.onreadystatechange = function() { reload_rdf(xmlDoc); };
+ xmlDoc.send(null);
+}
+
+function new_tag(tag) {
+ push_data('/new_tag?tag='+escape(tag.join('/')));
}
function add_tag(path, tag) {
- alert('Add tag '+tag+' to '+path.toString());
+ push_data('/add_tag?path='+escape(path.join('/'))
+ +'&tag='+escape(tag.join('/')));
}
function remove_tag(path, tag) {
- alert('Remove tag '+tag+' from '+path.toString());
+ push_data('/remove_tag?path='+escape(path.join('/'))
+ +'&tag='+escape(tag.join('/')));
}
/* The bindings themselves */
function set_selected_element(path) {
element = document.getElementById('element');
element.file_path = path;
- alert('Set selected element: '+path.toString());
}
function raw_tree_select() {
var path = document.getElementById('element').file_path;
var name = tree.columns.getPrimaryColumn();
id = tree_path(tree, row);
- if (value == true || value == "true") {
+ if (path == 'UNDEFINED') {
+ return;
+ } else if (value == true || value == 'true') {
add_tag(path, id);
} else {
remove_tag(path, id);