Variants done
This commit is contained in:
parent
36cce3a86e
commit
e1ce093ff6
|
@ -42,7 +42,6 @@ def export_entry(entry):
|
|||
homonymy = _original_xml_query_selector("head headword homonymy", entry, doc)
|
||||
original_homonymy = entry.original_xml.querySelectorAll("head headword homonymy homonymyFeature")
|
||||
|
||||
# todo: How do you know which one is changed/created anew etc - Perhaps go with position in array and save it in homonymy object or something?
|
||||
for hFeature in entry.homonymy:
|
||||
feature = doc.createElement("homonymyFeature")
|
||||
if hFeature.id >= 0:
|
||||
|
@ -56,8 +55,6 @@ def export_entry(entry):
|
|||
|
||||
|
||||
|
||||
console.log(homonymy)
|
||||
# console.log(entry.original_homonymy.querySelector("head headwo")
|
||||
# if({}) works uncorrectly in transcrypt
|
||||
if len(entry.lexical_unit) > 0:
|
||||
lexunit = _original_xml_query_selector("head lexicalUnit", entry, doc)
|
||||
|
@ -93,12 +90,16 @@ def export_entry(entry):
|
|||
# head.appendChild(measure_list)
|
||||
|
||||
# Same problem as homonymy
|
||||
variants = doc.createElement("variantList")
|
||||
head.appendChild(variants)
|
||||
|
||||
variants = _original_xml_query_selector("head variantList", entry, doc)
|
||||
original_variants = entry.original_xml.querySelectorAll("head variantList variant")
|
||||
for v in entry.variants:
|
||||
variant = doc.createElement("variant")
|
||||
variant.textContent = v
|
||||
if v.id >= 0:
|
||||
variant = original_variants[v.id]
|
||||
else:
|
||||
variants.appendChild(variant)
|
||||
|
||||
variant.textContent = v.value
|
||||
variants.appendChild(variant)
|
||||
|
||||
# relist = _original_xml_query_selector("head relatedEntryList", entry, doc)
|
||||
|
|
|
@ -4,8 +4,10 @@ from browser import document
|
|||
def generic_list_getter():
|
||||
result = []
|
||||
for input_el in document.getElementsByClassName("list-adder-input"):
|
||||
result_candidate = input_el.value
|
||||
if result_candidate != "":
|
||||
result_candidate = {"value": input_el.value}
|
||||
if input_el.hasAttribute("data-id"):
|
||||
result_candidate.id = int(input_el.getAttribute("data-id"))
|
||||
if result_candidate.value != "":
|
||||
result.append(result_candidate)
|
||||
return result
|
||||
|
||||
|
|
|
@ -86,20 +86,15 @@ class DoChosenExamples(Message):
|
|||
class EditVariants(Message):
|
||||
def update_model(self, model):
|
||||
variants = common_accessors.generic_list_getter()
|
||||
_remove_deleted_quries(variants, "head variantList variant", model)
|
||||
console.log(variants)
|
||||
model.entry.variants = variants
|
||||
|
||||
class EditHomonymy(Message):
|
||||
def update_model(self, model):
|
||||
homonymy = common_accessors.double_list_getter("value", "name")
|
||||
|
||||
keptHFeatureIds = [feature.id for feature in homonymy]
|
||||
for index, feature in enumerate(model.entry.original_xml.querySelectorAll("head headword homonymy homonymyFeature")):
|
||||
if (index not in keptHFeatureIds):
|
||||
feature.remove()
|
||||
|
||||
for index, feature in enumerate(homonymy):
|
||||
if (feature.id >= 0):
|
||||
feature.id = index
|
||||
_remove_deleted_quries(homonymy, "head headword homonymy homonymyFeature", model)
|
||||
|
||||
model.entry.homonymy = homonymy
|
||||
|
||||
|
@ -128,3 +123,13 @@ class ExampleClusterAdd(DataChgClickMessage):
|
|||
example = self.get_arg(0, Example)
|
||||
example.set_cluster(ExampleClusters.first_empty_cluster())
|
||||
|
||||
|
||||
def _remove_deleted_quries(updated_list, query, model):
|
||||
keptIds = [entry.id for entry in updated_list]
|
||||
for index, entry in enumerate(model.entry.original_xml.querySelectorAll(query)):
|
||||
if (index not in keptIds):
|
||||
entry.remove()
|
||||
|
||||
for index, entry in enumerate(updated_list):
|
||||
if (entry.id >= 0):
|
||||
entry.id = index
|
||||
|
|
|
@ -39,7 +39,7 @@ class Entry(Data):
|
|||
self.headword_audio = headword.getAttribute("audio") if headword and headword.hasAttribute("audio") else None
|
||||
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.variants = [{"value": v.textContent, "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head variantList variant"))]
|
||||
self.homonymy = [{"value": v.textContent, "name": v.getAttribute("name"), "id": index} for index, v in enumerate(entry_xml.querySelectorAll("head headword homonymy homonymyFeature "))]
|
||||
self.related_entries = [re.textContent for re in entry_xml.querySelectorAll("head relatedEntryList relatedEntry")]
|
||||
|
||||
|
@ -96,7 +96,7 @@ class Entry(Data):
|
|||
if len(self.variants) == 0:
|
||||
view_buttons.append(buttons[0])
|
||||
else:
|
||||
view_table.append((buttons[0], ", ".join(self.variants)))
|
||||
view_table.append((buttons[0], ", ".join(h.value for h in self.variants)))
|
||||
|
||||
if len(self.homonymy) == 0:
|
||||
view_buttons.append(buttons[4])
|
||||
|
|
|
@ -42,8 +42,11 @@ def question(question, current_value):
|
|||
def generic_list_editor(title, element_list_getter):
|
||||
content = [h("p", {}, title)]
|
||||
for slabel in element_list_getter():
|
||||
idAttr = {"data-id": slabel.id} if slabel.id >= 0 else {}
|
||||
content.append(h("label", {}, [
|
||||
h("input.list-adder-input", {"props": {"type": "text", "value": slabel}}, "")]))
|
||||
h("input.list-adder-input", {"props": {"type": "text", "value": slabel.value or slabel}, "attrs": idAttr}, "")]))
|
||||
|
||||
console.log(content)
|
||||
content.append(h("button", {"on": {"click": message.msg(message.AddToGenericList, element_list_getter)}}, "+"))
|
||||
return content
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user