Example clusters in example edit

This commit is contained in:
Ozbolt Menegatti 2020-01-28 23:06:16 +01:00
parent cab655497b
commit 3f9030f72d
5 changed files with 17 additions and 6 deletions

View File

@ -6,6 +6,8 @@ class Message:
def __init__(self, *args):
self._args = args
self.error = None
if len(self._args) == 2:
console.log(args)
def update_model(self, model):
raise NotImplementedError("This message does not implement update_model method")

View File

@ -40,8 +40,9 @@ class ShowRelatedEntriesEdit(ClickMessage):
class ShowExampleEdit(ClickMessage):
def update_model(self, model):
example = self.get_arg(0, Example)
sense = self.get_arg(1, Sense)
example.make_copy()
model.modal_set(lambda: modals.edit_example(example))
model.modal_set(lambda: modals.edit_example(example, sense))
class ShowEditTranslation(ClickMessage):

View File

@ -30,7 +30,7 @@ def edit_sense_label(sense):
return modal_template(content, "Translation", message.EditSenseLabel(sense))
def edit_example(example):
def edit_example(example, sense):
example_original = example
example = example_original.copy()
@ -69,7 +69,7 @@ def edit_example(example):
divs.append(h("hr", {}, []))
divs.append(h("div.flex.five.example-component", {}, [
h("div.one-fifth", {}, "Cluster"),
h("div.four-fifth", {}, show_toggle_cluster_buttons(list(range(10))))]))
h("div.four-fifth", {}, show_toggle_cluster_buttons(sense, example))]))
return modal_template(divs, "Edit Example", message.EditExampleText(example_original))

View File

@ -16,6 +16,13 @@ def show_toggle_cluster_buttons(sense, example):
return result
def example_sense(example, entry):
for sense in entry.senses:
for ex in sense.examples:
if ex == example:
return sense
def clean_label(label):
return label.replace("-- ", "")

View File

@ -27,7 +27,7 @@ class View:
return h("div", {"on": { "click": msg(Reset()) }}, [
View.view_entry(self.model.entry, self.model),
h("button.blk", {"on": { "click": lambda _: check_export(self.model) } }, "CHK"),
View.view_menu(self.model.menu_location, self.model.menu_target),
View.view_menu(self.model.menu_location, self.model.menu_target, self.model.entry),
View.view_modal(self.model.modal_shown, self.model.modal)])
@staticmethod
@ -174,7 +174,7 @@ class View:
@staticmethod
def view_menu(location, menu_target):
def view_menu(location, menu_target, entry):
style = {
"left": "{}px".format(location[0]),
"top": "{}px".format(location[1])
@ -201,8 +201,9 @@ class View:
elif type(menu_target) is Example:
example = menu_target
sense = example_sense(example, entry)
return h("span.popup-menu", { "style": style }, [
h("button.shyButton", { "on": {"click": msg(ShowExampleEdit(example))}}, ""),
h("button.shyButton", { "on": {"click": msg(ShowExampleEdit(example, sense))}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleMoveUp(example))}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleMoveDown(example))}}, ""),
h("button.shyButton", { "on": {"click": msg(ExampleBin(example))}}, "🗑")])