2020-06-22 11:11:50 +02:00
|
|
|
<script context="module">
|
2020-11-01 05:26:58 +01:00
|
|
|
// import _ from "./graph-helpers.scss";
|
2020-06-22 11:11:50 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="typescript">
|
2020-11-05 02:01:30 +01:00
|
|
|
import type { I18n } from "anki/i18n";
|
|
|
|
import type pb from "anki/backend_proto";
|
2020-11-01 05:26:58 +01:00
|
|
|
import { getGraphData, RevlogRange } from "./graph-helpers";
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-06-27 11:24:49 +02:00
|
|
|
export let i18n: I18n;
|
2020-06-30 08:23:46 +02:00
|
|
|
export let nightMode: boolean;
|
2020-12-22 22:06:12 +01:00
|
|
|
export let graphs: any[];
|
2020-06-27 11:24:49 +02:00
|
|
|
|
2020-12-22 22:25:47 +01:00
|
|
|
export let search: string;
|
2020-12-23 16:15:46 +01:00
|
|
|
export let revlogRange: RevlogRange;
|
2020-12-22 22:36:39 +01:00
|
|
|
export let withRangeBox: boolean;
|
2020-12-22 22:25:47 +01:00
|
|
|
|
2020-12-23 16:45:00 +01:00
|
|
|
let dataPromise;
|
2020-12-23 16:15:46 +01:00
|
|
|
let days;
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
enum SearchRange {
|
|
|
|
Deck = 1,
|
|
|
|
Collection = 2,
|
|
|
|
Custom = 3,
|
|
|
|
}
|
|
|
|
|
2020-12-23 16:45:00 +01:00
|
|
|
let displayedSearch = search;
|
2020-06-22 12:28:36 +02:00
|
|
|
let searchRange: SearchRange = SearchRange.Deck;
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-12-23 16:45:00 +01:00
|
|
|
let refreshing = true;
|
2020-06-22 12:28:36 +02:00
|
|
|
|
2020-12-23 16:45:00 +01:00
|
|
|
$: {
|
|
|
|
if (refreshing) {
|
|
|
|
dataPromise = getGraphData(search, days);
|
|
|
|
console.log(dataPromise)
|
|
|
|
refreshing = false;
|
2020-07-24 01:56:28 +02:00
|
|
|
}
|
2020-12-23 16:45:00 +01:00
|
|
|
}
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-06-22 13:39:16 +02:00
|
|
|
$: {
|
|
|
|
// refresh if either of these change
|
|
|
|
search;
|
|
|
|
days;
|
2020-12-23 16:45:00 +01:00
|
|
|
refreshing = true;
|
2020-06-22 13:39:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-22 12:28:36 +02:00
|
|
|
$: {
|
|
|
|
switch (searchRange as SearchRange) {
|
|
|
|
case SearchRange.Deck:
|
2020-06-22 13:39:16 +02:00
|
|
|
search = displayedSearch = "deck:current";
|
2020-06-22 12:28:36 +02:00
|
|
|
break;
|
|
|
|
case SearchRange.Collection:
|
2020-06-22 13:39:16 +02:00
|
|
|
search = displayedSearch = "";
|
2020-06-22 12:28:36 +02:00
|
|
|
break;
|
|
|
|
case SearchRange.Custom:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 11:11:50 +02:00
|
|
|
$: {
|
2020-06-27 07:35:34 +02:00
|
|
|
switch (revlogRange as RevlogRange) {
|
|
|
|
case RevlogRange.Year:
|
2020-06-22 11:11:50 +02:00
|
|
|
days = 365;
|
|
|
|
break;
|
2020-06-27 07:35:34 +02:00
|
|
|
case RevlogRange.All:
|
2020-06-22 11:11:50 +02:00
|
|
|
days = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 13:39:16 +02:00
|
|
|
const searchKeyUp = (e: KeyboardEvent) => {
|
|
|
|
// fetch data on enter
|
2020-11-01 05:26:58 +01:00
|
|
|
if (e.key == "Enter") {
|
2020-06-29 07:11:46 +02:00
|
|
|
const wasSame = search == displayedSearch;
|
2020-06-22 13:39:16 +02:00
|
|
|
search = displayedSearch;
|
2020-06-29 07:11:46 +02:00
|
|
|
if (wasSame) {
|
|
|
|
// force a refresh (user may have changed current deck, etc)
|
2020-12-23 16:45:00 +01:00
|
|
|
refreshing = true;
|
2020-06-29 07:11:46 +02:00
|
|
|
}
|
2020-06-22 13:39:16 +02:00
|
|
|
}
|
|
|
|
};
|
2020-06-27 14:10:56 +02:00
|
|
|
|
2020-07-06 10:29:35 +02:00
|
|
|
const year = i18n.tr(i18n.TR.STATISTICS_RANGE_1_YEAR_HISTORY);
|
2020-06-28 05:46:17 +02:00
|
|
|
const deck = i18n.tr(i18n.TR.STATISTICS_RANGE_DECK);
|
|
|
|
const collection = i18n.tr(i18n.TR.STATISTICS_RANGE_COLLECTION);
|
|
|
|
const searchLabel = i18n.tr(i18n.TR.STATISTICS_RANGE_SEARCH);
|
2020-07-06 10:29:35 +02:00
|
|
|
const all = i18n.tr(i18n.TR.STATISTICS_RANGE_ALL_HISTORY);
|
2020-06-22 11:11:50 +02:00
|
|
|
</script>
|
|
|
|
|
2020-12-22 22:36:39 +01:00
|
|
|
{#if withRangeBox}
|
|
|
|
<div class="range-box">
|
|
|
|
<div class="range-box-inner">
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={searchRange} value={SearchRange.Deck} />
|
|
|
|
{deck}
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
bind:group={searchRange}
|
|
|
|
value={SearchRange.Collection} />
|
|
|
|
{collection}
|
|
|
|
</label>
|
2020-06-26 07:34:21 +02:00
|
|
|
|
|
|
|
<input
|
2020-12-22 22:36:39 +01:00
|
|
|
type="text"
|
|
|
|
bind:value={displayedSearch}
|
|
|
|
on:keyup={searchKeyUp}
|
|
|
|
on:focus={() => {
|
2020-06-27 13:45:16 +02:00
|
|
|
searchRange = SearchRange.Custom;
|
2020-12-22 22:36:39 +01:00
|
|
|
}}
|
|
|
|
placeholder={searchLabel} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="range-box-inner">
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={revlogRange} value={RevlogRange.Year} />
|
|
|
|
{year}
|
|
|
|
</label>
|
|
|
|
<label>
|
|
|
|
<input type="radio" bind:group={revlogRange} value={RevlogRange.All} />
|
|
|
|
{all}
|
|
|
|
</label>
|
|
|
|
</div>
|
2020-06-26 07:34:21 +02:00
|
|
|
</div>
|
2020-12-22 22:36:39 +01:00
|
|
|
<div class="range-box-pad" />
|
|
|
|
{/if}
|
2020-06-22 11:11:50 +02:00
|
|
|
|
2020-12-23 16:45:00 +01:00
|
|
|
{#await dataPromise}
|
2020-12-25 20:07:52 +01:00
|
|
|
<div class="spin">◐</div>
|
2020-12-23 16:45:00 +01:00
|
|
|
{:then sourceData}
|
|
|
|
<div tabindex="-1" class="no-focus-outline">
|
2020-12-22 22:06:12 +01:00
|
|
|
{#each graphs as Graph}
|
|
|
|
<Graph {sourceData} {revlogRange} {i18n} {nightMode} />
|
|
|
|
{/each}
|
2020-12-23 16:45:00 +01:00
|
|
|
</div>
|
|
|
|
{:catch error}
|
|
|
|
<script>
|
|
|
|
alert({i18n.tr(i18n.TR.STATISTICS_ERROR_FETCHING)});
|
|
|
|
</script>
|
|
|
|
{/await}
|