|
| 1 | +<script lang="ts" setup> |
| 2 | +
|
| 3 | +import { isDefined } from '@togglecorp/fujs'; |
| 4 | +import { computed, inject, onMounted, ref, shallowRef, watchEffect } from 'vue'; |
| 5 | +import type { Project, TaskGroup, TutorialTileTask, Tutorial, CustomOption, ImageTask } from '@/utils/types'; |
| 6 | +import ValidateImageProjectTask from '@/components/ValidateImageProjectTask.vue'; |
| 7 | +import OptionButtons from '@/components/OptionButtons.vue'; |
| 8 | +import TaskProgress from './TaskProgress.vue'; |
| 9 | +import ProjectHeader from '@/components/ProjectHeader.vue' |
| 10 | +import ProjectInfo from './ProjectInfo.vue'; |
| 11 | +import createInformationPages from '@/utils/createInformationPages'; |
| 12 | +import { createFallbackInformationPages } from '@/utils/domain'; |
| 13 | +
|
| 14 | +interface Props { |
| 15 | + group: TaskGroup; |
| 16 | + first: boolean; |
| 17 | + options: CustomOption[]; |
| 18 | + project: Project; |
| 19 | + tasks: ImageTask[]; |
| 20 | + tutorial: Tutorial; |
| 21 | + tutorialTasks: TutorialTileTask[]; |
| 22 | +} |
| 23 | +
|
| 24 | +const taskOffset = ref(0); |
| 25 | +// const projectInfoRef = useTemplateRef('projectInfo'); |
| 26 | +
|
| 27 | +const props = withDefaults(defineProps<Props>(), { |
| 28 | + options: () => [ |
| 29 | + { |
| 30 | + mdiIcon: 'mdi-check-bold', |
| 31 | + description: `The shape does outline a building in the image`, |
| 32 | + iconColor: '#388E3C', |
| 33 | + shortKey: 1, |
| 34 | + title: 'Yes', |
| 35 | + value: 1, |
| 36 | + }, |
| 37 | + { |
| 38 | + mdiIcon: 'mdi-close-thick', |
| 39 | + description: `The shape doesn't match a building in the image`, |
| 40 | + iconColor: '#D32F2F', |
| 41 | + shortKey: 2, |
| 42 | + title: 'No', |
| 43 | + value: 0, |
| 44 | + }, |
| 45 | + { |
| 46 | + mdiIcon: 'mdi-minus-thick', |
| 47 | + description: `If you're not sure or there is cloud cover / bad imagery.`, |
| 48 | + iconColor: '#616161', |
| 49 | + title: 'Not sure', |
| 50 | + shortKey: 3, |
| 51 | + value: 2, |
| 52 | + }, |
| 53 | + ], |
| 54 | +}); |
| 55 | +
|
| 56 | +const logMappingStarted = inject<(projectType: string) => void>('logMappingStarted'); |
| 57 | +const saveResults = inject<(results: Record<string, number>, startTime: string) => void>('saveResults'); |
| 58 | +const arrowKeys = ref(true); |
| 59 | +const startTime = shallowRef<string>(); |
| 60 | +
|
| 61 | +const emit = defineEmits<{ created: []}>(); |
| 62 | +const results = ref<Record<string, number>>({}); |
| 63 | +
|
| 64 | +watchEffect(() => { |
| 65 | + startTime.value = new Date().toISOString(); |
| 66 | +}); |
| 67 | +
|
| 68 | +
|
| 69 | +const currentTask = computed(() => props.tasks[taskOffset.value]); |
| 70 | +
|
| 71 | +onMounted(() => { |
| 72 | + logMappingStarted?.(props.project.projectType); |
| 73 | + emit('created'); |
| 74 | +}); |
| 75 | +
|
| 76 | +function addResult(newValue: number) { |
| 77 | + results.value[currentTask.value.taskId] = newValue; |
| 78 | +} |
| 79 | +
|
| 80 | +const isLastTask = computed( |
| 81 | + () => (props.tasks.length - 1) === taskOffset.value |
| 82 | +); |
| 83 | +const currentTaskAnswered = computed( |
| 84 | + () => isDefined(results.value[currentTask.value.taskId]) |
| 85 | +) |
| 86 | +
|
| 87 | +function handleBack() { |
| 88 | + if (taskOffset.value > 0) { |
| 89 | + taskOffset.value = taskOffset.value - 1; |
| 90 | + } |
| 91 | +} |
| 92 | +
|
| 93 | +function handleForward() { |
| 94 | + if (taskOffset.value < (props.tasks.length - 1)) { |
| 95 | + taskOffset.value = taskOffset.value + 1; |
| 96 | + } |
| 97 | +} |
| 98 | +
|
| 99 | +</script> |
| 100 | + |
| 101 | +<template> |
| 102 | + <ProjectHeader |
| 103 | + :mission="$t('projectView.youAreLookingFor', { lookFor: props.project.lookFor })" |
| 104 | + > |
| 105 | + <Project-info |
| 106 | + ref="projectInfo" |
| 107 | + :first="first" |
| 108 | + :informationPages="createInformationPages(props.tutorial, props.project, createFallbackInformationPages)" |
| 109 | + :manualUrl="project?.manualUrl" |
| 110 | + @toggle-dialog="arrowKeys = !arrowKeys" |
| 111 | + > |
| 112 | + <!-- TODO: add instruction --> |
| 113 | + <!-- |
| 114 | + <template #instructions> |
| 115 | + <validate-project-instructions :mission="mission" :options="options" /> |
| 116 | + </template> |
| 117 | + --> |
| 118 | + <!-- FIXME: add tutorial --> |
| 119 | + <!-- |
| 120 | + <template #tutorial> |
| 121 | + <validate-project-tutorial |
| 122 | + :tutorial="tutorial" |
| 123 | + :tasks="tutorialTasks" |
| 124 | + :options="options" |
| 125 | + @tutorialComplete="projectInfoRef?.toggleDialog" |
| 126 | + /> |
| 127 | + </template> |
| 128 | + --> |
| 129 | + <!-- FIXME: add tutorial --> |
| 130 | + </Project-info> |
| 131 | + </ProjectHeader> |
| 132 | + <v-container |
| 133 | + class="ma-0 pa-0 container" |
| 134 | + > |
| 135 | + <ValidateImageProjectTask |
| 136 | + :task="currentTask" |
| 137 | + /> |
| 138 | + </v-container> |
| 139 | + <OptionButtons |
| 140 | + v-if="currentTask" |
| 141 | + :options="props.options" |
| 142 | + :result="results[currentTask.taskId]" |
| 143 | + :taskId="currentTask.taskId" |
| 144 | + @addResult="addResult" |
| 145 | + /> |
| 146 | + <v-toolbar color="white" density="compact" extension-height="20" extended> |
| 147 | + <v-spacer /> |
| 148 | + <v-btn |
| 149 | + :title="$t('validateProject.moveLeft')" |
| 150 | + icon="mdi-chevron-left" |
| 151 | + color="secondary" |
| 152 | + :disabled="taskOffset <= 0" |
| 153 | + @click="handleBack" |
| 154 | + v-shortkey.once="[arrowKeys ? 'arrowleft' : '']" |
| 155 | + @shortkey="handleBack" |
| 156 | + /> |
| 157 | + <v-btn |
| 158 | + v-if="isDefined(startTime)" |
| 159 | + :title="$t('projectView.saveResults')" |
| 160 | + icon="mdi-content-save" |
| 161 | + color="primary" |
| 162 | + :disabled="!isLastTask" |
| 163 | + @click="saveResults?.(results, startTime)" |
| 164 | + /> |
| 165 | + <v-btn |
| 166 | + :title="$t('validateProject.moveRight')" |
| 167 | + icon="mdi-chevron-right" |
| 168 | + color="secondary" |
| 169 | + :disabled="!currentTaskAnswered || isLastTask" |
| 170 | + @click="handleForward" |
| 171 | + v-shortkey.once="[arrowKeys ? 'arrowright' : '']" |
| 172 | + @shortkey="handleForward" |
| 173 | + /> |
| 174 | + <v-spacer /> |
| 175 | + <template #extension> |
| 176 | + <TaskProgress :progress="taskOffset + 1" :total="tasks.length" /> |
| 177 | + </template> |
| 178 | + </v-toolbar> |
| 179 | +</template> |
| 180 | + |
| 181 | +<style scoped> |
| 182 | +.container { |
| 183 | + height: calc(100vh - 390px); |
| 184 | +} |
| 185 | +</style> |
0 commit comments