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

Automatic task lock on feature map & minor mapper frontend improvements #2047

Merged
merged 4 commits into from
Jan 1, 2025
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
9 changes: 8 additions & 1 deletion src/mapper/src/lib/components/dialog-entities-actions.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script lang="ts">
import type { ProjectData } from '$lib/types';
import { TaskStatusEnum, type ProjectData } from '$lib/types';
import { getEntitiesStatusStore } from '$store/entities.svelte.ts';
import { getAlertStore } from '$store/common.svelte.ts';
import { getTaskStore } from '$store/tasks.svelte.ts';
import { mapTask } from '$lib/db/events';

type Props = {
isTaskActionModalOpen: boolean;
Expand All @@ -14,6 +16,7 @@

const entitiesStore = getEntitiesStatusStore();
const alertStore = getAlertStore();
const taskStore = getTaskStore();

const selectedEntityOsmId = $derived(entitiesStore.selectedEntity);
const selectedEntity = $derived(
Expand All @@ -38,6 +41,10 @@
status: 1,
label: `Task ${selectedEntity?.task_id} Feature ${selectedEntity?.osmid}`,
});

if (taskStore.selectedTaskId && taskStore.selectedTaskState === TaskStatusEnum['UNLOCKED_TO_MAP']) {
mapTask(projectData?.id, taskStore.selectedTaskId);
}
}
// Load entity in ODK Collect by intent
document.location.href = `odkcollect://form/${xformId}?feature=${entityUuid}`;
Expand Down
21 changes: 18 additions & 3 deletions src/mapper/src/routes/[projectId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
let maplibreMap: maplibregl.Map | undefined = $state(undefined);
let tabGroup: SlTabGroup;
let openedActionModal: 'entity-modal' | 'task-modal' | null = $state(null);
let isTaskActionModalOpen: boolean = $state(false);
let infoDialogRef: SlDialog | null = $state(null);
let isDrawEnabled: boolean = $state(false);
let latestEventTime: string = $state('');

const taskStore = getTaskStore();
const entitiesStore = getEntitiesStatusStore();
Expand All @@ -63,6 +63,21 @@
taskStore.setTaskIdIndexMap(taskIdIndexMap);
});

// update the latest time time every minute
$effect(() => {
const updateLatestTime = () => {
if (taskStore.latestEvent?.created_at) {
latestEventTime = convertDateToTimeAgo(taskStore.latestEvent.created_at);
}
};

updateLatestTime();

const interval = setInterval(updateLatestTime, 60000);

return () => clearInterval(interval); // Cleanup interval on unmount
});

function zoomToTask(taskId: number) {
const taskObj = data.project.tasks.find((task: ProjectTask) => task.id === taskId);

Expand Down Expand Up @@ -122,8 +137,8 @@
id="notification-banner"
class="absolute z-10 top-15 sm:top-18.8 right-0 font-sans flex bg-white text-black bg-opacity-70 text-sm sm:text-base px-1 rounded-bl-md"
>
<b class="">{convertDateToTimeAgo(taskStore.latestEvent.created_at)}</b>&nbsp;| {taskStore.latestEvent.event}
on task {taskStore.latestEvent.task_id} by {taskStore.latestEvent.username || 'anon'}
<b class="">{latestEventTime}</b>&nbsp;| {taskStore.latestEvent.event}
on task {taskStore.taskIdIndexMap[taskStore.latestEvent.task_id]} by {taskStore.latestEvent.username || 'anon'}
</div>
{/if}

Expand Down
Loading