2020-01-25 20:33:22 +00:00
|
|
|
from browser import document
|
|
|
|
from message.simple_messages import DataChgClickMessage, ClickMessage, NoReset
|
|
|
|
from message.message import Message
|
|
|
|
from model.example import Example, ComponentLexeme
|
2020-06-11 20:34:04 +00:00
|
|
|
from model.sense import Sense
|
2020-01-23 22:10:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_example_idx(example, model):
|
|
|
|
for sense in model.entry.senses:
|
|
|
|
for eidx, e in enumerate(sense.examples):
|
|
|
|
if e == example:
|
|
|
|
return (sense, eidx)
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleMoveUp(DataChgClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
sense, idx = _get_example_idx(example, model)
|
|
|
|
|
|
|
|
assert(idx >= 0)
|
|
|
|
if idx == 0:
|
|
|
|
return
|
|
|
|
|
|
|
|
sense.examples[idx], sense.examples[idx - 1] = sense.examples[idx - 1], sense.examples[idx]
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleMoveDown(DataChgClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
sense, idx = _get_example_idx(example, model)
|
|
|
|
|
|
|
|
assert(idx >= 0)
|
|
|
|
if idx == len(sense.examples) - 1:
|
|
|
|
return
|
|
|
|
|
|
|
|
sense.examples[idx], sense.examples[idx + 1] = sense.examples[idx + 1], sense.examples[idx]
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleBin(DataChgClickMessage):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
sense, idx = _get_example_idx(example, model)
|
|
|
|
|
|
|
|
assert(idx >= 0)
|
|
|
|
sense.examples.splice(idx, 1)
|
|
|
|
|
2020-01-25 20:33:22 +00:00
|
|
|
|
|
|
|
class EditExampleText(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
2020-06-11 20:34:04 +00:00
|
|
|
sense = self.get_arg(1, Sense)
|
|
|
|
|
2020-01-25 20:33:22 +00:00
|
|
|
example.overwrite_with_copy()
|
2020-05-19 20:10:36 +00:00
|
|
|
example.edited = True
|
2020-01-25 20:33:22 +00:00
|
|
|
|
2020-06-11 20:34:04 +00:00
|
|
|
# if this was a newly created example, now we can add it to the sense
|
|
|
|
# easier to add here than to add before editing and checking if the user
|
|
|
|
# canceled the operation
|
|
|
|
if example.newly_created:
|
|
|
|
example.newly_created = False
|
|
|
|
sense.examples.append(example)
|
|
|
|
|
2020-01-25 20:33:22 +00:00
|
|
|
idx = 0
|
|
|
|
for txt in document.getElementsByClassName("example-component-text"):
|
|
|
|
example.components[idx].text = txt.value
|
|
|
|
idx += 1
|
|
|
|
|
|
|
|
class ExampleRoleChange(NoReset):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
component_num = self.get_arg(1, int)
|
|
|
|
component_new_role = self.get_arg(2, str)
|
|
|
|
|
|
|
|
if component_new_role == "none":
|
|
|
|
component_new_role = None
|
|
|
|
|
|
|
|
example.copy().components[component_num].role = component_new_role
|
2020-06-11 16:47:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ExampleComponentSpace(NoReset):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
component_num = self.get_arg(1, int)
|
|
|
|
|
|
|
|
component = example.copy().components[component_num]
|
|
|
|
component.no_space = not component.no_space
|
|
|
|
|
2020-01-25 20:33:22 +00:00
|
|
|
|
|
|
|
class ExampleComponentAdd(NoReset):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
component_num = self.get_arg(1, int)
|
|
|
|
|
2020-02-16 23:00:03 +00:00
|
|
|
new_component = ComponentLexeme()
|
2020-01-25 20:33:22 +00:00
|
|
|
example.copy().components.insert(component_num + 1, new_component)
|
|
|
|
|
|
|
|
|
|
|
|
class ExampleComponentRemove(NoReset):
|
|
|
|
def update_model(self, model):
|
|
|
|
example = self.get_arg(0, Example)
|
|
|
|
component_num = self.get_arg(1, int)
|
|
|
|
|
|
|
|
example.copy().components.splice(component_num, 1)
|
2020-01-25 22:22:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ToggleExamples(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
model.examples_shown = not model.examples_shown
|
|
|
|
|
2020-02-03 05:11:26 +00:00
|
|
|
|
|
|
|
class ToggleClusters(Message):
|
|
|
|
def update_model(self, model):
|
|
|
|
model.clusters_shown = not model.clusters_shown
|
|
|
|
|