editing example clusters on main view

This commit is contained in:
Ozbolt Menegatti 2020-01-28 23:22:52 +01:00
parent ec5f72969c
commit 9a184011c1
4 changed files with 20 additions and 7 deletions

View File

@ -1,7 +1,7 @@
from message.simple_messages import NoReset, Reset, ModalNotOkClose, ClickMessage, DataChgClickMessage, KeyboardPress
from message.translation_edit import EditTranslation, MoveRight, MoveLeft, BinTranslation
from message.show_messages import ShowEntryLabelsEdit, ShowEditTranslation, ShowSenseLabelEdit, ShowSenseDefinitionEdit, ShowCommentEdit, ShowAddTranslation, ShowExampleEdit, ShowVariantsEdit, ShowRelatedEntriesEdit
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels
from message.simple_edits import EditSenseLabel, EditSenseDefinition, EditComment, AddSenseLabel, AddSense, AddExampleTranslation, DoChosenExamples, AddToLabelList, AddToGenericList, EditVariants, EditRelatedEntries, EditEntryLabels, ExampleClusterEdit
from message.show_menu import ShowTranslationMenu, ShowSenseMenu, ShowExampleMenu
from message.sense_edit import SenseMoveUp, SenseMoveDown, SenseBin
from message.example_edit import ExampleMoveUp, ExampleMoveDown, ExampleBin, ExampleRoleChange, ExampleComponentAdd, ExampleComponentRemove, EditExampleText, ToggleExamples

View File

@ -100,4 +100,9 @@ class EditEntryLabels(Message):
model.entry.labels = labels
class ExampleClusterEdit(Message):
def update_model(self, model):
example = self.get_arg(0, Example)
cluster = self.get_arg(1, int)
example.set_cluster(cluster)

View File

@ -27,19 +27,20 @@ class Sense(Editable):
sense_xml.querySelectorAll("exampleContainerList exampleContainer")]
# set limit for example cluster
self.reserved_example = max(cluster_mappings.values()) + 1
cluster_min = self.reserved_example + 1
cluster_min =max(cluster_mappings.values()) + 2
self._original_examples = set([cluster_min - 1])
self._original_examples = set(self.example_clusters())
def merge_labels(self):
return ", ".join(val for _, val in self.labels)
def example_clusters(self):
result = set()
result = self._original_examples
for ex in self.examples:
cluster = ex.get_cluster()
if cluster is not None:
result.add(cluster)
result.add(self.reserved_example)
return sorted(result)

View File

@ -1,18 +1,25 @@
from export import export_to_xml
from browser import window
from lib.snabbdom import h
import message
NUM2STR = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
def show_toggle_cluster_buttons(sense, example):
cls = example.get_cluster()
if cls is None:
return []
result = []
for opt in sense.example_clusters():
tag = "input.cluster-list-button"
if opt == example.get_cluster():
if opt == cls:
tag += ".cluster-button-checked"
result.append(h(tag, {"attrs": {"value": NUM2STR[opt], "type": "button"}}, []))
result.append(h(tag,
{"attrs": {"value": NUM2STR[opt], "type": "button"},
"on": {"click": message.msg(message.ExampleClusterEdit(example, opt))}}, []))
return result