File size: 18,609 Bytes
6952a04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html>

<head>
    <title>Knowledge Base</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
    <!-- Include AdminLTE CSS -->
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
    <!-- Include DataTables CSS -->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
    <!-- Include AdminLTE JS -->
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/adminlte.min.js"></script>
    <!-- Include DataTables JS -->
    <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.25/js/dataTables.bootstrap4.min.js"></script>
    <style>

        body {

            background-color: transparent !important;

        }



        .content-wrapper {

            background-color: transparent !important;

            text-align: center;

        }



        .wrapper {

            background-color: transparent !important;

        }



        .modal-content {

            background-color: #fff;

        }



        h1 {

            text-align: center;

            margin-bottom: 30px;

        }



        /* Adjust table width to full container width */

        .card-body {

            padding: 0;

        }



        .table {

            width: 100%;

        }



        .text-wrap {

            white-space: normal !important;

            word-break: break-word;

        }



        .center-align {

            padding-top: 20px;

            display: flex;

            justify-content: center;

            align-items: center;

            width: 100%;

        }



        .reduced-width {

            width: 50%;

            /* Adjust the percentage as needed */

        }

    </style>
</head>

<body>
    {% include 'sidepane.html' %}


    <div class="wrapper" style="position: relative; top: 0;">
        <div class="content-wrapper">
            <div class="content-header">
                <div class="container-fluid">
                    <div class="container mt-2">
                        <h1 class="m-0 text-center" style="flex-grow: 1;">Knowledge Base</h1>
                        <div class="form-group center-align">
                            <label for="company" class="mr-2">Company Name <span class="text-danger">*</span></label>
                            <select type="text" id="company" name="company" class="form-control reduced-width" required>
                                <option value="" selected>Select</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <section class="content" id="contentSection" style="display: none;">
                <div class="container-fluid">
                    <div class="form-group">
                        <!-- <label for="company_id">company_id</label>--->
                        <input type="hidden" id="company_id" name="company_id" class="form-control" required>
                    </div>
                    <div class="row">
                        <div class="col-12 d-flex justify-content-end mb-3">
                            <button class="btn btn-primary" id="add">Add</button>
                        </div>
                        <div class="row mb-2">
                            <div class="col-12">
                                <div class="col-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <div class="table-responsive">
                                                <div id="message-container">
                                                <table id="knowledgeTable" class="table table-bordered table-striped">
                                                    <thead>
                                                        <tr>
                                                            <th>Sno</th>
                                                            <th>Document Name</th>
                                                            <th>Document Description</th>
                                                            <th>Document Version</th>
                                                            <th>VectorDB Flag</th>
                                                            <th>View</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <tr>
                                                            <td>1</td>
                                                            <td>NewAge eWMS BusinessRequirementsDocument_V1.9 - Inbound
                                                            </td>
                                                            <td>GRN Inbound</td>
                                                            <td>1.9</td>
                                                            <td>Yes</td>
                                                            <td>
                                                                <button class="btn btn-primary viewButton">View</button>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>2</td>
                                                            <td>NewAge eWMS BusinessRequirementsDocument_V2.3 - Inbound
                                                            </td>
                                                            <td>GRN Inbound</td>
                                                            <td>2.3</td>
                                                            <td>No</td>
                                                            <td>
                                                                <button class="btn btn-primary viewButton">View</button>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>3</td>
                                                            <td>NewAge eWMS BusinessRequirementsDocument_V1.9 - Outbound
                                                            </td>
                                                            <td>GRN Outbound</td>
                                                            <td>1.9</td>
                                                            <td>Yes</td>
                                                            <td>
                                                                <button class="btn btn-primary viewButton">View</button>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>4</td>
                                                            <td class="text-wrap">NewAge eWMS
                                                                BusinessRequirementsDocument_V2.2 - Outbound</td>
                                                            <td>ASN Outbound</td>
                                                            <td>2.2</td>
                                                            <td>No</td>
                                                            <td>
                                                                <button class="btn btn-primary viewButton">View</button>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        </div>
            </section>
        </div>

        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"

            aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="addModalLabel">Add Document</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <!-- <label for="company_id">company_id</label>--->
                            <input type="hidden" id="company_id" name="company_id" class="form-control" required>
                        </div>
                        <form id="documentForm">
                            <div class="form-group">
                                <label for="uploadFile">Upload File<span class="text-danger">*</span></label>
                                <input type="file" class="form-control-file" id="uploadFile" name="uploadFile" required   accept=".pdf,.doc,.docx">
                                <small class="form-text text-muted">Accepted formats: .pdf, .doc, .docx</small>
                            </div>
                            <div class="form-group">
                                <label for="documentName">Document Name<span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="documentName" name="documentName" required>
                            </div>
                            <div class="form-group">
                                <label for="documentDescription">Document Description<span class="text-danger">*</span></label>
                                <textarea class="form-control" id="documentDescription" name="documentDescription"

                                    rows="3" required></textarea>
                            </div>
                            <div class="form-group">
                                <label for="department">Department<span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="department" name="department" required>
                            </div>
                            <div class="form-group">
                                <label for="version">Version<span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="version" name="version" required>
                            </div>
                            <div class="form-group">
                                <label for="lastUpdated">Last Updated<span class="text-danger">*</span></label>
                                <input type="text" class="form-control" id="lastUpdated" name="lastUpdated" required>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="button" id="save" onclick="save_file()" class="btn btn-primary">Save</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- JavaScript to handle modal display -->
    <script>

        document.addEventListener("DOMContentLoaded", function () {

            now = new Date().toISOString().substr(0, 10);

            document.getElementById('lastUpdated').value = now

           // clearFormFields();

        });

        document.addEventListener('DOMContentLoaded', function () {



            fetchCompanies();



            const companySelect = document.getElementById('company');

            const documentForm = document.getElementById('documentForm');



            companySelect.addEventListener('change', async function () {

                const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;

                console.log(`Selected Company Name: ${selectedCompanyName}`);



                if (selectedCompanyName !== "Select") {



                    try {

                        const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);

                        if (!response.ok) {

                            contentSection.style.display='none';

                            const messageContainer = document.getElementById('message-container');

                             if (messageContainer) {

                                 messageContainer.innerHTML = "<div class='alert alert-danger'>Document details do not exist for this company. Please fill in the details.</div>";

                              }

                            throw new Error('Network response was not ok');

                        }

                        const data = await response.json();

                        console.log(`Company ID: ${data.company_id}`);

                        const companyId = data.company_id;

                        document.getElementById('company_id').value = companyId;



                        if (companyId) {

                            contentSection.style.display = 'block';

                        }



                        

                    } catch (error) {

                        console.error('Error fetching company ID or data documents:', error);

                        documentForm.style.display = 'none';

                    }

                } else {

                    //clearFormFields();

                    documentForm.style.display = 'block';

                }

            });

        });

            function clearFormFields() {

                document.getElementById('uploadFile').value = "";

                document.getElementById('documentName').value = "";

                document.getElementById('documentDescription').value = "";

                document.getElementById('department').value = "";

                document.getElementById('version').value = "";

                //document.getElementById('lastUpdated').value = "";

            }

        



        $(document).ready(function () {

            // Show modal function

            $('#add').on('click', function () {

                clearFormFields();

                $('#addModal').modal('show');

            });

            $('.modal-footer .btn-secondary').on('click', function () {

                $('#addModal').modal('hide');

            });

            // Your save file function here

            // async function save_file() {

            //     alert('Save button clicked');

            //     // Your save file logic goes here

            // }

        });

        function save_file() {

            const uploadFile = document.getElementById("uploadFile").files[0];

            const documentName = document.getElementById("documentName").value;

            const documentDescription = document.getElementById("documentDescription").value;

            const department = document.getElementById("department").value;

            const version = document.getElementById("version").value;

            const lastUpdated = document.getElementById("lastUpdated").value;

            const company_id = document.getElementById("company_id").value;



            const formData = new FormData();

            formData.append("uploadFile", uploadFile);

            formData.append("documentName", documentName);

            formData.append("documentDescription", documentDescription);

            formData.append("department", department);

            formData.append("version", version);

            formData.append("lastUpdated", lastUpdated);

            formData.append("company_id", company_id);



            fetch('/upload_document', {

                method: 'POST',

                body: formData

            })

                .then(response => {

                    if (!response.ok) {

                        throw new Error('Network response was not ok');

                    }

                    return response.text();

                })

                .then(data => {

                    alert('Document saved successfully');

                   // $('#addModal').modal('hide');

                })

                .catch(error => console.error('Error:', error));

        }

        async function fetchCompanies() {

            try {

                const response = await fetch('/api/companies');

                if (!response.ok) {

                    throw new Error('Network response was not ok');

                }

                const data = await response.json();

                displayCompanies(data.companies);

            } catch (error) {

                console.error('Error fetching companies:', error);

            }

        }



        function displayCompanies(companies) {

            const companySelect = document.getElementById('company');

            companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown

            companies.forEach(company => {

                const option = document.createElement('option');

                option.value = company.name;

                option.textContent = company.name;

                companySelect.appendChild(option);

            });

        }

    </script>
</body>

</html>