diff --git a/src/lib/components/PointEditor.svelte b/src/lib/components/PointEditor.svelte index 02cfb5b..a5d17a4 100644 --- a/src/lib/components/PointEditor.svelte +++ b/src/lib/components/PointEditor.svelte @@ -1,8 +1,197 @@ \ No newline at end of file + $effect(() => { + onChange(); + }); + + // Modal controls + export function openModal() { + isOpen = true; + } + + function closeModal() { + isOpen = false; + onClose(); + } + + function handleDeletePoint(point: SavedPoint) { + deletePoint(point.id) + .then(() => { + $SavedPointsStore = $SavedPointsStore.filter((p) => p.id !== point.id); + SavedPointsStore.set($SavedPointsStore); + resetForm(); + addToast({ + header: "Точка удалена", + body: `Точка "${point.name}" успешно удалена.`, + color: "success", + }); + }) + .catch((error) => { + showAlert(`Ошибка при удалении точки: ${error.message}`); + console.error("Ошибка при удалении точки:", error); + }); + } + + function handleSavePoint() { + updatePoint(selectedPoint) + .then((updatedPoint) => { + $SavedPointsStore = $SavedPointsStore.map((p) => (p.id === updatedPoint.id ? updatedPoint : p)); + SavedPointsStore.set($SavedPointsStore); + resetForm(); + addToast({ + header: "Точка обновлена", + body: `Точка "${updatedPoint.name}" успешно обновлена.`, + color: "success", + }); + }) + .catch((error) => { + showAlert(`Ошибка при обновлении точки: ${error.message}`); + }); + } + + export function showAlert(message: string) { + isAlertVisible = true; + alertText = message; + } + + export function hideAlert() { + isAlertVisible = false; + alertText = ""; + } + + export function resetForm() { + hideAlert(); + closeModal(); + } + + + + + Редактирование точки + + + + + {"Редактирование точки"} + (isAlertVisible = false)} + fade={false} + class="mb-2" + > + + {alertText} + + { + e.preventDefault(); + handleSavePoint(); + }} + > + + Название точки: + + + + + Широта: + + Градусы + + + Долгота: + + Градусы + + + Высота: + + Метры над ур. моря + + + + + Обновить точку + + Отмена + + isConfirmationVisible = true} + > + Удалить точку + + + + + + + + { + isConfirmationVisible = false; + handleDeletePoint(selectedPoint); + }} + oncancel={() => { + isConfirmationVisible = false; + }} +> + Вы уверены, что хотите удалить эту точку? + \ No newline at end of file diff --git a/src/lib/components/PointListModal.svelte b/src/lib/components/PointListModal.svelte index 51e0e34..b47abc9 100644 --- a/src/lib/components/PointListModal.svelte +++ b/src/lib/components/PointListModal.svelte @@ -16,16 +16,24 @@ import { addToast } from "$lib/components/Toast.svelte"; import type { SavedPoint } from "$lib/types"; import { SavedPointsStore } from "$lib/stores"; + import ConfirmationPrompt from "./ConfirmationPrompt.svelte"; import { getSavedPoints, savePoint, updatePoint, deletePoint } from "$lib/api/points"; // Props - let { isOpen = $bindable(false), onClose = () => {}, onChange = () => {} } = $props(); + let { + isOpen = $bindable(false), + onClose = () => {}, + onChange = () => {}, + point = null, + coordinates = { id: 0, name: "", lat: 0, lon: 0, alt: 0 }, + } = $props(); // Runes - let selectedPoint = $state(null); - let newPoint = $state({ id: 0, name: "", lat: 0, lon: 0, alt: 0 }); + let selectedPoint = $state(point); + let newPoint = $state(coordinates as SavedPoint); let isEditing = $state(false); let isAlertVisible = $state(false); + let isConfirmationVisible = $state(false); let alertText = $state(""); // Table handler @@ -59,7 +67,13 @@ isEditing = true; } - function handleDeletePoint(point: SavedPoint) { + function confirmDeletePoint(point: SavedPoint) { + selectedPoint = point; + isConfirmationVisible = true; + } + + function handleDeletePoint(point: SavedPoint | null) { + if (!point) return; deletePoint(point.id) .then(() => { $SavedPointsStore = $SavedPointsStore.filter((p) => p.id !== point.id); @@ -129,7 +143,7 @@ } - + Сохраненные точки @@ -179,7 +193,7 @@ handleEditPoint(row)}> - handleDeletePoint(row)}> + confirmDeletePoint(row)}> @@ -275,3 +289,20 @@ + + { + isConfirmationVisible = false; + handleDeletePoint(selectedPoint); + }} + oncancel={() => { + isConfirmationVisible = false; + }} +> + Вы уверены, что хотите удалить эту точку? + \ No newline at end of file diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index a48518c..d027858 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -86,7 +86,7 @@ Войти {/if} - Назад + Назад diff --git a/src/routes/user/account/+page.svelte b/src/routes/user/account/+page.svelte index 7f58e31..7b1f76f 100644 --- a/src/routes/user/account/+page.svelte +++ b/src/routes/user/account/+page.svelte @@ -116,7 +116,7 @@ - + Учетная запись Сохраненные сценарии diff --git a/src/routes/user/templates/+page.svelte b/src/routes/user/templates/+page.svelte index b1948f8..7c1294c 100644 --- a/src/routes/user/templates/+page.svelte +++ b/src/routes/user/templates/+page.svelte @@ -16,6 +16,8 @@ import Navbar from "$lib/components/Navbar.svelte"; import Footer from "$lib/components/Footer.svelte"; import ConfirmationPrompt from "$lib/components/ConfirmationPrompt.svelte"; + import PointEditor from "$lib/components/PointEditor.svelte"; + import ToastContainer from "$lib/components/Toast.svelte"; import { addToast } from "$lib/components/Toast.svelte"; // TODO: Implement these imports @@ -35,12 +37,14 @@ let templatesTable = $derived(new TableHandler($SavedScenarioTemplatesStore, { rowsPerPage: 5 })); let templatesSearch = $derived(templatesTable.createSearch(["name"])); + let editPoint: SavedPoint | null = $state(null); + onMount(async () => { // Mock data for demonstration. Replace with API calls. - $SavedPointsStore = [ - { id: 1, name: "Baikonur Cosmodrome", lat: 45.96, lon: 63.3, alt: 90 }, - { id: 2, name: "Kennedy Space Center", lat: 28.57, lon: -80.64, alt: 3 }, - ]; + const pts = await getSavedPoints(); + $SavedPointsStore = pts; + SavedPointsStore.set($SavedPointsStore); + $SavedFlightProfilesStore = [ { id: 1, name: "Standard Weather Balloon", rate_profile_data: {ascent_rate: 5, descent_rate: 8, burst_altitude: 30000} }, { id: 2, name: "High Altitude Probe", rate_profile_data: {ascent_rate: 6, descent_rate: 10, burst_altitude: 40000} }, @@ -115,6 +119,10 @@ }, }); } + + function handleEditPoint(point: SavedPoint) { + editPoint = point; + } @@ -124,7 +132,7 @@ - + Учетная запись Сохраненные сценарии @@ -141,13 +149,28 @@ Точки запуска - pointsSearch.set()} - /> + + pointsSearch.set()} + /> + { + pointsSearch.value = ""; + pointsSearch.set(); + }} + disabled={!pointsSearch.value} + > + + + @@ -167,6 +190,9 @@ {row.lon.toFixed(4)} ° {row.alt} м + handleEditPoint(row)}> + + (showConfirm = false)} > {confirmConfig.body} - \ No newline at end of file + + + { editPoint = null; pointsTable.setRows($SavedPointsStore) }} +/> + + \ No newline at end of file diff --git a/static/css/custom.css b/static/css/custom.css index 41fa26e..bbba238 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -128,6 +128,10 @@ flex-direction: column; } +.modal-tinted { + filter: brightness(0.6); +} + @media (max-width: 767.98px) { .coordinates-display {
Вы уверены, что хотите удалить эту точку?
{confirmConfig.body}