| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * UIcomponent to create a new note at the given location | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |   import type { SpecialVisualizationState } from "../../SpecialVisualization" | 
					
						
							|  |  |  |   import { UIEventSource } from "../../../Logic/UIEventSource" | 
					
						
							|  |  |  |   import { LocalStorageSource } from "../../../Logic/Web/LocalStorageSource" | 
					
						
							|  |  |  |   import ValidatedInput from "../../InputElement/ValidatedInput.svelte" | 
					
						
							|  |  |  |   import SubtleButton from "../../Base/SubtleButton.svelte" | 
					
						
							|  |  |  |   import Tr from "../../Base/Tr.svelte" | 
					
						
							|  |  |  |   import Translations from "../../i18n/Translations.js" | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |   import type { Feature, Point } from "geojson" | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |   import LoginToggle from "../../Base/LoginToggle.svelte" | 
					
						
							|  |  |  |   import FilteredLayer from "../../../Models/FilteredLayer" | 
					
						
							|  |  |  |   import NewPointLocationInput from "../../BigComponents/NewPointLocationInput.svelte" | 
					
						
							|  |  |  |   import Layers from "../../../assets/svg/Layers.svelte" | 
					
						
							|  |  |  |   import AddSmall from "../../../assets/svg/AddSmall.svelte" | 
					
						
							|  |  |  |   import type { OsmTags } from "../../../Models/OsmFeature" | 
					
						
							|  |  |  |   import Loading from "../../Base/Loading.svelte" | 
					
						
							| 
									
										
										
										
											2024-06-21 12:30:07 +02:00
										 |  |  |   import NextButton from "../../Base/NextButton.svelte" | 
					
						
							| 
									
										
										
										
											2024-07-10 11:40:00 +02:00
										 |  |  |   import Note from "../../../assets/svg/Note.svelte" | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |   export let coordinate: UIEventSource<{ lon: number; lat: number }> | 
					
						
							|  |  |  |   export let state: SpecialVisualizationState | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |   let comment: UIEventSource<string> = LocalStorageSource.Get("note-text") | 
					
						
							|  |  |  |   let created = false | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |   let notelayer: FilteredLayer = state.layerState.filteredLayers.get("note") | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |   let hasFilter = notelayer?.hasFilter | 
					
						
							|  |  |  |   let isDisplayed = notelayer?.isDisplayed | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |   let submitted = false | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   function enableNoteLayer() { | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |     state.guistate.closeAll() | 
					
						
							|  |  |  |     isDisplayed.setData(true) | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async function uploadNote() { | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |     submitted = true | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |     let txt = comment.data | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     if (txt === undefined || txt === "") { | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |       return | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |     const loc = coordinate.data | 
					
						
							|  |  |  |     txt += "\n\n #MapComplete #" + state?.layout?.id | 
					
						
							|  |  |  |     const id = await state?.osmConnection?.openNote(loc.lat, loc.lon, txt) | 
					
						
							|  |  |  |     console.log("Created a note, got id", id) | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |     const feature = <Feature<Point, OsmTags>>{ | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |       type: "Feature", | 
					
						
							|  |  |  |       geometry: { | 
					
						
							|  |  |  |         type: "Point", | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |         coordinates: [loc.lon, loc.lat], | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |       }, | 
					
						
							|  |  |  |       properties: { | 
					
						
							|  |  |  |         id: "" + id.id, | 
					
						
							|  |  |  |         date_created: new Date().toISOString(), | 
					
						
							|  |  |  |         _first_comment: txt, | 
					
						
							|  |  |  |         comments: JSON.stringify([ | 
					
						
							|  |  |  |           { | 
					
						
							|  |  |  |             text: txt, | 
					
						
							|  |  |  |             html: txt, | 
					
						
							|  |  |  |             user: state.osmConnection?.userDetails?.data?.name, | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |             uid: state.osmConnection?.userDetails?.data?.uid, | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ]), | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-04-20 01:52:23 +02:00
										 |  |  |     // Normally, the 'Changes' will generate the new element. The 'notes' are an exception to this | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |     state.newFeatures.features.data.push(feature) | 
					
						
							|  |  |  |     state.newFeatures.features.ping() | 
					
						
							|  |  |  |     state.selectedElement?.setData(feature) | 
					
						
							| 
									
										
										
										
											2023-09-28 23:50:27 +02:00
										 |  |  |     if (state.featureProperties.trackFeature) { | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |       state.featureProperties.trackFeature(feature) | 
					
						
							| 
									
										
										
										
											2023-09-25 02:55:43 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-10-16 14:27:05 +02:00
										 |  |  |     comment.setData("") | 
					
						
							|  |  |  |     created = true | 
					
						
							|  |  |  |     state.selectedElement.setData(feature) | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | </script> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | {#if notelayer === undefined} | 
					
						
							|  |  |  |   <div class="alert"> | 
					
						
							|  |  |  |     This theme does not include the layer 'note'. As a result, no nodes can be created | 
					
						
							|  |  |  |   </div> | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  | {:else if submitted} | 
					
						
							| 
									
										
										
										
											2023-12-30 15:24:30 +01:00
										 |  |  |   <Loading /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | {:else if created} | 
					
						
							|  |  |  |   <div class="thanks"> | 
					
						
							|  |  |  |     <Tr t={Translations.t.notes.isCreated} /> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | {:else} | 
					
						
							|  |  |  |   <h3> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     <Tr t={Translations.t.notes.createNoteTitle} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   </h3> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   {#if $isDisplayed} | 
					
						
							|  |  |  |     <!-- The layer is displayed, so we can add a note without worrying for duplicates --> | 
					
						
							|  |  |  |     {#if $hasFilter} | 
					
						
							|  |  |  |       <div class="flex flex-col"> | 
					
						
							|  |  |  |         <!-- ...but a filter is set ...--> | 
					
						
							|  |  |  |         <div class="alert"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |           <Tr t={Translations.t.notes.noteLayerHasFilters} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |         </div> | 
					
						
							|  |  |  |         <SubtleButton on:click={() => notelayer.disableAllFilters()}> | 
					
						
							| 
									
										
										
										
											2023-12-01 15:23:28 +01:00
										 |  |  |           <Layers class="mr-4 h-8 w-8" /> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |           <Tr slot="message" t={Translations.t.notes.disableAllNoteFilters} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |         </SubtleButton> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     {:else} | 
					
						
							| 
									
										
										
										
											2024-06-24 13:11:35 +02:00
										 |  |  |       <form | 
					
						
							|  |  |  |         class="low-interaction flex flex-col rounded-sm p-2" | 
					
						
							|  |  |  |         on:submit|preventDefault={uploadNote} | 
					
						
							|  |  |  |       > | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |         <label class="neutral-label"> | 
					
						
							|  |  |  |           <Tr t={Translations.t.notes.createNoteIntro} /> | 
					
						
							|  |  |  |           <div class="w-full p-1"> | 
					
						
							|  |  |  |             <ValidatedInput autofocus={true} type="text" value={comment} /> | 
					
						
							| 
									
										
										
										
											2023-10-15 10:55:56 +02:00
										 |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |         </label> | 
					
						
							| 
									
										
										
										
											2023-10-15 10:55:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |         <div class="h-56 w-full"> | 
					
						
							|  |  |  |           <NewPointLocationInput value={coordinate} {state}> | 
					
						
							|  |  |  |             <div class="h-20 w-full pb-10" slot="image"> | 
					
						
							| 
									
										
										
										
											2024-07-10 11:40:00 +02:00
										 |  |  |               <Note class="h-10 w-full"/> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |           </NewPointLocationInput> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         <LoginToggle {state}> | 
					
						
							|  |  |  |           <span slot="loading"><!--empty: don't show a loading message--></span> | 
					
						
							|  |  |  |           <div slot="not-logged-in" class="alert"> | 
					
						
							|  |  |  |             <Tr t={Translations.t.notes.warnAnonymous} /> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         </LoginToggle> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         {#if $comment?.length >= 3} | 
					
						
							| 
									
										
										
										
											2024-06-21 12:30:07 +02:00
										 |  |  |           <NextButton on:click={uploadNote} clss="self-end primary"> | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |             <AddSmall slot="image" class="mr-4 h-8 w-8" /> | 
					
						
							| 
									
										
										
										
											2024-06-21 12:30:07 +02:00
										 |  |  |             <Tr t={Translations.t.notes.createNote} /> | 
					
						
							|  |  |  |           </NextButton> | 
					
						
							| 
									
										
										
										
											2023-12-26 22:30:27 +01:00
										 |  |  |         {:else} | 
					
						
							|  |  |  |           <div class="alert"> | 
					
						
							|  |  |  |             <Tr t={Translations.t.notes.textNeeded} /> | 
					
						
							|  |  |  |           </div> | 
					
						
							|  |  |  |         {/if} | 
					
						
							|  |  |  |       </form> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     {/if} | 
					
						
							|  |  |  |   {:else} | 
					
						
							|  |  |  |     <div class="flex flex-col"> | 
					
						
							|  |  |  |       <div class="alert"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         <Tr t={Translations.t.notes.noteLayerNotEnabled} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |       </div> | 
					
						
							|  |  |  |       <SubtleButton on:click={enableNoteLayer}> | 
					
						
							| 
									
										
										
										
											2023-11-19 04:38:34 +01:00
										 |  |  |         <Layers slot="image" class="mr-4 h-8 w-8" /> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         <Tr slot="message" t={Translations.t.notes.noteLayerDoEnable} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |       </SubtleButton> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   {/if} | 
					
						
							|  |  |  | {/if} |