explanationList

This commit is contained in:
matic_t 2020-08-04 07:00:53 -07:00
parent 964dc3f788
commit ad83665b0d
3 changed files with 26 additions and 27 deletions

View File

@ -153,7 +153,6 @@ def export_translation(doc, translation):
explanationList = doc.createElement("explanationList") explanationList = doc.createElement("explanationList")
for explanation in translation.explanationList: for explanation in translation.explanationList:
console.log(explanation)
el = doc.createElement("explanation") el = doc.createElement("explanation")
el.textContent = explanation el.textContent = explanation
explanationList.appendChild(el) explanationList.appendChild(el)

View File

@ -6,26 +6,27 @@ from model.translation import Translation
from model.sense import Sense from model.sense import Sense
class EditTranslation(DataChgClickMessage): class EditTranslation(DataChgClickMessage):
def update_model(self, model): def update_model(self, model):
self.translation = self.get_arg(0, Translation) self.translation = self.get_arg(0, Translation)
self.old_cluster_idx = self.get_arg(1, int) self.old_cluster_idx = self.get_arg(1, int)
self.translation.translation = document.getElementById("etv").value self.translation.translation = document.getElementById("etv").value
self.translation.explanation = document.getElementById("ete").value # This could be dangerous if generic_list_getter is getting data from any other list as well.
self.translation.explanationList = common_accessors.generic_list_getter()
# common_accessors.label_list_getter() # common_accessors.label_list_getter()
self.translation.tags = common_accessors.label_list_getter() self.translation.tags = common_accessors.label_list_getter()
# check if empty, remove! # check if empty, remove!
if self.translation.is_empty(): if self.translation.is_empty():
model.entry.remove_translation(self.translation) model.entry.remove_translation(self.translation)
return return
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1 new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
self.handle_cluster_change(new_cluster_idx, model) self.handle_cluster_change(new_cluster_idx, model)
@staticmethod @staticmethod
def get_translation_location(entry, translation): def get_translation_location(entry, translation):
def find_in_clusters(parent): def find_in_clusters(parent):
@ -34,7 +35,7 @@ class EditTranslation(DataChgClickMessage):
if search_translation == translation: if search_translation == translation:
return (ci, ti), (parent, cluster) return (ci, ti), (parent, cluster)
return None return None
for sense in entry.senses: for sense in entry.senses:
res = find_in_clusters(sense) res = find_in_clusters(sense)
if res is not None: if res is not None:
@ -43,21 +44,21 @@ class EditTranslation(DataChgClickMessage):
res = find_in_clusters(example) res = find_in_clusters(example)
if res is not None: if res is not None:
return res return res
window.console.log("should not be here...") window.console.log("should not be here...")
def handle_cluster_change(self, new_cluster_idx, model): def handle_cluster_change(self, new_cluster_idx, model):
if self.old_cluster_idx == new_cluster_idx: if self.old_cluster_idx == new_cluster_idx:
return return
(cidx, tidx), (parent, cluster) = EditTranslation.get_translation_location(model.entry, self.translation) (cidx, tidx), (parent, cluster) = EditTranslation.get_translation_location(model.entry, self.translation)
self.do_cluster_change(parent, cluster, cidx, tidx, new_cluster_idx) self.do_cluster_change(parent, cluster, cidx, tidx, new_cluster_idx)
def do_cluster_change(self, sense_or_example, cluster, cidx, tidx, new_cluster_idx): def do_cluster_change(self, sense_or_example, cluster, cidx, tidx, new_cluster_idx):
# remove the translation from the old cluster # remove the translation from the old cluster
cluster.splice(tidx, 1) cluster.splice(tidx, 1)
# we maybe are creating a new cluster, handle that # we maybe are creating a new cluster, handle that
if len(sense_or_example.translations) == new_cluster_idx: if len(sense_or_example.translations) == new_cluster_idx:
sense_or_example.translations.append([self.translation]) sense_or_example.translations.append([self.translation])
@ -66,12 +67,12 @@ class EditTranslation(DataChgClickMessage):
sense_or_example.translations[new_cluster_idx].append(self.translation) sense_or_example.translations[new_cluster_idx].append(self.translation)
else: else:
raise ValueError("Bad new cluster idx :(") raise ValueError("Bad new cluster idx :(")
# we still hold cluster reference, check if empty and remove if necessary # we still hold cluster reference, check if empty and remove if necessary
# we cant do this earlier since indexes change and yeah, fun stuff # we cant do this earlier since indexes change and yeah, fun stuff
if len(cluster) == 0: if len(cluster) == 0:
sense_or_example.translations.splice(cidx, 1) sense_or_example.translations.splice(cidx, 1)
class MoveRight(DataChgClickMessage): class MoveRight(DataChgClickMessage):
def update_model(self, model): def update_model(self, model):
@ -80,8 +81,8 @@ class MoveRight(DataChgClickMessage):
if idx != len(cluster) - 1: if idx != len(cluster) - 1:
cluster[idx], cluster[idx + 1] = cluster[idx + 1], cluster[idx] cluster[idx], cluster[idx + 1] = cluster[idx + 1], cluster[idx]
model.translation = None model.translation = None
class MoveLeft(DataChgClickMessage): class MoveLeft(DataChgClickMessage):
def update_model(self, model): def update_model(self, model):
translation = self.get_arg(0, Translation) translation = self.get_arg(0, Translation)
@ -89,8 +90,8 @@ class MoveLeft(DataChgClickMessage):
if idx != 0 and len(cluster) > 1: if idx != 0 and len(cluster) > 1:
cluster[idx], cluster[idx - 1] = cluster[idx - 1], cluster[idx] cluster[idx], cluster[idx - 1] = cluster[idx - 1], cluster[idx]
model.translation = None model.translation = None
class BinTranslation(DataChgClickMessage): class BinTranslation(DataChgClickMessage):
def update_model(self, model): def update_model(self, model):
translation = self.get_arg(0, Translation) translation = self.get_arg(0, Translation)
@ -101,7 +102,7 @@ class BinTranslation(DataChgClickMessage):
else: else:
cluster.splice(tidx, 1) cluster.splice(tidx, 1)
model.translation = None model.translation = None
class AddTranslation(EditTranslation): class AddTranslation(EditTranslation):
def handle_cluster_change(self, new_cluster_idx, _): def handle_cluster_change(self, new_cluster_idx, _):
@ -110,4 +111,4 @@ class AddTranslation(EditTranslation):
# we make a dummy cluster, cluster_idx and translation_idx # we make a dummy cluster, cluster_idx and translation_idx
# we give a correct new_cluster_idx # we give a correct new_cluster_idx
self.do_cluster_change(self.get_arg(2), [None, None], None, None, new_cluster_idx) self.do_cluster_change(self.get_arg(2), [None, None], None, None, new_cluster_idx)

View File

@ -19,10 +19,9 @@ def edit_translation(translation, parent, cluster_idx, num_clusters, cls):
# first line: transalation itself # first line: transalation itself
content.extend([ content.extend([
split_line2("Prevedek:", split_line2("Prevedek:", h("textarea#etv", {"props": {"value": translation.translation}}, ""))])
h("textarea#etv", {"props": {"value": translation.translation}}, "")),
split_line2("Razlaga:", content.extend(generic_list_editor("Razlage:", lambda: translation.explanationList))
h("textarea#ete", {"props": {"value": translation.explanation}}, ""))])
# cluster number # cluster number
options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)] options = [h("option", {"props": {"selected": idx == cluster_idx}}, str(idx + 1)) for idx in range(num_clusters + 1)]