From: Radek Czajka Date: Tue, 28 Jan 2025 12:53:20 +0000 (+0100) Subject: fix for postgres X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/HEAD?ds=inline;hp=18948ce1d84878c6307f2d0b732a9dbd03778cfb fix for postgres --- diff --git a/src/documents/models/chunk.py b/src/documents/models/chunk.py index 4d8f6d23..797fc174 100644 --- a/src/documents/models/chunk.py +++ b/src/documents/models/chunk.py @@ -75,8 +75,10 @@ class Chunk(dvcs_models.Document): def split(self, slug, title='', **kwargs): """ Create an empty chunk after this one """ - self.book.chunk_set.filter(number__gt=self.number).update( - number=models.F('number')+1) + # Single update makes unique constr choke on postgres. + for chunk in self.book.chunk_set.filter(number__gt=self.number).order_by('-number'): + chunk.number += 1 + chunk.save() new_chunk = None while not new_chunk: new_slug = self.book.make_chunk_slug(slug) diff --git a/src/redakcja/static/css/html.scss b/src/redakcja/static/css/html.scss index d9886d4f..3819c821 100644 --- a/src/redakcja/static/css/html.scss +++ b/src/redakcja/static/css/html.scss @@ -300,12 +300,19 @@ div[x-node] > .uwaga { * Przypisy w tekście */ -.htmlview .annotation-inline-box { - &:hover > span[x-annotation-box] { - display: block; +.htmlview .annotation-inline-box, +.htmlview .reference-inline-box { + &:hover { + > span[x-annotation-box], + > span[x-preview] + { + display: block; + } } - > span[x-annotation-box] { + > span[x-annotation-box], + > span[x-preview] + { display: none; width: 300px; font-size: 10pt; @@ -549,3 +556,27 @@ div[x-node] > .uwaga { } } } + + + +div[x-node="numeracja"] { + background: lightblue; + margin: 2em; + padding: 2em; + border-radius: 1em; + &::before { + content: "Reset numeracji"; + } +} + +*[x-number]::before { + display: block; + content: attr(x-number); + position: absolute; + text-align: right; + width: 40px; + left: -60px; + font-size: .9em; + opacity: .8; + +} diff --git a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js index 726c2439..2e1c28d2 100644 --- a/src/redakcja/static/js/wiki/view_editor_wysiwyg.js +++ b/src/redakcja/static/js/wiki/view_editor_wysiwyg.js @@ -515,7 +515,8 @@ element: source, stripOuter: true, success: function(text){ - $('textarea', $overlay).val($.trim(text)); + let ttext = $.trim(text); + $('textarea', $overlay).val(ttext); setTimeout(function(){ $('textarea', $overlay).elastic().focus(); @@ -659,6 +660,26 @@ $('*[x-annotation-box]', editable).css({ }).show(); } + if (editable.is('.reference-inline-box')) { + let preview = $('*[x-preview]', editable); + preview.show(); + let link = $("a", preview); + let href = link.attr('href'); + if (link.attr('title') == '?' && href.startsWith('https://www.wikidata.org/wiki/')) { + link.attr('title', '…'); + let qid = href.split('/').reverse()[0]; + $.ajax({ + url: 'https://www.wikidata.org/w/rest.php/wikibase/v1/entities/items/' + qid + '?_fields=labels', + dataType: "json", + success: function(data) { + link.attr( + 'title', + data['labels']['pl'] || data['labels']['en'] + ); + }, + }); + } + } }); self.caret = new Caret(element); @@ -732,6 +753,7 @@ callback(); } + let self = this; xml2html({ xml: this.doc.text, base: this.doc.getBase(), @@ -739,6 +761,7 @@ var htmlView = $('#html-view'); htmlView.html(element); + self.renumber(); if ('PropertiesPerspective' in $.wiki.perspectives) $.wiki.perspectives.PropertiesPerspective.enable(); @@ -921,6 +944,22 @@ } }) } + + renumber() { + let number = 0; + $('#html-view *').each((i, e) => { + let $e = $(e); + if ($e.closest('[x-node="abstrakt"]').length) return; + if ($e.closest('[x-node="nota_red"]').length) return; + let node = $e.attr('x-node'); + if (node == 'numeracja') { + number = 0; + } else if (['werset', 'akap', 'wers'].includes(node)) { + number ++; + $e.attr('x-number', number); + } + }) + } } $.wiki.VisualPerspective = VisualPerspective; diff --git a/src/wlxml/templates/wlxml/wl2html.xsl b/src/wlxml/templates/wlxml/wl2html.xsl index c3af0ff4..9716e19f 100644 --- a/src/wlxml/templates/wlxml/wl2html.xsl +++ b/src/wlxml/templates/wlxml/wl2html.xsl @@ -57,6 +57,20 @@ + +
+ +
+ + + + + + +
+
+
+