From 7a12b550f4a8366c8ace2f9c55706aba7c4b17f7 Mon Sep 17 00:00:00 2001 From: Lukasz Date: Fri, 23 Oct 2009 05:51:28 -0400 Subject: [PATCH] Fixes to pull/push logic. --- apps/api/handlers/library_handlers.py | 2 +- apps/api/views.py | 6 +- lib/wlrepo/__init__.py | 5 +- lib/wlrepo/mercurial_backend/document.py | 79 ++++++++++++++------- lib/wlrepo/mercurial_backend/library.py | 2 +- lib/wlrepo/mercurial_backend/revision.py | 8 +++ platforma/static/css/html.css | 67 +++++++++++++++-- platforma/static/js/models.js | 6 +- platforma/static/js/views/html.js | 57 +++++++++------ platforma/templates/registration/login.html | 2 +- 10 files changed, 171 insertions(+), 63 deletions(-) mode change 100644 => 100755 apps/api/handlers/library_handlers.py mode change 100644 => 100755 apps/api/views.py mode change 100644 => 100755 lib/wlrepo/__init__.py mode change 100644 => 100755 lib/wlrepo/mercurial_backend/document.py mode change 100644 => 100755 lib/wlrepo/mercurial_backend/library.py mode change 100644 => 100755 lib/wlrepo/mercurial_backend/revision.py mode change 100644 => 100755 platforma/static/css/html.css mode change 100644 => 100755 platforma/static/js/models.js mode change 100644 => 100755 platforma/static/js/views/html.js mode change 100644 => 100755 platforma/templates/registration/login.html diff --git a/apps/api/handlers/library_handlers.py b/apps/api/handlers/library_handlers.py old mode 100644 new mode 100755 index 942ea0e8..562ed1b3 --- a/apps/api/handlers/library_handlers.py +++ b/apps/api/handlers/library_handlers.py @@ -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" }) diff --git a/apps/api/views.py b/apps/api/views.py old mode 100644 new mode 100755 index a8118028..3e9cb015 --- a/apps/api/views.py +++ b/apps/api/views.py @@ -24,7 +24,7 @@ def render(request): style = etree.parse(style_filename) - data = u'%s' % LINE_SWAP_EXPR.sub(u'
\n', data) + data = u'<%s>%s' % (tag, LINE_SWAP_EXPR.sub(u'
\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 diff --git a/lib/wlrepo/__init__.py b/lib/wlrepo/__init__.py old mode 100644 new mode 100755 index f8c07c68..fc309dcd --- a/lib/wlrepo/__init__.py +++ b/lib/wlrepo/__init__.py @@ -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) diff --git a/lib/wlrepo/mercurial_backend/document.py b/lib/wlrepo/mercurial_backend/document.py old mode 100644 new mode 100755 index f7da32d2..3bd26a6a --- a/lib/wlrepo/mercurial_backend/document.py +++ b/lib/wlrepo/mercurial_backend/document.py @@ -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 diff --git a/lib/wlrepo/mercurial_backend/library.py b/lib/wlrepo/mercurial_backend/library.py old mode 100644 new mode 100755 index cde7af9f..316800fd --- a/lib/wlrepo/mercurial_backend/library.py +++ b/lib/wlrepo/mercurial_backend/library.py @@ -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.") diff --git a/lib/wlrepo/mercurial_backend/revision.py b/lib/wlrepo/mercurial_backend/revision.py old mode 100644 new mode 100755 index f05637d2..80b761f7 --- a/lib/wlrepo/mercurial_backend/revision.py +++ b/lib/wlrepo/mercurial_backend/revision.py @@ -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() diff --git a/platforma/static/css/html.css b/platforma/static/css/html.css old mode 100644 new mode 100755 index 6bc118dd..d49c7231 --- a/platforma/static/css/html.css +++ b/platforma/static/css/html.css @@ -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; } @@ -244,14 +246,65 @@ 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; diff --git a/platforma/static/js/models.js b/platforma/static/js/models.js old mode 100644 new mode 100755 index f945238d..ffaf999a --- a/platforma/static/js/models.js +++ b/platforma/static/js/models.js @@ -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'); diff --git a/platforma/static/js/views/html.js b/platforma/static/js/views/html.js old mode 100644 new mode 100755 index fa52bd0f..3696bdc8 --- a/platforma/static/js/views/html.js +++ b/platforma/static/js/views/html.js @@ -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 = $('EdytujPrzypisy'); + 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 = $( '
\n\

\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; } diff --git a/platforma/templates/registration/login.html b/platforma/templates/registration/login.html old mode 100644 new mode 100755 index 810bd4ec..e4b0897c --- a/platforma/templates/registration/login.html +++ b/platforma/templates/registration/login.html @@ -8,7 +8,7 @@

{{ form.as_p }}

- +
-- 2.20.1