Changing how senses are added and how buttons are shown.

This commit is contained in:
Ozbolt Menegatti 2019-11-20 18:58:48 +01:00
parent 06ab8f2230
commit 1039a686cc
7 changed files with 62 additions and 63 deletions

View File

@ -10,13 +10,13 @@ def export_to_xml(model):
def export_entry(entry): def export_entry(entry):
parser = __new__(DOMParser()) parser = __new__(DOMParser())
doc = parser.parseFromString("<entry />", "text/xml") doc = parser.parseFromString("<entry />", "text/xml")
entry_xml = doc.firstChild entry_xml = doc.firstChild
# create head # create head
head = doc.createElement("head") head = doc.createElement("head")
entry_xml.appendChild(head) entry_xml.appendChild(head)
status = doc.createElement("status") status = doc.createElement("status")
status.textContent = entry.status status.textContent = entry.status
head.appendChild(status) head.appendChild(status)
@ -37,6 +37,16 @@ def export_entry(entry):
comment.textContent = entry.comment comment.textContent = entry.comment
head.appendChild(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 # now lets do body
body = doc.createElement("body") body = doc.createElement("body")
entry_xml.appendChild(body) entry_xml.appendChild(body)
@ -52,14 +62,7 @@ def export_entry(entry):
def export_sense(doc, sense): def export_sense(doc, sense):
sense_xml = doc.createElement("sense") sense_xml = doc.createElement("sense")
sense_xml.appendChild(_export_label_list(doc, sense.labels))
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)
definition_list = doc.createElement("definitionList") definition_list = doc.createElement("definitionList")
sense_xml.appendChild(definition_list) sense_xml.appendChild(definition_list)
@ -92,9 +95,10 @@ def export_sense(doc, sense):
translation_container = doc.createElement("translationContainer") translation_container = doc.createElement("translationContainer")
example_container.appendChild(translation_container) example_container.appendChild(translation_container)
translation = doc.createElement("translation") for t in example.translations:
translation.textContent = example.translation translation = doc.createElement("translation")
translation_container.appendChild(translation) translation.textContent = t
translation_container.appendChild(translation)
return sense_xml return sense_xml
@ -103,28 +107,23 @@ def export_translation(doc, translation):
actual_t = doc.createElement("translation") actual_t = doc.createElement("translation")
actual_t.textContent = translation.translation actual_t.textContent = translation.translation
actual_t.setAttribute("source", translation.source) if translation.source:
actual_t.setAttribute("source", translation.source)
translation_xml.appendChild(actual_t) translation_xml.appendChild(actual_t)
explanation = doc.createElement("explanation") explanation = doc.createElement("explanation")
explanation.textContent = translation.explanation explanation.textContent = translation.explanation
translation_xml.appendChild(explanation) translation_xml.appendChild(explanation)
tags = doc.createElement("tagsContainer") translation_xml.appendChild(_export_label_list(doc, translation.tags))
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)
return translation_xml 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

View File

@ -1,6 +1,6 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose from message.simple_messages import NoReset, Reset, ModalNotOkClose
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation 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.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels
from message.message import msg from message.message import msg

View File

@ -34,12 +34,6 @@ class ShowSenseDefinitionEdit(ClickMessage):
model.modal = lambda: modals.edit_sense_definition(model.sense) 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): class ShowCommentEdit(ClickMessage):
def update_model(self, model): def update_model(self, model):
model.modal_shown = True model.modal_shown = True

View File

@ -17,13 +17,6 @@ class EditSenseLabel(Message):
sense.labels = common_accessors.label_list_getter() 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): class AddToGenericList(NoReset):
def update_model(self, model): def update_model(self, model):
list_getter = self.get_arg(0) list_getter = self.get_arg(0)
@ -46,10 +39,10 @@ class EditExampleTranslation(Message):
example.translations = common_accessors.generic_list_getter() example.translations = common_accessors.generic_list_getter()
class AddSense(QuestionMessage): class AddSense(Message):
def update_model(self, model): def update_model(self, model):
sense = Sense.new_empty() sense = Sense.new_empty()
sense.labels = [self.new_text] sense.definition = "New Sense"
model.entry.senses.append(sense) model.entry.senses.append(sense)

View File

@ -1,5 +1,6 @@
from model.sense import Sense from model.sense import Sense
from model.editable import Editable from model.editable import Editable
from model.tags import TAGS
class Entry(Editable): class Entry(Editable):
def __init__(self, entry_xml): def __init__(self, entry_xml):

View File

@ -47,10 +47,6 @@ def edit_entry_labels(entry):
return modal_template(content, "Translation", message.EditEntryLabels()) 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): def edit_sense_definition(sense):
return modal_template(question("Edit sense definition", sense.definition), "Sense definition", message.EditSenseDefinition(sense)) return modal_template(question("Edit sense definition", sense.definition), "Sense definition", message.EditSenseDefinition(sense))

View File

@ -20,7 +20,7 @@ class View:
def _view(self): def _view(self):
return h("div", {"on": { "click": msg(Reset()) }}, [ return h("div", {"on": { "click": msg(Reset()) }}, [
View.view_entry(self.model.entry), 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_menu(self.model.menu_location, self.model.menu_shown, self.model.translation),
View.view_modal(self.model.modal_shown, self.model.modal)]) View.view_modal(self.model.modal_shown, self.model.modal)])
@ -35,26 +35,42 @@ class View:
h("span#grammar", {}, entry.grammar)]), h("span#grammar", {}, entry.grammar)]),
View.view_entry_button_section(entry), View.view_entry_button_section(entry),
h("div#sense-container", {}, view_sense_list), h("div#sense-container", {}, view_sense_list),
h("button.add-button", {"on": {"click": msg(ShowSenseAdd())}}, "+")]) h("button.add-button", {"on": {"click": msg(AddSense())}}, "+")])
@staticmethod @staticmethod
def view_entry_button_section(entry): def view_entry_button_section(entry):
clk = lambda cls: {"on": {"click": msg(cls)}} clk = lambda cls: {"on": {"click": msg(cls)}}
buttons = [ buttons = [
h("button.warning", clk(ShowCommentEdit()), "Comment"),
h("button.normal", clk(ShowVariantsEdit()), "Variants"), 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: view_buttons = []
return h("div", {}, buttons) view_table = []
labels = ", ".join([val for _, val in entry.labels]) if len(entry.variants) == 0:
return h("table", {}, [ view_buttons.append(buttons[0])
h("tr", {}, [ h("td", {}, buttons[0]), h("td", {}, entry.comment)]), else:
h("tr", {}, [ h("td", {}, buttons[1]), h("td", {}, ", ".join(entry.variants))]), view_table.append((buttons[0], ", ".join(entry.variants)))
h("tr", {}, [ h("td", {}, buttons[2]), h("td", {}, labels)])])
if len(entry.labels) == 0:
view_buttons.append(buttons[1])
else:
labels = ", ".join([val for _, val in entry.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 @staticmethod
def view_sense(sense, senseNum): def view_sense(sense, senseNum):