Commit b87b3512 authored by Robin Tissot's avatar Robin Tissot
Browse files

Merge branch 'develop'

parents 572ff6a8 4b268c5c
......@@ -6,8 +6,10 @@ const BasePanel = Vue.extend({
};
},
watch: {
'ratio': function(n, o) {
if (this.part.loaded) this.refresh();
'part.loaded': function(n, o) {
if (this.part.loaded) {
this.refresh();
}
}
},
methods: {
......
......@@ -17,6 +17,7 @@ var diploLine = LineBase.extend({
mounted() {
Vue.nextTick(function() {
this.$parent.appendLine();
if (this.line.currentTrans) this.setElContent(this.line.currentTrans.content);
}.bind(this));
},
beforeDestroy() {
......
......@@ -43,6 +43,7 @@ var DiploPanel = BasePanel.extend({
this.editor = this.$el.querySelector('#diplomatic-lines');
this.sortModeBtn = this.$el.querySelector('#sortMode');
this.saveNotif = this.$el.querySelector('.tools #save-notif');
this.refresh();
},
methods: {
empty() {
......@@ -151,15 +152,18 @@ var DiploPanel = BasePanel.extend({
this.bulkUpdate();
this.bulkCreate();
},
setHeight() {
this.$el.querySelector('.content-container').style.minHeight = Math.round(this.part.image.size[1] * this.ratio) + 'px';
},
focusNextLine(sel, line) {
if (line.nextSibling) {
let range = document.createRange();
range.setStart(line.nextSibling, 0);
range.collapse(false);
sel.removeAllRanges();
if (line.nextSibling.offsetTop >
this.editor.parentNode.scrollTop + this.editor.parentNode.clientHeight) {
line.nextSibling.scrollIntoView(false);
}
sel.addRange(range);
}
},
......@@ -168,6 +172,12 @@ var DiploPanel = BasePanel.extend({
let range = document.createRange();
range.setStart(line.previousSibling, 0);
sel.removeAllRanges();
if (line.previousSibling.offsetTop - this.editor.parentNode.offsetTop <
this.editor.parentNode.scrollTop) {
line.previousSibling.scrollIntoView(true);
}
sel.addRange(range);
}
},
......@@ -285,12 +295,11 @@ var DiploPanel = BasePanel.extend({
elt.version_updated_at = lt.version_updated_at;
}
},
setHeight() {
this.$el.querySelector('.content-container').style.minHeight = Math.round(this.part.image.size[1] * this.ratio) + 'px';
},
updateView() {
/*
update the size of the panel
*/
this.setHeight();
}
},
}
});
......@@ -29,7 +29,6 @@ const visuLine = LineBase.extend({
this.textElement.style.fontSize = lineHeight * (1/2) + 'px';
return 10+'px';
},
computeTextLength() {
if (!this.line.currentTrans) return;
content = this.line.currentTrans.content;
......@@ -61,7 +60,6 @@ const visuLine = LineBase.extend({
textPathId() {
return this.line ? 'textPath'+this.line.pk : '';
},
maskStrokeColor() {
if (this.line.currentTrans && this.line.currentTrans.content) {
return 'none';
......@@ -73,7 +71,6 @@ const visuLine = LineBase.extend({
if (this.line == null || !this.line.mask) return '';
return this.line.mask.map(pt => Math.round(pt[0]*this.ratio)+','+Math.round(pt[1]*this.ratio)).join(' ');
},
fakeBaseline() {
// create a fake path based on the mask,
var min = this.line.mask.reduce((minPt, curPt) => (curPt[0] < minPt[0]) ? curPt : minPt);
......
......@@ -30,14 +30,17 @@ const VisuPanel = BasePanel.extend({
this.editLine = this.part.lines[index - 1];
}
},
resetLines() {
if (this.part.lines.length) {
this.$refs.visulines.forEach(function(line) {
line.reset();
});
}
},
updateView() {
this.$el.querySelector('svg').style.height = Math.round(this.part.image.size[1] * this.ratio) + 'px';
Vue.nextTick(function() {
if (this.part.lines.length) {
this.$refs.visulines.forEach(function(line) {
line.reset();
});
}
this.resetLines();
}.bind(this));
}
}
......
......@@ -44,7 +44,6 @@ class ImportForm(BootstrapFormMixin, forms.Form):
def clean_iiif_uri(self):
uri = self.cleaned_data.get('iiif_uri')
if uri:
try:
resp = requests.get(uri)
......@@ -83,7 +82,7 @@ class ImportForm(BootstrapFormMixin, forms.Form):
cleaned_data = super().clean()
if (not cleaned_data['resume_import']
and not cleaned_data.get('upload_file')
and not cleaned_data['iiif_uri']):
and not cleaned_data.get('iiif_uri')):
raise forms.ValidationError(_("Choose one type of import."))
return cleaned_data
......
......@@ -70,7 +70,8 @@ class PdfParser(ParserDocument):
def validate(self):
try:
self.doc = pyvips.Image.new_from_buffer(self.file.read(), "",
dpi=300, n=-1, access="sequential")
dpi=300, n=-1,
access="sequential")
except pyvips.error.Error as e:
logger.exception(e)
raise ParseError(_("Invalid pdf file."))
......@@ -83,21 +84,22 @@ class PdfParser(ParserDocument):
return 0
def parse(self, start_at=0, override=False, user=None):
self.doc = pyvips.Image.new_from_buffer(self.file.read(), "",
dpi=300, n=-1, access="sequential")
buff = self.file.read()
doc = pyvips.Image.new_from_buffer(buff, "",
dpi=300, n=-1,
access="sequential")
n_pages = doc.get('n-pages')
try:
self.doc.flatten(background=255)
n_pages = self.doc.get('n-pages')
page_width = self.doc.width
page_height = self.doc.height / n_pages
for i in range(0, n_pages):
page = self.doc.crop(0, i * page_height, page_width, page_height)
for page_nb in range(start_at, n_pages):
page = pyvips.Image.new_from_buffer(buff, "", dpi=300,
access="sequential",
page=page_nb)
part = DocumentPart(document=self.document)
part.image.save('%s_page_%d.png' % (self.file.name, i+1),
part.image.save('%s_page_%d.png' % (self.file.name, page_nb+1),
ContentFile(page.write_to_buffer('.png')))
part.save()
yield part
page_nb = page_nb + 1
except pyvips.error.Error as e:
msg = _("Parse error in {filename}: {error}, skipping it.").format(
filename=self.file.name, error=e.args[0]
......@@ -606,19 +608,19 @@ class IIIFManifestParser(ParserDocument):
def manifest(self):
try:
return json.loads(self.file.read())
except (json.JSONDecodeError) as e:
raise ParseError(e)
except (json.JSONDecodeError, UnicodeDecodeError) as e:
raise ParseError(_("Couldn't decode invalid manifest ({error})").format(error=e))
@cached_property
def canvases(self):
try:
return self.manifest["sequences"][0]["canvases"]
except (KeyError, IndexError) as e:
raise ParseError(e)
except (KeyError, IndexError):
return 0
def validate(self):
if len(self.canvases) < 1:
raise ParseError(_("Empty manifesto."))
raise ParseError(_("Empty or invalid manifest, no images found."))
@property
def total(self):
......@@ -633,13 +635,13 @@ class IIIFManifestParser(ParserDocument):
DocumentMetadata.objects.get_or_create(
document=self.document, key=md, value=metadata["value"][:512]
)
except KeyError as e:
except KeyError:
pass
try:
for i, canvas in enumerate(self.canvases):
if i < start_at:
continue
for i, canvas in enumerate(self.canvases):
if i < start_at:
continue
try:
resource = canvas["images"][0]["resource"]
url = resource["@id"]
uri_template = "{image}/{region}/{size}/{rotation}/{quality}.{format}"
......@@ -664,8 +666,10 @@ class IIIFManifestParser(ParserDocument):
part.save()
yield part
time.sleep(0.1) # avoid being throttled
except (KeyError, IndexError) as e:
raise ParseError(e)
except (KeyError, IndexError) as e:
if self.report:
self.report.append(_('Error while fetching {filename}: {error}').format(
filename=name, error=e))
class TranskribusPageXmlParser(PagexmlParser):
......
......@@ -56,7 +56,7 @@ class TaskReport(models.Model):
self.save()
self.user.notify(_('%(task_label)s error!') % {'task_label': self.label},
level='error',
level='danger',
links=[{'text': 'Report', 'src': self.uri}])
def end(self, extra_links=None):
......
......@@ -444,12 +444,12 @@ i.panel-icon {
}
.panel .content-container .js-wheelzoom-container {
min-height: calc(100vh - 190px);
min-height: calc(100vh - 200px);
}
.panel#diplo-panel .content-container {
overflow-y: scroll;
max-height: calc(100vh - 190px);
max-height: calc(100vh - 200px);
}
.panel .panel-img {
......@@ -648,4 +648,4 @@ i.panel-icon {
}
#reset-onboarding{
margin-top: 5%;
}
\ No newline at end of file
}
......@@ -544,47 +544,48 @@
</TranscriptionModal>
</div>
</VisuPanel>
</keep-alive>
<keep-alive>
<DiploPanel id="diplo-panel"
v-bind:part="part"
v-if="show.diplomatic && part.loaded"
ref="diploPanel"
inline-template>
<div class="col panel">
<div class="tools">
<i title="{% trans 'Text Panel' %}" class="panel-icon fas fa-list-ol"></i>
<i id="save-notif" title="{% trans "There is content waiting to be saved (don't leave the page)" %}" class="notice fas fa-save hide"></i>
<button id="sortMode"
title="{% trans "Toggle sorting mode." %}"
class="btn btn-sm ml-3 btn-info fas fa-sort"
@click="toggleSort"
autocomplete="off"></button>
</div>
<div class="content-container {{ document.read_direction }}">
<diploline v-for="line in part.lines"
v-bind:line="line"
v-bind:ratio="ratio"
v-bind:key="'DL' + line.pk">
</diploline>
<div id="diplomatic-lines"
contenteditable="true"
autocomplete="off"
@keydown="onKeyPress"
@keyup="constrainLineNumber"
@input="changed"
@focusin="startEdit"
@focusout="stopEdit"
@paste="onPaste"
@mousemove="showOverlay"
@mouseleave="hideOverlay">
</div>
</div>
</div>
</DiploPanel>
</keep-alive>
</keep-alive>
<keep-alive>
<DiploPanel id="diplo-panel"
v-bind:part="part"
v-if="show.diplomatic && part.loaded"
ref="diploPanel"
inline-template>
<div class="col panel">
<div class="tools">
<i title="{% trans 'Text Panel' %}" class="panel-icon fas fa-list-ol"></i>
<i id="save-notif" title="{% trans "There is content waiting to be saved (don't leave the page)" %}" class="notice fas fa-save hide"></i>
<button id="sortMode"
title="{% trans "Toggle sorting mode." %}"
class="btn btn-sm ml-3 btn-info fas fa-sort"
@click="toggleSort"
autocomplete="off"></button>
</div>
<div class="content-container {{ document.read_direction }}">
<diploline v-for="line in part.lines"
v-bind:line="line"
v-bind:ratio="ratio"
v-bind:key="'DL' + line.pk">
</diploline>
<div id="diplomatic-lines"
contenteditable="true"
autocomplete="off"
@keydown="onKeyPress"
@keyup="constrainLineNumber"
@input="changed"
@focusin="startEdit"
@focusout="stopEdit"
@paste="onPaste"
@mousemove="showOverlay"
@mouseleave="hideOverlay">
</div>
</div>
</div>
</DiploPanel>
</keep-alive>
<div class="col-sides">
{% if document.read_direction == 'rtl' %}
......
......@@ -12,7 +12,7 @@ django-redis==4.10.0
psycopg2-binary==2.7.6
django-ordered-model==3.1.1
easy-thumbnails==2.5
git+https://github.com/mittagessen/kraken.git@3.0b16#egg=kraken
git+https://github.com/mittagessen/kraken.git@3.0b17#egg=kraken
django-cleanup==3.0.1
djangorestframework==3.9.2
drf-nested-routers==0.91
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment