Changing how senses are added and how buttons are shown.
This commit is contained in:
parent
06ab8f2230
commit
1039a686cc
|
@ -37,6 +37,16 @@ def export_entry(entry):
|
|||
comment.textContent = entry.comment
|
||||
head.appendChild(comment)
|
||||
|
||||
head.appendChild(_export_label_list(doc, entry.labels))
|
||||
|
||||
variants = doc.createElement("variantList")
|
||||
head.appendChild(variants)
|
||||
|
||||
for v in entry.variants:
|
||||
variant = doc.createElement("variant")
|
||||
variant.textContent = v
|
||||
variants.appendChild(variant)
|
||||
|
||||
# now lets do body
|
||||
body = doc.createElement("body")
|
||||
entry_xml.appendChild(body)
|
||||
|
@ -52,14 +62,7 @@ def export_entry(entry):
|
|||
|
||||
def export_sense(doc, sense):
|
||||
sense_xml = doc.createElement("sense")
|
||||
|
||||
label_list = doc.createElement("labelList")
|
||||
sense_xml.appendChild(label_list)
|
||||
|
||||
for label in sense.labels:
|
||||
label_xml = doc.createElement("label")
|
||||
label_xml.textContent = label
|
||||
label_list.appendChild(label_xml)
|
||||
sense_xml.appendChild(_export_label_list(doc, sense.labels))
|
||||
|
||||
definition_list = doc.createElement("definitionList")
|
||||
sense_xml.appendChild(definition_list)
|
||||
|
@ -92,8 +95,9 @@ def export_sense(doc, sense):
|
|||
translation_container = doc.createElement("translationContainer")
|
||||
example_container.appendChild(translation_container)
|
||||
|
||||
for t in example.translations:
|
||||
translation = doc.createElement("translation")
|
||||
translation.textContent = example.translation
|
||||
translation.textContent = t
|
||||
translation_container.appendChild(translation)
|
||||
|
||||
return sense_xml
|
||||
|
@ -103,6 +107,7 @@ def export_translation(doc, translation):
|
|||
|
||||
actual_t = doc.createElement("translation")
|
||||
actual_t.textContent = translation.translation
|
||||
if translation.source:
|
||||
actual_t.setAttribute("source", translation.source)
|
||||
translation_xml.appendChild(actual_t)
|
||||
|
||||
|
@ -110,21 +115,15 @@ def export_translation(doc, translation):
|
|||
explanation.textContent = translation.explanation
|
||||
translation_xml.appendChild(explanation)
|
||||
|
||||
tags = doc.createElement("tagsContainer")
|
||||
translation_xml.appendChild(tags)
|
||||
|
||||
for tagname, tagvalue in translation.tags.items():
|
||||
name_el = doc.createElement("type")
|
||||
name_el.textContent = tagname
|
||||
value_el = doc.createElement("value")
|
||||
value_el.textContent = tagvalue
|
||||
|
||||
tag_el = doc.createElement("tag")
|
||||
tag_el.appendChild(name_el)
|
||||
tag_el.appendChild(value_el)
|
||||
|
||||
tags.appendChild(tag_el)
|
||||
|
||||
translation_xml.appendChild(_export_label_list(doc, translation.tags))
|
||||
return translation_xml
|
||||
|
||||
|
||||
def _export_label_list(doc, lst):
|
||||
result = doc.createElement("labelList")
|
||||
for key, value in lst:
|
||||
label_el = doc.createElement("label")
|
||||
label_el.textContent = value
|
||||
label_el.setAttribute('type', key)
|
||||
result.appendChild(label_el)
|
||||
return result
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from message.simple_messages import NoReset, Reset, ModalNotOkClose
|
||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||
from message.show_messages import ShowMenu, ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
|
||||
from message.show_messages import ShowMenu, ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
|
||||
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels
|
||||
|
||||
from message.message import msg
|
||||
|
|
|
@ -34,12 +34,6 @@ class ShowSenseDefinitionEdit(ClickMessage):
|
|||
model.modal = lambda: modals.edit_sense_definition(model.sense)
|
||||
|
||||
|
||||
class ShowSenseAdd(ClickMessage):
|
||||
def update_model(self, model):
|
||||
model.modal_shown = True
|
||||
model.modal = lambda: modals.add_sense()
|
||||
|
||||
|
||||
class ShowCommentEdit(ClickMessage):
|
||||
def update_model(self, model):
|
||||
model.modal_shown = True
|
||||
|
|
|
@ -17,13 +17,6 @@ class EditSenseLabel(Message):
|
|||
sense.labels = common_accessors.label_list_getter()
|
||||
|
||||
|
||||
class AddSenseLabel(NoReset):
|
||||
def update_model(self, model):
|
||||
sense = self.get_arg(0, Sense)
|
||||
# just adding to the copy to show in the modal
|
||||
sense.copy().labels.append("")
|
||||
|
||||
|
||||
class AddToGenericList(NoReset):
|
||||
def update_model(self, model):
|
||||
list_getter = self.get_arg(0)
|
||||
|
@ -46,10 +39,10 @@ class EditExampleTranslation(Message):
|
|||
example.translations = common_accessors.generic_list_getter()
|
||||
|
||||
|
||||
class AddSense(QuestionMessage):
|
||||
class AddSense(Message):
|
||||
def update_model(self, model):
|
||||
sense = Sense.new_empty()
|
||||
sense.labels = [self.new_text]
|
||||
sense.definition = "New Sense"
|
||||
model.entry.senses.append(sense)
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from model.sense import Sense
|
||||
from model.editable import Editable
|
||||
from model.tags import TAGS
|
||||
|
||||
class Entry(Editable):
|
||||
def __init__(self, entry_xml):
|
||||
|
|
|
@ -47,10 +47,6 @@ def edit_entry_labels(entry):
|
|||
return modal_template(content, "Translation", message.EditEntryLabels())
|
||||
|
||||
|
||||
def add_sense():
|
||||
return modal_template(question("Add sense with a label", ""), "Add sense", message.AddSense())
|
||||
|
||||
|
||||
def edit_sense_definition(sense):
|
||||
return modal_template(question("Edit sense definition", sense.definition), "Sense definition", message.EditSenseDefinition(sense))
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class View:
|
|||
def _view(self):
|
||||
return h("div", {"on": { "click": msg(Reset()) }}, [
|
||||
View.view_entry(self.model.entry),
|
||||
# h("button.blk", {"on": { "click": lambda _: console.log(export_to_xml(self.model)) } }, "XML2Console"),
|
||||
h("button.blk", {"on": { "click": lambda _: console.log(export_to_xml(self.model)) } }, "XML2Console"),
|
||||
View.view_menu(self.model.menu_location, self.model.menu_shown, self.model.translation),
|
||||
View.view_modal(self.model.modal_shown, self.model.modal)])
|
||||
|
||||
|
@ -35,26 +35,42 @@ class View:
|
|||
h("span#grammar", {}, entry.grammar)]),
|
||||
View.view_entry_button_section(entry),
|
||||
h("div#sense-container", {}, view_sense_list),
|
||||
h("button.add-button", {"on": {"click": msg(ShowSenseAdd())}}, "+")])
|
||||
h("button.add-button", {"on": {"click": msg(AddSense())}}, "+")])
|
||||
|
||||
|
||||
@staticmethod
|
||||
def view_entry_button_section(entry):
|
||||
clk = lambda cls: {"on": {"click": msg(cls)}}
|
||||
buttons = [
|
||||
h("button.warning", clk(ShowCommentEdit()), "Comment"),
|
||||
h("button.normal", clk(ShowVariantsEdit()), "Variants"),
|
||||
h("button.success", clk(ShowEntryLabelsEdit()), "Labels")]
|
||||
h("button.success", clk(ShowEntryLabelsEdit()), "Labels"),
|
||||
h("button.warning", clk(ShowCommentEdit()), "Comment")]
|
||||
|
||||
if entry.comment == "" and len(entry.labels) == 0 and len(entry.variants) == 0:
|
||||
return h("div", {}, buttons)
|
||||
view_buttons = []
|
||||
view_table = []
|
||||
|
||||
if len(entry.variants) == 0:
|
||||
view_buttons.append(buttons[0])
|
||||
else:
|
||||
view_table.append((buttons[0], ", ".join(entry.variants)))
|
||||
|
||||
if len(entry.labels) == 0:
|
||||
view_buttons.append(buttons[1])
|
||||
else:
|
||||
labels = ", ".join([val for _, val in entry.labels])
|
||||
return h("table", {}, [
|
||||
h("tr", {}, [ h("td", {}, buttons[0]), h("td", {}, entry.comment)]),
|
||||
h("tr", {}, [ h("td", {}, buttons[1]), h("td", {}, ", ".join(entry.variants))]),
|
||||
h("tr", {}, [ h("td", {}, buttons[2]), h("td", {}, labels)])])
|
||||
view_table.append((buttons[1], labels))
|
||||
|
||||
if entry.comment == "":
|
||||
view_buttons.append(buttons[2])
|
||||
else:
|
||||
view_table.append((buttons[2], entry.comment))
|
||||
|
||||
table_rows = [
|
||||
h("tr", {}, [ h("td", {}, btn), h("td", {}, content)])
|
||||
for btn, content in view_table]
|
||||
|
||||
view_buttons.append(h("table", {}, table_rows))
|
||||
return h("div", {}, view_buttons)
|
||||
|
||||
@staticmethod
|
||||
def view_sense(sense, senseNum):
|
||||
|
|
Loading…
Reference in New Issue
Block a user