| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | <script lang="ts"> | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * UIcomponent to create a new note at the given location | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02: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" | 
					
						
							|  |  |  |   import type { Feature, Point } from "geojson" | 
					
						
							|  |  |  |   import LoginToggle from "../Base/LoginToggle.svelte" | 
					
						
							|  |  |  |   import FilteredLayer from "../../Models/FilteredLayer" | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   export let coordinate: { lon: number; lat: number } | 
					
						
							|  |  |  |   export let state: SpecialVisualizationState | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   let comment: UIEventSource<string> = LocalStorageSource.Get("note-text") | 
					
						
							|  |  |  |   let created = false | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |   let notelayer: FilteredLayer = state.layerState.filteredLayers.get("note") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let hasFilter = notelayer?.hasFilter | 
					
						
							|  |  |  |   let isDisplayed = notelayer?.isDisplayed | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   function enableNoteLayer() { | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     state.guistate.closeAll() | 
					
						
							|  |  |  |     isDisplayed.setData(true) | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   async function uploadNote() { | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     let txt = comment.data | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     if (txt === undefined || txt === "") { | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |       return | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |     const loc = coordinate | 
					
						
							|  |  |  |     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-04-06 01:33:08 +02:00
										 |  |  |     const feature = <Feature<Point>>{ | 
					
						
							|  |  |  |       type: "Feature", | 
					
						
							|  |  |  |       geometry: { | 
					
						
							|  |  |  |         type: "Point", | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +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-06-14 20:39:36 +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-06-14 20:39:36 +02:00
										 |  |  |     state.newFeatures.features.data.push(feature) | 
					
						
							|  |  |  |     state.newFeatures.features.ping() | 
					
						
							|  |  |  |     state.selectedElement?.setData(feature) | 
					
						
							|  |  |  |     comment.setData("") | 
					
						
							|  |  |  |     created = true | 
					
						
							| 
									
										
										
										
											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> | 
					
						
							|  |  |  | {: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-06-14 20:44:01 +02:00
										 |  |  |           <img slot="image" src="./assets/svg/filter.svg" 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} | 
					
						
							|  |  |  |       <div> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |         <Tr t={Translations.t.notes.createNoteIntro} /> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:44:01 +02:00
										 |  |  |         <div class="border-grey-500 rounded-sm border"> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |           <div class="w-full p-1"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |             <ValidatedInput type="text" value={comment} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |           </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           <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> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-20 02:09:23 +02:00
										 |  |  |           {#if $comment?.length >= 3} | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |             <SubtleButton on:click={uploadNote}> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:44:01 +02:00
										 |  |  |               <img slot="image" src="./assets/svg/addSmall.svg" class="mr-4 h-8 w-8" /> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |               <Tr slot="message" t={Translations.t.notes.createNote} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |             </SubtleButton> | 
					
						
							|  |  |  |           {:else} | 
					
						
							|  |  |  |             <div class="alert"> | 
					
						
							| 
									
										
										
										
											2023-06-14 20:39:36 +02:00
										 |  |  |               <Tr t={Translations.t.notes.textNeeded} /> | 
					
						
							| 
									
										
										
										
											2023-04-06 01:33:08 +02:00
										 |  |  |             </div> | 
					
						
							|  |  |  |           {/if} | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     {/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-06-14 20:44:01 +02:00
										 |  |  |         <img slot="image" src="./assets/svg/layers.svg" 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} |