| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  | import {SubtleButton} from "../Base/SubtleButton"; | 
					
						
							|  |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | import State from "../../State"; | 
					
						
							|  |  |  | import {FeatureSourceUtils} from "../../Logic/FeatureSource/FeatureSource"; | 
					
						
							|  |  |  | import {Utils} from "../../Utils"; | 
					
						
							|  |  |  | import Combine from "../Base/Combine"; | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  | import CheckBoxes from "../Input/Checkboxes"; | 
					
						
							|  |  |  | import {GeoOperations} from "../../Logic/GeoOperations"; | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle"; | 
					
						
							|  |  |  | import Title from "../Base/Title"; | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  | export class DownloadPanel extends Toggle { | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  |     constructor() { | 
					
						
							|  |  |  |         const t = Translations.t.general.download | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |         const somethingLoaded = State.state.featurePipeline.features.map(features => features.length > 0); | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |         const includeMetaToggle = new CheckBoxes([t.includeMetaData.Clone()]) | 
					
						
							|  |  |  |         const metaisIncluded = includeMetaToggle.GetValue().map(selected => selected.length > 0) | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |         const buttonGeoJson = new SubtleButton(Svg.floppy_ui(), | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |             new Combine([t.downloadGeojson.Clone().SetClass("font-bold"), | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |                 t.downloadGeoJsonHelper.Clone()]).SetClass("flex flex-col")) | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  |             .onClick(() => { | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |                 const geojson = FeatureSourceUtils.extractGeoJson(State.state.featurePipeline, {metadata: metaisIncluded.data}) | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  |                 const name = State.state.layoutToUse.data.id; | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |                 Utils.offerContentsAsDownloadableFile(JSON.stringify(geojson), | 
					
						
							|  |  |  |                     `MapComplete_${name}_export_${new Date().toISOString().substr(0, 19)}.geojson`, { | 
					
						
							|  |  |  |                         mimetype: "application/vnd.geo+json" | 
					
						
							|  |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  |             }) | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         const buttonCSV = new SubtleButton(Svg.floppy_ui(), new Combine( | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |             [t.downloadCSV.Clone().SetClass("font-bold"), | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |                 t.downloadCSVHelper.Clone()]).SetClass("flex flex-col")) | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |             .onClick(() => { | 
					
						
							|  |  |  |                 const geojson = FeatureSourceUtils.extractGeoJson(State.state.featurePipeline, {metadata: metaisIncluded.data}) | 
					
						
							|  |  |  |                 const csv = GeoOperations.toCSV(geojson.features) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 Utils.offerContentsAsDownloadableFile(csv, | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |                     `MapComplete_${name}_export_${new Date().toISOString().substr(0, 19)}.csv`, { | 
					
						
							|  |  |  |                         mimetype: "text/csv" | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |                     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             }) | 
					
						
							|  |  |  |         const downloadButtons = new Combine( | 
					
						
							|  |  |  |             [new Title(t.title), buttonGeoJson, buttonCSV, includeMetaToggle, t.licenseInfo.Clone().SetClass("link-underline")]) | 
					
						
							| 
									
										
										
										
											2021-07-26 21:03:27 +02:00
										 |  |  |             .SetClass("w-full flex flex-col border-4 border-gray-300 rounded-3xl p-4") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-26 20:59:55 +02:00
										 |  |  |         super( | 
					
						
							|  |  |  |             downloadButtons, | 
					
						
							|  |  |  |             t.noDataLoaded.Clone(), | 
					
						
							|  |  |  |             somethingLoaded) | 
					
						
							| 
									
										
										
										
											2021-07-16 01:42:09 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } |