2024-07-09 18:18:26 +02:00
|
|
|
<script>
|
|
|
|
import Button from "../../layout/Button.svelte"
|
|
|
|
import { onMount } from "svelte";
|
|
|
|
import CardAccount from "./CardAccount.svelte";
|
|
|
|
import CardStatistics from "./CardStatistics.svelte";
|
|
|
|
import CardSubscription from "./CardSubscription.svelte";
|
|
|
|
import CardUsage from "./CardUsage.svelte";
|
|
|
|
import CardActivity from "./CardActivity.svelte";
|
|
|
|
import CardUpload from "./CardUpload.svelte";
|
|
|
|
import CardPrepaidTransactions from "./CardPrepaidTransactions.svelte";
|
2024-07-11 13:30:46 +02:00
|
|
|
import CardFsHome from "./CardFSHome.svelte";
|
2024-07-11 23:14:09 +02:00
|
|
|
import AddressReputation from "../../home_page/AddressReputation.svelte";
|
2024-07-09 18:18:26 +02:00
|
|
|
|
2024-07-11 15:30:32 +02:00
|
|
|
let cards = []
|
|
|
|
|
2024-07-09 18:18:26 +02:00
|
|
|
const save = () => {
|
|
|
|
let storage = {
|
2024-07-11 17:45:10 +02:00
|
|
|
size: {},
|
2024-07-09 18:18:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (const card of cards) {
|
2024-07-11 17:45:10 +02:00
|
|
|
if (card.size !== undefined && card.size !== 1) {
|
|
|
|
storage.size[card.id] = card.size
|
2024-07-11 15:30:32 +02:00
|
|
|
}
|
|
|
|
}
|
2024-07-09 18:18:26 +02:00
|
|
|
|
2024-07-11 15:30:32 +02:00
|
|
|
window.localStorage.setItem("dashboard_layout", JSON.stringify(storage))
|
2024-07-09 18:18:26 +02:00
|
|
|
}
|
|
|
|
|
2024-07-11 17:45:10 +02:00
|
|
|
const min_card_size = 0
|
|
|
|
const def_card_size = 1
|
|
|
|
const max_card_size = 3
|
|
|
|
|
|
|
|
const expand = i => {
|
|
|
|
if (cards[i].size === undefined) {
|
|
|
|
cards[i].size = def_card_size
|
|
|
|
}
|
|
|
|
if (cards[i].size < max_card_size) {
|
|
|
|
cards[i].size++
|
|
|
|
}
|
|
|
|
save()
|
|
|
|
}
|
|
|
|
const shrink = i => {
|
|
|
|
if (cards[i].size === undefined) {
|
|
|
|
cards[i].size = def_card_size
|
|
|
|
}
|
|
|
|
if (cards[i].size > min_card_size) {
|
|
|
|
cards[i].size--
|
|
|
|
}
|
|
|
|
save()
|
|
|
|
}
|
|
|
|
|
2024-07-11 15:30:32 +02:00
|
|
|
onMount(() => {
|
|
|
|
cards = [
|
|
|
|
{
|
|
|
|
id: "upload",
|
|
|
|
elem: CardUpload,
|
|
|
|
title: "Quick upload",
|
2024-07-11 17:45:10 +02:00
|
|
|
link: "/",
|
2024-07-11 15:30:32 +02:00
|
|
|
}, {
|
|
|
|
id: "filesystem_home",
|
|
|
|
elem: CardFsHome,
|
|
|
|
title: "Filesystem home",
|
|
|
|
link: "/d/me",
|
2024-07-11 17:45:10 +02:00
|
|
|
hidden: window.user.subscription.filesystem_access === false,
|
2024-07-11 15:30:32 +02:00
|
|
|
}, {
|
|
|
|
id: "account",
|
|
|
|
elem: CardAccount,
|
|
|
|
title: "Account",
|
|
|
|
link: "/user/settings",
|
|
|
|
}, {
|
|
|
|
id: "subscription",
|
|
|
|
elem: CardSubscription,
|
|
|
|
title: "Subscription",
|
|
|
|
link: "/user/subscription",
|
|
|
|
}, {
|
|
|
|
id: "prepaid_transactions",
|
|
|
|
elem: CardPrepaidTransactions,
|
|
|
|
title: "Prepaid transactions",
|
|
|
|
link: "/user/prepaid/transactions",
|
2024-07-11 17:45:10 +02:00
|
|
|
hidden: window.user.subscription.type !== "prepaid"
|
2024-07-11 15:30:32 +02:00
|
|
|
}, {
|
|
|
|
id: "usage",
|
|
|
|
elem: CardUsage,
|
|
|
|
title: "Usage",
|
|
|
|
}, {
|
|
|
|
id: "statistics",
|
|
|
|
elem: CardStatistics,
|
|
|
|
title: "Statistics",
|
|
|
|
}, {
|
|
|
|
id: "activiy",
|
|
|
|
elem: CardActivity,
|
|
|
|
title: "Activity",
|
|
|
|
link: "/user/activity",
|
|
|
|
},
|
|
|
|
]
|
2024-07-09 18:18:26 +02:00
|
|
|
|
2024-07-11 15:30:32 +02:00
|
|
|
// Apply the view settings from localstorage
|
|
|
|
try {
|
2024-07-11 17:45:10 +02:00
|
|
|
const layout = JSON.parse(window.localStorage.getItem("dashboard_layout"))
|
2024-07-09 18:18:26 +02:00
|
|
|
|
|
|
|
for (const card of cards) {
|
2024-07-11 23:08:13 +02:00
|
|
|
if (
|
|
|
|
layout !== null &&
|
|
|
|
layout.size !== undefined &&
|
|
|
|
layout.size[card.id] !== undefined
|
|
|
|
) {
|
2024-07-11 17:45:10 +02:00
|
|
|
card.size = layout.size[card.id]
|
|
|
|
} else {
|
|
|
|
card.size = 1
|
2024-07-11 15:30:32 +02:00
|
|
|
}
|
2024-07-09 18:18:26 +02:00
|
|
|
}
|
2024-07-11 15:30:32 +02:00
|
|
|
} catch (err) {
|
|
|
|
console.warn("Failed to load dashboard settings", err)
|
|
|
|
return
|
2024-07-09 18:18:26 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2024-07-11 23:14:09 +02:00
|
|
|
<div class="separator"></div>
|
|
|
|
|
|
|
|
<AddressReputation/>
|
|
|
|
|
2024-07-09 18:18:26 +02:00
|
|
|
<div class="cards">
|
2024-07-11 17:45:10 +02:00
|
|
|
{#each cards as card, i (card.id)}
|
|
|
|
{#if !card.hidden && card.size > 0}
|
|
|
|
<div
|
|
|
|
class="card"
|
|
|
|
class:size_1={card.size === 1}
|
|
|
|
class:size_2={card.size === 2}
|
|
|
|
class:size_3={card.size === 3}
|
|
|
|
>
|
|
|
|
<div class="title_box">
|
|
|
|
{#if card.link}
|
|
|
|
<Button link_href={card.link} icon="link" flat/>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
<h2>{card.title}</h2>
|
|
|
|
|
|
|
|
<Button click={() => shrink(i)} icon="zoom_out" flat/>
|
|
|
|
<span>
|
|
|
|
{card.size === undefined ? 1 : card.size}
|
|
|
|
</span>
|
|
|
|
<Button click={() => expand(i)} icon="zoom_in" flat/>
|
|
|
|
</div>
|
|
|
|
<div class="card_component">
|
|
|
|
<svelte:component this={card.elem} card_size={card.size}/>
|
|
|
|
</div>
|
2024-07-09 18:18:26 +02:00
|
|
|
</div>
|
2024-07-11 17:45:10 +02:00
|
|
|
{/if}
|
|
|
|
{/each}
|
2024-07-09 18:18:26 +02:00
|
|
|
</div>
|
|
|
|
|
2024-07-11 15:30:32 +02:00
|
|
|
<div class="cards">
|
2024-07-11 17:45:10 +02:00
|
|
|
{#each cards as card, i (card.id)}
|
|
|
|
{#if card.size === 0}
|
2024-07-11 18:01:24 +02:00
|
|
|
<div class="card size_1">
|
2024-07-11 15:30:32 +02:00
|
|
|
<div class="title_box">
|
|
|
|
{#if card.link}
|
|
|
|
<Button link_href={card.link} icon="link" flat/>
|
|
|
|
{/if}
|
|
|
|
|
2024-07-11 17:45:10 +02:00
|
|
|
<h2>{card.title}</h2>
|
|
|
|
|
|
|
|
<Button click={() => expand(i)} icon="visibility" flat/>
|
2024-07-11 15:30:32 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
|
2024-07-09 18:18:26 +02:00
|
|
|
<style>
|
2024-07-11 23:14:09 +02:00
|
|
|
.separator {
|
|
|
|
border-top: 1px solid var(--separator);
|
|
|
|
margin: 0 8px;
|
|
|
|
}
|
2024-07-09 18:18:26 +02:00
|
|
|
.cards {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
gap: 8px;
|
|
|
|
padding: 8px 0;
|
|
|
|
margin: 0 8px;
|
|
|
|
}
|
|
|
|
.card {
|
|
|
|
flex: 1 0 auto;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
max-width: 100%;
|
|
|
|
background: var(--body_background);
|
|
|
|
border-radius: 8px;
|
2024-08-29 15:44:17 +02:00
|
|
|
padding: 2px;
|
2024-07-09 18:18:26 +02:00
|
|
|
text-align: initial;
|
|
|
|
}
|
|
|
|
.card_component {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
overflow: auto;
|
2024-08-29 15:44:17 +02:00
|
|
|
padding: 6px;
|
2024-07-09 18:18:26 +02:00
|
|
|
}
|
2024-07-11 17:45:10 +02:00
|
|
|
.size_1 { width: 400px; }
|
|
|
|
.size_1 > .card_component { max-height: 400px; }
|
|
|
|
.size_2 { width: 800px; }
|
2024-07-11 23:22:36 +02:00
|
|
|
.size_2 > .card_component { max-height: 600px; }
|
2024-07-11 17:45:10 +02:00
|
|
|
.size_3 { width: 1200px; }
|
2024-07-11 23:22:36 +02:00
|
|
|
.size_3 > .card_component { max-height: 800px; }
|
2024-07-09 18:18:26 +02:00
|
|
|
|
|
|
|
.title_box {
|
|
|
|
flex: 0 0 auto;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
2024-07-11 17:45:10 +02:00
|
|
|
align-items: center;
|
2024-07-09 18:18:26 +02:00
|
|
|
border-bottom: 1px solid var(--separator);
|
|
|
|
}
|
|
|
|
.title_box > h2 {
|
|
|
|
flex: 1 1 auto;
|
|
|
|
margin: 0;
|
|
|
|
font-size: 1.5em;
|
|
|
|
border-bottom: none;
|
2024-08-29 15:44:17 +02:00
|
|
|
text-align: center;
|
2024-07-09 18:18:26 +02:00
|
|
|
}
|
|
|
|
</style>
|