Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapper Frontend: Map new feature in odk btn #1879

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 84 additions & 7 deletions src/mapper/src/lib/components/dialog-task-actions.svelte
Original file line number Diff line number Diff line change
@@ -1,31 +1,80 @@
<script lang="ts">
import { mapTask, finishTask, resetTask } from '$lib/db/events';
import type { ProjectData } from '$lib/types';
import { getTaskStore } from '$store/tasks.svelte.ts';
import { getAlertStore } from '$store/common.svelte.ts';

type Props = {
isTaskActionModalOpen: boolean;
toggleTaskActionModal: (value: boolean) => void;
selectedTab: string;
projectId: number;
projectData: ProjectData;
};

const taskStore = getTaskStore();
let { isTaskActionModalOpen, toggleTaskActionModal, selectedTab, projectId }: Props = $props();
const alertStore = getAlertStore();
let { isTaskActionModalOpen, toggleTaskActionModal, selectedTab, projectData }: Props = $props();

function mapNewFeature() {
const xformId = projectData?.odk_form_id;
if (!xformId) {
return;
}

const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);

if (isMobile) {
document.location.href = `odkcollect://form/${xformId}`;
} else {
alertStore.setAlert({
variant: 'warning',
message: 'Requires a mobile phone with ODK Collect.',
});
}
}
</script>

{#if taskStore.selectedTaskId && selectedTab === 'map' && isTaskActionModalOpen && (taskStore.selectedTaskState === 'UNLOCKED_TO_MAP' || taskStore.selectedTaskState === 'LOCKED_FOR_MAPPING')}
<div class="flex justify-center !w-[100vw] absolute bottom-[4rem] left-0 pointer-events-none z-50">
<div
class="bg-white w-full font-barlow-regular md:max-w-[580px] pointer-events-auto px-4 py-3 sm:py-4 rounded-t-3xl"
>
<div class="flex justify-between items-center">
<p class="text-[#333] text-xl font-barlow-semibold">Task #{taskStore.selectedTaskId}</p>
<div class="flex justify-end">
<hot-icon
name="close"
class="!text-[1.5rem] text-[#52525B] cursor-pointer hover:text-red-600 duration-200"
onclick={() => toggleTaskActionModal(false)}
onkeydown={(e: KeyboardEvent) => {
if (e.key === 'Enter') {
toggleTaskActionModal(false);
}
}}
role="button"
tabindex="0"
></hot-icon>
</div>
<div class="flex justify-between items-center">
<p class="text-[#333] text-xl font-barlow-semibold">Task #{taskStore.selectedTaskId}</p>
<div
onclick={() => {
mapNewFeature();
}}
onkeydown={(e: KeyboardEvent) => {
if (e.key === 'Enter') {
mapNewFeature();
}
}}
role="button"
tabindex="0"
class="flex items-center gap-1 cursor-pointer group"
>
<hot-icon
name="new-window"
class="!text-[1.25rem] duration-200 text-[#333333] font-light group-hover:text-black"
></hot-icon>
<p class="uppercase text-[0.813rem] text-red-600 group-hover:text-red-700">map new feature</p>
</div>
</div>

{#if taskStore.selectedTaskState === 'UNLOCKED_TO_MAP'}
<p class="my-4 sm:my-6">Do you want to start mapping task #{taskStore.selectedTaskId}?</p>
Expand All @@ -36,14 +85,28 @@
class="secondary"
onclick={() => toggleTaskActionModal(false)}
outline
onkeydown={(e: KeyboardEvent) => {
if (e.key === 'Enter') {
toggleTaskActionModal(false);
}
}}
role="button"
tabindex="0"
>
<span class="font-barlow-medium text-sm">CANCEL</span>
</sl-button>
<sl-button
variant="default"
size="small"
class="primary"
onclick={() => mapTask(projectId, taskStore.selectedTaskId)}
onclick={() => mapTask(projectData?.id, taskStore.selectedTaskId)}
onkeydown={(e: KeyboardEvent) => {
if (e.key === 'Enter') {
mapTask(projectData?.id, taskStore.selectedTaskId);
}
}}
role="button"
tabindex="0"
>
<hot-icon slot="prefix" name="location" class="!text-[1rem] text-white cursor-pointer duration-200"
></hot-icon>
Expand All @@ -54,11 +117,18 @@
<p class="my-4 sm:my-6">Task #{taskStore.selectedTaskId} has been locked. Is the task completely mapped?</p>
<div class="grid grid-cols-2 sm:grid-cols-3 gap-2">
<sl-button
onclick={() => resetTask(projectId, taskStore.selectedTaskId)}
onclick={() => resetTask(projectData?.id, taskStore.selectedTaskId)}
variant="default"
outline
size="small"
class="secondary"
onkeydown={(e: KeyboardEvent) => {
if (e.key === 'Enter') {
resetTask(projectData?.id, taskStore.selectedTaskId);
}
}}
role="button"
tabindex="0"
>
<hot-icon
slot="prefix"
Expand All @@ -68,10 +138,17 @@
<span class="font-barlow-medium text-sm">CANCEL MAPPING</span>
</sl-button>
<sl-button
onclick={() => finishTask(projectId, taskStore.selectedTaskId)}
onclick={() => finishTask(projectData?.id, taskStore.selectedTaskId)}
variant="default"
size="small"
class="green"
onkeydown={(e: KeyboardEvent) => {
if (e.key === 'Enter') {
finishTask(projectData?.id, taskStore.selectedTaskId);
}
}}
role="button"
tabindex="0"
>
<hot-icon slot="prefix" name="check" class="!text-[1rem] text-white cursor-pointer duration-200"></hot-icon>
<span class="font-barlow-medium text-sm">COMPLETE MAPPING</span>
Expand Down
4 changes: 2 additions & 2 deletions src/mapper/src/routes/[projectId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
isTaskActionModalOpen = value;
}}
{selectedTab}
projectId={data.projectId}
projectData={data?.project}
/>

{#if selectedTab !== 'map'}
Expand Down Expand Up @@ -203,7 +203,7 @@
class="z-9999 fixed bottom-0 left-0 right-0"
placement="bottom"
no-scroll-controls
onsl-tab-show={(e: CustomEvent<{ name: string }>) => {
onsl-tab-show={(e: CustomEvent<{ name: string }>) => {
selectedTab = e.detail.name;
if (
e.detail.name !== 'qrcode' &&
Expand Down
1 change: 1 addition & 0 deletions src/mapper/static/assets/icons/new-window.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.