Example translation editing

This commit is contained in:
Ozbolt Menegatti 2019-11-16 14:18:37 +01:00
parent 4a80ba878a
commit e287e2414a
8 changed files with 62 additions and 9 deletions

View File

@ -61,6 +61,7 @@ var entry = {"content": `<entry>
<example>The test was interesting.</example>
<translationContainer>
<translation>Preizkus je bil zanimiv.</translation>
<translation>Drugi prevod.</translation>
</translationContainer>
</exampleContainer>
</exampleContainerList>

View File

@ -152,6 +152,10 @@
.example-text {
._hoverable();
}
.example-translation-list {
._hoverable();
}
}
}
}

View File

@ -1,7 +1,8 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample
from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit, ShowExampleTranslationEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation
from message.message import msg

View File

@ -51,6 +51,7 @@ class ShowSenseAdd(GenericShowModal):
model.modal = lambda: modals.add_sense(NewSense())
# I don't need GenericShowModal since there is only one comment
class ShowCommentEdit(ClickMessage):
def update_model(self, model):
model.modal_shown = True
@ -63,6 +64,14 @@ class ShowExampleEdit(GenericShowModal):
model.modal = lambda: modals.edit_example(self.arg)
class ShowExampleTranslationEdit(GenericShowModal):
def update_model(self, model):
super().update_model(model)
example = self.arg
example.make_copy()
model.modal = lambda: modals.edit_example_translation(example)
class ShowEditTranslation(GenericShowModal):
def update_model(self, model):
model.modal_shown = True

View File

@ -32,6 +32,30 @@ class AddSenseLabel(NoReset):
def update_model(self, model):
# just adding to the copy to show in the modal
self.sense.copy().labels.append("")
class AddExampleTranslation(NoReset):
def __init__(self, _, prop):
assert(type(prop) is Example)
self.example = prop
def update_model(self, model):
# just adding to the copy to show in the modal
self.example.copy().translations.append("")
class EditExampleTranslation(Message):
def __init__(self, _, prop):
assert(type(prop) is Example)
self.example = prop
def update_model(self, model):
self.example.translations = []
for input_el in document.getElementsByClassName("example-translation-edit-input"):
new_example_translation = input_el.value
if new_example_translation != "":
self.example.translations.append(new_example_translation)
class AddSense(SimpleEditMessage):

View File

@ -81,6 +81,16 @@ def edit_sense_label(sense):
return modal_template(content, "Sense", message.EditSenseLabel, sense)
def edit_example_translation(example):
content = [h("span", {}, "Edit example translations")]
for slabel in example.copy().translations:
content.append(h("label", {}, [
h("input.example-translation-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
content.append(h("button", {"on": {"click": message.msg(message.AddExampleTranslation, example)}}, "+"))
return modal_template(content, "Example Translations", message.EditExampleTranslation, example)
def add_sense(sense):
return one_question_modal("Add sense", message.AddSense, "Add sense with a label", "", sense)

View File

@ -1,8 +1,10 @@
class Example:
from model.editable import Editable
class Example(Editable):
def __init__(self, example_xml):
example = example_xml.querySelector("example")
translation = example_xml.querySelector("translationContainer translation")
self.example = example.textContent if example else ""
self.translation = translation.textContent if translation else ""
self.translations = []
for translation in example_xml.querySelectorAll("translationContainer translation"):
self.translations.append(translation.textContent)

View File

@ -56,9 +56,11 @@ class View:
h("div.example-dot", {}, ""),
h("div.example-rest", {}, [
h("span.example-text", {"on": {"click": msg(ShowExampleEdit, example)} }, example.example),
h("div.example-translation", {}, [
h("span.example-arrow", {}, ""),
h("span", {}, example.translation)])])])
h("div.example-translation-list", { "on": {"click": msg(ShowExampleTranslationEdit, example)} }, [
h("div.example-translation", {}, [
h("span.example-arrow", {}, ""),
h("span", {}, t)])
for t in example.translations])])])
@staticmethod
def view_translations(translations, sense):