ShowExampleEdit becomes more complex, handles ctrl+click and selecting/moving examples
This commit is contained in:
parent
00827e7b0b
commit
e7283c3ba1
|
@ -1,7 +1,7 @@
|
||||||
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage
|
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage
|
||||||
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
|
||||||
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowExampleTranslationEdit, ShowVariantsEdit
|
from message.show_messages import 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, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditEntryLabels
|
||||||
from message.show_menu import ShowTranslationMenu, ShowSenseMenu
|
from message.show_menu import ShowTranslationMenu, ShowSenseMenu
|
||||||
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
|
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from message.message import Message
|
from message.message import Message
|
||||||
from message.translation_edit import AddTranslation, EditTranslation
|
from message.translation_edit import AddTranslation, EditTranslation
|
||||||
from message.simple_messages import ClickMessage
|
from message.simple_messages import ClickMessage, CtrlClickMessage
|
||||||
|
|
||||||
from model import Example, Sense, Translation
|
from model import Example, Sense, Translation
|
||||||
from view import modals
|
from view import modals
|
||||||
|
@ -35,13 +35,26 @@ class ShowVariantsEdit(ClickMessage):
|
||||||
model.modal = lambda: modals.edit_variants(model.entry)
|
model.modal = lambda: modals.edit_variants(model.entry)
|
||||||
|
|
||||||
|
|
||||||
class ShowExampleEdit(ClickMessage):
|
class ShowExampleEdit(CtrlClickMessage):
|
||||||
def update_model(self, model):
|
def update_model_noctrl(self, model):
|
||||||
model.modal_shown = True
|
model.modal_shown = True
|
||||||
example = self.get_arg(0, Example)
|
example = self.get_arg(0, Example)
|
||||||
model.modal = lambda: modals.edit_example(example)
|
|
||||||
|
|
||||||
|
# if some are chosen, then show modal for choosing senses
|
||||||
|
if len(model.chosen_examples) > 0 and example in model.chosen_examples:
|
||||||
|
chosen_examples = model.chosen_examples
|
||||||
|
model.modal = lambda: modals.do_chosen_examples(chosen_examples, model.entry)
|
||||||
|
else:
|
||||||
|
model.modal = lambda: modals.edit_example(example)
|
||||||
|
|
||||||
|
def update_model_ctrl(self, model):
|
||||||
|
example = self.get_arg(0, Example)
|
||||||
|
model.chosen_examples.append(example)
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
# special case, when choosing messages dont reset
|
||||||
|
return not self.ctrl
|
||||||
|
|
||||||
class ShowExampleTranslationEdit(ClickMessage):
|
class ShowExampleTranslationEdit(ClickMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
model.modal_shown = True
|
model.modal_shown = True
|
||||||
|
|
|
@ -69,6 +69,21 @@ class EditExample(QuestionMessage):
|
||||||
example.example = self.new_text
|
example.example = self.new_text
|
||||||
|
|
||||||
|
|
||||||
|
class DoChosenExamples(Message):
|
||||||
|
def update_model(self, model):
|
||||||
|
chosen_examples = self.get_arg(0, list)
|
||||||
|
selected = document.getElementById("chosen-examples-select").selectedIndex
|
||||||
|
|
||||||
|
# first, remove the selected examples from wherever they were
|
||||||
|
for sense in model.entry.senses:
|
||||||
|
for example in chosen_examples:
|
||||||
|
if example in sense.examples:
|
||||||
|
sense.examples.remove(example)
|
||||||
|
|
||||||
|
# now, append selected examples to chosen sense
|
||||||
|
model.entry.senses[selected].examples.extend(chosen_examples)
|
||||||
|
|
||||||
|
|
||||||
class EditVariants(Message):
|
class EditVariants(Message):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
variants = common_accessors.generic_list_getter()
|
variants = common_accessors.generic_list_getter()
|
||||||
|
|
|
@ -35,3 +35,7 @@ class Sense(Editable):
|
||||||
self.translations = [[] for _ in range(max_num_cluster)]
|
self.translations = [[] for _ in range(max_num_cluster)]
|
||||||
for clusterNum, translation in translations:
|
for clusterNum, translation in translations:
|
||||||
self.translations[clusterNum - 1].append(translation)
|
self.translations[clusterNum - 1].append(translation)
|
||||||
|
|
||||||
|
|
||||||
|
def merge_labels(self):
|
||||||
|
return ", ".join(val for _, val in self.labels)
|
||||||
|
|
|
@ -29,7 +29,6 @@ def edit_sense_label(sense):
|
||||||
return modal_template(content, "Translation", message.EditSenseLabel(sense))
|
return modal_template(content, "Translation", message.EditSenseLabel(sense))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def edit_example_translation(example):
|
def edit_example_translation(example):
|
||||||
etl_getter = lambda: example.copy().translations
|
etl_getter = lambda: example.copy().translations
|
||||||
content = generic_list_editor("Edit example translations", etl_getter)
|
content = generic_list_editor("Edit example translations", etl_getter)
|
||||||
|
@ -57,3 +56,16 @@ def edit_comment(comment):
|
||||||
|
|
||||||
def edit_example(example):
|
def edit_example(example):
|
||||||
return modal_template(question("Edit exmample", example.example), "Example", message.EditExample(example))
|
return modal_template(question("Edit exmample", example.example), "Example", message.EditExample(example))
|
||||||
|
|
||||||
|
|
||||||
|
def do_chosen_examples(example_list, entry):
|
||||||
|
options = []
|
||||||
|
for sense in entry.senses:
|
||||||
|
options.append(h("option", {}, sense.merge_labels()))
|
||||||
|
|
||||||
|
content = [
|
||||||
|
h("span", {}, "Choose sense for examples"),
|
||||||
|
h("label", {}, [
|
||||||
|
h("select#chosen-examples-select", {}, options)])]
|
||||||
|
|
||||||
|
return modal_template(content, "Examples picker", message.DoChosenExamples(example_list))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user