mapcomplete/preferences.ts

52 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

2020-07-31 19:54:30 +00:00
import {OsmConnection} from "./Logic/Osm/OsmConnection";
2020-08-07 14:01:18 +00:00
import Combine from "./UI/Base/Combine";
import {Button} from "./UI/Base/Button";
import {TextField} from "./UI/Input/TextField";
import {FixedUiElement} from "./UI/Base/FixedUiElement";
import {UIElement} from "./UI/UIElement";
import {UIEventSource} from "./Logic/UIEventSource";
2020-07-31 19:54:30 +00:00
const connection = new OsmConnection(false, new UIEventSource<string>(undefined), "");
2020-08-07 14:01:18 +00:00
let rendered = false;
function createTable(preferences: any) {
if (rendered) {
return;
}
rendered = true;
const prefs = [];
for (const key in preferences) {
const pref = connection.GetPreference(key, "");
let value: UIElement = new FixedUiElement(pref.data);
if (connection.userDetails.data.csCount > 500 &&
(key.startsWith("mapcomplete") || connection.userDetails.data.csCount > 2500)) {
value = new TextField({
2020-08-07 14:01:18 +00:00
value: pref
});
}
const c = [
"<tr><td>",
key,
"</td><td>",
new Button("delete", () => pref.setData("")),
"</td><td>",
2021-04-10 01:50:44 +00:00
value,
2020-08-07 14:01:18 +00:00
"</td></tr>"
];
prefs.push(...c);
}
2021-04-10 01:50:44 +00:00
new Combine(
2020-08-07 14:01:18 +00:00
["<table>",
...prefs,
"</table>"]
2021-04-10 01:50:44 +00:00
).AttachTo("maindiv");
2020-08-07 14:01:18 +00:00
}
connection.preferencesHandler.preferences.addCallback((prefs) => createTable(prefs))
2020-08-07 14:01:18 +00:00