| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Helps in uplaoding, by generating the rigth title, decription and by adding the tag to the changeset | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-17 17:23:15 +02:00
										 |  |  | import {UIEventSource} from "../UIEventSource"; | 
					
						
							| 
									
										
										
										
											2020-07-30 00:59:08 +02:00
										 |  |  | import {ImageUploadFlow} from "../../UI/ImageUploadFlow"; | 
					
						
							|  |  |  | import {SlideShow} from "../../UI/SlideShow"; | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  | import {State} from "../../State"; | 
					
						
							| 
									
										
										
										
											2020-08-30 01:13:18 +02:00
										 |  |  | import {Tag} from "../Tags"; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export class OsmImageUploadHandler { | 
					
						
							| 
									
										
										
										
											2020-08-30 01:13:18 +02:00
										 |  |  |     private readonly _tags: UIEventSource<any>; | 
					
						
							|  |  |  |     private readonly _slideShow: SlideShow; | 
					
						
							|  |  |  |     private readonly _preferedLicense: UIEventSource<string>; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     constructor(tags: UIEventSource<any>, | 
					
						
							| 
									
										
										
										
											2020-07-01 17:38:48 +02:00
										 |  |  |                 preferedLicense: UIEventSource<string>, | 
					
						
							| 
									
										
										
										
											2020-06-28 00:06:23 +02:00
										 |  |  |                 slideShow : SlideShow | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |     ) { | 
					
						
							| 
									
										
										
										
											2020-06-28 00:06:23 +02:00
										 |  |  |         this._slideShow = slideShow; // To move the slideshow (if any) to the last, just added element
 | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |         this._tags = tags; | 
					
						
							| 
									
										
										
										
											2020-07-01 17:38:48 +02:00
										 |  |  |         this._preferedLicense = preferedLicense; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private generateOptions(license: string) { | 
					
						
							|  |  |  |         const tags = this._tags.data; | 
					
						
							| 
									
										
										
										
											2020-06-28 00:06:23 +02:00
										 |  |  |         const self = this; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const title = tags.name ?? "Unknown area"; | 
					
						
							|  |  |  |         const description = [ | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |             "author:" + State.state.osmConnection.userDetails.data.name, | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |             "license:" + license, | 
					
						
							|  |  |  |             "wikidata:" + tags.wikidata, | 
					
						
							|  |  |  |             "osmid:" + tags.id, | 
					
						
							|  |  |  |             "name:" + tags.name | 
					
						
							|  |  |  |         ].join("\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-31 01:45:54 +02:00
										 |  |  |         const changes = State.state.changes; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |         return { | 
					
						
							|  |  |  |             title: title, | 
					
						
							|  |  |  |             description: description, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  |             handleURL: (url) => { | 
					
						
							| 
									
										
										
										
											2020-07-21 22:40:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 let key = "image"; | 
					
						
							|  |  |  |                 if (tags["image"] !== undefined) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     let freeIndex = 0; | 
					
						
							|  |  |  |                     while (tags["image:" + freeIndex] !== undefined) { | 
					
						
							|  |  |  |                         freeIndex++; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     key = "image:" + freeIndex; | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-07-21 22:40:46 +02:00
										 |  |  |                 console.log("Adding image:" + key, url); | 
					
						
							| 
									
										
										
										
											2020-08-28 03:16:21 +02:00
										 |  |  |                 changes.addTag(tags.id, new Tag(key, url)); | 
					
						
							| 
									
										
										
										
											2020-06-28 00:06:23 +02:00
										 |  |  |                 self._slideShow.MoveTo(-1); // set the last (thus newly added) image) to view
 | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |             }, | 
					
						
							| 
									
										
										
										
											2020-08-27 11:11:20 +02:00
										 |  |  |             allDone: () => { | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     getUI(): ImageUploadFlow { | 
					
						
							|  |  |  |         const self = this; | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |         return new ImageUploadFlow( | 
					
						
							| 
									
										
										
										
											2020-07-01 17:38:48 +02:00
										 |  |  |             this._preferedLicense, | 
					
						
							| 
									
										
										
										
											2020-06-27 03:06:51 +02:00
										 |  |  |             function (license) { | 
					
						
							| 
									
										
										
										
											2020-06-25 03:39:31 +02:00
										 |  |  |                 return self.generateOptions(license) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |