Skip to content

Commit 4dfe9fa

Browse files
authored
Merge pull request #5 from iceljc/features/add-refresh-agents
add refresh agents
2 parents 6e99a75 + aadc511 commit 4dfe9fa

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"node": ">=18.0.0"
77
},
88
"scripts": {
9-
"dev": "vite dev",
9+
"dev": "npm run open-browser && vite dev",
10+
"open-browser": "start http://localhost:5015/",
1011
"build": "vite build",
1112
"preview": "vite preview",
1213
"check": "svelte-kit sync && svelte-check --tsconfig ./jsconfig.json",

src/lib/services/agent-service.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ export async function saveAgent(agent) {
4444
await axios.put(url, agent);
4545
}
4646

47+
export async function refreshAgents() {
48+
const url = endpoints.agentRefreshUrl;
49+
await axios.post(url);
50+
}

src/lib/services/api-endpoints.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const endpoints = {
2121
agentSettingUrl: `${host}/agent/settings`,
2222
agentListUrl: `${host}/agents`,
2323
agentDetailUrl: `${host}/agent/{id}`,
24+
agentRefreshUrl: `${host}/refresh-agents`,
2425

2526
// router
2627
routerSettingUrl: `${host}/router/settings`,
Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
<script>
2-
import { Col, Row } from '@sveltestrap/sveltestrap';
2+
import { Alert, Button, Col, Row } from '@sveltestrap/sveltestrap';
33
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
44
import HeadTitle from '$lib/common/HeadTitle.svelte';
5-
import { onMount } from 'svelte';
5+
import { onMount } from 'svelte';
6+
import { refreshAgents } from '$lib/services/agent-service';
67
78
/** @type {import('$types').AgentModel[]} */
89
let agents = [];
10+
let isLoading = false;
11+
let isComplete = false;
12+
13+
const refreshAgentData = () => {
14+
isLoading = true;
15+
refreshAgents().then(res => {
16+
isComplete = true;
17+
isLoading = false;
18+
setTimeout(() => {
19+
isComplete = false;
20+
}, 3000);
21+
}).catch(err => {
22+
isLoading = false;
23+
});
24+
};
925
1026
onMount(async () => {
1127
agents = await getAgents({
@@ -18,7 +34,19 @@
1834

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

37+
{#if isLoading}
38+
<Alert color="secondary">
39+
<div>In Progress...</div>
40+
</Alert>
41+
{/if}
42+
43+
{#if isComplete}
44+
<Alert color="success">
45+
<div>Update comppleted!</div>
46+
</Alert>
47+
{/if}
48+
2149
<h3>Migrate agents from file repository to MongoDB</h3>
22-
<button class="btn btn-primary btn-sm">
23-
<i class="bx bx-copy" /> Start Migration
24-
</button>
50+
<Button color="primary" on:click={() => refreshAgentData()}>
51+
<i class="bx bx-copy" /> Start Migration
52+
</Button>

0 commit comments

Comments
 (0)