Fixes to pull/push logic.
authorLukasz <lreqc@debian.(none)>
Fri, 23 Oct 2009 09:51:28 +0000 (05:51 -0400)
committerLukasz <lreqc@debian.(none)>
Fri, 23 Oct 2009 09:51:28 +0000 (05:51 -0400)
apps/api/handlers/library_handlers.py [changed mode: 0644->0755]
apps/api/views.py [changed mode: 0644->0755]
lib/wlrepo/__init__.py [changed mode: 0644->0755]
lib/wlrepo/mercurial_backend/document.py [changed mode: 0644->0755]
lib/wlrepo/mercurial_backend/library.py [changed mode: 0644->0755]
lib/wlrepo/mercurial_backend/revision.py [changed mode: 0644->0755]
platforma/static/css/html.css [changed mode: 0644->0755]
platforma/static/js/models.js [changed mode: 0644->0755]
platforma/static/js/views/html.js [changed mode: 0644->0755]
platforma/templates/registration/login.html [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 942ea0e..562ed1b
@@ -512,7 +512,7 @@ class MergeHandler(BaseHandler):
                     "message": "You must first update your branch to the latest version."
                 })
 
-            if base_doc.parentof(doc) or base_doc.has_parent_from(doc):
+            if not base_doc.would_share():
                 return response.SuccessAllOk().django_response({
                     "result": "no-op"
                 })
old mode 100644 (file)
new mode 100755 (executable)
index a811802..3e9cb01
@@ -24,7 +24,7 @@ def render(request):
 
     style = etree.parse(style_filename)
 
-    data = u'<chunk>%s</chunk>' % LINE_SWAP_EXPR.sub(u'<br />\n', data)
+    data = u'<chunk><%s>%s</%s></chunk>' % (tag, LINE_SWAP_EXPR.sub(u'<br />\n', data), tag)
     log.info(data)    
     doc = etree.parse( StringIO(data) )
 
@@ -35,6 +35,4 @@ def render(request):
     }
 
     result = doc.xslt(style, **opts)
-    log.info( str(doc), str(result) )
-        
-    return HttpResponse( librarian.serialize_children(result.getroot()) )
\ No newline at end of file
+    return HttpResponse( librarian.serialize_children(result.getroot()[0]) )
\ No newline at end of file
old mode 100644 (file)
new mode 100755 (executable)
index f8c07c6..fc309dc
@@ -14,7 +14,7 @@ class Library(object):
         """List all documents in the library."""
         pass
 
-    def document_for_rev(self, rev):
+    def document_for_revision(self, rev):
         """Retrieve a document in the specified revision."""
         pass
 
@@ -73,6 +73,9 @@ class Document(object):
     def parentof(self, other):
         return self._revision.parentof(other._revision)
 
+    def parent(self):
+        return self._library.document_for_revision(self._revision.parent())
+
     def has_parent_from(self, other):
         return self._revision.has_parent_from(other._revision)
 
old mode 100644 (file)
new mode 100755 (executable)
index f7da32d..3bd26a6
@@ -111,7 +111,7 @@ class MercurialDocument(wlrepo.Document):
 
         shared = self.shared()
         
-        if shared.parentof(self):
+        if shared.ancestorof(self):
             return True
 
         if shared.has_parent_from(self):
@@ -132,45 +132,74 @@ class MercurialDocument(wlrepo.Document):
                 raise wlrepo.UpdateException("Revision %s has children." % self.revision)
 
             shared = self.shared()
-
-            # the shared version comes from our version
-            if self.parentof(self.shared()):
-                return self
-
-            # no changes since last update
+            #     *
+            #    /|
+            #   * |
+            #   | |
+            #
+            # we carry the latest version
             if shared.ancestorof(self):
-                return self
+               return self
 
-            # last share was from this branch
-            if shared.has_parent_from(self):
+            #   *
+            #   |\
+            #   | *
+            #   | |
+            #
+            # We just shared
+            if self.parentof(shared):
                 return self
 
-            if self._revision.merge_with(sv._revision, user=user,\
+            #  s     s  S
+            #  |     |  |
+            #  *<-S  *<-*
+            #  |  |  |  .
+            #
+            #  This is ok (s - shared, S - self)
+
+            if self._revision.merge_with(shared._revision, user=user,\
                 message="$AUTO$ Personal branch update."):
                 return self.latest()
             else:
                 raise wlrepo.UpdateException("Merge failed.")
         finally:
-            lock.release()  
+            lock.release()
 
-    def share(self, message):
-        lock = self.library.lock()
-        try:            
 
-            # nothing to do
-            if self.ismain():
-                return self
+    def would_share(self):
+        if self.ismain():
+            return False
 
-            shared = self.shared()
+        shared = self.shared()
 
-            # we just did this - move on
-            if self.parentof(shared):
-                return shared
+        # we just did this - move on
+        if self.parentof(shared):
+            return False
+
+        #     *
+        #    /|
+        #   * *
+        #   |\|
+        #   | *
+        #   | |
+        # Situation above is ok - what we don't want, is:
+        #     *
+        #    /|
+        #   * |
+        #   |\|
+        #   | *
+        #   | |
+        # We want to prevent stuff like this.
+        if self.parent().parentof(shared):
+            return False
 
-            # No changes since update
-            if shared.parentof(self):
-                return shared
+    def share(self, message):
+        lock = self.library.lock()
+        try:
 
+            if not self.would_share():
+                return self.shared()          
+      
             # The good situation
             #
             #         * local
old mode 100644 (file)
new mode 100755 (executable)
index cde7af9..316800f
@@ -80,7 +80,7 @@ class MercurialLibrary(wlrepo.Library):
     def ospath(self):
         return self._ospath.decode('utf-8')
 
-    def document_for_rev(self, revision):
+    def document_for_revision(self, revision):
         if revision is None:
             raise ValueError("Revision can't be None.")
         
old mode 100644 (file)
new mode 100755 (executable)
index f05637d..80b761f
@@ -99,5 +99,13 @@ class MercurialRevision(wlrepo.Revision):
         finally:
             lock.release()
 
+    def parent(self):
+        parents = self._changectx.parents()
+
+        if len(parents) == 1:
+            return parents[0]
+
+        return parents[0] if (parents[0].branch() == self.branch()) else parents[1]
+        
     def __eq__(self, other):
         return self._changectx.node() == other._changectx.node()
old mode 100644 (file)
new mode 100755 (executable)
index 6bc118d..d49c723
@@ -1,7 +1,5 @@
 /* Style widoku HTML. Nie należy tu ustawiać position ani marginesów */
 
-@namespace wl2o "";
-
 .htmlview {
     counter-reset: main;
     font-size: 16px;
@@ -10,6 +8,10 @@
     padding: 3em;    
 }
 
+.htmlview * {
+    position: relative;
+}
+
 .htmlview div {
     max-width: 36em;
 }
     counter-increment: main;
 }
 
-/* .htmlview *[wl2o\:editable] {
-    background-color: pink;
+.htmlview *[x-editable] {
+    border: 2px solid white;
+    padding: 5px;
 }
 
-.htmlview *[wl2o\:editable] *[wl2o\:editable] {
-    background-color: red;
-} */
+/* focused editable element */
+.htmlview *[x-editable]:hover,
+.htmlview *[x-editable][x-open]
+{
+    background-color: #dfdfdf;
+    border: 2px solid black;
+}
+
+.htmlview *[x-editable] *.context-menu {
+    position: absolute;
+    top: -24px;
+    left: -2px;
+    height: 24px;
+    
+    text-align: center;
+
+    font-size: 14px;
+    line-height: 24px;
+    font-weight: normal;
+    font-style: normal;
+
+    background-color: #dfdfdf;
+    margin: 0px;
+    padding: 0px;
 
+    border-top: 2px solid black;
+    border-left: 2px solid black;
+    border-right: 2px solid black;    
+    
+    display: none;
+    overflow: hidden;
+    
+    -moz-border-radius-topright: 5px;
+    -moz-border-radius-topleft: 5px;
+
+    -webkit-border-top-right-radius: 5px;
+    -webkit-border-top-left-radius: 5px;
+}
+
+.htmlview *[x-editable] *.context-menu * {
+    padding: 5px;
+}
+
+.htmlview *[x-editable] *.context-menu *:hover {
+    background-color: yellow;
+}
+
+.htmlview *[x-editable]:hover *.context-menu {
+    display: block;
+}
+
+.htmlview *[x-editable][x-open] *.context-menu {
+    display: none;
+}
 
 .htmlview .annotation:hover {
     background-color: #dfdfdf;
old mode 100644 (file)
new mode 100755 (executable)
index f945238..ffaf999
@@ -228,7 +228,7 @@ Editor.HTMLModel = Editor.Model.extend({
 
     getXMLPart: function(elem, callback)
     {
-        var path = elem.attr('wl2o:path');
+        var path = elem.attr('x-pointer');
         if(!this.xmlParts[path])
             this.loadXMLPart(elem, callback);
         else
@@ -237,7 +237,7 @@ Editor.HTMLModel = Editor.Model.extend({
 
     loadXMLPart: function(elem, callback)
     {
-        var path = elem.attr('wl2o:path');
+        var path = elem.attr('x-pointer');
         var self = this;
 
         $.ajax({
@@ -265,7 +265,7 @@ Editor.HTMLModel = Editor.Model.extend({
     putXMLPart: function(elem, data) {
         var self = this;
       
-        var path = elem.attr('wl2o:path');
+        var path = elem.attr('x-pointer');
         this.xmlParts[path] = data;
 
         this.set('state', 'dirty');
old mode 100644 (file)
new mode 100755 (executable)
index fa52bd0..3696bdc
@@ -15,12 +15,17 @@ var HTMLView = View.extend({
       
         $('.htmlview', this.element).html(this.model.get('data'));
         this.modelStateChanged('state', this.model.get('state'));
-        this.model.load();
+        this.model.load();       
     },
 
     modelDataChanged: function(property, value) {
         $('.htmlview', this.element).html(value);
         this.updatePrintLink();
+
+        $("*[x-editable]").each(function() {
+            var e = $('<span class="context-menu"><span class="edit-button">Edytuj</span><span>Przypisy</span></span>');
+            e.appendTo(this);
+        });
     },
 
     updatePrintLink: function() {
@@ -69,6 +74,7 @@ var HTMLView = View.extend({
         this.updatePrintLink();
 
         this.element.bind('click', this.itemClicked.bind(this));
+        // this.element.bind('mouseover', this.itemHover.bind(this));
     },
   
     reload: function() {
@@ -80,6 +86,16 @@ var HTMLView = View.extend({
         this._super();
     },
 
+    itemHover: function(event)
+    {
+        var $e = $(event.target);
+        if( $e.attr('x-editable') == 'editable' ) {
+            console.log('over:', $e[0]);
+            $e.css({'background-color': 'grey'});
+        }
+
+    },
+
     itemClicked: function(event) 
     {
         var self = this;
@@ -88,9 +104,15 @@ var HTMLView = View.extend({
         var editableContent = null;
         var $e = $(event.target);
 
-        var n = 0;
+        if($e.hasClass('edit-button'))
+            this.openForEdit($e);
+    },
+
+    openForEdit: function($e)
+    {
+        var n = 0;        
 
-        while( ($e[0] != this.element[0]) && !($e.attr('wl2o:editable'))
+        while( ($e[0] != this.element[0]) && !($e.attr('x-editable'))
             && n < 50)
         {
             // console.log($e, $e.parent(), this.element);
@@ -98,12 +120,13 @@ var HTMLView = View.extend({
             n += 1;
         }
       
-        if(!$e.attr('wl2o:editable'))
+        if(!$e.attr('x-editable'))
             return true;
-    
-        // start edition on this node
-        
 
+        var $origin = $e;
+        console.log("editable: ", $e);
+    
+        // start edition on this node       
         var $overlay = $(
         '<div class="html-editarea">\n\
             <p class="html-editarea-toolbar">\n\
@@ -117,13 +140,12 @@ var HTMLView = View.extend({
         var y = $e[0].offsetTop;
         var w = $e.outerWidth();
         var h = $e.innerHeight();
-        $overlay.css({position: 'absolute', height: h, left: "5%", top: y, width: "90%"});
-        $e.offsetParent().append($overlay);
+        $overlay.css({position: 'absolute', height: 1.2*h, left: x, top: y, width: w});
+        // $e.offsetParent().append($overlay);
 
-        // load the original XML content
-        console.log($e, $e.offsetParent(), $overlay);
+        
                         
-        $('.html-editarea-cancel-button', $overlay).click(function() {
+        /* $('.html-editarea-cancel-button', $overlay).click(function() {
             $overlay.remove();
         });
 
@@ -132,18 +154,13 @@ var HTMLView = View.extend({
 
             // put the part back to the model
             self.model.putXMLPart($e, $('textarea', $overlay).val());
-        });
-
-        $('textarea', $overlay).focus(function() {
-            $overlay.css('z-index', 3000);
-        }).blur(function() {
-            $overlay.css('z-index', 2000);
-        });
+        }); */
 
         this.model.getXMLPart($e, function(path, data) {
             $('textarea', $overlay).val(data);
         });
-        
+
+        $origin.attr('x-open', 'open');
         return false;
     }
   
old mode 100644 (file)
new mode 100755 (executable)
index 810bd4e..e4b0897
@@ -8,7 +8,7 @@
 <form method="POST" action="{% url django.contrib.auth.views.login %}">
 {{ form.as_p }}
 <p><input type="submit" value="Login" /></p>
-<input type="hidden" name="next" value="{{ next }}" />
+<input type="hidden" name="next" value="{{ next|urlencode }}" />
 </form>
 </div>