Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine alert #6

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/lib/services/agent-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export async function saveAgent(agent) {
await axios.put(url, agent);
}

/**
* Refresh agent data
*/
export async function refreshAgents() {
const url = endpoints.agentRefreshUrl;
await axios.post(url);
Expand Down
30 changes: 17 additions & 13 deletions src/routes/page/mongodb/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<script>
import { Alert, Button, Col, Row } from '@sveltestrap/sveltestrap';
import { Alert, Button } from '@sveltestrap/sveltestrap';
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
import HeadTitle from '$lib/common/HeadTitle.svelte';
import { onMount } from 'svelte';
import { refreshAgents } from '$lib/services/agent-service';

/** @type {import('$types').AgentModel[]} */
let agents = [];
let isLoading = false;
let isComplete = false;
let isError = false;
const duration = 3000;

const refreshAgentData = () => {
isLoading = true;
Expand All @@ -17,21 +16,20 @@
isLoading = false;
setTimeout(() => {
isComplete = false;
}, 3000);
}, duration);
}).catch(err => {
isLoading = false;
isComplete = false;
isError = true;
setTimeout(() => {
isError = false;
}, duration);
});
};

onMount(async () => {
agents = await getAgents({
isEvaluator: false
});
});
</script>

<HeadTitle title="MongoDB" />

<Breadcrumb title="MongoDB" pagetitle="Setting" />

{#if isLoading}
Expand All @@ -42,11 +40,17 @@

{#if isComplete}
<Alert color="success">
<div>Update comppleted!</div>
<div>Update completed!</div>
</Alert>
{/if}

{#if isError}
<Alert color="danger">
<div>Error!</div>
</Alert>
{/if}

<h3>Migrate agents from file repository to MongoDB</h3>
<Button color="primary" on:click={() => refreshAgentData()}>
<Button color="primary" on:click={() => refreshAgentData()} disabled={isComplete || isError}>
<i class="bx bx-copy" /> Start Migration
</Button>