THE REST: mostly fixing/changing how tags/labellist stuff works

This commit is contained in:
2019-11-17 21:33:58 +01:00
parent b09a84db06
commit 0c6dcbb2f0
8 changed files with 87 additions and 56 deletions

View File

@@ -1,7 +1,7 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowMenu, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowSenseAdd, ShowExampleEdit, ShowExampleTranslationEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, EditExample, AddExampleTranslation, EditExampleTranslation, AddToLabelList
from message.message import msg

View File

@@ -9,3 +9,20 @@ def generic_list_getter():
result.append(result_candidate)
return result
def label_list_getter():
result = []
for row in document.getElementsByClassName("label-list-row"):
ltype = row.querySelector(".label-type")
lvalue = row.querySelector(".label-value")
lother = row.querySelector(".label-value-other")
value = lother.value
if not value:
value = lvalue.options[lvalue.selectedIndex].text
if not value:
continue
result.append((ltype.textContent, value))
return result

View File

@@ -1,7 +1,7 @@
from message.message import Message, ClickMessage
from message.translation_edit import AddTranslation ,EditTranslation
from message.translation_edit import AddTranslation, EditTranslation
from model.sense import NewSense
from model import Example, Sense, Translation
from view import modals
@@ -72,9 +72,10 @@ class ShowEditTranslation(ClickMessage):
for cidx, cluster in enumerate(sense.translations):
for t in cluster:
if t == translation:
# fount the one!
# fount the one!
translation.make_copy()
model.modal = lambda: modals.edit_translation(
translation, cidx, num_clusters, EditTranslation, (translation, cidx))
translation, cidx, num_clusters, EditTranslation(translation, cidx))
return
console.log("Should not be here!")

View File

@@ -34,9 +34,15 @@ class AddExampleTranslation(NoReset):
# just adding to the copy to show in the modal
example.copy().translations.append("")
class AddToLabelList(NoReset):
def update_model(self, model):
list_to_add_to = self.get_arg(0, list)
thing_to_add_getter = self.get_arg(1)
thing_to_add = thing_to_add_getter()
# just adding to the copy to show in the modal
self.example.copy().translations.append("")
list_to_add_to.append(thing_to_add)
class EditExampleTranslation(Message):

View File

@@ -1,6 +1,8 @@
from message.message import Message, ClickMessage
import message.common_accessors as common_accessors
from browser import document, window
from model.translation import TAGS, NewTranslation
from model.translation import TAGS, Translation
from model.sense import Sense
def get_translation_location(entry, translation):
@@ -11,24 +13,16 @@ def get_translation_location(entry, translation):
return (si, ci, ti), (sense, cluster)
class EditTranslation(TranslationActionMessage):
def __init__(self, _, prop):
self.translation, self.old_cluster_idx = prop
class EditTranslation(ClickMessage):
def update_model(self, model):
self.translation = self.get_arg(0, Translation)
self.old_cluster_idx = self.get_arg(1, int)
self.translation.translation = document.getElementById("etv").value
self.translation.explanation = document.getElementById("ete").value
for tag in TAGS.keys():
select = document.getElementById("{}-s".format(tag))
other = document.getElementById("{}-o".format(tag))
if other.value:
self.translation.tags[tag] = other.value
elif select.selectedIndex > 0:
self.translation.tags[tag] = select.options[select.selectedIndex].text
else:
if tag in self.translation.tags:
del self.translation.tags[tag]
# common_accessors.label_list_getter()
self.translation.tags = common_accessors.label_list_getter()
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
self.handle_cluster_change(new_cluster_idx, model)
@@ -97,15 +91,10 @@ class BinTranslation(ClickMessage):
class AddTranslation(EditTranslation):
def __init__(self, _, prop):
self.translation = NewTranslation()
self.old_cluster_idx = -1
self.sense = prop
def handle_cluster_change(self, new_cluster_idx, _):
# we need to cheat here
# sense was actually given in constructor
# sense was actually given in constructor in third place
# we make a dummy cluster, cluster_idx and translation_idx
# we give a correct new_cluster_idx
self.do_cluster_change(self.sense, [None, None], None, None, new_cluster_idx)
self.do_cluster_change(self.get_arg(2, Sense), [None, None], None, None, new_cluster_idx)