diff --git a/2 b/2 new file mode 100644 index 0000000..2d82f0a --- /dev/null +++ b/2 @@ -0,0 +1,126 @@ + + +
+

Crons

+
+ +
+
+ +
+ +
+
+ +
+ + + + ID + + + + Run Every + Last Run + Next Run + Run Time + + + + + + + + + + + + {#each $rows as row (row.id)} + + + + + + + + + + + + + {/each} + +
TitleSlugDescriptionStateEnabled
+ + + +
{row.id}{row.title}{row.slug}{row.description}{row.run_every}s + {format(row.last_run * 1000, 'PP HH:mm')}
+ {formatDistance(row.last_run * 1000, new Date(), { addSuffix: true })} +
+ {format(row.next_run * 1000, 'PP HH:mm')}
+ {formatDistance(row.next_run * 1000, new Date(), { addSuffix: true })} +
{row.run_time}{row.cron_state ? 'RUNNING' : 'IDLE'}{row.is_enabled ? 'ENABLED' : 'DISABLED'}
+
+ +
+ +
+
diff --git a/frontend/src/lib/components/datatables/server/DtSrAutoRefresh.svelte b/frontend/src/lib/components/datatables/server/DtSrAutoRefresh.svelte new file mode 100644 index 0000000..4dd0d17 --- /dev/null +++ b/frontend/src/lib/components/datatables/server/DtSrAutoRefresh.svelte @@ -0,0 +1,58 @@ + + + + diff --git a/frontend/src/lib/components/datatables/server/index.js b/frontend/src/lib/components/datatables/server/index.js index c43f164..f6bc438 100644 --- a/frontend/src/lib/components/datatables/server/index.js +++ b/frontend/src/lib/components/datatables/server/index.js @@ -4,3 +4,4 @@ export { default as DtSrRowsPerPage } from './DtSrRowsPerPage.svelte'; export { default as DtSrSearch } from './DtSrSearch.svelte'; export { default as DtSrThFilter } from './DtSrThFilter.svelte'; export { default as DtSrThSort } from './DtSrThSort.svelte'; +export { default as DtSrAutoRefresh } from './DtSrAutoRefresh.svelte'; diff --git a/frontend/src/routes/(front)/remote-nodes/+page.svelte b/frontend/src/routes/(front)/remote-nodes/+page.svelte index a129ae5..3a59107 100644 --- a/frontend/src/routes/(front)/remote-nodes/+page.svelte +++ b/frontend/src/routes/(front)/remote-nodes/+page.svelte @@ -2,13 +2,14 @@ import { DataHandler } from '@vincjo/datatables/remote'; import { format, formatDistance } from 'date-fns'; import { loadData, loadCountries } from './api-handler'; - import { onMount, onDestroy } from 'svelte'; + import { onMount } from 'svelte'; import { DtSrRowsPerPage, DtSrThSort, DtSrThFilter, DtSrRowCount, - DtSrPagination + DtSrPagination, + DtSrAutoRefresh } from '$lib/components/datatables/server'; import { HostPortCell, @@ -33,10 +34,6 @@ const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 }); let rows = handler.getRows(); - const reloadData = () => { - handler.invalidate(); - }; - /** * Array containing network fees. * For now, I use static data to reduce the amount of API calls. @@ -72,45 +69,6 @@ {} ); - /** @type {number | undefined} */ - let intervalId; - let intervalValue = 0; - - const intervalOptions = [ - { value: 0, label: 'No' }, - { value: 5, label: '5s' }, - { value: 10, label: '10s' }, - { value: 30, label: '30s' }, - { value: 60, label: '1m' } - ]; - - const startInterval = () => { - const seconds = intervalValue; - if (isNaN(seconds) || seconds < 0) { - return; - } - - if (!intervalOptions.some((option) => option.value === seconds)) { - return; - } - - if (intervalId) { - clearInterval(intervalId); - } - - if (seconds > 0) { - reloadData(); - intervalId = setInterval(() => { - reloadData(); - }, seconds * 1000); - } - }; - - $: startInterval(); // Automatically start the interval on change - - onDestroy(() => { - clearInterval(intervalId); // Clear the interval when the component is destroyed - }); onMount(() => { loadCountries().then((data) => { countries = data; @@ -156,24 +114,14 @@
handler.invalidate()}>Reload
diff --git a/frontend/src/routes/(front)/remote-nodes/logs/+page.svelte b/frontend/src/routes/(front)/remote-nodes/logs/+page.svelte index 256ed2e..f80ff06 100644 --- a/frontend/src/routes/(front)/remote-nodes/logs/+page.svelte +++ b/frontend/src/routes/(front)/remote-nodes/logs/+page.svelte @@ -2,14 +2,15 @@ import { DataHandler } from '@vincjo/datatables/remote'; import { format, formatDistance } from 'date-fns'; import { loadData, loadNodeInfo } from './api-handler'; - import { onMount, onDestroy } from 'svelte'; + import { onMount } from 'svelte'; import { formatHashes, formatBytes } from '$lib/utils/strings'; import { DtSrRowsPerPage, DtSrThSort, DtSrThFilter, DtSrRowCount, - DtSrPagination + DtSrPagination, + DtSrAutoRefresh } from '$lib/components/datatables/server'; /** @param {number | null } runtime */ @@ -28,49 +29,6 @@ const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 }); let rows = handler.getRows(); - const reloadData = () => { - handler.invalidate(); - }; - - /** @type {number | undefined} */ - let intervalId; - let intervalValue = 0; - - const intervalOptions = [ - { value: 0, label: 'No' }, - { value: 5, label: '5s' }, - { value: 10, label: '10s' }, - { value: 30, label: '30s' }, - { value: 60, label: '1m' } - ]; - - const startInterval = () => { - const seconds = intervalValue; - if (isNaN(seconds) || seconds < 0) { - return; - } - - if (!intervalOptions.some((option) => option.value === seconds)) { - return; - } - - if (intervalId) { - clearInterval(intervalId); - } - - if (seconds > 0) { - reloadData(); - intervalId = setInterval(() => { - reloadData(); - }, seconds * 1000); - } - }; - - $: startInterval(); - - onDestroy(() => { - clearInterval(intervalId); - }); onMount(() => { pageId = new URLSearchParams(window.location.search).get('node_id') || '0'; loadNodeInfo(pageId).then((data) => { @@ -134,24 +92,14 @@
handler.invalidate()}>Reload
diff --git a/frontend/src/routes/(loggedin)/app/crons/+page.svelte b/frontend/src/routes/(loggedin)/app/crons/+page.svelte index 9dfd6f3..975a66f 100644 --- a/frontend/src/routes/(loggedin)/app/crons/+page.svelte +++ b/frontend/src/routes/(loggedin)/app/crons/+page.svelte @@ -2,60 +2,22 @@ import { DataHandler } from '@vincjo/datatables/remote'; import { format, formatDistance } from 'date-fns'; import { loadData } from './api-handler'; - import { onMount, onDestroy } from 'svelte'; - import { DtSrThSort, DtSrThFilter, DtSrRowCount } from '$lib/components/datatables/server'; + import { onMount } from 'svelte'; + import { + DtSrThSort, + DtSrThFilter, + DtSrRowCount, + DtSrAutoRefresh + } from '$lib/components/datatables/server'; const handler = new DataHandler([], { rowsPerPage: 1000, totalRows: 0 }); let rows = handler.getRows(); - const reloadData = () => { - handler.invalidate(); - }; - /** @type {string | number} */ let filterState = -1; /** @type {string | number} */ let filterEnabled = -1; - /** @type {number | undefined} */ - let intervalId; - let intervalValue = 0; - - const intervalOptions = [ - { value: 0, label: 'No' }, - { value: 5, label: '5s' }, - { value: 10, label: '10s' }, - { value: 30, label: '30s' }, - { value: 60, label: '1m' } - ]; - - const startInterval = () => { - const seconds = intervalValue; - if (isNaN(seconds) || seconds < 0) { - return; - } - - if (!intervalOptions.some((option) => option.value === seconds)) { - return; - } - - if (intervalId) { - clearInterval(intervalId); - } - - if (seconds > 0) { - reloadData(); - intervalId = setInterval(() => { - reloadData(); - }, seconds * 1000); - } - }; - - $: startInterval(); // Automatically start the interval on change - - onDestroy(() => { - clearInterval(intervalId); // Clear the interval when the component is destroyed - }); onMount(() => { handler.onChange((state) => loadData(state)); handler.invalidate(); @@ -69,24 +31,16 @@
handler.invalidate()} + > + >Reload
@@ -117,7 +71,7 @@ bind:value={filterState} on:change={() => { handler.filter(filterState, 'cron_state'); - reloadData(); + handler.invalidate(); }} > @@ -133,7 +87,7 @@ bind:value={filterEnabled} on:change={() => { handler.filter(filterEnabled, 'is_enabled'); - reloadData(); + handler.invalidate(); }} > diff --git a/frontend/src/routes/(loggedin)/app/prober/+page.svelte b/frontend/src/routes/(loggedin)/app/prober/+page.svelte index 57488f8..5eae831 100644 --- a/frontend/src/routes/(loggedin)/app/prober/+page.svelte +++ b/frontend/src/routes/(loggedin)/app/prober/+page.svelte @@ -2,14 +2,15 @@ import { DataHandler } from '@vincjo/datatables/remote'; import { format, formatDistance } from 'date-fns'; import { loadData, createProber, editProber, deleteProber } from './api-handler'; - import { onMount, onDestroy } from 'svelte'; + import { onMount } from 'svelte'; import { getModalStore, getToastStore } from '@skeletonlabs/skeleton'; import { DtSrRowsPerPage, DtSrThSort, DtSrThFilter, DtSrRowCount, - DtSrPagination + DtSrPagination, + DtSrAutoRefresh } from '$lib/components/datatables/server'; const modalStore = getModalStore(); const toastStore = getToastStore(); @@ -111,49 +112,6 @@ const handler = new DataHandler([], { rowsPerPage: 10, totalRows: 0 }); let rows = handler.getRows(); - const reloadData = () => { - handler.invalidate(); - }; - - /** @type {number | undefined} */ - let intervalId; - let intervalValue = 0; - - const intervalOptions = [ - { value: 0, label: 'No' }, - { value: 5, label: '5s' }, - { value: 10, label: '10s' }, - { value: 30, label: '30s' }, - { value: 60, label: '1m' } - ]; - - const startInterval = () => { - const seconds = intervalValue; - if (isNaN(seconds) || seconds < 0) { - return; - } - - if (!intervalOptions.some((option) => option.value === seconds)) { - return; - } - - if (intervalId) { - clearInterval(intervalId); - } - - if (seconds > 0) { - reloadData(); - intervalId = setInterval(() => { - reloadData(); - }, seconds * 1000); - } - }; - - $: startInterval(); // Automatically start the interval on change - - onDestroy(() => { - clearInterval(intervalId); // Clear the interval when the component is destroyed - }); onMount(() => { handler.onChange((state) => loadData(state)); handler.invalidate(); @@ -169,20 +127,15 @@
-