Spaces:
Sleeping
Sleeping
Update templates/knowledgebase.html
Browse files- templates/knowledgebase.html +760 -666
templates/knowledgebase.html
CHANGED
@@ -1,667 +1,761 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html>
|
3 |
-
|
4 |
-
<head>
|
5 |
-
<title>Knowledge Base</title>
|
6 |
-
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
7 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
8 |
-
<!-- Include AdminLTE CSS -->
|
9 |
-
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
|
10 |
-
<!-- Include DataTables CSS -->
|
11 |
-
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
|
12 |
-
<!-- Include AdminLTE JS -->
|
13 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/adminlte.min.js"></script>
|
14 |
-
<!-- Include DataTables JS -->
|
15 |
-
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
|
16 |
-
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
|
17 |
-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
|
18 |
-
<style>
|
19 |
-
body {
|
20 |
-
background-color: transparent !important;
|
21 |
-
}
|
22 |
-
.content-wrapper{
|
23 |
-
flex: 1;
|
24 |
-
overflow-y: auto;
|
25 |
-
}
|
26 |
-
|
27 |
-
.wrapper {
|
28 |
-
display: flex;
|
29 |
-
flex-direction: column;
|
30 |
-
height: 100vh;
|
31 |
-
}
|
32 |
-
|
33 |
-
|
34 |
-
.modal-content {
|
35 |
-
background-color: #fff;
|
36 |
-
}
|
37 |
-
|
38 |
-
.content-header {
|
39 |
-
padding: 1rem;
|
40 |
-
}
|
41 |
-
|
42 |
-
h1 {
|
43 |
-
text-align: center;
|
44 |
-
margin-bottom: 30px;
|
45 |
-
}
|
46 |
-
|
47 |
-
.card {
|
48 |
-
padding: 0;
|
49 |
-
margin-top: -15px;
|
50 |
-
margin-left: -40px;
|
51 |
-
}
|
52 |
-
|
53 |
-
.table-responsive {
|
54 |
-
width: 100%;
|
55 |
-
overflow-x: auto;
|
56 |
-
/*overflow-y: scroll;*/
|
57 |
-
/* Allows horizontal scrolling if necessary */
|
58 |
-
}
|
59 |
-
|
60 |
-
.table,
|
61 |
-
.table-bordered {
|
62 |
-
width: 100%;
|
63 |
-
border-collapse: collapse;
|
64 |
-
margin-right: 7.5px;
|
65 |
-
}
|
66 |
-
|
67 |
-
|
68 |
-
.text-wrap {
|
69 |
-
white-space: normal !important;
|
70 |
-
word-break: break-word;
|
71 |
-
}
|
72 |
-
div.dataTables_wrapper div.dataTables_length select{
|
73 |
-
width: 60px;
|
74 |
-
display: inline-block;
|
75 |
-
}
|
76 |
-
|
77 |
-
th {
|
78 |
-
white-space: nowrap;
|
79 |
-
}
|
80 |
-
|
81 |
-
th:nth-child(1),
|
82 |
-
td:nth-child(1) {
|
83 |
-
/* Sno column */
|
84 |
-
width: 2%;
|
85 |
-
}
|
86 |
-
|
87 |
-
th:nth-child(2),
|
88 |
-
td:nth-child(2) {
|
89 |
-
/* Document Name column */
|
90 |
-
width: auto;
|
91 |
-
}
|
92 |
-
|
93 |
-
th:nth-child(3),
|
94 |
-
td:nth-child(3) {
|
95 |
-
/* Document Description column */
|
96 |
-
width: auto;
|
97 |
-
}
|
98 |
-
|
99 |
-
th:nth-child(4),
|
100 |
-
td:nth-child(4) {
|
101 |
-
/* Document Version column */
|
102 |
-
width: 20%;
|
103 |
-
}
|
104 |
-
|
105 |
-
th:nth-child(5),
|
106 |
-
td:nth-child(5) {
|
107 |
-
/* VectorDB Flag column */
|
108 |
-
width: auto;
|
109 |
-
}
|
110 |
-
|
111 |
-
th:nth-child(6),
|
112 |
-
td:nth-child(6) {
|
113 |
-
/* View column */
|
114 |
-
width: 10%;
|
115 |
-
}
|
116 |
-
|
117 |
-
th:nth-child(7),
|
118 |
-
td:nth-child(7) {
|
119 |
-
/* Edit column */
|
120 |
-
width: 10%;
|
121 |
-
}
|
122 |
-
|
123 |
-
th:nth-child(8),
|
124 |
-
td:nth-child(8) {
|
125 |
-
/* Delete column */
|
126 |
-
width: auto;
|
127 |
-
}
|
128 |
-
.alert {
|
129 |
-
position: relative;
|
130 |
-
padding: 15px;
|
131 |
-
margin-bottom: 20px;
|
132 |
-
border: 1px solid transparent;
|
133 |
-
border-radius: 4px;
|
134 |
-
}
|
135 |
-
|
136 |
-
.alert-success {
|
137 |
-
color: #3c763d;
|
138 |
-
background-color: #dff0d8;
|
139 |
-
border-color: #d6e9c6;
|
140 |
-
}
|
141 |
-
|
142 |
-
.alert-danger {
|
143 |
-
color: #a94442;
|
144 |
-
background-color: #f2dede;
|
145 |
-
border-color: #ebccd1;
|
146 |
-
}
|
147 |
-
|
148 |
-
.close {
|
149 |
-
position: absolute;
|
150 |
-
bottom: 10px;
|
151 |
-
right: 10px;
|
152 |
-
border: none;
|
153 |
-
background: none;
|
154 |
-
font-size: 16px;
|
155 |
-
cursor: pointer;
|
156 |
-
}
|
157 |
-
|
158 |
-
</style>
|
159 |
-
</head>
|
160 |
-
|
161 |
-
<body>
|
162 |
-
{% include 'sidepane.html' %}
|
163 |
-
<div class="wrapper">
|
164 |
-
<div class="main-header" style="border-bottom: none;">
|
165 |
-
<div class="container mt-2">
|
166 |
-
<div class="form-group left-align" >
|
167 |
-
<label for="company" class="mr-1" style="margin-left:-40px; margin-top: 12px;">Company Name <span class="text-danger">*</span></label>
|
168 |
-
<select type="text" id="company" name="company" class="form-control" style="width:20%;margin-left:-40px;"required>
|
169 |
-
<option value="" selected>Select</option>
|
170 |
-
</select>
|
171 |
-
<div class="col-12 d-flex justify-content-end mb-3">
|
172 |
-
<button class="btn btn-primary" style="margin-top:-40px;margin-right: -10px;position: fixed;"
|
173 |
-
id="add" data-action="add">Add</button>
|
174 |
-
</div>
|
175 |
-
</div>
|
176 |
-
</div>
|
177 |
-
<div class="row">
|
178 |
-
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
|
179 |
-
</div>
|
180 |
-
|
181 |
-
<section class="content" id="contentSection" style="display: none;">
|
182 |
-
<div class="container-fluid">
|
183 |
-
<div>
|
184 |
-
<div class="form-group">
|
185 |
-
<!-- <label for="company_id">company_id</label>--->
|
186 |
-
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
|
187 |
-
</div>
|
188 |
-
<div class="row">
|
189 |
-
<div class="col-12">
|
190 |
-
<div class="card">
|
191 |
-
<div id="message-container">
|
192 |
-
<div class="card-body table-container">
|
193 |
-
<table id="knowledgeTable" class="table table-bordered table-striped">
|
194 |
-
<thead>
|
195 |
-
<tr>
|
196 |
-
|
197 |
-
<th>Sno</th>
|
198 |
-
<th>Document Name</th>
|
199 |
-
<th>Document Description</th>
|
200 |
-
<th>Document Version</th>
|
201 |
-
<th>VectorDB Flag</th>
|
202 |
-
<th>View</th>
|
203 |
-
<th>Edit</th>
|
204 |
-
<th>Delete</th>
|
205 |
-
<!-- <th style="display:none;">Company ID</th> -->
|
206 |
-
</tr>
|
207 |
-
</thead>
|
208 |
-
<tbody>
|
209 |
-
|
210 |
-
</tbody>
|
211 |
-
</table>
|
212 |
-
</div>
|
213 |
-
</div>
|
214 |
-
</div>
|
215 |
-
</div>
|
216 |
-
</div>
|
217 |
-
</section>
|
218 |
-
</div>
|
219 |
-
|
220 |
-
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
|
221 |
-
aria-hidden="true">
|
222 |
-
<div class="modal-dialog" role="document">
|
223 |
-
<div class="modal-content">
|
224 |
-
<div class="modal-header">
|
225 |
-
<h5 class="modal-title" id="addModalLabel">Add Document Details</h5>
|
226 |
-
<button type="button" class="btn-close" data-dismiss="modal" >
|
227 |
-
<span aria-hidden="true" data-backdrop="static" data-keyboard="false"></span>
|
228 |
-
</button>
|
229 |
-
</div>
|
230 |
-
<div class="modal-body">
|
231 |
-
<div class="form-group">
|
232 |
-
<!-- <label for="company_id">company_id</label>--->
|
233 |
-
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
|
234 |
-
</div>
|
235 |
-
<form id="documentForm">
|
236 |
-
<div class="form-group">
|
237 |
-
<label for="uploadFile">Upload File<span class="text-danger">*</span></label>
|
238 |
-
<span id="file-name"></span>
|
239 |
-
<input type="hidden" id="file_name" name="file_name" class="form-control" required>
|
240 |
-
<input type="file" class="form-control-file" id="uploadFile" name="uploadFile" required
|
241 |
-
accept=".pdf,.doc,.docx">
|
242 |
-
<small class="form-text text-muted">Accepted formats: .pdf, .doc, .docx</small>
|
243 |
-
</div>
|
244 |
-
<div class="form-group">
|
245 |
-
<label for="documentName">Document Name<span class="text-danger">*</span></label>
|
246 |
-
<input type="text" class="form-control" id="documentName" name="documentName" required>
|
247 |
-
</div>
|
248 |
-
<div class="form-group">
|
249 |
-
<label for="documentDescription">Document Description<span
|
250 |
-
class="text-danger">*</span></label>
|
251 |
-
<textarea class="form-control" id="documentDescription" name="documentDescription"
|
252 |
-
rows="3" required></textarea>
|
253 |
-
</div>
|
254 |
-
<div class="form-group">
|
255 |
-
<label for="department">Department<span class="text-danger">*</span></label>
|
256 |
-
<input type="text" class="form-control" id="department" name="department" required>
|
257 |
-
</div>
|
258 |
-
<div class="form-group">
|
259 |
-
<label for="version">Version<span class="text-danger">*</span></label>
|
260 |
-
<input type="text" class="form-control" id="version" name="version" required>
|
261 |
-
</div>
|
262 |
-
<div class="form-group">
|
263 |
-
<label for="lastUpdated">Last Updated<span class="text-danger">*</span></label>
|
264 |
-
<input type="text" class="form-control" id="lastUpdated" name="lastUpdated" required>
|
265 |
-
</div>
|
266 |
-
</form>
|
267 |
-
</div>
|
268 |
-
<div class="modal-footer">
|
269 |
-
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> -->
|
270 |
-
<button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button>
|
271 |
-
<button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
|
272 |
-
</div>
|
273 |
-
</div>
|
274 |
-
</div>
|
275 |
-
</div>
|
276 |
-
</div>
|
277 |
-
|
278 |
-
{%include 'footer.html'%}
|
279 |
-
|
280 |
-
<!-- JavaScript to handle modal display -->
|
281 |
-
<script>
|
282 |
-
document.addEventListener("DOMContentLoaded", function () {
|
283 |
-
now = new Date().toISOString().replace('T', ' ').substr(0, 19);
|
284 |
-
document.getElementById('lastUpdated').value = now;
|
285 |
-
const inputs = document.querySelectorAll("#documentForm input, textarea");
|
286 |
-
|
287 |
-
inputs.forEach((input, index) => {
|
288 |
-
input.addEventListener("keydown", function (event) {
|
289 |
-
if (event.key === "Enter") {
|
290 |
-
event.preventDefault();
|
291 |
-
moveToNextInput(inputs, index);
|
292 |
-
}
|
293 |
-
});
|
294 |
-
});
|
295 |
-
|
296 |
-
function moveToNextInput(inputs, currentIndex) {
|
297 |
-
const nextInput = inputs[currentIndex + 1];
|
298 |
-
if (nextInput) {
|
299 |
-
nextInput.focus();
|
300 |
-
} else {
|
301 |
-
// Optionally, submit the form or trigger the save button
|
302 |
-
document.getElementById("save").focus();
|
303 |
-
}
|
304 |
-
}
|
305 |
-
// $(document).on('click', '.btn-view', function () {
|
306 |
-
// const companyId = $(this).data('id');
|
307 |
-
// console.log("company_id in view",companyId);
|
308 |
-
// viewCompany(companyId);
|
309 |
-
// });
|
310 |
-
|
311 |
-
// // Edit
|
312 |
-
// $(document).on('click', '.btn-edit', function () {
|
313 |
-
// const companyId = $(this).data('id');
|
314 |
-
// console.log("company_id in edit",companyId);
|
315 |
-
// editCompany(companyId);
|
316 |
-
// });
|
317 |
-
|
318 |
-
// // Delete company
|
319 |
-
// $(document).on('click', '.btn-delete', function () {
|
320 |
-
// const kid = $(this).data('id'); // Get the company ID from the da
|
321 |
-
// console.log("company_id in delete",kid);
|
322 |
-
// if (confirm("Are you sure you want to delete this company?")) {
|
323 |
-
// deleteCompany(kid); // Call the delete function with the company ID
|
324 |
-
// }
|
325 |
-
// });
|
326 |
-
fetchCompanies();
|
327 |
-
|
328 |
-
const companySelect = document.getElementById('company');
|
329 |
-
const documentForm = document.getElementById('documentForm');
|
330 |
-
const table = $('#knowledgeTable').DataTable(); // Initialize DataTable at the start
|
331 |
-
|
332 |
-
companySelect.addEventListener('change', async function () {
|
333 |
-
$("#message-container").empty();
|
334 |
-
const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
|
335 |
-
console.log(`Selected Company Name: ${selectedCompanyName}`);
|
336 |
-
|
337 |
-
if (selectedCompanyName !== "Select") {
|
338 |
-
try {
|
339 |
-
const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
|
340 |
-
if (!response.ok) {
|
341 |
-
contentSection.style.display = 'none';
|
342 |
-
displayErrorMessage("
|
343 |
-
throw new Error('Network response was not ok');
|
344 |
-
}
|
345 |
-
const data = await response.json();
|
346 |
-
console.log('data returned', data);
|
347 |
-
const companyId = data.company_id;
|
348 |
-
document.getElementById('company_id').value = companyId;
|
349 |
-
|
350 |
-
if (companyId) {
|
351 |
-
try {
|
352 |
-
const Response = await fetch(`/api/document_upload?company_id=${companyId}&company_name=${selectedCompanyName}`);
|
353 |
-
const connectorsResponse = await Response.json();
|
354 |
-
console.log("knowledge data table after connecting to table", connectorsResponse);
|
355 |
-
table.clear();
|
356 |
-
if (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {
|
357 |
-
//displayEmptyTable();
|
358 |
-
|
359 |
-
displayErrorMessage("
|
360 |
-
contentSection.style.display = 'none';
|
361 |
-
} else {
|
362 |
-
|
363 |
-
connectorsResponse.forEach((company, index) => {
|
364 |
-
table.row.add([
|
365 |
-
|
366 |
-
index + 1,
|
367 |
-
company.document_name,
|
368 |
-
company.document_desc,
|
369 |
-
company.version,
|
370 |
-
company.vectorDBflag,
|
371 |
-
`<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,
|
372 |
-
`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
// "<a href='#' class='btn btn-
|
377 |
-
// "<a href='#' class='btn btn-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
document.getElementById('
|
420 |
-
document.getElementById('
|
421 |
-
document.getElementById('
|
422 |
-
document.getElementById('
|
423 |
-
document.getElementById('
|
424 |
-
document.getElementById('
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
$('#
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
$('#addModal').modal('
|
444 |
-
});
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
$('#
|
461 |
-
|
462 |
-
|
463 |
-
$('#
|
464 |
-
$('#
|
465 |
-
$('#
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
}
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
//
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
const
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
667 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<title>Knowledge Base</title>
|
6 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
8 |
+
<!-- Include AdminLTE CSS -->
|
9 |
+
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
|
10 |
+
<!-- Include DataTables CSS -->
|
11 |
+
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
|
12 |
+
<!-- Include AdminLTE JS -->
|
13 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/adminlte.min.js"></script>
|
14 |
+
<!-- Include DataTables JS -->
|
15 |
+
<script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
|
16 |
+
<script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
|
17 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
|
18 |
+
<style>
|
19 |
+
body {
|
20 |
+
background-color: transparent !important;
|
21 |
+
}
|
22 |
+
.content-wrapper{
|
23 |
+
flex: 1;
|
24 |
+
overflow-y: auto;
|
25 |
+
}
|
26 |
+
|
27 |
+
.wrapper {
|
28 |
+
display: flex;
|
29 |
+
flex-direction: column;
|
30 |
+
height: 100vh;
|
31 |
+
}
|
32 |
+
|
33 |
+
|
34 |
+
.modal-content {
|
35 |
+
background-color: #fff;
|
36 |
+
}
|
37 |
+
|
38 |
+
.content-header {
|
39 |
+
padding: 1rem;
|
40 |
+
}
|
41 |
+
|
42 |
+
h1 {
|
43 |
+
text-align: center;
|
44 |
+
margin-bottom: 30px;
|
45 |
+
}
|
46 |
+
|
47 |
+
.card {
|
48 |
+
padding: 0;
|
49 |
+
margin-top: -15px;
|
50 |
+
margin-left: -40px;
|
51 |
+
}
|
52 |
+
|
53 |
+
.table-responsive {
|
54 |
+
width: 100%;
|
55 |
+
overflow-x: auto;
|
56 |
+
/*overflow-y: scroll;*/
|
57 |
+
/* Allows horizontal scrolling if necessary */
|
58 |
+
}
|
59 |
+
|
60 |
+
.table,
|
61 |
+
.table-bordered {
|
62 |
+
width: 100%;
|
63 |
+
border-collapse: collapse;
|
64 |
+
margin-right: 7.5px;
|
65 |
+
}
|
66 |
+
|
67 |
+
|
68 |
+
.text-wrap {
|
69 |
+
white-space: normal !important;
|
70 |
+
word-break: break-word;
|
71 |
+
}
|
72 |
+
div.dataTables_wrapper div.dataTables_length select{
|
73 |
+
width: 60px;
|
74 |
+
display: inline-block;
|
75 |
+
}
|
76 |
+
|
77 |
+
th {
|
78 |
+
white-space: nowrap;
|
79 |
+
}
|
80 |
+
|
81 |
+
th:nth-child(1),
|
82 |
+
td:nth-child(1) {
|
83 |
+
/* Sno column */
|
84 |
+
width: 2%;
|
85 |
+
}
|
86 |
+
|
87 |
+
th:nth-child(2),
|
88 |
+
td:nth-child(2) {
|
89 |
+
/* Document Name column */
|
90 |
+
width: auto;
|
91 |
+
}
|
92 |
+
|
93 |
+
th:nth-child(3),
|
94 |
+
td:nth-child(3) {
|
95 |
+
/* Document Description column */
|
96 |
+
width: auto;
|
97 |
+
}
|
98 |
+
|
99 |
+
th:nth-child(4),
|
100 |
+
td:nth-child(4) {
|
101 |
+
/* Document Version column */
|
102 |
+
width: 20%;
|
103 |
+
}
|
104 |
+
|
105 |
+
th:nth-child(5),
|
106 |
+
td:nth-child(5) {
|
107 |
+
/* VectorDB Flag column */
|
108 |
+
width: auto;
|
109 |
+
}
|
110 |
+
|
111 |
+
th:nth-child(6),
|
112 |
+
td:nth-child(6) {
|
113 |
+
/* View column */
|
114 |
+
width: 10%;
|
115 |
+
}
|
116 |
+
|
117 |
+
th:nth-child(7),
|
118 |
+
td:nth-child(7) {
|
119 |
+
/* Edit column */
|
120 |
+
width: 10%;
|
121 |
+
}
|
122 |
+
|
123 |
+
th:nth-child(8),
|
124 |
+
td:nth-child(8) {
|
125 |
+
/* Delete column */
|
126 |
+
width: auto;
|
127 |
+
}
|
128 |
+
.alert {
|
129 |
+
position: relative;
|
130 |
+
padding: 15px;
|
131 |
+
margin-bottom: 20px;
|
132 |
+
border: 1px solid transparent;
|
133 |
+
border-radius: 4px;
|
134 |
+
}
|
135 |
+
|
136 |
+
.alert-success {
|
137 |
+
color: #3c763d;
|
138 |
+
background-color: #dff0d8;
|
139 |
+
border-color: #d6e9c6;
|
140 |
+
}
|
141 |
+
|
142 |
+
.alert-danger {
|
143 |
+
color: #a94442;
|
144 |
+
background-color: #f2dede;
|
145 |
+
border-color: #ebccd1;
|
146 |
+
}
|
147 |
+
|
148 |
+
.close {
|
149 |
+
position: absolute;
|
150 |
+
bottom: 10px;
|
151 |
+
right: 10px;
|
152 |
+
border: none;
|
153 |
+
background: none;
|
154 |
+
font-size: 16px;
|
155 |
+
cursor: pointer;
|
156 |
+
}
|
157 |
+
|
158 |
+
</style>
|
159 |
+
</head>
|
160 |
+
|
161 |
+
<body>
|
162 |
+
{% include 'sidepane.html' %}
|
163 |
+
<div class="wrapper">
|
164 |
+
<div class="main-header" style="border-bottom: none;">
|
165 |
+
<div class="container mt-2">
|
166 |
+
<div class="form-group left-align" >
|
167 |
+
<label for="company" class="mr-1" style="margin-left:-40px; margin-top: 12px;">Company Name <span class="text-danger">*</span></label>
|
168 |
+
<select type="text" id="company" name="company" class="form-control" style="width:20%;margin-left:-40px;"required>
|
169 |
+
<option value="" selected>Select</option>
|
170 |
+
</select>
|
171 |
+
<div class="col-12 d-flex justify-content-end mb-3">
|
172 |
+
<button class="btn btn-primary" style="margin-top:-40px;margin-right: -10px;position: fixed;"
|
173 |
+
id="add" data-action="add">Add</button>
|
174 |
+
</div>
|
175 |
+
</div>
|
176 |
+
</div>
|
177 |
+
<div class="row">
|
178 |
+
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
|
179 |
+
</div>
|
180 |
+
|
181 |
+
<section class="content" id="contentSection" style="display: none;">
|
182 |
+
<div class="container-fluid">
|
183 |
+
<div>
|
184 |
+
<div class="form-group">
|
185 |
+
<!-- <label for="company_id">company_id</label>--->
|
186 |
+
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
|
187 |
+
</div>
|
188 |
+
<div class="row">
|
189 |
+
<div class="col-12">
|
190 |
+
<div class="card">
|
191 |
+
<div id="message-container">
|
192 |
+
<div class="card-body table-container">
|
193 |
+
<table id="knowledgeTable" class="table table-bordered table-striped">
|
194 |
+
<thead>
|
195 |
+
<tr>
|
196 |
+
|
197 |
+
<th>Sno</th>
|
198 |
+
<th>Document Name</th>
|
199 |
+
<th>Document Description</th>
|
200 |
+
<th>Document Version</th>
|
201 |
+
<th>VectorDB Flag</th>
|
202 |
+
<th>View</th>
|
203 |
+
<th>Edit</th>
|
204 |
+
<th>Delete</th>
|
205 |
+
<!-- <th style="display:none;">Company ID</th> -->
|
206 |
+
</tr>
|
207 |
+
</thead>
|
208 |
+
<tbody>
|
209 |
+
|
210 |
+
</tbody>
|
211 |
+
</table>
|
212 |
+
</div>
|
213 |
+
</div>
|
214 |
+
</div>
|
215 |
+
</div>
|
216 |
+
</div>
|
217 |
+
</section>
|
218 |
+
</div>
|
219 |
+
|
220 |
+
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"
|
221 |
+
aria-hidden="true">
|
222 |
+
<div class="modal-dialog" role="document">
|
223 |
+
<div class="modal-content">
|
224 |
+
<div class="modal-header">
|
225 |
+
<h5 class="modal-title" id="addModalLabel">Add Document Details</h5>
|
226 |
+
<button type="button" class="btn-close" data-dismiss="modal" >
|
227 |
+
<span aria-hidden="true" data-backdrop="static" data-keyboard="false"></span>
|
228 |
+
</button>
|
229 |
+
</div>
|
230 |
+
<div class="modal-body">
|
231 |
+
<div class="form-group">
|
232 |
+
<!-- <label for="company_id">company_id</label>--->
|
233 |
+
<input type="hidden" id="company_id" name="company_id" class="form-control" required>
|
234 |
+
</div>
|
235 |
+
<form id="documentForm">
|
236 |
+
<div class="form-group">
|
237 |
+
<label for="uploadFile">Upload File<span class="text-danger">*</span></label>
|
238 |
+
<span id="file-name"></span>
|
239 |
+
<input type="hidden" id="file_name" name="file_name" class="form-control" required>
|
240 |
+
<input type="file" class="form-control-file" id="uploadFile" name="uploadFile" required
|
241 |
+
accept=".pdf,.doc,.docx">
|
242 |
+
<small class="form-text text-muted">Accepted formats: .pdf, .doc, .docx</small>
|
243 |
+
</div>
|
244 |
+
<div class="form-group">
|
245 |
+
<label for="documentName">Document Name<span class="text-danger">*</span></label>
|
246 |
+
<input type="text" class="form-control" id="documentName" name="documentName" required>
|
247 |
+
</div>
|
248 |
+
<div class="form-group">
|
249 |
+
<label for="documentDescription">Document Description<span
|
250 |
+
class="text-danger">*</span></label>
|
251 |
+
<textarea class="form-control" id="documentDescription" name="documentDescription"
|
252 |
+
rows="3" required></textarea>
|
253 |
+
</div>
|
254 |
+
<div class="form-group">
|
255 |
+
<label for="department">Department<span class="text-danger">*</span></label>
|
256 |
+
<input type="text" class="form-control" id="department" name="department" required>
|
257 |
+
</div>
|
258 |
+
<div class="form-group">
|
259 |
+
<label for="version">Version<span class="text-danger">*</span></label>
|
260 |
+
<input type="text" class="form-control" id="version" name="version" required>
|
261 |
+
</div>
|
262 |
+
<div class="form-group">
|
263 |
+
<label for="lastUpdated">Last Updated<span class="text-danger">*</span></label>
|
264 |
+
<input type="text" class="form-control" id="lastUpdated" name="lastUpdated" required>
|
265 |
+
</div>
|
266 |
+
</form>
|
267 |
+
</div>
|
268 |
+
<div class="modal-footer">
|
269 |
+
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> -->
|
270 |
+
<button type="button" id="saveupdate" class="btn btn-primary" style="display: none;">Update</button>
|
271 |
+
<button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
|
272 |
+
</div>
|
273 |
+
</div>
|
274 |
+
</div>
|
275 |
+
</div>
|
276 |
+
</div>
|
277 |
+
|
278 |
+
{%include 'footer.html'%}
|
279 |
+
|
280 |
+
<!-- JavaScript to handle modal display -->
|
281 |
+
<script>
|
282 |
+
document.addEventListener("DOMContentLoaded", function () {
|
283 |
+
now = new Date().toISOString().replace('T', ' ').substr(0, 19);
|
284 |
+
document.getElementById('lastUpdated').value = now;
|
285 |
+
const inputs = document.querySelectorAll("#documentForm input, textarea");
|
286 |
+
|
287 |
+
inputs.forEach((input, index) => {
|
288 |
+
input.addEventListener("keydown", function (event) {
|
289 |
+
if (event.key === "Enter") {
|
290 |
+
event.preventDefault();
|
291 |
+
moveToNextInput(inputs, index);
|
292 |
+
}
|
293 |
+
});
|
294 |
+
});
|
295 |
+
|
296 |
+
function moveToNextInput(inputs, currentIndex) {
|
297 |
+
const nextInput = inputs[currentIndex + 1];
|
298 |
+
if (nextInput) {
|
299 |
+
nextInput.focus();
|
300 |
+
} else {
|
301 |
+
// Optionally, submit the form or trigger the save button
|
302 |
+
document.getElementById("save").focus();
|
303 |
+
}
|
304 |
+
}
|
305 |
+
// $(document).on('click', '.btn-view', function () {
|
306 |
+
// const companyId = $(this).data('id');
|
307 |
+
// console.log("company_id in view",companyId);
|
308 |
+
// viewCompany(companyId);
|
309 |
+
// });
|
310 |
+
|
311 |
+
// // Edit knowledge base details
|
312 |
+
// $(document).on('click', '.btn-edit', function () {
|
313 |
+
// const companyId = $(this).data('id');
|
314 |
+
// console.log("company_id in edit",companyId);
|
315 |
+
// editCompany(companyId);
|
316 |
+
// });
|
317 |
+
|
318 |
+
// // Delete company
|
319 |
+
// $(document).on('click', '.btn-delete', function () {
|
320 |
+
// const kid = $(this).data('id'); // Get the company ID from the da
|
321 |
+
// console.log("company_id in delete",kid);
|
322 |
+
// if (confirm("Are you sure you want to delete this company?")) {
|
323 |
+
// deleteCompany(kid); // Call the delete function with the company ID
|
324 |
+
// }
|
325 |
+
// });
|
326 |
+
fetchCompanies();
|
327 |
+
|
328 |
+
const companySelect = document.getElementById('company');
|
329 |
+
const documentForm = document.getElementById('documentForm');
|
330 |
+
const table = $('#knowledgeTable').DataTable(); // Initialize DataTable at the start
|
331 |
+
|
332 |
+
companySelect.addEventListener('change', async function () {
|
333 |
+
$("#message-container").empty();
|
334 |
+
const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
|
335 |
+
console.log(`Selected Company Name: ${selectedCompanyName}`);
|
336 |
+
|
337 |
+
if (selectedCompanyName !== "Select") {
|
338 |
+
try {
|
339 |
+
const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
|
340 |
+
if (!response.ok) {
|
341 |
+
contentSection.style.display = 'none';
|
342 |
+
displayErrorMessage("Knowledgebase details do not exist for this company. Please fill in the details.");
|
343 |
+
throw new Error('Network response was not ok');
|
344 |
+
}
|
345 |
+
const data = await response.json();
|
346 |
+
console.log('data returned', data);
|
347 |
+
const companyId = data.company_id;
|
348 |
+
document.getElementById('company_id').value = companyId;
|
349 |
+
|
350 |
+
if (companyId) {
|
351 |
+
try {
|
352 |
+
const Response = await fetch(`/api/document_upload?company_id=${companyId}&company_name=${selectedCompanyName}`);
|
353 |
+
const connectorsResponse = await Response.json();
|
354 |
+
console.log("knowledge data table after connecting to table", connectorsResponse);
|
355 |
+
table.clear();
|
356 |
+
if (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {
|
357 |
+
//displayEmptyTable();
|
358 |
+
|
359 |
+
displayErrorMessage("Knowledgebase details do not exist for this company. Please fill in the details.");
|
360 |
+
contentSection.style.display = 'none';
|
361 |
+
} else {
|
362 |
+
|
363 |
+
connectorsResponse.forEach((company, index) => {
|
364 |
+
table.row.add([
|
365 |
+
|
366 |
+
index + 1,
|
367 |
+
company.document_name,
|
368 |
+
company.document_desc,
|
369 |
+
company.version,
|
370 |
+
company.vectorDBflag,
|
371 |
+
`<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,
|
372 |
+
`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,
|
373 |
+
`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,
|
374 |
+
company.row_id
|
375 |
+
// "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>",
|
376 |
+
// "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
|
377 |
+
// "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
|
378 |
+
]).draw(false);
|
379 |
+
});
|
380 |
+
contentSection.style.display = 'block';
|
381 |
+
}
|
382 |
+
} catch (error) {
|
383 |
+
console.error('Error fetching company documents:', error);
|
384 |
+
//displayEmptyTable();
|
385 |
+
|
386 |
+
displayErrorMessage("Knowledgebase details1 do not exist for this company. Please fill in the details.");
|
387 |
+
contentSection.style.display = 'none';
|
388 |
+
}
|
389 |
+
} else {
|
390 |
+
// displayEmptyTable();
|
391 |
+
|
392 |
+
displayErrorMessage("Details for knowledgebase do not exist for this company. Please fill in the details.");
|
393 |
+
}
|
394 |
+
} catch (error) {
|
395 |
+
console.error('No details for this company ID or data documents:', error);
|
396 |
+
// displayEmptyTable();
|
397 |
+
|
398 |
+
displayErrorMessage("Knowledgebase details do not exist for this company. Please fill in the details.");
|
399 |
+
contentSection.style.display = 'none';
|
400 |
+
}
|
401 |
+
} else {
|
402 |
+
table.clear().draw();
|
403 |
+
document.getElementById('contentSection').style.display = 'none';
|
404 |
+
clearFormFields();
|
405 |
+
}
|
406 |
+
});
|
407 |
+
|
408 |
+
function displayErrorMessage(message) {
|
409 |
+
const messageContainer = document.getElementById('message-container');
|
410 |
+
if (messageContainer) {
|
411 |
+
messageContainer.innerHTML = `<div class='alert alert-danger'>${message}</div>`;
|
412 |
+
}
|
413 |
+
}
|
414 |
+
|
415 |
+
});
|
416 |
+
|
417 |
+
function clearFormFields() {
|
418 |
+
document.getElementById('file-name').textContent=""
|
419 |
+
document.getElementById('uploadFile').value = "";
|
420 |
+
document.getElementById('documentName').value = "";
|
421 |
+
document.getElementById('documentDescription').value = "";
|
422 |
+
document.getElementById('department').value = "";
|
423 |
+
document.getElementById('version').value = "";
|
424 |
+
//document.getElementById('lastUpdated').value = "";
|
425 |
+
}
|
426 |
+
|
427 |
+
|
428 |
+
$(document).ready(function () {
|
429 |
+
// Show modal function
|
430 |
+
$('#add').on('click', function () {
|
431 |
+
$('#documentName').removeAttr('readonly');
|
432 |
+
$('#documentDescription').removeAttr('readonly');
|
433 |
+
$('#department').removeAttr('readonly');
|
434 |
+
$('#version').removeAttr('readonly');
|
435 |
+
$('#lastUpdated').removeAttr('readonly');
|
436 |
+
const modalTitle = document.getElementById('addModalLabel');
|
437 |
+
modalTitle.textContent = 'Add Knowledgebase Details';
|
438 |
+
$('#uploadFile').show();
|
439 |
+
$('#saveupdate').hide();
|
440 |
+
$('#save').show();
|
441 |
+
clearFormFields();
|
442 |
+
$('#message-container').empty(); // Clear the message container
|
443 |
+
$('#addModal').modal('show');
|
444 |
+
});
|
445 |
+
|
446 |
+
|
447 |
+
$('.modal-footer .btn-secondary, .modal-header .btn-close').on('click', function () {
|
448 |
+
$('#addModal').modal('hide');
|
449 |
+
});
|
450 |
+
// $('#knowledgeTable').DataTable({
|
451 |
+
// autoWidth: false
|
452 |
+
// });
|
453 |
+
|
454 |
+
});
|
455 |
+
function viewCompany(button) {
|
456 |
+
var companyId = $(button).data('kid-id');
|
457 |
+
const modalTitle = document.getElementById('addModalLabel');
|
458 |
+
modalTitle.textContent = 'View Knowledgebase Details';
|
459 |
+
$.getJSON(`/api/getknowledgebase/${companyId}`, function (company) {
|
460 |
+
$('#uploadFile').hide();
|
461 |
+
$('#file-name').text(company.file_path).attr('readonly','readonly');
|
462 |
+
$('#documentName').val(company.document_name).attr('readonly', 'readonly');
|
463 |
+
$('#documentDescription').val(company.document_desc).attr('readonly', 'readonly');
|
464 |
+
$('#department').val(company.department).attr('readonly', 'readonly');
|
465 |
+
$('#version').val(company.version).attr('readonly', 'readonly');
|
466 |
+
//$('#lastUpdated').val(company.last_updated).attr('readonly', 'readonly');
|
467 |
+
var lastUpdated = company.last_updated;
|
468 |
+
$('#lastUpdated').val(lastUpdated).attr('readonly', 'readonly');
|
469 |
+
$('#save').hide();
|
470 |
+
$('#saveupdate').hide();
|
471 |
+
$('#addModal').modal('show');
|
472 |
+
}).fail(function () {
|
473 |
+
alert("Error retrieving knowledge base details.");
|
474 |
+
});
|
475 |
+
}
|
476 |
+
|
477 |
+
// Edit knowledge base details
|
478 |
+
function editCompany(button) {
|
479 |
+
var companyId = $(button).data('kid-id');
|
480 |
+
const modalTitle = document.getElementById('addModalLabel');
|
481 |
+
modalTitle.textContent = 'Edit Knowledgebase Details';
|
482 |
+
|
483 |
+
// Fetch company details by ID
|
484 |
+
$.getJSON(`/api/getknowledgebase/${companyId}`, function (company) {
|
485 |
+
|
486 |
+
const fileName = company.file_path.split('/').pop();
|
487 |
+
const fileContent = new Blob([""], { type: 'text/plain' });
|
488 |
+
const file = new File([fileContent], fileName, { type: fileContent.type });
|
489 |
+
const dataTransfer = new DataTransfer();
|
490 |
+
dataTransfer.items.add(file);
|
491 |
+
|
492 |
+
// Set the file input's files property to the created file
|
493 |
+
const fileInput = document.getElementById('uploadFile');
|
494 |
+
fileInput.files = dataTransfer.files;
|
495 |
+
|
496 |
+
// Check if the input element is of type 'file'
|
497 |
+
if (fileInput.type === 'file') {
|
498 |
+
console.log("The input is of type 'file'.");
|
499 |
+
} else {
|
500 |
+
console.log("The input is NOT of type 'file'.");
|
501 |
+
}
|
502 |
+
|
503 |
+
// Check if the value is of type 'File'
|
504 |
+
const files = fileInput.files;
|
505 |
+
if (files.length > 0 && files[0] instanceof File) {
|
506 |
+
console.log("The value is of type 'File':", files[0].name);
|
507 |
+
} else {
|
508 |
+
console.log("No file is selected or the value is not of type 'File'.");
|
509 |
+
}
|
510 |
+
|
511 |
+
$('#uploadFileLabel').text(files[0].name);
|
512 |
+
$('#uploadFile').text(files[0].name)
|
513 |
+
$('#documentName').val(company.document_name);
|
514 |
+
$('#documentDescription').val(company.document_desc);
|
515 |
+
$('#department').val(company.department);
|
516 |
+
$('#version').val(company.version);
|
517 |
+
$('#lastUpdated').val(company.last_updated);
|
518 |
+
$('#company_id').val(company.company_id);
|
519 |
+
|
520 |
+
// Show/hide appropriate elements
|
521 |
+
$('#uploadFile').show(); // Hide the file upload field
|
522 |
+
$('#save').hide(); // Hide the default save button
|
523 |
+
$('#saveupdate').show(); // Show the update button
|
524 |
+
|
525 |
+
// Ensure fields are editable
|
526 |
+
$('#documentName').removeAttr('readonly');
|
527 |
+
$('#documentDescription').removeAttr('readonly');
|
528 |
+
$('#department').removeAttr('readonly');
|
529 |
+
$('#version').removeAttr('readonly');
|
530 |
+
$('#lastUpdated').removeAttr('readonly');
|
531 |
+
$('#company_id').val(company.company_id); // Ensure company_id is included if necessary
|
532 |
+
|
533 |
+
// Show the modal
|
534 |
+
$('#addModal').modal('show');
|
535 |
+
|
536 |
+
// Set up the click event for the update button
|
537 |
+
$('#saveupdate').off('click').on('click', function () {
|
538 |
+
saveupdate(companyId,files[0].name); // Pass the company ID for updating
|
539 |
+
});
|
540 |
+
}).fail(function () {
|
541 |
+
alert("Error retrieving knowledge base details.");
|
542 |
+
});
|
543 |
+
}
|
544 |
+
|
545 |
+
|
546 |
+
function saveupdate(companyId, filename) {
|
547 |
+
const formData = new FormData();
|
548 |
+
const fileInput = document.getElementById("uploadFile");
|
549 |
+
const uploadFile = fileInput.files[0]; // Get the file object
|
550 |
+
const company_id=document.getElementById("company_id").value;
|
551 |
+
formData.append("company_id", $('#company_id').val());
|
552 |
+
formData.append("documentName", $('#documentName').val());
|
553 |
+
formData.append("documentDescription", $('#documentDescription').val());
|
554 |
+
formData.append("department", $('#department').val());
|
555 |
+
formData.append("version", $('#version').val());
|
556 |
+
formData.append("vectorDBFlag", 'NO');
|
557 |
+
formData.append("lastUpdated", $('#lastUpdated').val());
|
558 |
+
console.log("company_id to table refresh",company_id)
|
559 |
+
// Append the file only if it exists, otherwise, append the filename
|
560 |
+
if (uploadFile) {
|
561 |
+
formData.append("file_path", uploadFile); // Append the file object
|
562 |
+
} else {
|
563 |
+
formData.append("file_path", filename); // Append the existing filename
|
564 |
+
}
|
565 |
+
|
566 |
+
$.ajax({
|
567 |
+
url: `/api/putknowledgebase/${companyId}`,
|
568 |
+
type: 'PUT',
|
569 |
+
data: formData,
|
570 |
+
processData: false, // Required for FormData
|
571 |
+
contentType: false, // Required for FormData
|
572 |
+
success: function (response) {
|
573 |
+
// alert('Knowledgebase details updated successfully.');
|
574 |
+
const messageContainer = document.getElementById('message-container');
|
575 |
+
if(messageContainer)
|
576 |
+
messageContainer.innerHTML = `
|
577 |
+
<div class='alert alert-success'>
|
578 |
+
Knowledgebasse Data updated successfully
|
579 |
+
<button class='close' onclick='dismissMessage()'>OK</button>
|
580 |
+
</div>`;
|
581 |
+
$('#addModal').modal('hide'); // Close the modal after saving
|
582 |
+
fetchUpdatedDocuments(company_id);
|
583 |
+
},
|
584 |
+
error: function () {
|
585 |
+
const messageContainer = document.getElementById('message-container');
|
586 |
+
if(messageContainer)
|
587 |
+
messageContainer.innerHTML = `
|
588 |
+
<div class='alert alert-danger'>
|
589 |
+
No changes have been made to update knowledgebase details.
|
590 |
+
<button class='close' onclick='dismissMessage()'>OK</button>
|
591 |
+
</div>`;
|
592 |
+
$('#addModal').modal('hide');
|
593 |
+
// alert('Form has no changes to update knowledge base details.');
|
594 |
+
}
|
595 |
+
});
|
596 |
+
}
|
597 |
+
|
598 |
+
async function fetchUpdatedDocuments(company_id) {
|
599 |
+
console.log("company_id",company_id);
|
600 |
+
var table = $('#knowledgeTable').DataTable();
|
601 |
+
const Response = await fetch(`/api/document_update?company_id=${company_id}`);
|
602 |
+
const connectorsResponse = await Response.json();
|
603 |
+
console.log("knowledge data table after connecting to table", connectorsResponse);
|
604 |
+
table.clear();
|
605 |
+
if (!Array.isArray(connectorsResponse) || connectorsResponse.length === 0) {
|
606 |
+
//displayEmptyTable();
|
607 |
+
|
608 |
+
displayErrorMessage("Knowledgebase details do not exist for this company. Please fill in the details.");
|
609 |
+
contentSection.style.display = 'none';
|
610 |
+
} else {
|
611 |
+
|
612 |
+
connectorsResponse.forEach((company, index) => {
|
613 |
+
table.row.add([
|
614 |
+
|
615 |
+
index + 1,
|
616 |
+
company.document_name,
|
617 |
+
company.document_desc,
|
618 |
+
company.version,
|
619 |
+
company.vectorDBflag,
|
620 |
+
`<a href='#' class='btn btn-info btn-sm'data-kid-id='${company.row_id}' data-action="view" onclick='viewCompany(this)''><i class='fas fa-eye'></i></a>`,
|
621 |
+
`<a href='#' class='btn btn-warning btn-sm'data-kid-id='${company.row_id}' data-action="edit" onclick='editCompany(this)'><i class='fas fa-edit'></i></a>`,
|
622 |
+
//`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`,
|
623 |
+
`<a href='#' class='btn btn-danger btn-sm' data-kid-id='${company.row_id}' onclick='deleteCompany(this)'><i class='fas fa-trash'></i></a>`,
|
624 |
+
company.row_id
|
625 |
+
// "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>",
|
626 |
+
// "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>",
|
627 |
+
// "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></button>"
|
628 |
+
]).draw(false);
|
629 |
+
});
|
630 |
+
contentSection.style.display = 'block';
|
631 |
+
}
|
632 |
+
}
|
633 |
+
// Delete company
|
634 |
+
function deleteCompany(button) {
|
635 |
+
var companyId = $(button).data('kid-id');
|
636 |
+
console.log("k_id deleted",companyId);
|
637 |
+
$.ajax({
|
638 |
+
type: "DELETE",
|
639 |
+
url: `/api/delknowledgebase/${companyId}`,
|
640 |
+
success: function () {
|
641 |
+
var table = $('#knowledgeTable').DataTable();
|
642 |
+
table.row($(button).closest('tr')).remove().draw();
|
643 |
+
const messageContainer = document.getElementById('message-container');
|
644 |
+
if(messageContainer)
|
645 |
+
messageContainer.innerHTML = `
|
646 |
+
<div class='alert alert-danger'>
|
647 |
+
Knowledgebase data deleted successfully.
|
648 |
+
<button class='close' onclick='dismissMessage()'>OK</button>
|
649 |
+
</div>`;
|
650 |
+
// alert("Knowledgebase data deleted successfully.");
|
651 |
+
fetchCompanies(); // Refresh the table
|
652 |
+
},
|
653 |
+
error: function (xhr) {
|
654 |
+
alert("Error deleting company: " + xhr.responseJSON.detail);
|
655 |
+
}
|
656 |
+
});
|
657 |
+
}
|
658 |
+
function save_file() {
|
659 |
+
const form = document.getElementById('documentForm');
|
660 |
+
|
661 |
+
// Check if the form is valid
|
662 |
+
if (!form.checkValidity()) {
|
663 |
+
// If the form is invalid, show validation messages and stop the submission
|
664 |
+
form.reportValidity();
|
665 |
+
return;
|
666 |
+
}
|
667 |
+
const uploadFile = document.getElementById("uploadFile").files[0];
|
668 |
+
const documentName = document.getElementById("documentName").value;
|
669 |
+
const documentDescription = document.getElementById("documentDescription").value;
|
670 |
+
const department = document.getElementById("department").value;
|
671 |
+
const version = document.getElementById("version").value;
|
672 |
+
const lastUpdated = document.getElementById("lastUpdated").value;
|
673 |
+
const company_id = document.getElementById("company_id").value;
|
674 |
+
|
675 |
+
//const formData = new FormData();
|
676 |
+
var formData = new FormData($('#documentForm')[0]);
|
677 |
+
const vectorDBFlag = "NO"; // Example value
|
678 |
+
const view = "<a href='#' class='btn btn-info btn-sm'><i class='fas fa-eye'></i></a>";
|
679 |
+
const edit = "<a href='#' class='btn btn-warning btn-sm'><i class='fas fa-edit'></i></a>";
|
680 |
+
const dele= "<a href='#' class='btn btn-danger btn-sm'><i class='fas fa-trash'></i></a>";
|
681 |
+
|
682 |
+
|
683 |
+
formData.append("uploadFile", uploadFile);
|
684 |
+
formData.append("documentName", documentName);
|
685 |
+
formData.append("documentDescription", documentDescription);
|
686 |
+
formData.append("department", department);
|
687 |
+
formData.append("version", version);
|
688 |
+
formData.append("lastUpdated", lastUpdated);
|
689 |
+
formData.append("vectorDBflag", vectorDBFlag);
|
690 |
+
formData.append("company_id", company_id);
|
691 |
+
console.log("formdata",formData);
|
692 |
+
fetch('/upload_document', {
|
693 |
+
method: 'POST',
|
694 |
+
body: formData
|
695 |
+
})
|
696 |
+
.then(response => {
|
697 |
+
if (!response.ok) {
|
698 |
+
throw new Error('Network response was not ok');
|
699 |
+
}
|
700 |
+
return response.text();
|
701 |
+
})
|
702 |
+
.then(data => {
|
703 |
+
var table = $('#knowledgeTable').DataTable();
|
704 |
+
var rowCount = table.rows().count();
|
705 |
+
table.row.add([
|
706 |
+
rowCount + 1,
|
707 |
+
documentName,
|
708 |
+
documentDescription,
|
709 |
+
version,
|
710 |
+
vectorDBFlag,
|
711 |
+
view,
|
712 |
+
edit,
|
713 |
+
dele
|
714 |
+
]).draw(false);
|
715 |
+
|
716 |
+
const messageContainer = document.getElementById('message-container');
|
717 |
+
if(messageContainer)
|
718 |
+
messageContainer.innerHTML = `
|
719 |
+
<div class='alert alert-success'>
|
720 |
+
Knowledgebase Data saved successfully
|
721 |
+
<button class='close' onclick='dismissMessage()'>OK</button>
|
722 |
+
</div>`;
|
723 |
+
// alert('Document saved successfully');
|
724 |
+
$('#addModal').modal('hide');
|
725 |
+
document.getElementById('contentSection').style.display = 'block'; // Show the table section
|
726 |
+
})
|
727 |
+
.catch(error => console.error('Error:', error));
|
728 |
+
}
|
729 |
+
function dismissMessage() {
|
730 |
+
const messageContainer = document.getElementById('message-container');
|
731 |
+
if (messageContainer) {
|
732 |
+
messageContainer.innerHTML = '';
|
733 |
+
}
|
734 |
+
}
|
735 |
+
async function fetchCompanies() {
|
736 |
+
try {
|
737 |
+
const response = await fetch('/api/companies');
|
738 |
+
if (!response.ok) {
|
739 |
+
throw new Error('Network response was not ok');
|
740 |
+
}
|
741 |
+
const data = await response.json();
|
742 |
+
displayCompanies(data.companies);
|
743 |
+
} catch (error) {
|
744 |
+
console.error('Error fetching companies:', error);
|
745 |
+
}
|
746 |
+
}
|
747 |
+
|
748 |
+
function displayCompanies(companies) {
|
749 |
+
const companySelect = document.getElementById('company');
|
750 |
+
companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
|
751 |
+
companies.forEach(company => {
|
752 |
+
const option = document.createElement('option');
|
753 |
+
option.value = company.name;
|
754 |
+
option.textContent = company.name;
|
755 |
+
companySelect.appendChild(option);
|
756 |
+
});
|
757 |
+
}
|
758 |
+
</script>
|
759 |
+
</body>
|
760 |
+
|
761 |
</html>
|