Redmind commited on
Commit
53c83bf
·
verified ·
1 Parent(s): d8e21eb

Update templates/data_connectors.html

Browse files
Files changed (1) hide show
  1. templates/data_connectors.html +647 -661
templates/data_connectors.html CHANGED
@@ -1,662 +1,648 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Data Connectors</title>
8
- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
9
- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
10
- <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
11
- <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
12
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
13
-
14
- <style>
15
- html,
16
- body {
17
- height: 90%;
18
- margin: 0;
19
- display: flex;
20
- flex-direction: column;
21
- }
22
-
23
- body {
24
- display: inline-flex;
25
- flex-direction: column;
26
- min-height: 90%;
27
- }
28
-
29
- .main-content {
30
- flex: 1;
31
- display: inline-flex;
32
- flex-direction: column;
33
- align-items: center;
34
- justify-content: flex-start;
35
- padding: 30px;
36
- }
37
-
38
- /* .container {
39
- margin-top: 50px;
40
- margin-left: 320px;
41
- max-width: 800px;
42
- padding: 10px;
43
- border: 1px solid #ccc;
44
- border-radius: 5px;
45
- background-color: #fff;
46
- position: relative;
47
- z-index: 1;
48
- } */
49
-
50
- .form-group {
51
- margin-bottom: 20px;
52
- }
53
-
54
- .form-group label {
55
- font-weight: bold;
56
- margin-top: -10px;
57
- margin-left:-22px;
58
- display: block;
59
- }
60
-
61
- .form-group input,
62
- .form-group select,
63
- .form-group textarea {
64
- width: 90%;
65
- margin-left:-22px;
66
- padding: 2px;
67
- border: 1px solid #ccc;
68
- border-radius: 4px;
69
- }
70
-
71
- .btn-primary {
72
- margin-right: 10px;
73
- color: white;
74
- font-size: 16px;
75
- font-weight: bold;
76
- }
77
-
78
- /* .btn-container {
79
- text-align: center;
80
- margin-top: 20px;
81
- margin-bottom: 10px;
82
- } */
83
- .btn-primary {
84
- margin-right: 10px;
85
- color: white;
86
- font-size: 16px;
87
- font-weight: bold;
88
- }
89
-
90
-
91
- .btn-container {
92
- text-align: center;
93
- margin-top: 30px;
94
- margin-left: 20px;
95
- margin-right: 0px;
96
- margin-bottom: 10px;
97
- /* color: white; */
98
- }
99
-
100
- .btn-container1 {
101
- text-align: center;
102
- margin-top: 50px;
103
- margin-left: 30px;
104
- margin-right: 30px;
105
- margin-bottom: 10px;
106
- color: white;
107
- }
108
-
109
- /* #selectedTables,
110
- #labelselected {
111
- display: none;
112
- } */
113
- .btn-primary:focus,
114
- .btn-primary:active {
115
- color: white;
116
- background-color: #007bff;
117
- border-color: #007bff;
118
- box-shadow: none;
119
- }
120
-
121
- #saveBtn1 {
122
-
123
- margin: 0 auto;
124
- }
125
-
126
- /* footer {
127
- position: relative;
128
- margin-top: auto;
129
- width: 100%;
130
- color: black;
131
- text-align: right;
132
- padding-right: 245px;
133
- padding-top: 20px;
134
- background-color: #f8f9fa;
135
- border: none !important;
136
- }
137
- */
138
- .small-select {
139
- margin-top: 5px;
140
- width: 200px;
141
- /* Adjust the width as needed */
142
- }
143
-
144
- .custom-dropdown {
145
- width: 250px;
146
- /* Adjust the width as needed */
147
- }
148
- /* Ensure the new row aligns with the previous row */
149
- #schema-table-section {
150
-
151
- margin-left: -20px; /* Adjust this if you need spacing between rows */
152
- padding-top: 5px; /* Adjust padding if needed */
153
- }
154
-
155
- .alert {
156
- position: relative;
157
- padding: 15px;
158
- margin-bottom: 20px;
159
- border: 1px solid transparent;
160
- border-radius: 4px;
161
- }
162
-
163
- .alert-success {
164
- color: #3c763d;
165
- background-color: #dff0d8;
166
- border-color: #d6e9c6;
167
- }
168
-
169
- .alert-danger {
170
- color: #a94442;
171
- background-color: #f2dede;
172
- border-color: #ebccd1;
173
- }
174
-
175
- .close {
176
- position: absolute;
177
- bottom: 10px;
178
- right: 10px;
179
- border: none;
180
- background: none;
181
- font-size: 16px;
182
- cursor: pointer;
183
- }
184
-
185
-
186
- </style>
187
- </head>
188
-
189
- <body>
190
- {% include 'sidepane.html' %}
191
- <div class="wrapper">
192
- <div class="main-header" style="border-bottom: none;">
193
- <!-- Content Header (Page header) -->
194
- <div class="content-header">
195
- <div class="container-fluid">
196
- <div class="container mt-2">
197
- <div class="form-group left-align">
198
- <label for="company" class="mr-1" style="margin-left:-60px;margin-top:-1px;">Company Name <span class="text-danger">*</span></label>
199
- <select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;margin-bottom:10px" required>
200
- <option value="" selected>Select</option>
201
- </select>
202
- </div>
203
- <div class="row">
204
- <div id="message-container" style="padding:20px;margin-left: 150px;width:500px;"></div>
205
- </div>
206
- </div>
207
- </div>
208
- </div>
209
- <form id="databaseconnectorForm" class="needs-validation" novalidate action="/save_data_connectors"
210
- method="post" style="display:none;">
211
- <div class="form-group">
212
- <!-- <label for="company_id">company_id</label>--->
213
- <input type="hidden" id="company_id" name="company_id" class="form-control" required>
214
- </div>
215
- <div class="row">
216
- <div class="col-md-3">
217
- <div class="form-group">
218
- <label for="database">Database Type<span class="text-danger">*</span></label>
219
- <select type="text" id="database" name="database" class="form-control" required>
220
- <option value="" selected>Select</option>
221
- <option value="Postgres">Postgres</option>
222
- <option value="mysql">mysql</option>
223
- </select>
224
- </div>
225
- </div>
226
- <div class="col-md-3">
227
- <div class="form-group">
228
- <label for="server">Server IP <span class="text-danger">*</span></label>
229
- <input type="text" id="server" name="server" class="form-control" required>
230
- </div>
231
- </div>
232
- <div class="col-md-3">
233
- <div class="form-group">
234
- <label for="port">Port <span class="text-danger">*</span></label>
235
- <input type="text" id="port" name="port" class="form-control" required>
236
- </div>
237
- </div>
238
- <div class="col-md-3">
239
- <div class="form-group">
240
- <label for="databaseName">Database Name <span class="text-danger">*</span></label>
241
- <input type="text" id="databaseName" name="databaseName" class="form-control" required>
242
- </div>
243
- </div>
244
- </div>
245
- <div class="row">
246
- <div class="col-md-3">
247
- <div class="form-group">
248
- <label for="userame">UserName <span class="text-danger">*</span></label>
249
- <input type="text" id="username" name="username" class="form-control" required>
250
- </div>
251
- </div>
252
- <div class="col-md-3">
253
- <div class="form-group">
254
- <label for="password">Password <span class="text-danger">*</span></label>
255
- <input type="password" id="password" name="password" class="form-control" required>
256
- </div>
257
- </div>
258
-
259
- <div class="col-md-6">
260
- <div class="form-group d-flex justify-content-between">
261
- <div class="form-group btn-container">
262
- <button type="button" id="connectBtn" class="btn btn-primary">Connect</button>
263
- <button type="reset" class="btn btn-primary">Clear</button>
264
- </div>
265
- </div>
266
- </div>
267
- </div>
268
-
269
- <div id="schema-table-section" style="display: none;">
270
- <div class="row">
271
- <div class="col-md-3">
272
- <div class="form-group1">
273
- <label for="schemas">Select Schemas <span class="text-danger">*</span></label>
274
- <select type="text" id="schemas" name="schemas" class="form-control" required>
275
- <option value="" selected>Select</option>
276
- <option value="schema1">Lookup</option>
277
- <option value="schema2">Public</option>
278
- <option value="schema3" selected>tenant_default</option>
279
- </select>
280
- </div>
281
- </div>
282
-
283
- <div class="col-md-3">
284
- <div class="form-group1">
285
- <label for="tableschema" style="margin-left: 30px;margin-right: 30px;">Select Tables <span
286
- class="text-danger">*</span></label>
287
- <div class="dropdown custom-dropdown">
288
- <button class="btn btn-secondary dropdown-toggle"
289
- style="margin-left: 30px;margin-right: 0px;" type="button" id="tablesDropdown"
290
- data-bs-toggle="dropdown" aria-expanded="false">
291
- Select Tables
292
- </button>
293
- <ul class="dropdown-menu" aria-labelledby="tablesDropdown">
294
- <li>
295
- <select type="text" id="tableschema" name="tableschema" class="form-control"
296
- multiple required>
297
- <option value="customer_master">customer_master</option>
298
- <option value="efs_company_master">efs_company_master</option>
299
- <option value="efs_group_company_master">efs_group_company_master</option>
300
- <option value="efs_region_master">efs_region_master</option>
301
- <option value="party_address_detail">party_address_detail</option>
302
- <option value="wms_warehouse_master">wms_warehouse_master</option>
303
- </select>
304
- </li>
305
- </ul>
306
- </div>
307
- </div>
308
- </div>
309
- <!-- <div class="col-md-3">
310
- <div class="btn-container1">
311
- <button type="button" id="saveBtn" class="btn btn-primary">Save</button>
312
- </div>
313
- </div>
314
- </div>
315
- <div class="row">-->
316
- <div class="col-md-3">
317
- <div class="form-group1">
318
- <label for="selectedTables" id="labelselected">Selected Tables</label>
319
- <textarea type="text" id="selectedTables" name="selectedTables" class="form-control"
320
- rows="4" readonly></textarea>
321
- </div>
322
- </div>
323
-
324
- <div class="col-md-3">
325
- <div class="form-group">
326
- <div class="btn-container1">
327
- <button type="submit" id="saveBtn" class="btn btn-primary">Save</button>
328
- </div>
329
- </div>
330
- </div>
331
- </div>
332
- </div>
333
- </form>
334
- </div>
335
- </div>
336
- </div>
337
- <footer class="footer">
338
- {%include 'footer.html'%}
339
- </footer>
340
- <script>
341
- // document.getElementById('database').addEventListener('change', function () {
342
- // const selectedDatabaseType =this.value;
343
- // if (selectedDatabaseType) {
344
- // fetchDatabaseDetails(selectedDatabaseType);
345
- // }
346
- // });
347
-
348
- // async function fetchDatabaseDetails(databaseType) {
349
- // try {
350
- // const response = await fetch(`/api/get_database_details?database_type=${encodeURIComponent(databaseType)}`);
351
- // if (!response.ok) {
352
- // throw new Error('Network response was not ok');
353
- // }
354
- // const connectorsData= await response.json();
355
- // //document.getElementById('server').value = connectorsData.server;
356
- // // document.getElementById('port').value = connectorsData.port;
357
- // // document.getElementById('databaseName').value = connectorsData.database_name;
358
- // // document.getElementById('username').value = connectorsData.username;
359
- // // document.getElementById('password').value = connectorsData.password;
360
- // // document.getElementById('selectedTables').value = connectorsData.dbtablename;
361
- // //updateFormFields(data);
362
- // } catch (error) {
363
- // console.error('Error fetching database details:', error);
364
- // }
365
- // }
366
- document.addEventListener('DOMContentLoaded', function () {
367
- fetchCompanies();
368
- const companySelect = document.getElementById('company');
369
- const databaseconnectorForm = document.getElementById('databaseconnectorForm');
370
- database.addEventListener('change', async function () {
371
- $("#message-container").empty();
372
- });
373
- companySelect.addEventListener('change', async function () {
374
- $("#message-container").empty();
375
- const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
376
- console.log(`Selected Company Name: ${selectedCompanyName}`);
377
-
378
- if (selectedCompanyName !== "Select") {
379
- $("#schema-table-section").hide();
380
- try {
381
- const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
382
- if (!response.ok) {
383
- throw new Error('Network response was not ok');
384
- }
385
- const data = await response.json();
386
- console.log(`Company ID: ${data.company_id}`);
387
- const companyId = data.company_id;
388
- document.getElementById('company_id').value = companyId;
389
-
390
- if (companyId) {
391
- try {
392
- const connectorsResponse = await fetch(`/api/check_data_connectors?company_id=${companyId}&company_name=${selectedCompanyName}`);
393
- if (!connectorsResponse.ok) {
394
- throw new Error('data connector Network response was not ok');
395
- }
396
- const connectorsData = await connectorsResponse.json();
397
- //setMultiSelectValues(document.getElementById('database'), connectorsData.databasetype); // Ensure this is an array
398
- //setMultiSelectValues(document.getElementById('databaseName'), connectorsData.database_name); // Ensure this is an array
399
- document.getElementById('database').value = connectorsData.databasetype;
400
- document.getElementById('server').value=connectorsData.serverip; // document.getElementById('server').value = connectorsData.serverip;
401
- document.getElementById('port').value = connectorsData.port;
402
- document.getElementById('databaseName').value = connectorsData.database_name;
403
- document.getElementById('username').value = connectorsData.username;
404
- document.getElementById('password').value = connectorsData.password;
405
- document.getElementById('selectedTables').value = connectorsData.dbtablename;
406
- databaseconnectorForm.style.display = 'block';
407
-
408
- } catch (error) {
409
- document.getElementById('database').value = " ";
410
- document.getElementById('server').value = " ";
411
- document.getElementById('port').value = " ";
412
- document.getElementById('databaseName').value = " ";
413
- document.getElementById('username').value = " ";
414
- document.getElementById('password').value = " ";
415
- document.getElementById('selectedTables').value = " ";
416
- console.error('Error fetching data from data connectors:', error);
417
- ("Company name does not exist. Please fill in the details.");
418
-
419
- // Optionally, you can insert a message into the DOM
420
- const messageContainer = document.getElementById('message-container');
421
- if (messageContainer) {
422
- messageContainer.innerHTML = "<div class='alert alert-danger'>Database details does not exist for this Company name.. Please fill in the details.</div>";
423
- }
424
-
425
-
426
- databaseconnectorForm.style.display = 'block';
427
- }
428
- } else {
429
- console.log(`Company ID does not exist, you can create and save data: ${data.company_id}`);
430
- databaseconnectorForm.style.display = 'none';
431
- }
432
-
433
- } catch (error) {
434
-
435
- console.error('Error fetching company ID or data connectors:', error);
436
- databaseconnectorForm.style.display = 'none';
437
- }
438
- } else {
439
- databaseconnectorForm.style.display = 'none';
440
- }
441
- });
442
-
443
- // document.getElementById("connectBtn").addEventListener("click", function (event) {
444
- // var database = document.getElementById("database").value;
445
- // var server = document.getElementById("server").value;
446
- // var port = document.getElementById("port").value;
447
- // var databaseName = document.getElementById("databaseName").value;
448
- // var username = document.getElementById("username").value;
449
- // var password = document.getElementById("password").value;
450
-
451
- // if (!database || !server || !port || !databaseName || !username || !password) {
452
- // alert("Please fill in all required fields.");
453
- // return;
454
- // }
455
-
456
- // document.getElementById("schema-table-section").style.display = "block";
457
- // });
458
- $("#tableschema").change(function () {
459
- var selectedTables = $(this).val();
460
- var currentText = $("#selectedTables").val();
461
- selectedTables.forEach(function (table) {
462
- if (!currentText.includes(table)) {
463
- if (currentText.length > 1) {
464
- currentText += ", " + table;
465
- } else {
466
- currentText = table;
467
- }
468
- }
469
- });
470
- $("#selectedTables").val(currentText);
471
- });
472
- document.getElementById("connectBtn").addEventListener("click", function (event) {
473
- var database = document.getElementById("database").value;
474
- var server = document.getElementById("server").value;
475
- var port = document.getElementById("port").value;
476
- var databaseName = document.getElementById("databaseName").value;
477
- var username = document.getElementById("username").value;
478
- var password = document.getElementById("password").value || "";
479
-
480
- if (!database || !server || !port || !databaseName || !username) {
481
- alert("Please fill in all required fields.");
482
- return;
483
- }
484
- document.getElementById("schema-table-section").style.display = "block";
485
- fetch("/api/connect", {
486
- method: "POST",
487
- headers: {
488
- "Content-Type": "application/json"
489
- },
490
- body: JSON.stringify({
491
- database_type: database,
492
- server: server,
493
- port: port,
494
- databaseName: databaseName,
495
- username: username,
496
- password: password
497
- })
498
- })
499
- .then(response => response.json())
500
- .then(data => {
501
- if (data.success) {
502
- populateSchemaDropdown(data.schemas);
503
- // Set default selection for tables
504
- if (data.schemas.length > 0) {
505
- updateTablesDropdown(data.schema_tables, data.schemas[0]);
506
- schemas.addEventListener("change", function (event) {
507
- var selectedSchema = event.target.value;
508
- updateTablesDropdown(data.schema_tables, selectedSchema);
509
- });
510
- }
511
- } else {
512
- alert("Failed to connect to the database. Please check your credentials.");
513
- }
514
- })
515
- .catch(error => {
516
- console.error("Error:", error);
517
- alert("An error occurred while connecting to the database.");
518
- });
519
- });
520
-
521
- function populateSchemaDropdown(schemas) {
522
- var schemaSelect = document.getElementById("schemas");
523
- schemaSelect.innerHTML = ""; // Clear any existing options
524
-
525
- schemas.forEach(function (schema) {
526
- var option = document.createElement("option");
527
- option.value = schema;
528
- option.textContent = schema;
529
- schemaSelect.appendChild(option);
530
- });
531
-
532
- }
533
-
534
- function updateTablesDropdown(schemaTables, selectedSchema) {
535
- var tableSchemaSelect = document.getElementById("tableschema");
536
- tableSchemaSelect.innerHTML = ""; // Clear any existing options
537
-
538
- if (schemaTables[selectedSchema]) {
539
- schemaTables[selectedSchema].forEach(function (table) {
540
- var option = document.createElement("option");
541
- option.value = table;
542
- option.textContent = table;
543
- tableSchemaSelect.appendChild(option);
544
- });
545
- }
546
- }
547
-
548
- // $("#tableschema").change(function () {
549
- // var selectedTables = $(this).val();
550
- // var currentText = $("#selectedTables").val();
551
- // selectedTables.forEach(function (table) {
552
- // if (!currentText.includes(table)) {
553
- // if (currentText.length > 1) {
554
- // currentText += ", " + table;
555
- // } else {
556
- // currentText = table;
557
- // }
558
- // }
559
- // });
560
- // $("#selectedTables").val(currentText);
561
- // });
562
-
563
- // document.getElementById("saveBtn").addEventListener("click", function (event) {
564
- // var tables = Array.from(document.getElementById("tableschema").selectedOptions).map(option => option.value);
565
- // if (tables.length === 0) {
566
- // alert("Please select at least one table.");
567
- // return;
568
- // }
569
-
570
- // var selectedTables = document.getElementById("selectedTables");
571
- // selectedTables.value = tables.join(", ");
572
- // selectedTables.style.display = "block";
573
- // document.getElementById("labelselected").style.display = "block";
574
- // document.getElementById("saveBtn1").style.display = "block";
575
- // });
576
- document.getElementById("saveBtn").addEventListener("click", async function (event) {
577
- //event.preventDefault(); // Prevent default form submission
578
-
579
- const form = document.getElementById('databaseconnectorForm');
580
- const formData = new FormData(form);
581
- console.log("formdatat",formData);
582
- try {
583
- const response = await fetch(form.action, {
584
- method: form.method,
585
- body: formData
586
- });
587
- console.log('Response:', response);
588
- if (!response.ok) {
589
- throw new Error('Network response was not ok');
590
-
591
- }
592
-
593
- const result = await response.json();
594
- // // Optionally, handle the response from the server
595
- if (result.success) {
596
- // alert('Data saved successfully');
597
-
598
-
599
- const messageContainer = document.getElementById('message-container');
600
- if(messageContainer)
601
- messageContainer.innerHTML = `
602
- <div class='alert alert-success'>
603
- Data saved successfully
604
- <button class='close' onclick='dismissMessage()'>OK</button>
605
- </div>`;
606
- }
607
- } catch (error) {
608
- console.error('Error saving data:', error);
609
- alert('An error occurred while saving data');
610
- }
611
- });
612
- });
613
- function dismissMessage() {
614
- const messageContainer = document.getElementById('message-container');
615
- if (messageContainer) {
616
- messageContainer.innerHTML = '';
617
- }
618
- }
619
- function handleError() {
620
- document.getElementById('database').value = " ";
621
- document.getElementById('server').value = " ";
622
- document.getElementById('port').value = " ";
623
- document.getElementById('databaseName').value = " ";
624
- document.getElementById('username').value = " ";
625
- document.getElementById('password').value = " ";
626
- }
627
- async function fetchCompanies() {
628
- try {
629
- const response = await fetch('/api/companies');
630
- if (!response.ok) {
631
- throw new Error('Network response was not ok');
632
- }
633
- const data = await response.json();
634
- displayCompanies(data.companies);
635
- } catch (error) {
636
- console.error('Error fetching companies:', error);
637
- }
638
- }
639
-
640
- function displayCompanies(companies) {
641
- const companySelect = document.getElementById('company');
642
- companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
643
- companies.forEach(company => {
644
- const option = document.createElement('option');
645
- option.value = company.name;
646
- option.textContent = company.name;
647
- companySelect.appendChild(option);
648
- });
649
- }
650
-
651
- function setMultiSelectValues(selectElement, values) {
652
- // Ensure values is an array
653
- if (!Array.isArray(values)) {
654
- values = [values];
655
- }
656
- Array.from(selectElement.options).forEach(option => {
657
- option.selected = values.includes(option.value);
658
- });
659
- }
660
- </script>
661
- </body>
662
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Data Connectors</title>
8
+ <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
9
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
10
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/adminlte.min.css">
11
+ <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
12
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" />
13
+
14
+ <style>
15
+ html,
16
+ body {
17
+ height: 90%;
18
+ margin: 0;
19
+ display: flex;
20
+ flex-direction: column;
21
+ }
22
+
23
+ body {
24
+ display: inline-flex;
25
+ flex-direction: column;
26
+ min-height: 90%;
27
+ }
28
+
29
+ .main-content {
30
+ flex: 1;
31
+ display: inline-flex;
32
+ flex-direction: column;
33
+ align-items: center;
34
+ justify-content: flex-start;
35
+ padding: 30px;
36
+ }
37
+
38
+ /* .container {
39
+ margin-top: 50px;
40
+ margin-left: 320px;
41
+ max-width: 800px;
42
+ padding: 10px;
43
+ border: 1px solid #ccc;
44
+ border-radius: 5px;
45
+ background-color: #fff;
46
+ position: relative;
47
+ z-index: 1;
48
+ } */
49
+
50
+ .form-group {
51
+ margin-bottom: 20px;
52
+ }
53
+
54
+ .form-group label {
55
+ font-weight: bold;
56
+ margin-top: -10px;
57
+ margin-left:-22px;
58
+ display: block;
59
+ }
60
+
61
+ .form-group input,
62
+ .form-group select,
63
+ .form-group textarea {
64
+ width: 90%;
65
+ margin-left:-22px;
66
+ padding: 2px;
67
+ border: 1px solid #ccc;
68
+ border-radius: 4px;
69
+ }
70
+
71
+ .btn-primary {
72
+ margin-right: 10px;
73
+ color: white;
74
+ font-size: 16px;
75
+ font-weight: bold;
76
+ }
77
+
78
+ /* .btn-container {
79
+ text-align: center;
80
+ margin-top: 20px;
81
+ margin-bottom: 10px;
82
+ } */
83
+ .btn-primary {
84
+ margin-right: 10px;
85
+ color: white;
86
+ font-size: 16px;
87
+ font-weight: bold;
88
+ }
89
+
90
+
91
+ .btn-container {
92
+ text-align: center;
93
+ margin-top: 30px;
94
+ margin-left: 20px;
95
+ margin-right: 0px;
96
+ margin-bottom: 10px;
97
+ /* color: white; */
98
+ }
99
+
100
+ .btn-container1 {
101
+ text-align: center;
102
+ margin-top: 50px;
103
+ margin-left: 30px;
104
+ margin-right: 30px;
105
+ margin-bottom: 10px;
106
+ color: white;
107
+ }
108
+
109
+ /* #selectedTables,
110
+ #labelselected {
111
+ display: none;
112
+ } */
113
+ .btn-primary:focus,
114
+ .btn-primary:active {
115
+ color: white;
116
+ background-color: #007bff;
117
+ border-color: #007bff;
118
+ box-shadow: none;
119
+ }
120
+
121
+ #saveBtn1 {
122
+
123
+ margin: 0 auto;
124
+ }
125
+
126
+ /* footer {
127
+ position: relative;
128
+ margin-top: auto;
129
+ width: 100%;
130
+ color: black;
131
+ text-align: right;
132
+ padding-right: 245px;
133
+ padding-top: 20px;
134
+ background-color: #f8f9fa;
135
+ border: none !important;
136
+ }
137
+ */
138
+ .small-select {
139
+ margin-top: 5px;
140
+ width: 200px;
141
+ /* Adjust the width as needed */
142
+ }
143
+
144
+ .custom-dropdown {
145
+ width: 250px;
146
+ /* Adjust the width as needed */
147
+ }
148
+ /* Ensure the new row aligns with the previous row */
149
+ #schema-table-section {
150
+
151
+ margin-left: -20px; /* Adjust this if you need spacing between rows */
152
+ padding-top: 5px; /* Adjust padding if needed */
153
+ }
154
+
155
+ .alert {
156
+ position: relative;
157
+ padding: 15px;
158
+ margin-bottom: 20px;
159
+ border: 1px solid transparent;
160
+ border-radius: 4px;
161
+ }
162
+
163
+ .alert-success {
164
+ color: #3c763d;
165
+ background-color: #dff0d8;
166
+ border-color: #d6e9c6;
167
+ }
168
+
169
+ .alert-danger {
170
+ color: #a94442;
171
+ background-color: #f2dede;
172
+ border-color: #ebccd1;
173
+ }
174
+
175
+ .close {
176
+ position: absolute;
177
+ bottom: 10px;
178
+ right: 10px;
179
+ border: none;
180
+ background: none;
181
+ font-size: 16px;
182
+ cursor: pointer;
183
+ }
184
+
185
+
186
+ </style>
187
+ </head>
188
+
189
+ <body>
190
+ {% include 'sidepane.html' %}
191
+ <div class="wrapper">
192
+ <div class="main-header" style="border-bottom: none;">
193
+ <!-- Content Header (Page header) -->
194
+ <div class="content-header">
195
+ <div class="container-fluid">
196
+ <div class="container mt-2">
197
+ <div class="form-group left-align">
198
+ <label for="company" class="mr-1" style="margin-left:-60px;margin-top:-1px;">Company Name <span class="text-danger">*</span></label>
199
+ <select type="text" id="company" name="company" class="form-control "style="width: 20%;margin-left:-60px;margin-bottom:-35px" required>
200
+ <option value="" selected>Select</option>
201
+ </select>
202
+ </div>
203
+ <div class="row">
204
+ <div id="message-container" style="padding:10px 10px;margin-left: 150px;width:500px;margin-bottom:-20px; margin-top: -30px;"></div>
205
+ </div>
206
+ </div>
207
+ </div>
208
+ </div>
209
+ <form id="databaseconnectorForm" class="needs-validation" novalidate action="/save_data_connectors"
210
+ method="post" style="display:none;">
211
+ <div class="form-group">
212
+ <!-- <label for="company_id">company_id</label>--->
213
+ <input type="hidden" id="company_id" name="company_id" class="form-control" required>
214
+ </div>
215
+ <div class="row">
216
+ <div class="col-md-3">
217
+ <div class="form-group">
218
+ <label for="database">Database Type<span class="text-danger">*</span></label>
219
+ <select type="text" id="database" name="database" class="form-control" required>
220
+ <option value="" selected>Select</option>
221
+ <option value="Postgres">Postgres</option>
222
+ <option value="mysql">mysql</option>
223
+ </select>
224
+ </div>
225
+ </div>
226
+ <div class="col-md-3">
227
+ <div class="form-group">
228
+ <label for="server">Server IP <span class="text-danger">*</span></label>
229
+ <input type="text" id="server" name="server" class="form-control" required>
230
+ </div>
231
+ </div>
232
+ <div class="col-md-3">
233
+ <div class="form-group">
234
+ <label for="port">Port <span class="text-danger">*</span></label>
235
+ <input type="text" id="port" name="port" class="form-control" required>
236
+ </div>
237
+ </div>
238
+ <div class="col-md-3">
239
+ <div class="form-group">
240
+ <label for="databaseName">Database Name <span class="text-danger">*</span></label>
241
+ <input type="text" id="databaseName" name="databaseName" class="form-control" required>
242
+ </div>
243
+ </div>
244
+ </div>
245
+ <div class="row">
246
+ <div class="col-md-3">
247
+ <div class="form-group">
248
+ <label for="userame">UserName <span class="text-danger">*</span></label>
249
+ <input type="text" id="username" name="username" class="form-control" required>
250
+ </div>
251
+ </div>
252
+ <div class="col-md-3">
253
+ <div class="form-group">
254
+ <label for="password">Password <span class="text-danger">*</span></label>
255
+ <input type="password" id="password" name="password" class="form-control" required>
256
+ </div>
257
+ </div>
258
+
259
+ <div class="col-md-6">
260
+ <div class="form-group d-flex justify-content-between">
261
+ <div class="form-group btn-container">
262
+ <button type="button" id="connectBtn" class="btn btn-primary">Connect</button>
263
+ <button type="reset" class="btn btn-primary">Clear</button>
264
+ </div>
265
+ </div>
266
+ </div>
267
+ </div>
268
+
269
+ <div id="schema-table-section" style="display: none;">
270
+ <div class="row">
271
+ <div class="col-md-3">
272
+ <div class="form-group1">
273
+ <label for="schemas">Select Schemas <span class="text-danger">*</span></label>
274
+ <select type="text" id="schemas" name="schemas" class="form-control" required>
275
+ <option value="" selected>Select</option>
276
+ <option value="schema1">Lookup</option>
277
+ <option value="schema2">Public</option>
278
+ <option value="schema3" selected>tenant_default</option>
279
+ </select>
280
+ </div>
281
+ </div>
282
+
283
+ <div class="col-md-3">
284
+ <div class="form-group1">
285
+ <label for="tableschema" style="margin-left: 30px;margin-right: 30px;">Select Tables <span
286
+ class="text-danger">*</span></label>
287
+ <div class="dropdown custom-dropdown">
288
+ <button class="btn btn-secondary dropdown-toggle"
289
+ style="margin-left: 30px;margin-right: 0px;" type="button" id="tablesDropdown"
290
+ data-bs-toggle="dropdown" aria-expanded="false">
291
+ Select Tables
292
+ </button>
293
+ <ul class="dropdown-menu" aria-labelledby="tablesDropdown">
294
+ <li>
295
+ <select type="text" id="tableschema" name="tableschema" class="form-control"
296
+ multiple required>
297
+ <option value="customer_master">customer_master</option>
298
+ <option value="efs_company_master">efs_company_master</option>
299
+ <option value="efs_group_company_master">efs_group_company_master</option>
300
+ <option value="efs_region_master">efs_region_master</option>
301
+ <option value="party_address_detail">party_address_detail</option>
302
+ <option value="wms_warehouse_master">wms_warehouse_master</option>
303
+ </select>
304
+ </li>
305
+ </ul>
306
+ </div>
307
+ </div>
308
+ </div>
309
+ <!-- <div class="col-md-3">
310
+ <div class="btn-container1">
311
+ <button type="button" id="saveBtn" class="btn btn-primary">Save</button>
312
+ </div>
313
+ </div>
314
+ </div>
315
+ <div class="row">-->
316
+ <div class="col-md-3">
317
+ <div class="form-group1">
318
+ <label for="selectedTables" id="labelselected">Selected Tables</label>
319
+ <textarea type="text" id="selectedTables" name="selectedTables" class="form-control"
320
+ rows="4" readonly></textarea>
321
+ </div>
322
+ </div>
323
+
324
+ <div class="col-md-3">
325
+ <div class="form-group">
326
+ <div class="btn-container1">
327
+ <button type="submit" id="saveBtn" class="btn btn-primary">Save</button>
328
+ </div>
329
+ </div>
330
+ </div>
331
+ </div>
332
+ </div>
333
+ </form>
334
+ </div>
335
+ </div>
336
+ </div>
337
+ <footer class="footer">
338
+ {%include 'footer.html'%}
339
+ </footer>
340
+ <script>
341
+ // document.getElementById('database').addEventListener('change', function () {
342
+ // const selectedDatabaseType =this.value;
343
+ // if (selectedDatabaseType) {
344
+ // fetchDatabaseDetails(selectedDatabaseType);
345
+ // }
346
+ // });
347
+
348
+ // async function fetchDatabaseDetails(databaseType) {
349
+ // try {
350
+ // const response = await fetch(`/api/get_database_details?database_type=${encodeURIComponent(databaseType)}`);
351
+ // if (!response.ok) {
352
+ // throw new Error('Network response was not ok');
353
+ // }
354
+ // const connectorsData= await response.json();
355
+ // //document.getElementById('server').value = connectorsData.server;
356
+ // // document.getElementById('port').value = connectorsData.port;
357
+ // // document.getElementById('databaseName').value = connectorsData.database_name;
358
+ // // document.getElementById('username').value = connectorsData.username;
359
+ // // document.getElementById('password').value = connectorsData.password;
360
+ // // document.getElementById('selectedTables').value = connectorsData.dbtablename;
361
+ // //updateFormFields(data);
362
+ // } catch (error) {
363
+ // console.error('Error fetching database details:', error);
364
+ // }
365
+ // }
366
+ document.addEventListener('DOMContentLoaded', function () {
367
+ fetchCompanies();
368
+ const companySelect = document.getElementById('company');
369
+ const databaseconnectorForm = document.getElementById('databaseconnectorForm');
370
+ database.addEventListener('change', async function () {
371
+ $("#message-container").empty();
372
+ });
373
+ companySelect.addEventListener('change', async function () {
374
+ $("#message-container").empty();
375
+ const selectedCompanyName = companySelect.options[companySelect.selectedIndex].text;
376
+ console.log(`Selected Company Name: ${selectedCompanyName}`);
377
+
378
+ if (selectedCompanyName !== "Select") {
379
+ $("#schema-table-section").hide();
380
+ try {
381
+ const response = await fetch(`/api/company_id?company_name=${encodeURIComponent(selectedCompanyName)}`);
382
+ if (!response.ok) {
383
+ throw new Error('Network response was not ok');
384
+ }
385
+ const data = await response.json();
386
+ console.log(`Company ID: ${data.company_id}`);
387
+ const companyId = data.company_id;
388
+ document.getElementById('company_id').value = companyId;
389
+
390
+ if (companyId) {
391
+ try {
392
+ const connectorsResponse = await fetch(`/api/check_data_connectors?company_id=${companyId}&company_name=${selectedCompanyName}`);
393
+ if (!connectorsResponse.ok) {
394
+ throw new Error('data connector Network response was not ok');
395
+ }
396
+ const connectorsData = await connectorsResponse.json();
397
+ //setMultiSelectValues(document.getElementById('database'), connectorsData.databasetype); // Ensure this is an array
398
+ //setMultiSelectValues(document.getElementById('databaseName'), connectorsData.database_name); // Ensure this is an array
399
+ document.getElementById('database').value = connectorsData.databasetype;
400
+ document.getElementById('server').value=connectorsData.serverip; // document.getElementById('server').value = connectorsData.serverip;
401
+ document.getElementById('port').value = connectorsData.port;
402
+ document.getElementById('databaseName').value = connectorsData.database_name;
403
+ document.getElementById('username').value = connectorsData.username;
404
+ document.getElementById('password').value = connectorsData.password;
405
+ document.getElementById('selectedTables').value = connectorsData.dbtablename;
406
+ databaseconnectorForm.style.display = 'block';
407
+
408
+ } catch (error) {
409
+ document.getElementById('database').value = " ";
410
+ document.getElementById('server').value = " ";
411
+ document.getElementById('port').value = " ";
412
+ document.getElementById('databaseName').value = " ";
413
+ document.getElementById('username').value = " ";
414
+ document.getElementById('password').value = " ";
415
+ document.getElementById('selectedTables').value = " ";
416
+ console.error('Error fetching data from data connectors:', error);
417
+ ("Company name does not exist. Please fill in the details.");
418
+
419
+ // Optionally, you can insert a message into the DOM
420
+ const messageContainer = document.getElementById('message-container');
421
+ if (messageContainer) {
422
+ messageContainer.innerHTML = "<div class='alert alert-danger'>Database details does not exist for this Company name.. Please fill in the details.</div>";
423
+ }
424
+
425
+
426
+ databaseconnectorForm.style.display = 'block';
427
+ }
428
+ } else {
429
+ console.log(`Company ID does not exist, you can create and save data: ${data.company_id}`);
430
+ databaseconnectorForm.style.display = 'none';
431
+ }
432
+
433
+ } catch (error) {
434
+
435
+ console.error('Error fetching company ID or data connectors:', error);
436
+ databaseconnectorForm.style.display = 'none';
437
+ }
438
+ } else {
439
+ databaseconnectorForm.style.display = 'none';
440
+ }
441
+ });
442
+
443
+ // document.getElementById("connectBtn").addEventListener("click", function (event) {
444
+ // var database = document.getElementById("database").value;
445
+ // var server = document.getElementById("server").value;
446
+ // var port = document.getElementById("port").value;
447
+ // var databaseName = document.getElementById("databaseName").value;
448
+ // var username = document.getElementById("username").value;
449
+ // var password = document.getElementById("password").value;
450
+
451
+ // if (!database || !server || !port || !databaseName || !username || !password) {
452
+ // alert("Please fill in all required fields.");
453
+ // return;
454
+ // }
455
+
456
+ // document.getElementById("schema-table-section").style.display = "block";
457
+ // });
458
+ $("#tableschema").change(function () {
459
+ var selectedTables = $(this).val();
460
+ var currentText = $("#selectedTables").val();
461
+ selectedTables.forEach(function (table) {
462
+ if (!currentText.includes(table)) {
463
+ if (currentText.length > 1) {
464
+ currentText += ", " + table;
465
+ } else {
466
+ currentText = table;
467
+ }
468
+ }
469
+ });
470
+ $("#selectedTables").val(currentText);
471
+ });
472
+ document.getElementById("connectBtn").addEventListener("click", function (event) {
473
+ var database = document.getElementById("database").value;
474
+ var server = document.getElementById("server").value;
475
+ var port = document.getElementById("port").value;
476
+ var databaseName = document.getElementById("databaseName").value;
477
+ var username = document.getElementById("username").value;
478
+ var password = document.getElementById("password").value || "";
479
+
480
+ if (!database || !server || !port || !databaseName || !username) {
481
+ alert("Please fill in all required fields.");
482
+ return;
483
+ }
484
+ // document.getElementById("schema-table-section").style.display = "block";
485
+ fetch("/api/connect", {
486
+ method: "POST",
487
+ headers: {
488
+ "Content-Type": "application/json"
489
+ },
490
+ body: JSON.stringify({
491
+ database_type: database,
492
+ server: server,
493
+ port: port,
494
+ databaseName: databaseName,
495
+ username: username,
496
+ password: password
497
+ })
498
+ })
499
+ .then(response => response.json())
500
+ .then(data => {
501
+ if (data.success) {
502
+ document.getElementById("schema-table-section").style.display = "block";
503
+ populateSchemaDropdown(data.schemas);
504
+ // Set default selection for tables
505
+ if (data.schemas.length > 0) {
506
+ updateTablesDropdown(data.schema_tables, data.schemas[0]);
507
+ schemas.addEventListener("change", function (event) {
508
+ var selectedSchema = event.target.value;
509
+ updateTablesDropdown(data.schema_tables, selectedSchema);
510
+ });
511
+ }
512
+ } else {
513
+ alert("Failed to connect to the database. Please check your credentials.");
514
+ document.getElementById("schema-table-section").style.display = "none";
515
+ }
516
+ })
517
+ .catch(error => {
518
+ console.error("Error:", error);
519
+ alert("An error occurred while connecting to the database.");
520
+ });
521
+ });
522
+
523
+ function populateSchemaDropdown(schemas) {
524
+ var schemaSelect = document.getElementById("schemas");
525
+ schemaSelect.innerHTML = ""; // Clear any existing options
526
+
527
+ schemas.forEach(function (schema) {
528
+ var option = document.createElement("option");
529
+ option.value = schema;
530
+ option.textContent = schema;
531
+ schemaSelect.appendChild(option);
532
+ });
533
+
534
+ }
535
+
536
+ function updateTablesDropdown(schemaTables, selectedSchema) {
537
+ var tableSchemaSelect = document.getElementById("tableschema");
538
+ tableSchemaSelect.innerHTML = ""; // Clear any existing options
539
+
540
+ if (schemaTables[selectedSchema]) {
541
+ schemaTables[selectedSchema].forEach(function (table) {
542
+ var option = document.createElement("option");
543
+ option.value = table;
544
+ option.textContent = table;
545
+ tableSchemaSelect.appendChild(option);
546
+ });
547
+ }
548
+ }
549
+
550
+ document.getElementById("saveBtn").addEventListener("click", async function (event) {
551
+ event.preventDefault(); // Prevent the default form submission
552
+
553
+ // Set the password value
554
+ //document.getElementById("password").value = "root";
555
+
556
+ const form = document.getElementById('databaseconnectorForm');
557
+ const formData = new FormData(form);
558
+
559
+ try {
560
+ const response = await fetch(form.action, {
561
+ method: "POST",
562
+ body: formData
563
+ });
564
+
565
+ if (!response.ok) {
566
+ throw new Error('Network response was not ok');
567
+ }
568
+
569
+ const data = await response.json();
570
+
571
+ console.log("result", response);
572
+
573
+ const messageContainer = document.getElementById('message-container');
574
+ if (data.created) {
575
+ if (messageContainer) {
576
+ const messageType = data.created ? 'alert-success' : 'alert-danger';
577
+ messageContainer.innerHTML = `
578
+ <div class='alert ${messageType}'>
579
+ ${data.msg}
580
+ <button class='close' onclick='dismissMessage()'>OK</button>
581
+ </div>`;
582
+ }
583
+ }
584
+
585
+ } catch (error) {
586
+ console.error('Error saving data:', error);
587
+ const messageContainer = document.getElementById('message-container');
588
+ if (messageContainer) {
589
+ messageContainer.innerHTML = `
590
+ <div class='alert alert-danger'>
591
+ An error occurred while saving data.
592
+ <button class='close' onclick='dismissMessage()'>OK</button>
593
+ </div>`;
594
+ }
595
+ }
596
+ });
597
+
598
+ });
599
+ function dismissMessage() {
600
+ const messageContainer = document.getElementById('message-container');
601
+ if (messageContainer) {
602
+ messageContainer.innerHTML = '';
603
+ }
604
+ }
605
+ function handleError() {
606
+ document.getElementById('database').value = " ";
607
+ document.getElementById('server').value = " ";
608
+ document.getElementById('port').value = " ";
609
+ document.getElementById('databaseName').value = " ";
610
+ document.getElementById('username').value = " ";
611
+ document.getElementById('password').value = " ";
612
+ }
613
+ async function fetchCompanies() {
614
+ try {
615
+ const response = await fetch('/api/companies');
616
+ if (!response.ok) {
617
+ throw new Error('Network response was not ok');
618
+ }
619
+ const data = await response.json();
620
+ displayCompanies(data.companies);
621
+ } catch (error) {
622
+ console.error('Error fetching companies:', error);
623
+ }
624
+ }
625
+
626
+ function displayCompanies(companies) {
627
+ const companySelect = document.getElementById('company');
628
+ companySelect.innerHTML = '<option value="" selected>Select</option>'; // Reset the dropdown
629
+ companies.forEach(company => {
630
+ const option = document.createElement('option');
631
+ option.value = company.name;
632
+ option.textContent = company.name;
633
+ companySelect.appendChild(option);
634
+ });
635
+ }
636
+
637
+ function setMultiSelectValues(selectElement, values) {
638
+ // Ensure values is an array
639
+ if (!Array.isArray(values)) {
640
+ values = [values];
641
+ }
642
+ Array.from(selectElement.options).forEach(option => {
643
+ option.selected = values.includes(option.value);
644
+ });
645
+ }
646
+ </script>
647
+ </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
648
  </html>