Skip to content

Commit 0383b97

Browse files
authored
Merge pull request #16 from iceljc/features/refine-conversation-elements
Features/refine conversation elements
2 parents 2d24627 + e93fb99 commit 0383b97

File tree

14 files changed

+246
-79
lines changed

14 files changed

+246
-79
lines changed

package-lock.json

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"chart.js": "^4.4.0",
5050
"drawflow": "^0.0.59",
5151
"fullcalendar": "^6.1.9",
52+
"lodash": "^4.17.21",
5253
"moment": "^2.30.1",
5354
"overlayscrollbars": "^2.4.4",
5455
"overlayscrollbars-svelte": "^0.5.2",
File renamed without changes.

src/routes/page/plugin/plugin-pagination.svelte renamed to src/lib/common/PlainPagination.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
Col,
55
Row,
66
} from '@sveltestrap/sveltestrap';
7-
import { afterUpdate } from 'svelte';
87
98
/** @type {import('$lib/helpers/types').Pagination} */
109
export let pagination = { page: 1, size: 10, count: 0 };
@@ -23,9 +22,9 @@
2322
/** @type {number[]} */
2423
$: pages = Array.from({ length: maxPage - minPage + 1 }, (_, i) => minPage + i);
2524
/** @type {boolean} */
26-
$: disableBackward = pagination.page === firstPage;
25+
$: disableBackward = pagination.page === firstPage || pagination.count === 0;
2726
/** @type {boolean} */
28-
$: disableForward = pagination.page === totalPages;
27+
$: disableForward = pagination.page === totalPages || pagination.count === 0;
2928
3029
/**
3130
* @param {any} e

src/lib/common/Pager.svelte renamed to src/lib/common/TablePagination.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/** @type {number} */
1414
$: totalPages = Math.ceil(pagination.count / pagination.size);
1515
/** @type {number} */
16-
$: start = (pagination.page - 1) * pagination.size + 1;
16+
$: start = pagination.count <= 0 ? 0 : (pagination.page - 1) * pagination.size + 1;
1717
/** @type {number} */
1818
$: end = Math.min(pagination.page * pagination.size, pagination.count);
1919
/** @type {number} */
@@ -23,9 +23,9 @@
2323
/** @type {number[]} */
2424
$: pages = Array.from({ length: maxPage - minPage + 1 }, (_, i) => minPage + i);
2525
/** @type {boolean} */
26-
$: disableBackward = pagination.page === firstPage;
26+
$: disableBackward = pagination.page === firstPage || pagination.count === 0;
2727
/** @type {boolean} */
28-
$: disableForward = pagination.page === totalPages;
28+
$: disableForward = pagination.page === totalPages || pagination.count === 0;
2929
3030
/**
3131
* @param {any} e

src/lib/helpers/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484

8585
/**
8686
* @typedef {Object} AgentFilter
87+
* @property {Pagination} pager - Pagination
8788
* @property {boolean} [isRouter]
8889
* @property {boolean} [isEvaluator]
8990
* @property {boolean} [allowRouting]

src/lib/services/agent-service.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ export async function getSettings() {
1111
return response.data;
1212
}
1313

14+
/**
15+
* Get conversation list
16+
* @param {import('$types').ConversationFilter} filter
17+
* @returns {Promise<import('$types').PagedItems<import('$types').ConversationModel>>}
18+
*/
19+
1420
/**
1521
* Get agent list
1622
* @param {import('$types').AgentFilter} filter
17-
* @returns {Promise<import('$types').AgentModel[]>}
23+
* @returns {Promise<import('$types').PagedItems<import('$types').AgentModel>>}
1824
*/
1925
export async function getAgents(filter) {
2026
let url = endpoints.agentListUrl;
21-
const response = await axios.get(url, {
22-
params: filter
23-
});
27+
const response = await axios.post(url, { ...filter });
2428
return response.data;
2529
}
2630

src/routes/VerticalLayout/Sidebar.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { page } from '$app/stores';
77
import { browser } from '$app/environment';
88
import { _ } from 'svelte-i18n'
9+
import { isMenuButton } from 'svelte-jsoneditor';
910
1011
/** @type {import('$types').PluginMenuDefModel[]} */
1112
export let menu
@@ -131,6 +132,11 @@
131132
};
132133
133134
const removeActiveDropdown = () => {
135+
document.querySelectorAll('.vertical-menu .mm-active').forEach((menu) => {
136+
menu.querySelectorAll('.active').forEach(child => child.classList.remove('active'));
137+
menu.classList.remove('mm-active');
138+
});
139+
134140
document.querySelectorAll('.vertical-menu .has-arrow').forEach((menu) => {
135141
if (menu.nextElementSibling) {
136142
menu.nextElementSibling.classList.add('mm-collapse');

src/routes/chat/[agentId]/[conversationId]/chat-box.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import Swal from 'sweetalert2/dist/sweetalert2.js';
2323
import "sweetalert2/src/sweetalert2.scss";
2424
import { replaceNewLine } from '$lib/helpers/http';
25+
import _ from "lodash";
2526
2627
const options = {
2728
scrollbars: {
@@ -203,7 +204,7 @@
203204
</div>
204205
</div>
205206
206-
<div class="scrollbar" style="height: 75vh">
207+
<div class="scrollbar" style="height: 80vh">
207208
<div class="chat-conversation p-3">
208209
<ul class="list-unstyled mb-0">
209210
<li>
@@ -269,7 +270,7 @@
269270
</div>
270271
</div>
271272
272-
<div class="p-3 chat-input-section" style="height: 15vh">
273+
<div class="p-3 chat-input-section" style="height: 10vh">
273274
<div class="row">
274275
<div class="col-auto">
275276
<button
@@ -280,8 +281,8 @@
280281
</button>
281282
</div>
282283
<div class="col">
283-
<div class="position-relative">
284-
<textarea rows={3} maxlength={500} class="form-control chat-input" bind:value={text} on:keydown={e => onSendMessage(e)} placeholder="Enter Message..." />
284+
<div class="position-relative">
285+
<textarea rows={1} maxlength={500} class="form-control chat-input" bind:value={text} on:keydown={e => onSendMessage(e)} placeholder="Enter Message..." />
285286
<div class="chat-input-links" id="tooltip-container">
286287
<ul class="list-inline mb-0">
287288
<li class="list-inline-item">
@@ -295,8 +296,9 @@
295296
<button
296297
type="submit"
297298
class="btn btn-primary btn-rounded chat-send waves-effect waves-light"
299+
disabled={!!!_.trim(text)}
298300
on:click={sendTextMessage}
299-
><span class="d-none d-sm-inline-block me-2">Send</span>
301+
><span class="d-none d-sm-inline-block me-2">Send</span>
300302
<i class="mdi mdi-send" />
301303
</button>
302304
</div>

src/routes/page/agent/+page.svelte

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,79 @@
55
import CardAgent from './card-agent.svelte';
66
import { getAgents } from '$lib/services/agent-service.js';
77
import { onMount } from 'svelte';
8+
import PlainPagination from '$lib/common/PlainPagination.svelte';
89
9-
/** @type {import('$types').AgentModel[]} */
10-
let agents = [];
10+
const firstPage = 1;
11+
const pageSize = 12;
12+
13+
/** @type {import('$types').PagedItems<import('$types').AgentModel>} */
14+
let agents = { items: [], count: 0 };
15+
16+
/** @type {import('$types').AgentFilter} */
17+
const initFilter = {
18+
pager: { page: firstPage, size: pageSize, count: 0 },
19+
isEvaluator: false
20+
};
21+
22+
/** @type {import('$types').AgentFilter} */
23+
let filter = { ... initFilter };
24+
25+
/** @type {import('$types').Pagination} */
26+
let pager = filter.pager;
1127
1228
onMount(async () => {
13-
agents = await getAgents({
14-
isEvaluator: false
15-
});
29+
await getPagedAgents();
1630
});
31+
32+
async function getPagedAgents() {
33+
agents = await getAgents(filter);
34+
refresh();
35+
}
36+
37+
function refresh() {
38+
refreshAgents();
39+
refreshPager(agents.count, filter.pager.page, filter.pager.size);
40+
}
41+
42+
function refreshAgents() {
43+
agents = {
44+
items: agents?.items?.map(t => { return { ...t }; }) || [],
45+
count: agents?.count || 0
46+
};
47+
}
48+
49+
/** @param {number} totalItemsCount */
50+
function refreshPager(totalItemsCount, page = firstPage, pageCount = pageSize) {
51+
pager = {
52+
page: page,
53+
size: pageCount || 0,
54+
count: totalItemsCount || 0
55+
};
56+
}
57+
58+
/**
59+
* @param {number} pageNum
60+
*/
61+
function pageTo(pageNum) {
62+
pager = {
63+
...pager,
64+
page: pageNum
65+
};
66+
67+
filter = {
68+
...filter,
69+
pager: pager
70+
};
71+
72+
getPagedAgents();
73+
}
1774
</script>
1875
1976
<HeadTitle title="Agent List" />
20-
2177
<Breadcrumb title="Agent" pagetitle="List" />
2278
2379
<Row>
24-
<CardAgent agents={agents} />
25-
</Row>
80+
<CardAgent agents={agents.items} />
81+
</Row>
82+
83+
<PlainPagination pagination={pager} pageTo={pageTo} />

0 commit comments

Comments
 (0)