Skip to content

Commit 8d4f855

Browse files
authored
Merge pull request #262 from iceljc/features/refine-chat-window
add global event
2 parents dc8381a + 50c585c commit 8d4f855

File tree

10 files changed

+176
-23
lines changed

10 files changed

+176
-23
lines changed

src/lib/helpers/enums.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,10 @@ const userAction = {
127127
Edit: "edit",
128128
Chat: "chat"
129129
};
130-
export const UserAction = Object.freeze(userAction);
130+
export const UserAction = Object.freeze(userAction);
131+
132+
const globalEvent = {
133+
Search: "search",
134+
Chat: "chat"
135+
};
136+
export const GlobalEvent = Object.freeze(globalEvent);

src/lib/helpers/store.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const conversationUserStatesKey = "conversation_user_states";
88
const conversationSearchOptionKey = "conversation_search_option";
99
const conversationUserMessageKey = "conversation_user_messages";
1010

11+
/** @type {Writable<import('$commonTypes').GlobalEvent>} */
12+
export const globalEventStore = writable({ name: "", payload: {} });
13+
14+
1115
/** @type {Writable<import('$userTypes').UserModel>} */
1216
export const userStore = writable({ id: "", full_name: "", expires: 0, token: null });
1317

src/lib/helpers/types/agentTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* @typedef {Object} AgentFilter
2929
* @property {import('$commonTypes').Pagination} pager - Pagination
3030
* @property {string} [type]
31+
* @property {string} [agentName]
3132
* @property {boolean} [isPublic]
3233
* @property {boolean} [disabled]
3334
* @property {string[]} [agentIds]

src/lib/helpers/types/commonTypes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@
3131
*/
3232

3333

34+
/**
35+
* @typedef {Object} GlobalEvent
36+
* @property {string} name
37+
* @property {any} payload
38+
*/
39+
3440
export default {};

src/lib/scss/custom/pages/_users.scss

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
}
3333

3434
.basic-info {
35-
margin: 15px 0px 8px 0px;
35+
margin: 15px 0px 0px 0px;
3636
display: flex;
3737
flex-wrap: wrap;
3838

@@ -46,6 +46,32 @@
4646
}
4747
}
4848

49+
.user-permission-container {
50+
display: flex;
51+
gap: 5px;
52+
53+
.permission-wrapper {
54+
display: flex;
55+
flex-direction: column;
56+
gap: 3px;
57+
58+
.edit-wrapper {
59+
display: flex;
60+
gap: 3px;
61+
}
62+
63+
input[type="text"] {
64+
height: 30px;
65+
font-size: 12px;
66+
}
67+
}
68+
69+
70+
.list-add {
71+
font-size: 18px;
72+
}
73+
}
74+
4975
.user-agent-container {
5076
margin: 20px 0px;
5177
padding: 0px 2rem;

src/routes/VerticalLayout/Header.svelte

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
<script>
22
import { browser } from '$app/environment';
3-
import { Input, Dropdown, DropdownToggle, DropdownMenu, Row, Col } from '@sveltestrap/sveltestrap';
4-
import Link from 'svelte-link';
3+
import { _ } from 'svelte-i18n';
4+
import { Input } from '@sveltestrap/sveltestrap';
55
import LanguageDropdown from '$lib/common/LanguageDropdown.svelte';
66
import FullScreenDropdown from '$lib/common/FullScreenDropdown.svelte';
77
import NotificationDropdown from '$lib/common/NotificationDropdown.svelte';
88
import ProfileDropdown from '$lib/common/ProfileDropdown.svelte';
99
import { OverlayScrollbars } from 'overlayscrollbars';
1010
import { PUBLIC_LOGO_URL } from '$env/static/public';
11-
import { _ } from 'svelte-i18n'
12-
/**
13-
* @type {any}
14-
*/
11+
import { globalEventStore } from '$lib/helpers/store';
12+
import { GlobalEvent } from '$lib/helpers/enums';
13+
14+
/** @type {any} */
1515
export let user;
16-
export let toggleRightBar;
16+
17+
/** @type {() => void} */
18+
export let toggleRightBar = () => {};
19+
20+
/** @type {string} */
21+
let searchText = '';
1722
1823
const toggleSideBar = () => {
1924
if (browser) {
@@ -42,6 +47,13 @@
4247
}
4348
}
4449
};
50+
51+
/** @param {any} e */
52+
const search = (e) => {
53+
if (e.key !== 'Enter') return;
54+
55+
globalEventStore.set({ name: GlobalEvent.Search, payload: searchText });
56+
}
4557
</script>
4658

4759
<header id="page-topbar">
@@ -72,15 +84,22 @@
7284
type="button"
7385
class="btn btn-sm px-3 font-size-16 header-item waves-effect"
7486
id="vertical-menu-btn"
75-
on:click={toggleSideBar}
87+
on:click={() => toggleSideBar()}
7688
>
7789
<i class="fa fa-fw fa-bars" />
7890
</button>
7991

8092
<!-- App Search-->
8193
<form class="app-search d-none d-lg-block">
8294
<div class="position-relative">
83-
<Input type="text" class="form-control" placeholder="{$_('Search')}..." />
95+
<Input
96+
type="text"
97+
class="form-control"
98+
placeholder="{$_('Search')}..."
99+
maxlength={100}
100+
bind:value={searchText}
101+
on:keydown={e => search(e)}
102+
/>
84103
<span class="bx bx-search-alt" />
85104
</div>
86105
</form>

src/routes/VerticalLayout/Index.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
</script>
4040

4141
<div id="layout-wrapper">
42-
<Header user={user} {toggleRightBar} />
42+
<Header user={user} toggleRightBar={() => toggleRightBar()} />
4343
{#if menu}
4444
<Sidebar menu={menu}/>
4545
{/if}
@@ -52,5 +52,5 @@
5252
<Footer />
5353
</div>
5454

55-
<RightSidebar {closebar} />
55+
<RightSidebar closebar={() => closebar()} />
5656
</div>

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { onMount } from 'svelte';
2+
import { onDestroy, onMount } from 'svelte';
33
import { Button, Col, Row } from '@sveltestrap/sveltestrap';
44
import Breadcrumb from '$lib/common/Breadcrumb.svelte';
55
import HeadTitle from '$lib/common/HeadTitle.svelte';
@@ -11,8 +11,9 @@
1111
import { _ } from 'svelte-i18n'
1212
import { goto } from '$app/navigation';
1313
import Swal from 'sweetalert2';
14-
import { UserPermission } from '$lib/helpers/enums';
14+
import { GlobalEvent, UserPermission } from '$lib/helpers/enums';
1515
import { ADMIN_ROLES } from '$lib/helpers/constants';
16+
import { globalEventStore } from '$lib/helpers/store';
1617
1718
1819
const firstPage = 1;
@@ -38,9 +39,26 @@
3839
/** @type {import('$userTypes').UserModel} */
3940
let user;
4041
42+
/** @type {any} */
43+
let unsubscriber;
44+
4145
onMount(async () => {
4246
user = await myInfo();
4347
getPagedAgents();
48+
49+
unsubscriber = globalEventStore.subscribe((/** @type {import('$commonTypes').GlobalEvent} */ event) => {
50+
if (event.name !== GlobalEvent.Search) return;
51+
52+
filter = {
53+
pager: { page: firstPage, size: pageSize, count: 0 },
54+
agentName: event.payload || null
55+
};
56+
getPagedAgents();
57+
});
58+
});
59+
60+
onDestroy(() => {
61+
unsubscriber?.();
4462
});
4563
4664
function getPagedAgents() {

src/routes/page/users/+page.svelte

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script>
2-
import { onMount } from 'svelte';
2+
import { onDestroy, onMount } from 'svelte';
33
import {
44
Button,
55
Card,
@@ -19,6 +19,8 @@
1919
import { getUsers, updateUser } from '$lib/services/user-service';
2020
import UserItem from './user-item.svelte';
2121
import { getAgents } from '$lib/services/agent-service';
22+
import { globalEventStore } from '$lib/helpers/store';
23+
import { GlobalEvent } from '$lib/helpers/enums';
2224
2325
const duration = 3000;
2426
const firstPage = 1;
@@ -45,6 +47,9 @@
4547
/** @type {import('$commonTypes').IdName[]} */
4648
let agents = [];
4749
50+
/** @type {any} */
51+
let unsubscriber;
52+
4853
let searchOption = {
4954
userName: '',
5055
externalId: '',
@@ -53,13 +58,33 @@
5358
};
5459
5560
onMount(async () => {
56-
isLoading = true;
61+
init();
62+
63+
unsubscriber = globalEventStore.subscribe((/** @type {import('$commonTypes').GlobalEvent} */ event) => {
64+
if (event.name !== GlobalEvent.Search) return;
65+
66+
const userNames = event.payload ? [event.payload] : undefined;
67+
filter = {
68+
page: firstPage,
69+
size: pageSize,
70+
user_names: userNames
71+
};
72+
getPagedUsers();
73+
});
74+
});
75+
76+
onDestroy(() => {
77+
unsubscriber?.();
78+
});
79+
80+
function init() {
81+
isLoading = true;
5782
getPagedAgents().then(() => {
5883
getPagedUsers().then(() => {
5984
isLoading = false;
6085
});
6186
});
62-
});
87+
}
6388
6489
function getPagedUsers() {
6590
userItems = [];

src/routes/page/users/user-item.svelte

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,28 @@
192192
const updated = {
193193
...innerItem,
194194
role: lodash.trim(innerItem.role),
195+
permissions: innerItem.permissions.filter(x => x?.length > 0),
195196
agent_actions: list
196197
};
197198
innerItem = { ...updated };
198199
return updated;
199200
}
201+
202+
function addPermission() {
203+
innerItem = {
204+
...innerItem,
205+
permissions: [ ...innerItem.permissions, '' ]
206+
};
207+
}
208+
209+
/** @param {number} index */
210+
function deletePermission(index) {
211+
const permissions = innerItem.permissions.filter((_, idx) => idx !== index);
212+
innerItem = {
213+
...innerItem,
214+
permissions: permissions
215+
};
216+
}
200217
</script>
201218
202219
<tr in:fly={{ y: -5, duration: 800 }}>
@@ -283,15 +300,46 @@
283300
</div>
284301
</li>
285302
{/if}
286-
{#if item.permissions}
303+
</ul>
304+
<ul>
287305
<li>
288-
<div class="wrappable">
289-
<span class="fw-bold text-primary">{'Permissions:'}</span>
290-
<span>{item.permissions?.length > 0 ? item.permissions.join(', ') : 'N/A'}</span>
306+
<div class="user-permission-container">
307+
<div class="fw-bold text-primary">{'Permissions:'}</div>
308+
<div class="permission-wrapper">
309+
{#each innerItem.permissions as permission, index}
310+
<div class="edit-wrapper">
311+
<Input
312+
type="text"
313+
class="edit-text-box"
314+
bind:value={permission}
315+
/>
316+
<div class="line-align-center">
317+
<i
318+
class="bx bxs-no-entry text-danger"
319+
role="link"
320+
tabindex="0"
321+
on:keydown={() => {}}
322+
on:click={() => deletePermission(index)}
323+
/>
324+
</div>
325+
</div>
326+
{/each}
327+
{#if innerItem.permissions?.length < 5}
328+
<div class="list-add line-align-center">
329+
<i
330+
class="bx bx bx-list-plus text-primary clickable"
331+
role="link"
332+
tabindex="0"
333+
on:keydown={() => {}}
334+
on:click={() => addPermission()}
335+
/>
336+
</div>
337+
{/if}
338+
</div>
291339
</div>
292340
</li>
293-
{/if}
294341
</ul>
342+
295343
{#if innerActions.length > 0}
296344
<div class="user-agent-container">
297345
<div class="action-row action-title">

0 commit comments

Comments
 (0)