Skip to content

Commit

Permalink
Merge branch 'dev' into playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
CvdL-UM committed Oct 9, 2024
2 parents a4e23ba + f28092e commit 1d44138
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 214 deletions.
15 changes: 8 additions & 7 deletions lawnotation-ui/components/LabelStudio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<Badge :value="assignment.status" :severity="assignment.status == AssignmentStatuses.DONE ? 'success' : 'danger'"
class="capitalize px-2" />
</div>
<div v-if="!isEditor && assignmentsTotal" class="flex items-center w-1/3">
<span class="font-semibold mr-2">{{ assignment.seq_pos }}/{{ assignmentsTotal }}</span>
<div v-if="!isEditor && previousCount != undefined && totalCount" class="flex items-center w-1/3">
<span class="font-semibold mr-2">{{ previousCount }}/{{ totalCount }}</span>
<span class="w-full">
<ProgressBar :value="Math.round((assignment.seq_pos / assignmentsTotal) * 100)"> {{ Math.round(assignment.seq_pos / assignmentsTotal * 100)}}% </ProgressBar>
<ProgressBar :value="Math.round((previousCount / totalCount) * 100)"> {{ Math.round(previousCount / totalCount * 100)}}% </ProgressBar>
</span>
</div>
<div v-if="!isEditor && assignmentsTotal">
<Button :disabled="assignment.seq_pos == 1" label="Back" class="mr-3" icon="pi pi-arrow-left" @click="clickPrevious" icon-pos="left" outlined />
<Button :label="assignment.seq_pos < assignmentsTotal ? 'Next' : 'Finish'" icon="pi pi-arrow-right" @click="clickNext" icon-pos="right" />
<div v-if="!isEditor && totalCount && previousCount != undefined">
<Button :disabled="previousCount <= 1" label="Back" class="mr-3" icon="pi pi-arrow-left" @click="clickPrevious" icon-pos="left" outlined />
<Button :label="previousCount < totalCount ? 'Next' : 'Finish'" icon="pi pi-arrow-right" @click="clickNext" icon-pos="right" />
</div>
<div v-else>
<Button label="Save" icon="pi pi-check" @click="clickNext" icon-pos="right" />
Expand Down Expand Up @@ -44,7 +44,8 @@ const emit = defineEmits(["previousAssignment", "nextAssignment"]);
const props = defineProps<{
user: any;
assignment: Assignment | undefined;
assignmentsTotal: number | undefined;
totalCount: number | undefined;
previousCount: number | undefined;
annotations: LSSerializedAnnotations | undefined;
relations: LSSerializedRelation[] | undefined;
text: string | undefined;
Expand Down
48 changes: 25 additions & 23 deletions lawnotation-ui/pages/annotate/[task_id]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
},
]" />

<template v-if="task && assignmentCounts">
<template v-if="task && totalCount">
<div class="dimmer-wrapper min-h-0">
<Dimmer v-model="loading" />
<div class="dimmer-content h-full">
<LabelStudio v-if="loadedData" :assignment="assignment" :assignmentsTotal="assignmentCounts.total" :user="user" :isEditor="isEditor" :text="doc?.full_text"
<LabelStudio v-if="loadedData" :assignment="assignment" :previousCount="previousCount" :totalCount="totalCount" :user="user" :isEditor="isEditor" :text="doc?.full_text"
:annotations="ls_annotations" :relations="ls_relations" :labels="labels" :guidelines="task?.ann_guidelines"
:annotation_level="task.annotation_level" :isHtml="isHtml" :key="key" @nextAssignment="loadNext" @previousAssignment="loadPrevious">
</LabelStudio>
Expand All @@ -37,6 +37,7 @@ import type {
AnnotationRelation,
LSSerializedRelation,
} from "~/types";
import { Direction } from "~/utils/enums";
import Breadcrumb from "~/components/Breadcrumb.vue";
import { isDocumentLevel, getDocFormat } from "~/utils/levels";
import { authorizeClient } from "~/utils/authorize.client";
Expand All @@ -54,13 +55,12 @@ const task = ref<Task>();
const doc = ref<Document>();
const loadedData = ref(false);
// const annotations = reactive<Annotation[]>([]);
// const relations = reactive<AnnotationRelation[]>([]);
const ls_annotations = reactive<LSSerializedAnnotations>([]);
const ls_relations = reactive<LSSerializedRelation[]>([]);
const labels = reactive<LsLabels>([]);
const isEditor = ref<boolean>();
const assignmentCounts = ref<{ next: number; total: number }>();
const previousCount = ref<number>(0);
const totalCount = ref<number>(0);
const loading = ref(false);
const key = ref("ls-default");
Expand All @@ -69,10 +69,9 @@ const isHtml = computed(() => {
return getDocFormat(doc?.value?.name!) == 'html';
});
// const seq_pos = ref(assignment.value?.seq_pos ?? 1);
const seq_pos = ref<number>(assignment.value?.seq_pos ?? 0);
watch(seq_pos, (val) => {
if (!Array.isArray(route.query.seq) && route.query.seq == val.toString()) return;
if (!Array.isArray(route.query.seq) && route.query.seq == val?.toString()) return;
router.replace({
path: route.path,
Expand All @@ -83,28 +82,26 @@ watch(seq_pos, (val) => {
const loadPrevious = async () => {
if (!assignment.value) throw Error("Assignment not found");
if (assignment.value.seq_pos <= 1) throw Error("Already at first item");
seq_pos.value -= 1;
await loadData();
if (previousCount.value < 1) throw Error("Already at first item");
previousCount.value--;
await loadData(Direction.PREVIOUS);
};
const loadNext = async () => {
if (!assignment.value) throw Error("Assignment not found");
if (!totalCount.value) throw Error("Assignment Counts not found");
if (assignmentCounts.value && seq_pos.value + 1 > assignmentCounts.value.total) {
// TODO: go to page /done
if (previousCount.value >= totalCount.value) {
$toast.success(`All assignments were completed!`);
if (task.value)
navigateTo(`/tasks/${task.value.id}`)
} else {
seq_pos.value++;
await loadData();
previousCount.value++;
await loadData(Direction.NEXT);
}
};
const loadData = async () => {
const loadData = async (dir: Direction = Direction.CURRENT) => {
try {
if (!user.value) throw new Error("Must be logged in");
Expand All @@ -115,8 +112,11 @@ const loadData = async () => {
annotator_id: user.value.id,
task_id: +route.params.task_id,
seq_pos: seq_pos.value,
dir: dir
});
seq_pos.value = assignment?.value?.seq_pos!;
if (!assignment.value) throw Error("Assignment not found");
doc.value = await $trpc.document.findById.query(assignment.value.document_id);
Expand Down Expand Up @@ -174,25 +174,27 @@ const loadCounters = async () => {
const counts = await $trpc.assignment.countAssignmentsByUserAndTask.query({
annotator_id: user.value.id,
task_id: +route.params.task_id,
seq_pos: seq_pos.value
});
assignmentCounts.value = counts;
} catch (error) {
totalCount.value = counts.total;
previousCount.value = counts.previous + 1;
} catch (error) {
throw new Error(error.message);
}
};
const init = async () => {
await loadCounters();
if (
route.query.seq &&
!Array.isArray(route.query.seq) &&
parseInt(route.query.seq) > 0 &&
parseInt(route.query.seq) <= assignmentCounts.value!.total
parseInt(route.query.seq) > 0
) {
seq_pos.value = parseInt(route.query.seq);
}
loadData();
await loadCounters();
loadData(Direction.CURRENT);
};
onMounted(async () => {
Expand Down
31 changes: 14 additions & 17 deletions lawnotation-ui/pages/tasks/[task_id]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@
]" />

<div v-if="task">
<div class="max-w-screen-md w-full mx-auto" v-if="assignmentCounts">
<div class="flex justify-between mb-1">
<span class="text-base font-medium text-gray-500 text-muted">Assignment</span>
<span class="text-sm font-medium text-blue-700" data-test="progress">{{ assignmentCounts.next - 1 }} / {{ assignmentCounts.total
}}</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div class="bg-blue-600 h-2.5 rounded-full transition-all duration-500" :style="{
width: `${((assignmentCounts.next - 1) / assignmentCounts.total) * 100}%`,
}"></div>
</div>
<div class="flex items-center mx-auto w-1/2" v-if="totalCount">
<span class="font-semibold mr-2">{{ previousCount }}/{{ totalCount }}</span>
<span class="w-full">
<ProgressBar :value="Math.round((previousCount / totalCount) * 100)"> {{ Math.round(previousCount / totalCount * 100)}}% </ProgressBar>
</span>
</div>
<div class="text-center my-10">
<div v-if="assignmentCounts && assignmentCounts.next <= assignmentCounts.total">
<NuxtLink :to="`/annotate/${task.id}?seq=${assignmentCounts?.next}`">
<div v-if="nextAssignment && totalCount <= totalCount">
<NuxtLink :to="`/annotate/${task.id}?seq=${nextAssignment.seq_pos}`">
<button class="base btn-primary" data-test="annotate-next-assignment-button">Annotate Next Assignment</button>
</NuxtLink>
</div>
Expand Down Expand Up @@ -64,7 +58,10 @@ const user = useSupabaseUser();
const route = useRoute();
const task = await $trpc.task.findById.query(+route.params.task_id);
const assignmentCounts = ref<{ next: number; total: number }>();
const nextAssignment = await $trpc.assignment.findNextAssignmentsByUserAndTask.query({ annotator_id: user.value?.id!, task_id: task.id });
const previousCount = ref<number>(0);
const totalCount = ref<number>(0);
const loadCounters = async () => {
try {
Expand All @@ -73,18 +70,18 @@ const loadCounters = async () => {
const counts = await $trpc.assignment.countAssignmentsByUserAndTask.query({
annotator_id: user.value.id,
task_id: task.id,
task_id: task.id
});
assignmentCounts.value = counts;
previousCount.value = counts.previous;
totalCount.value = counts.total;
} catch (error) {
if (error instanceof Error)
$toast.error(`Problem loading counters: ${error.message}`);
}
};
onMounted(async () => {
// task.value = await $trpc.task.findById.query(+route.params.task_id);
await loadCounters();
});
Expand Down
Loading

0 comments on commit 1d44138

Please sign in to comment.