|
11 | 11 | import { _ } from 'svelte-i18n' |
12 | 12 | import { goto } from '$app/navigation'; |
13 | 13 | import Swal from 'sweetalert2'; |
14 | | - import { GlobalEvent, UserPermission } from '$lib/helpers/enums'; |
| 14 | + import { AgentType, GlobalEvent, UserPermission } from '$lib/helpers/enums'; |
15 | 15 | import { ADMIN_ROLES } from '$lib/helpers/constants'; |
16 | 16 | import { globalEventStore } from '$lib/helpers/store'; |
| 17 | + import MultiSelect from '$lib/common/MultiSelect.svelte'; |
17 | 18 | |
18 | 19 | |
19 | 20 | const firstPage = 1; |
|
42 | 43 | /** @type {any} */ |
43 | 44 | let unsubscriber; |
44 | 45 |
|
| 46 | + let agentTypeOptions = Object.entries(AgentType).map(([k, v]) => ( |
| 47 | + { key: k, value: v } |
| 48 | + )); |
| 49 | +
|
| 50 | + /** @type {string[]} */ |
| 51 | + let selectedAgentTypes = []; |
| 52 | +
|
45 | 53 | onMount(async () => { |
46 | 54 | user = await myInfo(); |
47 | 55 | getPagedAgents(); |
|
50 | 58 | if (event.name !== GlobalEvent.Search) return; |
51 | 59 |
|
52 | 60 | filter = { |
53 | | - pager: { page: firstPage, size: pageSize, count: 0 }, |
| 61 | + pager: initFilter.pager, |
| 62 | + types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null, |
54 | 63 | similarName: event.payload || null |
55 | 64 | }; |
56 | 65 | getPagedAgents(); |
|
138 | 147 |
|
139 | 148 | getPagedAgents(); |
140 | 149 | } |
| 150 | +
|
| 151 | + |
| 152 | + /** |
| 153 | + * @param {any} e |
| 154 | + */ |
| 155 | + function selectAgentTypeOption(e) { |
| 156 | + // @ts-ignore |
| 157 | + selectedAgentTypes = e.detail.selecteds?.map(x => x.value) || []; |
| 158 | + } |
| 159 | +
|
| 160 | + function searchAgents() { |
| 161 | + filter = { |
| 162 | + ...filter, |
| 163 | + types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null, |
| 164 | + pager: initFilter.pager |
| 165 | + }; |
| 166 | + getPagedAgents(); |
| 167 | + } |
141 | 168 | </script> |
142 | 169 |
|
143 | 170 | <HeadTitle title="{$_('List')}" /> |
144 | 171 | <Breadcrumb title="{$_('Agent')}" pagetitle="{$_('List')}" /> |
145 | 172 | <LoadingToComplete isLoading={isLoading} /> |
146 | 173 |
|
147 | | -{#if !!user && (ADMIN_ROLES.includes(user.role || '') || !!user.permissions?.includes(UserPermission.CreateAgent))} |
148 | | -<Button class="mb-4" color="primary" on:click={() => createNewAgent()}> |
149 | | - <i class="bx bx-copy" /> {$_('New Agent')} |
150 | | -</Button> |
151 | | -{/if} |
| 174 | +<div class="agents-header-container mb-4"> |
| 175 | + <div> |
| 176 | + {#if !!user && (ADMIN_ROLES.includes(user.role || '') || !!user.permissions?.includes(UserPermission.CreateAgent))} |
| 177 | + <Button color="primary" on:click={() => createNewAgent()}> |
| 178 | + <i class="bx bx-copy" /> {$_('New Agent')} |
| 179 | + </Button> |
| 180 | + {/if} |
| 181 | + </div> |
| 182 | + <div class="agent-filter"> |
| 183 | + <MultiSelect |
| 184 | + tag={'agent-label-select'} |
| 185 | + placeholder={'Select agent labels'} |
| 186 | + selectedText={'labels'} |
| 187 | + options={[]} |
| 188 | + on:select={e => {}} |
| 189 | + /> |
| 190 | + <MultiSelect |
| 191 | + tag={'agent-type-select'} |
| 192 | + placeholder={'Select agent types'} |
| 193 | + selectedText={'types'} |
| 194 | + options={agentTypeOptions} |
| 195 | + on:select={e => selectAgentTypeOption(e)} |
| 196 | + /> |
| 197 | + <Button |
| 198 | + class="btn btn-light" |
| 199 | + on:click={(e) => searchAgents()} |
| 200 | + > |
| 201 | + <i class="mdi mdi-magnify" /> |
| 202 | + </Button> |
| 203 | + </div> |
| 204 | +</div> |
| 205 | +
|
152 | 206 |
|
153 | 207 | <Row> |
154 | 208 | <CardAgent agents={agents.items} /> |
|
0 commit comments