Small code cleanups, documentation
This commit is contained in:
parent
cb42a4fcc5
commit
085d762bff
4 changed files with 37 additions and 34 deletions
|
@ -18,7 +18,7 @@ export default class LazyElement extends UIElement {
|
||||||
}
|
}
|
||||||
self.Update();
|
self.Update();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if(this._content.Activate){
|
if (this._content.Activate) {
|
||||||
// THis is ugly - I know
|
// THis is ugly - I know
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this._content.Activate();
|
this._content.Activate();
|
||||||
|
|
|
@ -8,6 +8,7 @@ import TagRenderingAnswer from "./TagRenderingAnswer";
|
||||||
import State from "../../State";
|
import State from "../../State";
|
||||||
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
|
import TagRenderingConfig from "../../Customizations/JSON/TagRenderingConfig";
|
||||||
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
|
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
|
||||||
|
import {Utils} from "../../Utils";
|
||||||
|
|
||||||
export default class FeatureInfoBox extends ScrollableFullScreen {
|
export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||||
private static featureInfoboxCache: Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>> = new Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>>();
|
private static featureInfoboxCache: Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>> = new Map<LayerConfig, Map<UIEventSource<any>, FeatureInfoBox>>();
|
||||||
|
@ -24,18 +25,8 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
static construct(tags: UIEventSource<any>, layer: LayerConfig): FeatureInfoBox {
|
static construct(tags: UIEventSource<any>, layer: LayerConfig): FeatureInfoBox {
|
||||||
let innerMap = FeatureInfoBox.featureInfoboxCache.get(layer);
|
let innerMap = Utils.getOrSetDefault(FeatureInfoBox.featureInfoboxCache, layer,() => new Map<UIEventSource<any>, FeatureInfoBox>())
|
||||||
if (innerMap === undefined) {
|
return Utils.getOrSetDefault(innerMap, tags, () => new FeatureInfoBox(tags, layer));
|
||||||
innerMap = new Map<UIEventSource<any>, FeatureInfoBox>();
|
|
||||||
FeatureInfoBox.featureInfoboxCache.set(layer, innerMap);
|
|
||||||
}
|
|
||||||
|
|
||||||
let featureInfoBox = innerMap.get(tags);
|
|
||||||
if (featureInfoBox === undefined) {
|
|
||||||
featureInfoBox = new FeatureInfoBox(tags, layer);
|
|
||||||
innerMap.set(tags, featureInfoBox);
|
|
||||||
}
|
|
||||||
return featureInfoBox;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GenerateTitleBar(tags: UIEventSource<any>,
|
private static GenerateTitleBar(tags: UIEventSource<any>,
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* Shows the reviews and scoring base on mangrove.reviesw
|
* Shows the reviews and scoring base on mangrove.reviews
|
||||||
|
* The middle element is some other component shown in the middle, e.g. the review input element
|
||||||
*/
|
*/
|
||||||
import {UIEventSource} from "../../Logic/UIEventSource";
|
import {UIEventSource} from "../../Logic/UIEventSource";
|
||||||
import {Review} from "../../Logic/Web/Review";
|
import {Review} from "../../Logic/Web/Review";
|
||||||
|
|
51
Utils.ts
51
Utils.ts
|
@ -8,7 +8,7 @@ export class Utils {
|
||||||
* This is a workaround and yet another hack
|
* This is a workaround and yet another hack
|
||||||
*/
|
*/
|
||||||
public static runningFromConsole = false;
|
public static runningFromConsole = false;
|
||||||
|
|
||||||
public static readonly assets_path = "./assets/svg/";
|
public static readonly assets_path = "./assets/svg/";
|
||||||
|
|
||||||
static EncodeXmlValue(str) {
|
static EncodeXmlValue(str) {
|
||||||
|
@ -46,7 +46,7 @@ export class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Round(i: number) {
|
public static Round(i: number) {
|
||||||
if(i < 0){
|
if (i < 0) {
|
||||||
return "-" + Utils.Round(-i);
|
return "-" + Utils.Round(-i);
|
||||||
}
|
}
|
||||||
const j = "" + Math.floor(i * 10);
|
const j = "" + Math.floor(i * 10);
|
||||||
|
@ -86,8 +86,8 @@ export class Utils {
|
||||||
}
|
}
|
||||||
return ls;
|
return ls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NoEmpty(array: string[]): string[]{
|
public static NoEmpty(array: string[]): string[] {
|
||||||
const ls: string[] = [];
|
const ls: string[] = [];
|
||||||
for (const t of array) {
|
for (const t of array) {
|
||||||
if (t === "") {
|
if (t === "") {
|
||||||
|
@ -98,18 +98,18 @@ export class Utils {
|
||||||
return ls;
|
return ls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EllipsesAfter(str : string, l : number = 100){
|
public static EllipsesAfter(str: string, l: number = 100) {
|
||||||
if(str === undefined){
|
if (str === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
if(str.length <= l){
|
if (str.length <= l) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
return str.substr(0, l - 3)+"...";
|
return str.substr(0, l - 3) + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dedup(arr: string[]):string[]{
|
public static Dedup(arr: string[]): string[] {
|
||||||
if(arr === undefined){
|
if (arr === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const newArr = [];
|
const newArr = [];
|
||||||
|
@ -141,7 +141,7 @@ export class Utils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Date will be undefined on failure
|
// Date will be undefined on failure
|
||||||
public static LoadCustomCss(location: string){
|
public static LoadCustomCss(location: string) {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const head = document.getElementsByTagName('head')[0];
|
||||||
const link = document.createElement('link');
|
const link = document.createElement('link');
|
||||||
link.id = "customCss";
|
link.id = "customCss";
|
||||||
|
@ -150,26 +150,37 @@ export class Utils {
|
||||||
link.href = location;
|
link.href = location;
|
||||||
link.media = 'all';
|
link.media = 'all';
|
||||||
head.appendChild(link);
|
head.appendChild(link);
|
||||||
console.log("Added custom layout ",location)
|
console.log("Added custom layout ", location)
|
||||||
}
|
}
|
||||||
static Merge(source: any, target: any){
|
|
||||||
|
static Merge(source: any, target: any) {
|
||||||
target = JSON.parse(JSON.stringify(target));
|
target = JSON.parse(JSON.stringify(target));
|
||||||
source = JSON.parse(JSON.stringify(source));
|
source = JSON.parse(JSON.stringify(source));
|
||||||
for (const key in source) {
|
for (const key in source) {
|
||||||
const sourceV = source[key];
|
const sourceV = source[key];
|
||||||
const targetV = target[key]
|
const targetV = target[key]
|
||||||
if(typeof sourceV === "object"){
|
if (typeof sourceV === "object") {
|
||||||
if(targetV === undefined){
|
if (targetV === undefined) {
|
||||||
target[key] = sourceV;
|
target[key] = sourceV;
|
||||||
}else{
|
} else {
|
||||||
Utils.Merge(sourceV, targetV);
|
Utils.Merge(sourceV, targetV);
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
target[key] = sourceV;
|
target[key] = sourceV;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getOrSetDefault<K, V>(dict: Map<K, V>, k: K, v: () => V) {
|
||||||
|
let found = dict.get(k);
|
||||||
|
if (found !== undefined) {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
dict.set(k, v());
|
||||||
|
return dict.get(k);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue