| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  | import Combine from "../Base/Combine"; | 
					
						
							|  |  |  | import ScrollableFullScreen from "../Base/ScrollableFullScreen"; | 
					
						
							|  |  |  | import Translations from "../i18n/Translations"; | 
					
						
							|  |  |  | import {UIEventSource} from "../../Logic/UIEventSource"; | 
					
						
							|  |  |  | import BaseUIElement from "../BaseUIElement"; | 
					
						
							|  |  |  | import Toggle from "../Input/Toggle"; | 
					
						
							|  |  |  | import {DownloadPanel} from "./DownloadPanel"; | 
					
						
							|  |  |  | import {SubtleButton} from "../Base/SubtleButton"; | 
					
						
							|  |  |  | import Svg from "../../Svg"; | 
					
						
							|  |  |  | import ExportPDF from "../ExportPDF"; | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  | import FilteredLayer from "../../Models/FilteredLayer"; | 
					
						
							|  |  |  | import FeaturePipeline from "../../Logic/FeatureSource/FeaturePipeline"; | 
					
						
							|  |  |  | import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; | 
					
						
							|  |  |  | import {BBox} from "../../Logic/BBox"; | 
					
						
							|  |  |  | import BaseLayer from "../../Models/BaseLayer"; | 
					
						
							|  |  |  | import Loc from "../../Models/Loc"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | interface DownloadState  { | 
					
						
							|  |  |  |     filteredLayers: UIEventSource<FilteredLayer[]> | 
					
						
							|  |  |  |     featurePipeline: FeaturePipeline, | 
					
						
							|  |  |  |     layoutToUse: LayoutConfig, | 
					
						
							|  |  |  |     currentBounds: UIEventSource<BBox>, | 
					
						
							|  |  |  |     backgroundLayer:UIEventSource<BaseLayer>, | 
					
						
							|  |  |  |     locationControl: UIEventSource<Loc>, | 
					
						
							|  |  |  |     featureSwitchExportAsPdf: UIEventSource<boolean>, | 
					
						
							|  |  |  |     featureSwitchEnableExport: UIEventSource<boolean>, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class AllDownloads extends ScrollableFullScreen { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  |     constructor(isShown: UIEventSource<boolean>,state: { | 
					
						
							|  |  |  |         filteredLayers: UIEventSource<FilteredLayer[]> | 
					
						
							|  |  |  |         featurePipeline: FeaturePipeline, | 
					
						
							|  |  |  |         layoutToUse: LayoutConfig, | 
					
						
							|  |  |  |         currentBounds: UIEventSource<BBox>, | 
					
						
							|  |  |  |         backgroundLayer:UIEventSource<BaseLayer>, | 
					
						
							|  |  |  |         locationControl: UIEventSource<Loc>, | 
					
						
							|  |  |  |         featureSwitchExportAsPdf: UIEventSource<boolean>, | 
					
						
							|  |  |  |         featureSwitchEnableExport: UIEventSource<boolean>, | 
					
						
							|  |  |  |     }) { | 
					
						
							|  |  |  |         super(AllDownloads.GenTitle, () => AllDownloads.GeneratePanel(state), "downloads", isShown); | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private static GenTitle(): BaseUIElement { | 
					
						
							|  |  |  |         return Translations.t.general.download.title | 
					
						
							|  |  |  |             .Clone() | 
					
						
							|  |  |  |             .SetClass("text-2xl break-words font-bold p-2"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  |     private static GeneratePanel(state: DownloadState): BaseUIElement { | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |         const isExporting = new UIEventSource(false, "Pdf-is-exporting") | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |         const generatePdf = () => { | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |             isExporting.setData(true) | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |             new ExportPDF( | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     freeDivId: "belowmap", | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  |                     background: state.backgroundLayer, | 
					
						
							|  |  |  |                     location: state.locationControl, | 
					
						
							|  |  |  |                     features: state.featurePipeline, | 
					
						
							|  |  |  |                     layout: state.layoutToUse, | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |                 }).isRunning.addCallbackAndRun(isRunning => isExporting.setData(isRunning)) | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |         const loading = Svg.loading_svg().SetClass("animate-rotate"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 01:38:57 +02:00
										 |  |  |         const dloadTrans = Translations.t.general.download | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |         const icon = new Toggle(loading, Svg.floppy_ui(), isExporting); | 
					
						
							|  |  |  |         const text = new Toggle( | 
					
						
							| 
									
										
										
										
											2021-10-03 01:38:57 +02:00
										 |  |  |             dloadTrans.exporting.Clone(), | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |             new Combine([ | 
					
						
							| 
									
										
										
										
											2021-10-03 01:38:57 +02:00
										 |  |  |                 dloadTrans.downloadAsPdf.Clone().SetClass("font-bold"), | 
					
						
							|  |  |  |                 dloadTrans.downloadAsPdfHelper.Clone()] | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |             ).SetClass("flex flex-col") | 
					
						
							|  |  |  |                 .onClick(() => { | 
					
						
							|  |  |  |                     generatePdf() | 
					
						
							|  |  |  |                 }), | 
					
						
							|  |  |  |             isExporting); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |         const pdf = new Toggle( | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |             new SubtleButton( | 
					
						
							|  |  |  |                 icon, | 
					
						
							|  |  |  |                 text), | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |             undefined, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  |             state.featureSwitchExportAsPdf | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-22 20:10:19 +02:00
										 |  |  |         const exportPanel = new Toggle( | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  |             new DownloadPanel(state), | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |             undefined, | 
					
						
							| 
									
										
										
										
											2022-02-16 01:34:28 +01:00
										 |  |  |             state.featureSwitchEnableExport | 
					
						
							| 
									
										
										
										
											2021-07-28 16:48:59 +02:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return new Combine([pdf, exportPanel]).SetClass("flex flex-col"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |