Skip to content

Commit 0d9c9c5

Browse files
authored
Merge pull request #218 from iceljc/features/refine-chat-window
add adv search
2 parents 6a37233 + 691fcef commit 0d9c9c5

File tree

11 files changed

+345
-107
lines changed

11 files changed

+345
-107
lines changed

src/lib/helpers/enums.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ const knowledgePayloadName = {
8080
DataSource: 'dataSource',
8181
FileId: 'fileId',
8282
FileName: 'fileName',
83-
FileSource: 'fileSource'
83+
FileSource: 'fileSource',
84+
FileUrl: 'fileUrl'
8485
};
8586
export const KnowledgePayloadName = Object.freeze(knowledgePayloadName);
8687

src/lib/helpers/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function skipLoader(config) {
6060
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/page', 'g'),
6161
new RegExp('http(s*)://(.*?)/knowledge/(.*?)/search', 'g'),
6262
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/create', 'g'),
63-
new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/list', 'g')
63+
new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/page', 'g')
6464
];
6565

6666
const putRegexes = [

src/lib/scss/custom/pages/_knowledgebase.scss

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@
173173
white-space: wrap !important;
174174
}
175175

176+
.more-detail-item {
177+
.link {
178+
color: var(--bs-primary);
179+
180+
&:hover {
181+
text-decoration: underline;
182+
}
183+
}
184+
}
185+
176186
.more-detail {
177187
margin: 2px 0px;
178188
padding-left: 2rem;
@@ -297,4 +307,55 @@
297307
border-radius: 10px;
298308
padding: 10px;
299309
background-color: var(--bs-light);
300-
}
310+
}
311+
312+
.knowledge-adv-search-container {
313+
.knowledge-adv-search-btn {
314+
display: flex;
315+
justify-content: flex-start;
316+
gap: 10px;
317+
font-size: 18px;
318+
319+
input {
320+
outline: none !important;
321+
box-shadow: none !important;
322+
}
323+
}
324+
325+
.knowledge-adv-search-items {
326+
margin-top: 15px;
327+
display: flex;
328+
flex-direction: column;
329+
gap: 10px;
330+
331+
.knowledge-adv-search-item {
332+
display: flex;
333+
gap: 10px;
334+
335+
.search-item-cb {
336+
flex: 0 0 20px;
337+
338+
.form-check {
339+
font-size: 15px;
340+
margin-bottom: 0.125rem;
341+
}
342+
343+
input[type="checkbox"] {
344+
outline: none !important;
345+
box-shadow: none !important;
346+
}
347+
}
348+
349+
.search-item-name {
350+
font-size: 15px;
351+
flex: 0 0 100px;
352+
}
353+
354+
.search-item-content {
355+
flex: 0.3;
356+
min-width: 150px;
357+
max-width: 350px;
358+
}
359+
}
360+
}
361+
}

src/lib/services/api-endpoints.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const endpoints = {
6060

6161
// knowledge base
6262
vectorKnowledgeCollectionsUrl: `${host}/knowledge/vector/collections`,
63-
vectorKnowledgePageDataUrl: `${host}/knowledge/vector/{collection}/page`,
63+
vectorKnowledgePageListUrl: `${host}/knowledge/vector/{collection}/page`,
6464
vectorKnowledgeSearchUrl: `${host}/knowledge/vector/{collection}/search`,
6565
vectorKnowledgeCreateUrl: `${host}/knowledge/vector/{collection}/create`,
6666
vectorKnowledgeUpdateUrl: `${host}/knowledge/vector/{collection}/update`,
@@ -74,7 +74,7 @@ export const endpoints = {
7474

7575
knowledgeDocumentUploadUrl: `${host}/knowledge/document/{collection}/upload`,
7676
knowledgeDocumentDeleteUrl: `${host}/knowledge/document/{collection}/delete/{fileId}`,
77-
knowledgeDocumentListUrl: `${host}/knowledge/document/{collection}/list`,
77+
knowledgeDocumentPageListUrl: `${host}/knowledge/document/{collection}/page`,
7878

7979
// chathub
8080
chatHubUrl: `${host}/chatHub`,

src/lib/services/knowledge-base-service.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export async function getVectorKnowledgeCollections(type) {
1717
}
1818

1919
/**
20-
* @param {import('$knowledgeTypes').SearchKnowledgeRequest} request
2120
* @param {string} collection
21+
* @param {import('$knowledgeTypes').SearchKnowledgeRequest} request
2222
* @returns {Promise<import('$knowledgeTypes').KnowledgeSearchViewModel[]>}
2323
*/
24-
export async function searchVectorKnowledge(request, collection) {
24+
export async function searchVectorKnowledge(collection, request) {
2525
const url = replaceUrl(endpoints.vectorKnowledgeSearchUrl, {
2626
collection: collection
2727
});
@@ -31,12 +31,12 @@ export async function searchVectorKnowledge(request, collection) {
3131
}
3232

3333
/**
34-
* @param {import('$knowledgeTypes').KnowledgeFilter} filter
3534
* @param {string} collection
35+
* @param {import('$knowledgeTypes').KnowledgeFilter} filter
3636
* @returns {Promise<import('$knowledgeTypes').KnowledgeSearchPageResult>}
3737
*/
38-
export async function getPagedVectorKnowledgeData(filter, collection) {
39-
const url = replaceUrl(endpoints.vectorKnowledgePageDataUrl, {
38+
export async function getVectorKnowledgePageList(collection, filter) {
39+
const url = replaceUrl(endpoints.vectorKnowledgePageListUrl, {
4040
collection: collection
4141
});
4242

@@ -96,11 +96,11 @@ export async function updateVectorKnowledgeData(id, collection, text, dataSource
9696

9797

9898
/**
99-
* @param {string} id
10099
* @param {string} collection
100+
* @param {string} id
101101
* @returns {Promise<boolean>}
102102
*/
103-
export async function deleteVectorKnowledgeData(id, collection) {
103+
export async function deleteVectorKnowledgeData(collection, id) {
104104
const url = replaceUrl(endpoints.vectorKnowledgeDeleteUrl, {
105105
collection: collection,
106106
id: id
@@ -160,8 +160,8 @@ export async function deleteKnowledgeDocument(collection, fileId) {
160160
* @param {import('$knowledgeTypes').KnowledgeDocRequest} request
161161
* @returns {Promise<import('$knowledgeTypes').KnowledgeDocPagedResult>}
162162
*/
163-
export async function getKnowledgeDocuments(collection, request) {
164-
const url = replaceUrl(endpoints.knowledgeDocumentListUrl, {
163+
export async function getKnowledgeDocumentPageList(collection, request) {
164+
const url = replaceUrl(endpoints.knowledgeDocumentPageListUrl, {
165165
collection: collection
166166
});
167167

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<script>
2+
import { onMount, onDestroy } from 'svelte';
3+
import { fly } from 'svelte/transition';
4+
import { Input, Tooltip } from '@sveltestrap/sveltestrap';
5+
import util from "lodash";
6+
7+
8+
const maxLength = 50;
9+
10+
/** @type {{ key: string, displayName: string }[]} */
11+
export let items;
12+
13+
/** @type {boolean} */
14+
export let disabled = false;
15+
16+
17+
/** @type {boolean} */
18+
let showAdvSearch = false;
19+
20+
/** @type {any[]} */
21+
let innerItems = [];
22+
23+
24+
onMount(() => {
25+
init();
26+
});
27+
28+
onDestroy(() => {
29+
reset();
30+
});
31+
32+
function init() {
33+
showAdvSearch = false;
34+
reset();
35+
}
36+
37+
38+
/** @param {any} e */
39+
function toggleAdvSearch(e) {
40+
showAdvSearch = e.target.checked;
41+
if (!showAdvSearch) {
42+
reset();
43+
}
44+
}
45+
46+
function reset() {
47+
innerItems = items?.map(x => {
48+
return {
49+
key: x.key,
50+
checked: false,
51+
displayName: x.displayName,
52+
value: ''
53+
};
54+
}) || [];
55+
}
56+
57+
58+
/**
59+
* @param {number} idx
60+
* @param {any} e
61+
*/
62+
function toggleItemCheckbox(idx, e) {
63+
const found = innerItems.find((_, index) => index === idx);
64+
if (found) {
65+
found.checked = e.target.checked;
66+
innerItems = innerItems.map((x, index) => {
67+
return index === idx ? { ...found } : x;
68+
});
69+
}
70+
}
71+
72+
/**
73+
* @param {number} idx
74+
* @param {any} e
75+
*/
76+
function changeItemValue(idx, e) {
77+
const found = innerItems.find((_, index) => index === idx);
78+
if (found) {
79+
found.value = e.target.value;
80+
innerItems = innerItems.map((x, index) => {
81+
return index === idx ? { ...found } : x;
82+
});
83+
}
84+
}
85+
</script>
86+
87+
88+
<div
89+
class="knowledge-adv-search-container"
90+
in:fly={{ y: -10, duration: 500 }}
91+
out:fly={{ y: -10, duration: 200 }}
92+
>
93+
<div class="knowledge-adv-search-btn text-primary fw-bold">
94+
<Input
95+
type="switch"
96+
disabled={disabled}
97+
checked={showAdvSearch}
98+
on:change={e => toggleAdvSearch(e)}
99+
/>
100+
<div class="line-align-center">
101+
<div>{'Advance Search'}</div>
102+
</div>
103+
{#if showAdvSearch}
104+
<div class="line-align-center" id="adv-search-tooltip">
105+
<i class="bx bx-info-circle" />
106+
</div>
107+
<Tooltip target="adv-search-tooltip" placement="top" class="demo-tooltip-note">
108+
<ul>
109+
<li>{'Select the checkbox to enable seaching in each field.'}</li>
110+
<li>{'Empty value will not be used to search.'}</li>
111+
</ul>
112+
</Tooltip>
113+
{/if}
114+
</div>
115+
116+
{#if showAdvSearch}
117+
<div
118+
class={'knowledge-adv-search-items'}
119+
in:fly={{ y: -10, duration: 500 }}
120+
out:fly={{ y: -10, duration: 200 }}
121+
>
122+
{#each innerItems as item, idx (idx)}
123+
<div class="knowledge-adv-search-item">
124+
<div class="search-item-cb line-align-center">
125+
<Input
126+
type="checkbox"
127+
disabled={disabled}
128+
checked={item.checked}
129+
on:change={e => toggleItemCheckbox(idx, e)}
130+
/>
131+
</div>
132+
<div class="search-item-name fw-bold line-align-center">
133+
<div>{`${item.displayName}:`}</div>
134+
</div>
135+
<div class="search-item-content line-align-center">
136+
<Input
137+
type="text"
138+
disabled={!item.checked || disabled}
139+
maxlength={maxLength}
140+
value={item.value}
141+
on:input={e => changeItemValue(idx, e)}
142+
/>
143+
</div>
144+
</div>
145+
{/each}
146+
</div>
147+
{/if}
148+
</div>

0 commit comments

Comments
 (0)