forked from MapComplete/MapComplete
Feature: show quota in debug panel
This commit is contained in:
parent
c4f0e18b9e
commit
722f7e86cc
2 changed files with 24 additions and 4 deletions
|
@ -7,12 +7,13 @@ import LoginButton from "../Base/LoginButton.svelte"
|
||||||
import ThemeViewState from "../../Models/ThemeViewState"
|
import ThemeViewState from "../../Models/ThemeViewState"
|
||||||
import OrientationDebugPanel from "../Debug/OrientationDebugPanel.svelte"
|
import OrientationDebugPanel from "../Debug/OrientationDebugPanel.svelte"
|
||||||
import AllTagsPanel from "../Popup/AllTagsPanel/AllTagsPanel.svelte"
|
import AllTagsPanel from "../Popup/AllTagsPanel/AllTagsPanel.svelte"
|
||||||
import { ImmutableStore, UIEventSource } from "../../Logic/UIEventSource"
|
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||||
import ClearCaches from "../Popup/ClearCaches.svelte"
|
import ClearCaches from "../Popup/ClearCaches.svelte"
|
||||||
import Locale from "../i18n/Locale"
|
import Locale from "../i18n/Locale"
|
||||||
import LanguageUtils from "../../Utils/LanguageUtils"
|
import LanguageUtils from "../../Utils/LanguageUtils"
|
||||||
import LanguagePicker from "../InputElement/LanguagePicker.svelte"
|
import LanguagePicker from "../InputElement/LanguagePicker.svelte"
|
||||||
import PendingChangesIndicator from "../BigComponents/PendingChangesIndicator.svelte"
|
import PendingChangesIndicator from "../BigComponents/PendingChangesIndicator.svelte"
|
||||||
|
import { Utils } from "../../Utils"
|
||||||
|
|
||||||
export class SettingsVisualisations {
|
export class SettingsVisualisations {
|
||||||
public static initList(): SpecialVisualizationSvelte[] {
|
public static initList(): SpecialVisualizationSvelte[] {
|
||||||
|
@ -79,14 +80,23 @@ export class SettingsVisualisations {
|
||||||
group: "settings",
|
group: "settings",
|
||||||
docs: "Shows the current state of storage",
|
docs: "Shows the current state of storage",
|
||||||
args: [],
|
args: [],
|
||||||
constr(state: SpecialVisualizationState): SvelteUIElement {
|
constr: function(state: SpecialVisualizationState): SvelteUIElement {
|
||||||
const data = {}
|
const data = {}
|
||||||
for (const key in localStorage) {
|
for (const key in localStorage) {
|
||||||
data[key] = localStorage[key]
|
data[key] = localStorage[key]
|
||||||
}
|
}
|
||||||
const tags = new ImmutableStore(data)
|
const tags = new UIEventSource(data)
|
||||||
|
|
||||||
|
navigator.storage.estimate().then(estimate => {
|
||||||
|
data["__usage:current:bytes"] = estimate.usage
|
||||||
|
data["__usage:current:human"] = Utils.toHumanByteSize(estimate.usage)
|
||||||
|
data["__usage:quota:bytes"] = estimate.quota
|
||||||
|
data["__usage:quota:human"] = Utils.toHumanByteSize(estimate.quota)
|
||||||
|
tags.ping()
|
||||||
|
|
||||||
|
})
|
||||||
return new SvelteUIElement(AllTagsPanel, { state, tags })
|
return new SvelteUIElement(AllTagsPanel, { state, tags })
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
funcName: "clear_caches",
|
funcName: "clear_caches",
|
||||||
|
|
10
src/Utils.ts
10
src/Utils.ts
|
@ -1150,6 +1150,16 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
|
||||||
return hours + ":" + Utils.TwoDigits(minutes) + ":" + Utils.TwoDigits(seconds)
|
return hours + ":" + Utils.TwoDigits(minutes) + ":" + Utils.TwoDigits(seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static toHumanByteSize(bytes: number): string {
|
||||||
|
const scale = ["b", "KB", "MB", "GB", "TB"] as const
|
||||||
|
let i = 0
|
||||||
|
while (bytes > 1000) {
|
||||||
|
bytes = bytes / 1000
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return Math.round(bytes) + scale[i]
|
||||||
|
}
|
||||||
|
|
||||||
public static HomepageLink(): string {
|
public static HomepageLink(): string {
|
||||||
if (typeof window === "undefined") {
|
if (typeof window === "undefined") {
|
||||||
return "https://mapcomplete.org"
|
return "https://mapcomplete.org"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue