Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpestov committed Oct 17, 2024
1 parent 7e0d31c commit 53c40e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
4 changes: 3 additions & 1 deletion src/components/annotations/AnnotationsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface Props {
types: AnnotationType[]
}
const props = defineProps<Props>();
const emit = defineEmits(['init'])
const annotations = computed<Annotation[]>(() => annotationStore.annotations);
const filteredAnnotations = computed<Annotation[]>(() => annotationStore.filteredAnnotations);
Expand All @@ -53,14 +54,15 @@ watch(
annotationStore.resetAnnotations();
annotationStore.selectFilteredAnnotations(props.types);
annotationStore.highlightTargetsLevel0();
emit('init')
},
{ immediate: true },
);
const unsubscribe = TextEventBus.on('click', ({ target }) => {
// Next we look up which annotations need to be selected
// Next we look up which annotations need to be selected
let annotationIds = {};
Utils.getValuesFromAttribute(target, 'data-annotation-ids').forEach((value) => annotationIds[value] = true);
Expand Down
15 changes: 8 additions & 7 deletions src/components/annotations/variants/VariantsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const contentsStore = useContentsStore();
allocateWitnessColorInVariantItem()
const emit = defineEmits(['init'])
const annotations = computed<Annotation[]>(() => annotationStore.annotations);
const activeContentUrl = computed<string>(() => contentsStore.activeContentUrl);
const filteredAnnotations = computed<Annotation[]>(() => annotationStore.filteredAnnotations);
Expand All @@ -31,6 +33,7 @@ watch(
annotationStore.resetAnnotations();
annotationStore.selectFilteredAnnotations([{ name: 'Variant' }]);
annotationStore.highlightTargetsLevel0();
emit('init')
},
{ immediate: true },
);
Expand All @@ -39,17 +42,16 @@ const unsubscribe = TextEventBus.on('click', ({ target }) => {
const ids = getAnnotationIdsFromTarget(target)
const annotations = filteredAnnotations.value.filter((filtered) => ids.find(id => filtered.id === id))
if(!annotationStore.isSingleSelectMode) {
const annotations = filteredAnnotations.value.filter((filtered) => ids.find(id => filtered.id === id))
if (!annotationStore.isSingleSelectMode) {
// We check if the found annotation ids are currently displayed in the active tab, if not we skip the handling
// the annotations referring to the target are not displayed - we do not proceed further
if (annotations.length === 0) return
}
else {
} else {
// if we are in single select mode, we still have variant annotations, but there are not shown
// if we click at a part of text whose related annotations are not in the variant annotations, then we do not proceed further
const variantAnnotations = getVariantAnnotations(annotationStore.annotations, 'Variant')
if(!variantAnnotations.find((annotation) => annotation.id === ids[0])){
if (!variantAnnotations.find((annotation) => annotation.id === ids[0])) {
return
}
}
Expand All @@ -60,8 +62,7 @@ const unsubscribe = TextEventBus.on('click', ({ target }) => {
if (targetIsSelected) {
annotationStore.removeFilteredAnnotations(ids)
annotationStore.deactivateAnnotationsByIds(ids)
}
else {
} else {
annotationStore.addFilteredAnnotations(ids)
annotationStore.activateAnnotationsByIds(ids)
}
Expand Down
28 changes: 20 additions & 8 deletions src/components/panels/Panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,25 @@ export default {
if (!url) return;
const selected = false;
const events = {
const actionEvents = {
update: (value) => {
if (value === null) return;
if (value) annotationStore.selectAll();
else annotationStore.selectNone();
},
};
const viewEvents = {
init: () => {
tabs.value[i].actions[0].props.selected = false
}
}
unsubscribe.value = annotationStore.$onAction(({
name, args,
}) => {
if (tabs.value.length
&& tabs.value[0]?.actions?.length
&& tabs.value[i]?.actions?.length
&& (name === 'setActiveAnnotations')) {
const activeAnnotations = args[0];
const activeAmount = Object.keys(activeAnnotations).length;
Expand All @@ -309,45 +315,51 @@ export default {
selected,
label: t('select_all'),
},
events,
events: actionEvents,
}];
tabs.value = [...tabs.value, {
component,
label,
props: { ...connector.options },
actions,
events: viewEvents
}];
}
function createVariantsView(view) {
function createVariantsView(view, i) {
const annotationStore = useAnnotationsStore();
const { connector, label } = view;
const { component } = findComponent(connector.id);
const selectedSingleMode = false
const eventsSingleSelectMode = {
update: (value) => {
if (value) annotationStore.enableSingleSelectMode();
else annotationStore.disableSingleSelectMode();
},
};
const viewEvents = {
init: () => {
tabs.value[i].actions[0].props.selected = false
}
}
const actions = [{
component: 'PanelToggleAction',
props: {
selected: selectedSingleMode,
selected: false,
label: t('single_select_mode'),
},
events: eventsSingleSelectMode,
}];
tabs.value = [...tabs.value, {
component,
label,
props: { ...connector.options },
actions,
events: viewEvents
}];
}
Expand Down

0 comments on commit 53c40e4

Please sign in to comment.