sense labels now proper label list

This commit is contained in:
Ozbolt Menegatti 2019-11-17 22:09:09 +01:00
parent 0835b3eda2
commit a058a50017
4 changed files with 16 additions and 15 deletions

View File

@ -14,11 +14,7 @@ class QuestionMessage(Message):
class EditSenseLabel(Message): class EditSenseLabel(Message):
def update_model(self, model): def update_model(self, model):
sense = self.get_arg(0, Sense) sense = self.get_arg(0, Sense)
sense.labels = [] sense.labels = common_accessors.label_list_getter()
for input_el in document.getElementsByClassName("sense-edit-input"):
new_sense_label = input_el.value
if new_sense_label != "":
sense.labels.append(new_sense_label)
class AddSenseLabel(NoReset): class AddSenseLabel(NoReset):

View File

@ -1,13 +1,24 @@
from model.example import Example from model.example import Example
from model.translation import Translation from model.translation import Translation
from model.editable import Editable from model.editable import Editable
from model.tags import TAGS
class Sense(Editable): class Sense(Editable):
def __init__(self, sense_xml): def __init__(self, sense_xml):
definition = sense_xml.querySelector("definitionList definition") definition = sense_xml.querySelector("definitionList definition")
self.labels = [label.textContent for label in sense_xml.querySelectorAll("sense > labelList label")] self.labels = []
for tag_xml in sense_xml.querySelectorAll("sense > labelList label"):
t_type = tag_xml.getAttribute("type")
t_value = tag_xml.textContent
if t_type not in TAGS:
# using some default
t_type = TAGS.keys()[0]
self.labels.append((t_type, t_value))
self.definition = definition.textContent if definition else "" self.definition = definition.textContent if definition else ""
self.examples = [Example(example_xml) for example_xml in self.examples = [Example(example_xml) for example_xml in

View File

@ -25,15 +25,9 @@ def edit_translation(translation, cluster_idx, num_clusters, cls):
def edit_sense_label(sense): def edit_sense_label(sense):
content = [h("span", {}, "Edit sense labels")] content = label_list_editor(sense.copy().labels, message.AddToLabelList(sense.copy().labels))
return modal_template(content, "Translation", message.EditSenseLabel(sense))
for slabel in sense.copy().labels:
content.append(h("label", {}, [
h("input.sense-edit-input", {"props": {"type": "text", "value": slabel}}, "")]))
content.append(h("button", {"on": {"click": message.msg(message.AddSenseLabel(sense))}}, "+"))
return modal_template(content, "Sense", message.EditSenseLabel(sense))
def edit_example_translation(example): def edit_example_translation(example):

View File

@ -45,7 +45,7 @@ class View:
h("div.sense-num", {}, str(senseNum + 1)), h("div.sense-num", {}, str(senseNum + 1)),
h("div.sense", {}, [ h("div.sense", {}, [
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit(sense)) }}, [ h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit(sense)) }}, [
h("span.sense-label", {}, slabel) for slabel in sense.labels ]), h("span.sense-label", {}, slabel) for _, slabel in sense.labels ]),
h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit(sense)) }}, sense.definition), h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit(sense)) }}, sense.definition),
h("div", {}, View.view_translations(sense.translations, sense)), h("div", {}, View.view_translations(sense.translations, sense)),
h("div", {}, examples)])]) h("div", {}, examples)])])