diff --git a/UI/LanguagePicker.ts b/UI/LanguagePicker.ts new file mode 100644 index 0000000..304642a --- /dev/null +++ b/UI/LanguagePicker.ts @@ -0,0 +1,23 @@ +import {UIElement} from "./UIElement"; +import {DropDown} from "./Input/DropDown"; +import Locale from "./i18n/Locale"; + +export default class LanguagePicker { + + + public static CreateLanguagePicker( + languages : string[] , + label: string | UIElement = "") { + + if (languages.length <= 1) { + return undefined; + } + + return new DropDown(label, languages.map(lang => { + return {value: lang, shown: lang} + } + ), Locale.language); + } + + +} \ No newline at end of file diff --git a/UI/i18n/Locale.ts b/UI/i18n/Locale.ts index e58d6ad..9482766 100644 --- a/UI/i18n/Locale.ts +++ b/UI/i18n/Locale.ts @@ -1,7 +1,6 @@ import {UIEventSource} from "../../Logic/UIEventSource"; import {UIElement} from "../UIElement"; import {LocalStorageSource} from "../../Logic/Web/LocalStorageSource"; -import {DropDown} from "../Input/DropDown"; export default class Locale { @@ -18,21 +17,6 @@ export default class Locale { } return source; } - - public static CreateLanguagePicker( - languages : string[] , - label: string | UIElement = "") { - - if (languages.length <= 1) { - return undefined; - } - - return new DropDown(label, languages.map(lang => { - return {value: lang, shown: lang} - } - ), Locale.language); - } - } diff --git a/UI/i18n/Translations.ts b/UI/i18n/Translations.ts index 325e3c1..ff29875 100644 --- a/UI/i18n/Translations.ts +++ b/UI/i18n/Translations.ts @@ -131,7 +131,7 @@ export default class Translations { for (const subKey in tr) { if (Translations.isTranslation(tr[subKey])) { copy[subKey] = new Translation(tr[subKey]); - } else if(tr[subKey].translations === undefined /**should not be a translation alreay*/){ + } else if(tr[subKey].translations === undefined /**should not be a translation already*/){ queue.push(tr[subKey]); } } diff --git a/Utils.ts b/Utils.ts index 99ff991..9e5cdf7 100644 --- a/Utils.ts +++ b/Utils.ts @@ -1,6 +1,5 @@ import {UIElement} from "./UI/UIElement"; import * as $ from "jquery" -import {FixedUiElement} from "./UI/Base/FixedUiElement"; export class Utils { @@ -156,61 +155,4 @@ export class Utils { } - public static generateStats(action:(stats:string) => void) { - // Binary searches the latest changeset - function search(lowerBound: number, - upperBound: number, - onCsFound: ((id: number, lastDate: Date) => void), - depth = 0) { - if (depth > 30) { - return; - } - const tested = Math.floor((lowerBound + upperBound) / 2); - console.log("Testing", tested) - Utils.changesetDate(tested, (createdAtDate: Date) => { - new FixedUiElement(`Searching, value between ${lowerBound} and ${upperBound}. Queries till now: ${depth}`).AttachTo('maindiv') - if (lowerBound + 1 >= upperBound) { - onCsFound(lowerBound, createdAtDate); - return; - } - if (createdAtDate !== undefined) { - search(tested, upperBound, onCsFound, depth + 1) - } else { - search(lowerBound, tested, onCsFound, depth + 1); - } - }) - - } - - - search(91000000, 100000000, (last, lastDate: Date) => { - const link = "http://osm.org/changeset/" + last; - - const delta = 100000; - - Utils.changesetDate(last - delta, (prevDate) => { - - - const diff = (lastDate.getTime() - prevDate.getTime()) / 1000; - - // Diff: seconds needed/delta changesets - const secsPerCS = diff / delta; - - const stillNeeded = 1000000 - (last % 1000000); - const timeNeededSeconds = Math.floor(secsPerCS * stillNeeded); - - const secNeeded = timeNeededSeconds % 60; - const minNeeded = Math.floor(timeNeededSeconds / 60) % 60; - const hourNeeded = Math.floor(timeNeededSeconds / (60 * 60)) % 24; - const daysNeeded = Math.floor(timeNeededSeconds / (24 * 60 * 60)); - - const result = `Last changeset: ${link}
We needed ${(Math.floor(diff / 60))} minutes for the last ${delta} changesets.
-This is around ${secsPerCS} seconds/changeset.
The next million (still ${stillNeeded} away) will be broken in around ${daysNeeded} days ${hourNeeded}:${minNeeded}:${secNeeded}` - action(result); - }) - - } - ); - } - } diff --git a/test.ts b/test.ts index 4979d12..77feaa5 100644 --- a/test.ts +++ b/test.ts @@ -1,4 +1,4 @@ -//* +/* import {UIEventSource} from "./Logic/UIEventSource"; @@ -21,7 +21,68 @@ new FeatureInfoBox(src, SharedLayers.sharedLayers["ghost_bike"]).AttachTo('maind import {Utils} from "./Utils"; import {FixedUiElement} from "./UI/Base/FixedUiElement"; -Utils.generateStats((stats) => { - new FixedUiElement(stats).AttachTo('maindiv') + +function generateStats(action: (stats: string) => void) { + // Binary searches the latest changeset + function search(lowerBound: number, + upperBound: number, + onCsFound: ((id: number, lastDate: Date) => void), + depth = 0) { + if (depth > 30) { + return; + } + const tested = Math.floor((lowerBound + upperBound) / 2); + console.log("Testing", tested) + Utils.changesetDate(tested, (createdAtDate: Date) => { + new FixedUiElement(`Searching, value between ${lowerBound} and ${upperBound}. Queries till now: ${depth}`).AttachTo('maindiv') + if (lowerBound + 1 >= upperBound) { + onCsFound(lowerBound, createdAtDate); + return; + } + if (createdAtDate !== undefined) { + search(tested, upperBound, onCsFound, depth + 1) + } else { + search(lowerBound, tested, onCsFound, depth + 1); + } + }) + + } + + + search(91000000, 100000000, (last, lastDate: Date) => { + const link = "http://osm.org/changeset/" + last; + + const delta = 100000; + + Utils.changesetDate(last - delta, (prevDate) => { + + + const diff = (lastDate.getTime() - prevDate.getTime()) / 1000; + + // Diff: seconds needed/delta changesets + const secsPerCS = diff / delta; + + const stillNeeded = 1000000 - (last % 1000000); + const timeNeededSeconds = Math.floor(secsPerCS * stillNeeded); + + const secNeeded = timeNeededSeconds % 60; + const minNeeded = Math.floor(timeNeededSeconds / 60) % 60; + const hourNeeded = Math.floor(timeNeededSeconds / (60 * 60)) % 24; + const daysNeeded = Math.floor(timeNeededSeconds / (24 * 60 * 60)); + + const result = `Last changeset: ${link}
We needed ${(Math.floor(diff / 60))} minutes for the last ${delta} changesets.
+This is around ${secsPerCS} seconds/changeset.
The next million (still ${stillNeeded} away) will be broken in around ${daysNeeded} days ${hourNeeded}:${minNeeded}:${secNeeded}` + action(result); + }) + + } + ); + +} + +generateStats((stats) => { + new FixedUiElement(stats).AttachTo('maindiv') }) + + //*/ \ No newline at end of file