forked from MapComplete/MapComplete
		
	Tweaks to import flow
This commit is contained in:
		
							parent
							
								
									3fb7cc90fc
								
							
						
					
					
						commit
						ce017e0341
					
				
					 6 changed files with 8970 additions and 71 deletions
				
			
		|  | @ -46,15 +46,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L | |||
|         if(firstRender === undefined){ | ||||
|             throw `Layer ${layerJson.id} does not have a pointRendering: `+context | ||||
|         } | ||||
|         const icon = firstRender.icon | ||||
|         const iconBadges = [] | ||||
|         const title = layer.presets[0].title | ||||
|         if (icon !== undefined) { | ||||
|             iconBadges.push({ | ||||
|                 if: {and: []}, | ||||
|                 then: icon | ||||
|             }) | ||||
|         } | ||||
| 
 | ||||
|         const importButton = {} | ||||
|         { | ||||
|  | @ -123,7 +115,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L | |||
|             "tagRenderings": [ | ||||
|                 { | ||||
|                     "id": "Intro", | ||||
|                     "render": "{_intro}" | ||||
|                     render: "{_intro}" | ||||
|                 }, | ||||
|                 { | ||||
|                     "id": "conversation", | ||||
|  | @ -138,12 +130,12 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L | |||
|                 { | ||||
|                     "id": "close_note_", | ||||
|                     "render": embed( | ||||
|                         "{close_note(", t.notFound.Subs({title}), ", ./assets/svg/close.svg, id, This feature does not exist)}"), | ||||
|                         "{close_note(", t.notFound.Subs({title}), ", ./assets/svg/close.svg, id, This feature does not exist, 18)}"), | ||||
|                     condition: "closed_at=" | ||||
|                 }, | ||||
|                 { | ||||
|                     "id": "close_note_mapped", | ||||
|                     "render": embed("{close_note(", t.alreadyMapped.Subs({title}), ", ./assets/svg/checkmark.svg, id, Already mapped)}"), | ||||
|                     "render": embed("{close_note(", t.alreadyMapped.Subs({title}), ", ./assets/svg/duplicate.svg, id, Already mapped, 18)}"), | ||||
|                     condition: "closed_at=" | ||||
|                 }, | ||||
|                 { | ||||
|  | @ -172,7 +164,6 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L | |||
|                             then: "circle:white;checkmark:black" | ||||
|                         }] | ||||
|                     }, | ||||
|                     iconBadges, | ||||
|                     "iconSize": "40,40,center" | ||||
|                 } | ||||
|             ] | ||||
|  |  | |||
|  | @ -191,7 +191,7 @@ ${Utils.special_visualizations_importRequirementDocs} | |||
|                         importFlow, | ||||
|                         isImported | ||||
|                     ), | ||||
|                     t.zoomInMore, | ||||
|                     t.zoomInMore.SetClass("alert"), | ||||
|                     state.locationControl.map(l => l.zoom >= 18) | ||||
|                 ), | ||||
|                 pleaseLoginButton, | ||||
|  |  | |||
|  | @ -71,7 +71,7 @@ export default class NewNoteUi extends Toggle { | |||
|             new Combine([new Toggle(undefined, t.warnAnonymous.SetClass("alert"), state?.osmConnection?.isLoggedIn),  | ||||
|                 new Toggle(postNote, | ||||
|                     t.textNeeded.SetClass("alert"), | ||||
|                     text.GetValue().map(txt => txt.length > 3) | ||||
|                     text.GetValue().map(txt => txt?.length > 3) | ||||
|                     ) | ||||
|              | ||||
|             ]).SetClass("flex justify-end items-center") | ||||
|  |  | |||
|  | @ -46,6 +46,7 @@ import FileSelectorButton from "./Input/FileSelectorButton"; | |||
| import {LoginToggle} from "./Popup/LoginButton"; | ||||
| import {start} from "repl"; | ||||
| import {SubstitutedTranslation} from "./SubstitutedTranslation"; | ||||
| import {Feature} from "@turf/turf"; | ||||
| 
 | ||||
| export interface SpecialVisualization { | ||||
|     funcName: string, | ||||
|  | @ -95,6 +96,88 @@ export class AllTagsPanel extends VariableUiElement { | |||
|     } | ||||
| } | ||||
| 
 | ||||
| class CloseNoteButton implements SpecialVisualization { | ||||
|     public readonly funcName = "close_note" | ||||
|     public readonly docs = "Button to close a note. A predifined text can be defined to close the note with. If the note is already closed, will show a small text." | ||||
|     public readonly args = [ | ||||
|         { | ||||
|             name: "text", | ||||
|             doc: "Text to show on this button", | ||||
|         }, | ||||
|         { | ||||
|             name: "icon", | ||||
|             doc: "Icon to show", | ||||
|             defaultValue: "checkmark.svg" | ||||
|         }, | ||||
|         { | ||||
|             name: "idkey", | ||||
|             doc: "The property name where the ID of the note to close can be found", | ||||
|             defaultValue: "id" | ||||
|         }, | ||||
|         { | ||||
|             name: "comment", | ||||
|             doc: "Text to add onto the note when closing", | ||||
|         }, | ||||
|         { | ||||
|             name: "minZoom", | ||||
|             doc: "If set, only show the closenote button if zoomed in enough" | ||||
|         }, | ||||
|         { | ||||
|             name: "zoomButton", | ||||
|             doc: "Text to show if not zoomed in enough" | ||||
|         } | ||||
|     ] | ||||
| 
 | ||||
|     public constr(state: FeaturePipelineState, tags, args): BaseUIElement { | ||||
|         const t = Translations.t.notes; | ||||
| 
 | ||||
|         const params: { | ||||
|             text: string, | ||||
|             icon: string, | ||||
|             idkey: string, | ||||
|             comment: string, | ||||
|             minZoom: string, | ||||
|             zoomButton: string | ||||
|         } = Utils.ParseVisArgs(this.args, args) | ||||
| 
 | ||||
|         let icon = Svg.checkmark_svg() | ||||
|         if (params.icon !== "checkmark.svg" && (args[2] ?? "") !== "") { | ||||
|             icon = new Img(args[1]) | ||||
|         } | ||||
|         let textToShow = t.closeNote; | ||||
|         if ((params.text ?? "") !== "") { | ||||
|             textToShow = Translations.T(args[0]) | ||||
|         } | ||||
| 
 | ||||
|         let closeButton: BaseUIElement = new SubtleButton(icon, textToShow) | ||||
|         const isClosed = tags.map(tags => (tags["closed_at"] ?? "") !== ""); | ||||
|         closeButton.onClick(() => { | ||||
|             const id = tags.data[args[2] ?? "id"] | ||||
|             state.osmConnection.closeNote(id, args[3]) | ||||
|                 ?.then(_ => { | ||||
|                     tags.data["closed_at"] = new Date().toISOString(); | ||||
|                     tags.ping() | ||||
|                 }) | ||||
|         }) | ||||
|          | ||||
|         if((params.minZoom??"") !== "" && !isNaN(Number(params.minZoom))){ | ||||
|           closeButton =  new Toggle( | ||||
|                 closeButton, | ||||
|                 params.zoomButton ?? "", | ||||
|                 state.  locationControl.map(l => l.zoom >= Number(params.minZoom)) | ||||
|             ) | ||||
|         } | ||||
|          | ||||
|         return new LoginToggle(new Toggle( | ||||
|             t.isClosed.SetClass("thanks"), | ||||
|             closeButton, | ||||
|              | ||||
|             isClosed | ||||
|         ), t.loginToClose, state) | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| export default class SpecialVisualizations { | ||||
| 
 | ||||
|     public static specialVisualizations = SpecialVisualizations.init() | ||||
|  | @ -655,58 +738,7 @@ export default class SpecialVisualizations { | |||
|                         }) | ||||
|                     } | ||||
|                 }, | ||||
|                 { | ||||
|                     funcName: "close_note", | ||||
|                     docs: "Button to close a note. A predifined text can be defined to close the note with. If the note is already closed, will show a small text.", | ||||
|                     args: [ | ||||
|                         { | ||||
|                             name: "text", | ||||
|                             doc: "Text to show on this button", | ||||
|                         }, | ||||
|                         { | ||||
|                             name: "icon", | ||||
|                             doc: "Icon to show", | ||||
|                             defaultValue: "checkmark.svg" | ||||
|                         }, | ||||
|                         { | ||||
|                             name: "Id-key", | ||||
|                             doc: "The property name where the ID of the note to close can be found", | ||||
|                             defaultValue: "id" | ||||
|                         }, | ||||
|                         { | ||||
|                             name: "comment", | ||||
|                             doc: "Text to add onto the note when closing", | ||||
|                         } | ||||
|                     ], | ||||
|                     constr: (state, tags, args) => { | ||||
|                         const t = Translations.t.notes; | ||||
| 
 | ||||
|                         let icon = Svg.checkmark_svg() | ||||
|                         if (args[1] !== "checkmark.svg" && (args[2] ?? "") !== "") { | ||||
|                             icon = new Img(args[1]) | ||||
|                         } | ||||
|                         let textToShow = t.closeNote; | ||||
|                         if ((args[0] ?? "") !== "") { | ||||
|                             textToShow = Translations.T(args[0]) | ||||
|                         } | ||||
| 
 | ||||
|                         const closeButton = new SubtleButton(icon, textToShow) | ||||
|                         const isClosed = tags.map(tags => (tags["closed_at"] ?? "") !== ""); | ||||
|                         closeButton.onClick(() => { | ||||
|                             const id = tags.data[args[2] ?? "id"] | ||||
|                             state.osmConnection.closeNote(id, args[3]) | ||||
|                                 ?.then(_ => { | ||||
|                                     tags.data["closed_at"] = new Date().toISOString(); | ||||
|                                     tags.ping() | ||||
|                                 }) | ||||
|                         }) | ||||
|                         return new LoginToggle(new Toggle( | ||||
|                             t.isClosed.SetClass("thanks"), | ||||
|                             closeButton, | ||||
|                             isClosed | ||||
|                         ), t.loginToClose, state) | ||||
|                     } | ||||
|                 }, | ||||
|                 new CloseNoteButton(), | ||||
|                 { | ||||
|                     funcName: "add_note_comment", | ||||
|                     docs: "A textfield to add a comment to a node (with the option to close the note).", | ||||
|  | @ -778,7 +810,7 @@ export default class SpecialVisualizations { | |||
|                                 new Title("Add a comment"), | ||||
|                                 textField, | ||||
|                                 new Combine([ | ||||
|                                     new Toggle(addCommentButton, undefined, textField.GetValue().map(t => t !==undefined && t.length > 1)).SetClass("mr-2") | ||||
|                                     new Toggle(addCommentButton, undefined, textField.GetValue().map(t => t !== undefined && t.length > 1)).SetClass("mr-2") | ||||
|                                     , stateButtons]).SetClass("flex justify-end") | ||||
|                             ]).SetClass("border-2 border-black rounded-xl p-4 block"), | ||||
|                             t.loginToAddComment, state) | ||||
|  | @ -860,15 +892,15 @@ export default class SpecialVisualizations { | |||
| 
 | ||||
|                 }, | ||||
|                 { | ||||
|                     funcName:"title", | ||||
|                     funcName: "title", | ||||
|                     args: [], | ||||
|                     docs:"Shows the title of the popup. Useful for some cases, e.g. 'What is phone number of {title()}?'", | ||||
|                     example:"`What is the phone number of {title()}`, which might automatically become `What is the phone number of XYZ`.", | ||||
|                     docs: "Shows the title of the popup. Useful for some cases, e.g. 'What is phone number of {title()}?'", | ||||
|                     example: "`What is the phone number of {title()}`, which might automatically become `What is the phone number of XYZ`.", | ||||
|                     constr: (state, tagsSource, args, guistate) => | ||||
|                         new VariableUiElement(tagsSource.map(tags => { | ||||
|                             const layer = state.layoutToUse.getMatchingLayer(tags) | ||||
|                             const title = layer?.title?.GetRenderValue(tags) | ||||
|                             if(title === undefined){ | ||||
|                             if (title === undefined) { | ||||
|                                 return undefined | ||||
|                             } | ||||
|                             return new SubstitutedTranslation(title, tagsSource, state) | ||||
|  |  | |||
							
								
								
									
										8868
									
								
								assets/svg/duplicate.svg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8868
									
								
								assets/svg/duplicate.svg
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| After Width: | Height: | Size: 273 KiB | 
|  | @ -381,6 +381,14 @@ | |||
|       "https://commons.wikimedia.org/wiki/File:Download-icon.svg" | ||||
|     ] | ||||
|   }, | ||||
|   { | ||||
|     "path": "duplicate.svg", | ||||
|     "license": "CC0", | ||||
|     "authors": [ | ||||
|       "Pieter Vander Vennet" | ||||
|     ], | ||||
|     "sources": [] | ||||
|   }, | ||||
|   { | ||||
|     "path": "envelope.svg", | ||||
|     "license": "CC0; trivial", | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue