mapcomplete/UI/BigComponents/AllDownloads.ts

73 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-07-28 16:48:59 +02:00
import State from "../../State";
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";
import {FixedUiElement} from "../Base/FixedUiElement";
2021-07-28 16:48:59 +02:00
export default class AllDownloads extends ScrollableFullScreen {
constructor(isShown: UIEventSource<boolean>) {
super(AllDownloads.GenTitle, AllDownloads.GeneratePanel, "layers", isShown);
}
private static GenTitle(): BaseUIElement {
return Translations.t.general.download.title
.Clone()
.SetClass("text-2xl break-words font-bold p-2");
}
private static GeneratePanel(): BaseUIElement {
const isExporting = new UIEventSource(false, "Pdf-is-exporting")
2021-07-28 16:48:59 +02:00
const generatePdf = () => {
isExporting.setData(true)
2021-07-28 16:48:59 +02:00
new ExportPDF(
{
freeDivId: "belowmap",
background: State.state.backgroundLayer,
location: State.state.locationControl,
features: State.state.featurePipeline,
2021-07-28 16:48:59 +02:00
layout: State.state.layoutToUse,
}).isRunning.addCallbackAndRun(isRunning => isExporting.setData(isRunning))
2021-07-28 16:48:59 +02:00
}
const loading = Svg.loading_svg().SetClass("animate-rotate");
2021-10-03 01:38:57 +02:00
const dloadTrans = Translations.t.general.download
const icon = new Toggle(loading, Svg.floppy_ui(), isExporting);
const text = new Toggle(
2021-10-03 01:38:57 +02:00
dloadTrans.exporting.Clone(),
new Combine([
2021-10-03 01:38:57 +02:00
dloadTrans.downloadAsPdf.Clone().SetClass("font-bold"),
dloadTrans.downloadAsPdfHelper.Clone()]
).SetClass("flex flex-col")
.onClick(() => {
generatePdf()
}),
isExporting);
2021-07-28 16:48:59 +02:00
const pdf = new Toggle(
new SubtleButton(
icon,
text),
2021-07-28 16:48:59 +02:00
undefined,
State.state.featureSwitchExportAsPdf
)
const exportPanel = new Toggle(
2021-07-28 16:48:59 +02:00
new DownloadPanel(),
undefined,
State.state.featureSwitchEnableExport
)
return new Combine([pdf, exportPanel]).SetClass("flex flex-col");
}
}