2020-07-31 04:58:58 +02:00
|
|
|
import {UIElement} from "../UI/UIElement";
|
|
|
|
import {State} from "../State";
|
|
|
|
import Translations from "../UI/i18n/Translations";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "./UIEventSource";
|
2020-07-31 04:58:58 +02:00
|
|
|
import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
|
|
|
|
import Combine from "../UI/Base/Combine";
|
|
|
|
import {Img} from "../UI/Img";
|
|
|
|
import {CheckBox} from "../UI/Input/CheckBox";
|
2020-08-26 15:36:04 +02:00
|
|
|
import {PersonalLayout} from "./PersonalLayout";
|
2020-08-26 20:11:43 +02:00
|
|
|
import {Layout} from "../Customizations/Layout";
|
2020-07-31 04:58:58 +02:00
|
|
|
|
2020-08-26 15:36:04 +02:00
|
|
|
export class PersonalLayersPanel extends UIElement {
|
2020-07-31 16:17:16 +02:00
|
|
|
private checkboxes: UIElement[] = [];
|
2020-08-26 15:36:04 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
constructor() {
|
2020-08-26 15:36:04 +02:00
|
|
|
super(State.state.favouriteLayers);
|
2020-07-31 16:17:16 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
this.ListenTo(State.state.osmConnection.userDetails);
|
2020-09-10 19:33:06 +02:00
|
|
|
this.ListenTo(State.state.favouriteLayers);
|
2020-07-31 04:58:58 +02:00
|
|
|
|
2020-08-26 20:11:43 +02:00
|
|
|
this.UpdateView([]);
|
|
|
|
const self = this;
|
|
|
|
State.state.installedThemes.addCallback(extraThemes => {
|
|
|
|
self.UpdateView(extraThemes.map(layout => layout.layout));
|
|
|
|
self.Update();
|
|
|
|
})
|
|
|
|
}
|
2020-07-31 04:58:58 +02:00
|
|
|
|
|
|
|
|
2020-08-26 20:11:43 +02:00
|
|
|
private UpdateView(extraThemes: Layout[]) {
|
|
|
|
this.checkboxes = [];
|
|
|
|
const favs = State.state.favouriteLayers.data ?? [];
|
2020-07-31 04:58:58 +02:00
|
|
|
const controls = new Map<string, UIEventSource<boolean>>();
|
2020-08-26 20:11:43 +02:00
|
|
|
const allLayouts = AllKnownLayouts.layoutsList.concat(extraThemes);
|
2020-08-30 01:13:18 +02:00
|
|
|
console.log("ALL LAYOUTS", allLayouts)
|
2020-08-26 20:11:43 +02:00
|
|
|
for (const layout of allLayouts) {
|
2020-08-30 01:13:18 +02:00
|
|
|
if (layout.id === PersonalLayout.NAME) {
|
2020-07-31 16:17:16 +02:00
|
|
|
continue;
|
|
|
|
}
|
2020-08-26 15:36:04 +02:00
|
|
|
if (layout.hideFromOverview &&
|
2020-07-31 21:54:30 +02:00
|
|
|
State.state.osmConnection.userDetails.data.name !== "Pieter Vander Vennet") {
|
2020-07-31 16:17:16 +02:00
|
|
|
continue
|
|
|
|
}
|
2020-08-26 20:11:43 +02:00
|
|
|
|
2020-07-31 04:58:58 +02:00
|
|
|
const header =
|
|
|
|
new Combine([
|
|
|
|
`<div class="custom-layer-panel-header-img"><img src='${layout.icon}'></div>`,
|
|
|
|
"<span><b>",
|
|
|
|
layout.title,
|
|
|
|
"</b><br/>",
|
|
|
|
layout.description ?? "",
|
|
|
|
"</span>",
|
|
|
|
], 'custom-layer-panel-header')
|
|
|
|
this.checkboxes.push(header);
|
|
|
|
|
|
|
|
for (const layer of layout.layers) {
|
2020-09-10 19:33:06 +02:00
|
|
|
if(typeof layer === "string"){
|
|
|
|
continue;
|
|
|
|
}
|
2020-08-26 20:11:43 +02:00
|
|
|
let icon = layer.icon;
|
|
|
|
if (icon !== undefined && typeof (icon) !== "string") {
|
2020-08-30 01:13:18 +02:00
|
|
|
icon = icon.GetContent({"id": "node/-1"}).txt ?? "./assets/bug.svg";
|
2020-08-26 20:11:43 +02:00
|
|
|
}
|
2020-07-31 04:58:58 +02:00
|
|
|
const image = (layer.icon ? `<img src='${layer.icon}'>` : Img.checkmark);
|
2020-07-31 16:17:16 +02:00
|
|
|
const noimage = (layer.icon ? `<img src='${layer.icon}'>` : Img.no_checkmark);
|
|
|
|
|
2020-08-26 20:11:43 +02:00
|
|
|
let name = layer.name ?? layer.id;
|
|
|
|
if (name === undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (typeof (name) !== "string") {
|
2020-08-22 14:59:52 +02:00
|
|
|
name = name.InnerRender();
|
|
|
|
}
|
2020-08-26 20:11:43 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
const content = new Combine([
|
|
|
|
"<span>",
|
2020-08-22 14:59:52 +02:00
|
|
|
"<b>", name ?? "", "</b> ",
|
2020-07-31 16:17:16 +02:00
|
|
|
layer.description !== undefined ? new Combine(["<br/>", layer.description]) : "",
|
|
|
|
"</span>"])
|
2020-07-31 04:58:58 +02:00
|
|
|
const cb = new CheckBox(
|
|
|
|
new Combine([
|
2020-07-31 16:17:16 +02:00
|
|
|
image, content
|
2020-07-31 04:58:58 +02:00
|
|
|
]),
|
|
|
|
new Combine([
|
2020-07-31 16:17:16 +02:00
|
|
|
"<span style='opacity: 0.1'>",
|
2020-08-26 20:11:43 +02:00
|
|
|
noimage, "</span>",
|
2020-07-31 16:17:16 +02:00
|
|
|
"<del>",
|
|
|
|
content,
|
|
|
|
"</del>"
|
2020-07-31 04:58:58 +02:00
|
|
|
]),
|
|
|
|
controls[layer.id] ?? (favs.indexOf(layer.id) >= 0)
|
|
|
|
);
|
2020-08-28 03:16:21 +02:00
|
|
|
cb.SetClass("custom-layer-checkbox");
|
2020-07-31 04:58:58 +02:00
|
|
|
controls[layer.id] = cb.isEnabled;
|
|
|
|
|
|
|
|
cb.isEnabled.addCallback((isEnabled) => {
|
2020-08-26 15:36:04 +02:00
|
|
|
const favs = State.state.favouriteLayers;
|
2020-07-31 04:58:58 +02:00
|
|
|
if (isEnabled) {
|
2020-08-26 15:36:04 +02:00
|
|
|
favs.data.push(layer.id);
|
2020-07-31 04:58:58 +02:00
|
|
|
} else {
|
2020-08-26 15:36:04 +02:00
|
|
|
favs.data.splice(favs.data.indexOf(layer.id), 1);
|
2020-07-31 04:58:58 +02:00
|
|
|
}
|
2020-08-26 15:36:04 +02:00
|
|
|
favs.ping();
|
2020-07-31 04:58:58 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
this.checkboxes.push(cb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-26 15:36:04 +02:00
|
|
|
State.state.favouriteLayers.addCallback((layers) => {
|
2020-07-31 16:17:16 +02:00
|
|
|
for (const layerId of layers) {
|
|
|
|
controls[layerId]?.setData(true);
|
|
|
|
}
|
|
|
|
})
|
2020-07-31 04:58:58 +02:00
|
|
|
|
2020-07-31 16:17:16 +02:00
|
|
|
}
|
2020-07-31 04:58:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InnerRender(): string {
|
|
|
|
const t = Translations.t.favourite;
|
|
|
|
const userDetails = State.state.osmConnection.userDetails.data;
|
|
|
|
if(!userDetails.loggedIn){
|
2020-07-31 16:17:16 +02:00
|
|
|
return t.loginNeeded.Render();
|
2020-07-31 04:58:58 +02:00
|
|
|
}
|
2020-07-31 16:17:16 +02:00
|
|
|
|
|
|
|
return new Combine([
|
2020-07-31 04:58:58 +02:00
|
|
|
t.panelIntro,
|
|
|
|
...this.checkboxes
|
|
|
|
], "custom-layer-panel").Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|