Skip to content

Commit 9ef4b3e

Browse files
committed
Create a component for AnnotationNotAnInsectButton.vue
1 parent 6493ab6 commit 9ef4b3e

File tree

2 files changed

+70
-45
lines changed

2 files changed

+70
-45
lines changed

src/components/annotations/AnnotationCreator.vue

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
<div class="flex grow">
4545
<BestPhotoTag v-if="isStarted" />
4646
<div v-if="!isStarted" class="flex gap-2">
47-
<Button label="Not an insect" severity="danger" icon="pi pi-times" outlined
48-
class="not-hover:text-white!" @click="confirmNotInsect($event)"
49-
:loading="isSubmittingNotInsect || loading" />
47+
<AnnotationNotAnInsectButton :observation="assignment.observation" :loading="loading"
48+
@on-submit-success="onSubmitAnnotation(true)" />
5049
<Button v-if="!isStarted" label="Annotate this picture" icon="pi pi-arrow-right" iconPos="right"
5150
@click="startAnnotation" :loading="loading" />
5251
</div>
@@ -98,23 +97,18 @@
9897

9998
<script setup lang='ts'>
10099
import { computed, ref, watch } from 'vue';
101-
import { useConfirm } from "primevue/useconfirm";
102-
import { useToast } from "primevue/usetoast";
103100
import VueMagnifier from '@websitebeaver/vue-magnifier';
104101
import '@websitebeaver/vue-magnifier/styles.css'
105102
106103
import { AnnotationType } from 'mosquito-alert';
107-
import type { Assignment, AnnotationRequest } from 'mosquito-alert';
104+
import type { Assignment } from 'mosquito-alert';
108105
109106
import AnnotationForm from './AnnotationForm.vue';
110107
import AnnotationTypeTag from './AnnotationTypeTag.vue';
111108
import AnnotationGalleriaFullScreen from './AnnotationGalleriaFullScreen.vue';
109+
import AnnotationNotAnInsectButton from './AnnotationNotAnInsectButton.vue';
112110
import ObservationInfoData from '../observations/ObservationInfoData.vue';
113111
import BestPhotoTag from '../photos/BestPhotoTag.vue';
114-
import { identificationTasksApi } from '@/services/apiService';
115-
116-
const confirm = useConfirm();
117-
const toast = useToast();
118112
119113
const numVisible = ref(7);
120114
@@ -125,7 +119,6 @@ const isFavourite = ref(false);
125119
const activePhotoIndex = ref(0);
126120
const showGalleriaFullscreen = ref(false);
127121
const observationDialogVisible = ref(false);
128-
const isSubmittingNotInsect = ref(false);
129122
130123
const activePhoto = computed(() => {
131124
return props.assignment.observation.photos[activePhotoIndex.value];
@@ -176,38 +169,4 @@ const onSubmitAnnotation = (shouldContinue: boolean) => {
176169
}
177170
}
178171
179-
const confirmNotInsect = (event: MouseEvent) => {
180-
isSubmittingNotInsect.value = true;
181-
confirm.require({
182-
target: event.currentTarget as HTMLElement,
183-
message: 'Are you sure you want to mark this image as not an insect?',
184-
icon: 'pi pi-info-circle',
185-
rejectProps: {
186-
label: 'Cancel',
187-
severity: 'secondary',
188-
outlined: true
189-
},
190-
acceptProps: {
191-
label: 'Accept',
192-
severity: 'danger'
193-
},
194-
accept: () => {
195-
const annotationRequest = <AnnotationRequest>{
196-
classification: null,
197-
}
198-
identificationTasksApi.annotationsCreate({
199-
observationUuid: props.assignment.observation.uuid,
200-
annotationRequest: annotationRequest,
201-
}).then(() => {
202-
toast.add({ severity: 'info', summary: 'Annotation rejected', detail: 'Marked as not an insect', life: 3000 });
203-
onSubmitAnnotation(true);
204-
}).catch(() => {
205-
toast.add({ severity: 'danger', summary: 'Failed', detail: 'Annotation failed', life: 3000 });
206-
})
207-
},
208-
reject: () => { }
209-
});
210-
isSubmittingNotInsect.value = false;
211-
}
212-
213172
</script>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template>
2+
<Button label="Not an insect" severity="danger" icon="pi pi-times" outlined class="not-hover:text-white!"
3+
@click="confirmNotInsect($event)" :loading="isSubmitting || loading" />
4+
</template>
5+
6+
<script setup lang="ts">
7+
import { ref } from 'vue'
8+
9+
import { useConfirm } from "primevue/useconfirm";
10+
import { useToast } from "primevue/usetoast";
11+
12+
import { identificationTasksApi } from '@/services/apiService';
13+
import type { Observation, AssignedObservation, AnnotationRequest } from 'mosquito-alert';
14+
15+
const confirm = useConfirm();
16+
const toast = useToast();
17+
18+
const props = withDefaults(defineProps<{
19+
observation: Observation | AssignedObservation,
20+
loading?: boolean
21+
}>(), {
22+
loading: false
23+
});
24+
25+
const emit = defineEmits<{
26+
(e: 'onSubmitSuccess'): void
27+
(e: 'onSubmitFailure'): void
28+
}>()
29+
30+
const isSubmitting = ref<boolean>(false)
31+
32+
const confirmNotInsect = (event: MouseEvent) => {
33+
isSubmitting.value = true;
34+
confirm.require({
35+
target: event.currentTarget as HTMLElement,
36+
message: 'Are you sure you want to mark this image as not an insect?',
37+
icon: 'pi pi-info-circle',
38+
rejectProps: {
39+
label: 'Cancel',
40+
severity: 'secondary',
41+
outlined: true
42+
},
43+
acceptProps: {
44+
label: 'Accept',
45+
severity: 'danger'
46+
},
47+
accept: () => {
48+
const annotationRequest = <AnnotationRequest>{
49+
classification: null,
50+
}
51+
identificationTasksApi.annotationsCreate({
52+
observationUuid: props.observation.uuid,
53+
annotationRequest: annotationRequest,
54+
}).then(() => {
55+
toast.add({ severity: 'info', summary: 'Observation rejected', detail: 'Marked as not an insect', life: 3000 });
56+
emit('onSubmitSuccess')
57+
}).catch(() => {
58+
toast.add({ severity: 'danger', summary: 'Failed', detail: 'Annotation failed', life: 3000 });
59+
emit('onSubmitFailure')
60+
})
61+
},
62+
reject: () => { }
63+
});
64+
isSubmitting.value = false;
65+
}
66+
</script>

0 commit comments

Comments
 (0)