sense -> relatedEntryList read/edit/view/write

This commit is contained in:
Ozbolt Menegatti 2020-01-21 22:18:43 +01:00
parent 8eada0d246
commit 28dc5472c6
7 changed files with 41 additions and 8 deletions

View File

@ -64,6 +64,14 @@ def export_entry(entry):
variant.textContent = v
variants.appendChild(variant)
relist = doc.createElement("relatedEntryList")
head.appendChild(relist)
for re in entry.related_entries:
relateEntry = doc.createElement("relatedEntry")
relateEntry.textContent = re
relist.appendChild(relateEntry)
head.appendChild(_export_label_list(doc, entry.labels))
comment = doc.createElement("comment")

View File

@ -1,7 +1,7 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabel
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin

View File

@ -31,6 +31,12 @@ class ShowVariantsEdit(ClickMessage):
model.modal_set(lambda: modals.edit_variants(model.entry))
class ShowRelatedEntriesEdit(ClickMessage):
def update_model(self, model):
model.entry.make_copy()
model.modal_set(lambda: modals.edit_related_entries(model.entry))
class ShowExampleEdit(KeyPlusClickMessage):
def update_model_default(self, model):
example = self.get_arg(0, Example)

View File

@ -95,6 +95,12 @@ class EditVariants(Message):
model.entry.variants = variants
class EditRelatedEntries(Message):
def update_model(self, model):
related_entries = common_accessors.generic_list_getter()
model.entry.related_entries = related_entries
class EditEntryLabels(Message):
def update_model(self, model):
labels = common_accessors.label_list_getter()

View File

@ -14,6 +14,7 @@ class Entry(Editable):
self.grammar = grammar.textContent if grammar else ""
self.comment = comment.textContent if comment else ""
self.variants = [v.textContent for v in entry_xml.querySelectorAll("head variantList variant")]
self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
self.lexical_unit = {}
lex_unit = entry_xml.querySelector("lexical_unit lexeme,lexicalUnit lexeme")

View File

@ -43,6 +43,12 @@ def edit_variants(entry):
return modal_template(content, "Add or remove variants", message.EditVariants())
def edit_related_entries(entry):
reget = lambda: entry.copy().related_entries
content = generic_list_editor("Related entries", reget)
return modal_template(content, "Add or remove related entries", message.EditRelatedEntries())
def edit_entry_labels(entry):
content = label_list_editor(entry.copy().labels, message.AddToLabelList(entry.copy().labels))
return modal_template(content, "Translation", message.EditEntryLabels())

View File

@ -49,8 +49,9 @@ class View:
clk = lambda cls: {"on": {"click": msg(cls)}}
buttons = [
h("button.normal", clk(ShowVariantsEdit()), "Variants"),
h("button.success", clk(ShowRelatedEntriesEdit()), "Povezano"),
h("button.success", clk(ShowEntryLabelsEdit()), "Labels"),
h("button.warning", clk(ShowCommentEdit()), "Comment")]
h("button.normal", clk(ShowCommentEdit()), "Comment")]
view_buttons = []
view_table = []
@ -60,16 +61,21 @@ class View:
else:
view_table.append((buttons[0], ", ".join(entry.variants)))
if len(entry.labels) == 0:
if len(entry.related_entries) == 0:
view_buttons.append(buttons[1])
else:
labels = ", ".join([clean_label(val) for _, val in entry.labels])
view_table.append((buttons[1], labels))
view_table.append((buttons[1], ", ".join(entry.related_entries)))
if entry.comment == "":
if len(entry.labels) == 0:
view_buttons.append(buttons[2])
else:
view_table.append((buttons[2], entry.comment))
labels = ", ".join([clean_label(val) for _, val in entry.labels])
view_table.append((buttons[2], labels))
if entry.comment == "":
view_buttons.append(buttons[3])
else:
view_table.append((buttons[3], entry.comment))
table_rows = [
h("tr", {}, [ h("td", {}, btn), h("td", {}, content)])