|
1 | 1 | <script>
|
2 | 2 | import { onMount } from 'svelte';
|
3 |
| - import { _ } from 'svelte-i18n' |
| 3 | + import { _ } from 'svelte-i18n'; |
| 4 | + import Swal from 'sweetalert2'; |
| 5 | + import 'overlayscrollbars/overlayscrollbars.css'; |
| 6 | + import { OverlayScrollbars } from 'overlayscrollbars'; |
4 | 7 | import {
|
5 | 8 | Button,
|
6 | 9 | Card,
|
|
17 | 20 | import Breadcrumb from '$lib/common/Breadcrumb.svelte';
|
18 | 21 | import HeadTitle from '$lib/common/HeadTitle.svelte';
|
19 | 22 | import TablePagination from '$lib/common/TablePagination.svelte';
|
20 |
| - import { getAgentTasks } from '$lib/services/task-service'; |
21 |
| - import { utcToLocal } from '$lib/helpers/datetime'; |
22 |
| - import Swal from 'sweetalert2'; |
23 |
| - import { replaceNewLine } from '$lib/helpers/http'; |
24 |
| - import 'overlayscrollbars/overlayscrollbars.css'; |
25 |
| - import { OverlayScrollbars } from 'overlayscrollbars'; |
| 23 | + import LoadingToComplete from '$lib/common/LoadingToComplete.svelte'; |
| 24 | + import { getAgentTasks, updateAgentTask } from '$lib/services/task-service'; |
26 | 25 | import { AgentTaskStatus } from '$lib/helpers/enums';
|
| 26 | + import TaskItem from './task-item.svelte'; |
| 27 | + |
27 | 28 |
|
28 |
| - let isError = false; |
29 | 29 | const duration = 3000;
|
30 | 30 | const firstPage = 1;
|
31 | 31 | const pageSize = 10;
|
|
42 | 42 | }
|
43 | 43 | };
|
44 | 44 |
|
| 45 | + let isLoading = false; |
| 46 | + let isComplete = false; |
| 47 | + let successText = "Update completed!"; |
| 48 | +
|
45 | 49 | /** @type {import('$commonTypes').PagedItems<import('$agentTypes').AgentTaskModel>} */
|
46 | 50 | let tasks = { count: 0, items: [] };
|
47 | 51 |
|
|
123 | 127 | refreshPager(tasks.count);
|
124 | 128 | }
|
125 | 129 |
|
126 |
| - /** @param {string} taskId */ |
127 |
| - function handleTaskDeletion(taskId) { |
128 |
| - /*deleteConversation(conversationId).then(async () => { |
129 |
| - isLoading = false; |
130 |
| - isComplete = true; |
131 |
| - setTimeout(() => { |
132 |
| - isComplete = false; |
133 |
| - }, duration); |
134 |
| - await reloadConversations(); |
135 |
| - }).catch(err => { |
136 |
| - isLoading = false; |
137 |
| - isComplete = false; |
138 |
| - isError = true; |
139 |
| - setTimeout(() => { |
140 |
| - isError = false; |
141 |
| - }, duration); |
142 |
| - });*/ |
143 |
| - } |
144 |
| -
|
145 |
| - /** @param {string} taskId */ |
146 |
| - function openDeleteModal(taskId) { |
147 |
| - // @ts-ignore |
148 |
| - Swal.fire({ |
149 |
| - title: 'Are you sure?', |
150 |
| - text: "You won't be able to revert this!", |
151 |
| - icon: 'warning', |
152 |
| - customClass: 'custom-modal', |
153 |
| - showCancelButton: true, |
154 |
| - confirmButtonText: 'Yes, delete it!' |
155 |
| - }).then((result) => { |
156 |
| - if (result.value) { |
157 |
| - handleTaskDeletion(taskId); |
158 |
| - } |
159 |
| - }); |
160 |
| - } |
161 |
| -
|
162 | 130 | /**
|
163 | 131 | * @param {any} e
|
164 | 132 | */
|
|
200 | 168 | };
|
201 | 169 | }
|
202 | 170 | }
|
| 171 | +
|
| 172 | + /** @param {any} e */ |
| 173 | + function onTaskSaved(e) { |
| 174 | + const task = e.detail.task; |
| 175 | + if (!task) return; |
| 176 | +
|
| 177 | + openSaveModal(task); |
| 178 | + } |
| 179 | +
|
| 180 | + /** @param {import('$agentTypes').AgentTaskModel} task */ |
| 181 | + function openSaveModal(task) { |
| 182 | + // @ts-ignore |
| 183 | + Swal.fire({ |
| 184 | + title: 'Are you sure?', |
| 185 | + text: "You can change it back.", |
| 186 | + icon: 'warning', |
| 187 | + customClass: 'custom-modal', |
| 188 | + showCancelButton: true, |
| 189 | + confirmButtonText: 'Yes, save it!' |
| 190 | + }).then((result) => { |
| 191 | + if (result.value) { |
| 192 | + handleTaskSave(task); |
| 193 | + } |
| 194 | + }); |
| 195 | + } |
| 196 | +
|
| 197 | + /** @param {import('$agentTypes').AgentTaskModel} task */ |
| 198 | + function handleTaskSave(task) { |
| 199 | + updateAgentTask(task.agent_id, task.id, task).then(async () => { |
| 200 | + isLoading = false; |
| 201 | + isComplete = true; |
| 202 | + successText = "Update completed!"; |
| 203 | + setTimeout(() => { |
| 204 | + isComplete = false; |
| 205 | + successText = ''; |
| 206 | + }, duration); |
| 207 | + }).catch(() => { |
| 208 | + isLoading = false; |
| 209 | + isComplete = false; |
| 210 | + successText = ''; |
| 211 | + }); |
| 212 | + } |
| 213 | +
|
| 214 | + |
| 215 | +
|
| 216 | + /** @param {any} e */ |
| 217 | + function onTaskDeleted(e) { |
| 218 | + const task = e.detail.task; |
| 219 | + if (!task) return; |
| 220 | +
|
| 221 | + openDeleteModal(task.id); |
| 222 | + } |
| 223 | +
|
| 224 | + /** @param {string} taskId */ |
| 225 | + function openDeleteModal(taskId) { |
| 226 | + // @ts-ignore |
| 227 | + Swal.fire({ |
| 228 | + title: 'Are you sure?', |
| 229 | + text: "You won't be able to revert this!", |
| 230 | + icon: 'warning', |
| 231 | + customClass: 'custom-modal', |
| 232 | + showCancelButton: true, |
| 233 | + confirmButtonText: 'Yes, delete it!' |
| 234 | + }).then((result) => { |
| 235 | + if (result.value) { |
| 236 | + handleTaskDeletion(taskId); |
| 237 | + } |
| 238 | + }); |
| 239 | + } |
| 240 | +
|
| 241 | + /** @param {string} taskId */ |
| 242 | + function handleTaskDeletion(taskId) { |
| 243 | + /*deleteConversation(conversationId).then(async () => { |
| 244 | + isLoading = false; |
| 245 | + isComplete = true; |
| 246 | + setTimeout(() => { |
| 247 | + isComplete = false; |
| 248 | + }, duration); |
| 249 | + await reloadConversations(); |
| 250 | + }).catch(err => { |
| 251 | + isLoading = false; |
| 252 | + isComplete = false; |
| 253 | + isError = true; |
| 254 | + setTimeout(() => { |
| 255 | + isError = false; |
| 256 | + }, duration); |
| 257 | + });*/ |
| 258 | + } |
203 | 259 | </script>
|
204 | 260 |
|
205 | 261 | <HeadTitle title="{$_('Task List')}" />
|
206 | 262 | <Breadcrumb title="{$_('Agent')}" pagetitle="{$_('Task')}" />
|
| 263 | +<LoadingToComplete isLoading={isLoading} isComplete={isComplete} /> |
207 | 264 |
|
208 | 265 | <Row>
|
209 | 266 | <Col lg="12">
|
|
263 | 320 | <th scope="col">{$_('Description')}</th>
|
264 | 321 | <th scope="col">{$_('Agent')}</th>
|
265 | 322 | <th scope="col">{$_('Details')}</th>
|
266 |
| - <th scope="col">{$_('Updated Date')}</th> |
| 323 | + <th scope="col">{$_('Updated Time')}</th> |
267 | 324 | <th scope="col">{$_('Enabled')}</th>
|
268 | 325 | <th scope="col">{$_('Status')}</th>
|
269 | 326 | <th scope="col">{$_('Action')}</th>
|
270 | 327 | </tr>
|
271 | 328 | </thead>
|
272 | 329 | <tbody>
|
273 | 330 | {#each tasks.items as task}
|
274 |
| - <tr> |
275 |
| - <td scope="row"> |
276 |
| - <a href="page/conversation/{task.id}">{task.name}</a> |
277 |
| - </td> |
278 |
| - <td>{task.description}</td> |
279 |
| - <td>{task.agent_name}</td> |
280 |
| - <td><div style="max-height: 100px;" class="scrollbar">{@html replaceNewLine(task.content)}</div></td> |
281 |
| - <td>{utcToLocal(task.updated_datetime)}</td> |
282 |
| - <td><span class="badge bg-success">{task.enabled ? $_("Enabled") : $_("Disabled")}</span></td> |
283 |
| - <td><span class="badge bg-info">{task.status}</span></td> |
284 |
| - <td> |
285 |
| - <ul class="list-unstyled hstack gap-1 mb-0"> |
286 |
| - <li data-bs-toggle="tooltip" data-bs-placement="top" title="View"> |
287 |
| - <a href="page/task/{task.id}?agentId={task.agent_id}" target="_blank" class="btn btn-sm btn-soft-danger"> |
288 |
| - <i class="mdi mdi-eye-outline" /> |
289 |
| - </a> |
290 |
| - </li> |
291 |
| - <li data-bs-toggle="tooltip" data-bs-placement="top" title="Delete"> |
292 |
| - <Button on:click={() => openDeleteModal(task.id)} class="btn btn-sm btn-soft-danger"> |
293 |
| - <i class="mdi mdi-delete-outline" /> |
294 |
| - </Button> |
295 |
| - </li> |
296 |
| - </ul> |
297 |
| - </td> |
298 |
| - </tr> |
| 331 | + <TaskItem |
| 332 | + task={task} |
| 333 | + on:save={e => onTaskSaved(e)} |
| 334 | + on:delete={e => onTaskDeleted(e)} |
| 335 | + /> |
299 | 336 | {/each}
|
300 | 337 | </tbody>
|
301 | 338 | </Table>
|
|
0 commit comments