Skip to content

Commit b166c59

Browse files
authored
Merge pull request #273 from iceljc/features/refine-chat-window
move mongo to settings
2 parents 66f068a + 16f2566 commit b166c59

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

src/lib/services/agent-service.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ export async function deleteAgent(agentId) {
6363

6464
/**
6565
* Refresh agent data
66+
* @returns {Promise<string>}
6667
*/
6768
export async function refreshAgents() {
6869
const url = endpoints.agentRefreshUrl;
69-
await axios.post(url);
70+
const response = await axios.post(url);
71+
return response.data;
7072
}
7173

7274
/**

src/routes/page/mongodb/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { refreshAgents } from '$lib/services/agent-service';
66
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
77
import { _ } from 'svelte-i18n';
8-
import Swal from 'sweetalert2'
8+
import Swal from 'sweetalert2';
99
1010
let isLoading = false;
1111
let isComplete = false;

src/routes/page/setting/+page.svelte

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
2-
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
3-
import HeadTitle from '$lib/common/HeadTitle.svelte';
2+
import { onMount } from 'svelte';
43
import { _ } from 'svelte-i18n';
4+
import Swal from 'sweetalert2';
55
import {
66
Card,
77
CardBody,
@@ -13,43 +13,94 @@
1313
NavLink,
1414
Row,
1515
TabContent,
16-
TabPane
16+
TabPane,
17+
Button
1718
} from '@sveltestrap/sveltestrap';
18-
import { onMount } from 'svelte';
19+
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
20+
import HeadTitle from '$lib/common/HeadTitle.svelte';
1921
import { getSettings, getSettingDetail } from '$lib/services/setting-service';
2022
import { JSONEditor } from 'svelte-jsoneditor';
23+
import { refreshAgents } from '$lib/services/agent-service';
24+
import LoadingToComplete from '$lib/common/LoadingToComplete.svelte';
25+
26+
const duration = 3000;
27+
let isLoading = false;
28+
let isComplete = false;
29+
let isError = false;
30+
let successText = '';
31+
let errorText = '';
2132
22-
let customActiveTab = '1';
33+
let selectedTab = '1';
2334
/** @type {string[]} */
2435
let settings = [];
2536
26-
let content = {
27-
json: {
28-
}
29-
};
37+
let content = { json: {} };
3038
3139
onMount(async () => {
3240
settings = await getSettings();
33-
customActiveTab = settings[0];
34-
handleGetSettingDetail(settings[0]);
41+
selectedTab = settings[0];
42+
handleGetSettingDetail(selectedTab);
3543
});
3644
3745
/**
38-
*
3946
* @param {string} tab
4047
*/
4148
async function handleGetSettingDetail(tab) {
42-
customActiveTab = tab;
49+
selectedTab = tab;
4350
const detail = await getSettingDetail(tab);
4451
content = {
4552
json: detail
4653
};
4754
}
55+
56+
function readyToRefresh() {
57+
// @ts-ignore
58+
Swal.fire({
59+
title: 'Are you sure?',
60+
text: "You will migrate all agents data to mongoDb.",
61+
icon: 'warning',
62+
showCancelButton: true,
63+
confirmButtonText: 'Yes',
64+
cancelButtonText: 'No'
65+
}).then((result) => {
66+
if (result.value) {
67+
refreshAgentData();
68+
}
69+
});
70+
}
71+
72+
const refreshAgentData = () => {
73+
isLoading = true;
74+
refreshAgents().then(res => {
75+
isComplete = true;
76+
isLoading = false;
77+
successText = res;
78+
setTimeout(() => {
79+
isComplete = false;
80+
successText = '';
81+
}, duration);
82+
}).catch(err => {
83+
isLoading = false;
84+
isComplete = false;
85+
isError = true;
86+
errorText = 'Failed to migrate agents.';
87+
setTimeout(() => {
88+
isError = false;
89+
errorText = '';
90+
}, duration);
91+
});
92+
};
4893
</script>
4994

5095
<HeadTitle title="{$_('Settings')}" />
51-
5296
<Breadcrumb title="{$_('Settings')}" pagetitle="{$_('Detail')}" />
97+
<LoadingToComplete
98+
isLoading={isLoading}
99+
isComplete={isComplete}
100+
isError={isError}
101+
successText={successText}
102+
errorText={errorText}
103+
/>
53104

54105
<Card>
55106
<CardBody>
@@ -62,7 +113,7 @@
62113
<NavLink
63114
style="cursor: pointer"
64115
on:click={() => handleGetSettingDetail(tab)}
65-
active={customActiveTab == tab}
116+
active={selectedTab == tab}
66117
>
67118
<span class="d-block d-sm-none">
68119
<i class="fas fa-home" />
@@ -73,14 +124,14 @@
73124
{/each}
74125
</Nav>
75126

76-
<TabContent activeTab={customActiveTab} class="p-3 text-muted">
127+
<TabContent class="p-3 text-muted">
77128
{#each settings as tab}
78-
<TabPane tabId={tab} class={customActiveTab == tab ? 'active' : ''}>
129+
<TabPane tabId={tab} class={selectedTab == tab ? 'active' : ''}>
79130
<Row>
80131
<Col sm="12">
81132
<CardText class="mb-0">
82133
<div class="my-json-editor">
83-
<JSONEditor bind:content expand={() => { return true;}}/>
134+
<JSONEditor bind:content />
84135
</div>
85136
</CardText>
86137
</Col>
@@ -91,6 +142,18 @@
91142
</CardBody>
92143
</Card>
93144

145+
146+
<Card>
147+
<CardBody>
148+
<CardTitle class="h4">{$_('Migrate agents from file repository to MongoDB')}</CardTitle>
149+
<p class="card-title-desc"></p>
150+
151+
<Button color="primary" on:click={() => readyToRefresh()} disabled={isLoading}>
152+
<i class="bx bx-copy" /> {$_('Start Migration')}
153+
</Button>
154+
</CardBody>
155+
</Card>
156+
94157
<style>
95158
.my-json-editor {
96159
/* define a custom theme color */

0 commit comments

Comments
 (0)