Spaces:
Runtime error
Runtime error
Update templates/company_profile.html
Browse files- templates/company_profile.html +100 -37
templates/company_profile.html
CHANGED
@@ -169,10 +169,10 @@
|
|
169 |
<div class="row mb-2">
|
170 |
<div class="col-12">
|
171 |
<div class="col-12 d-flex justify-content-end mb-3">
|
172 |
-
<button class="btn btn-primary" style="margin-bottom:-30px;position:fixed"
|
173 |
-
id="add">Add</button>
|
174 |
</div>
|
175 |
</div>
|
|
|
176 |
<div class="row">
|
177 |
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
|
178 |
</div>
|
@@ -180,14 +180,13 @@
|
|
180 |
</div>
|
181 |
</div>
|
182 |
<!-- Main content -->
|
183 |
-
<section class="content">
|
184 |
<div class="container-fluid">
|
185 |
<div class="row">
|
186 |
<div class="col-12">
|
187 |
<div class="card">
|
188 |
<div class="card-body table-container">
|
189 |
-
<table id="companyTable"
|
190 |
-
class="custom-select-lm table table-bordered table-striped">
|
191 |
<thead>
|
192 |
<tr>
|
193 |
<th>Sno</th>
|
@@ -247,6 +246,10 @@
|
|
247 |
Please select at least one LLM tool.
|
248 |
</div>
|
249 |
</div>
|
|
|
|
|
|
|
|
|
250 |
</form>
|
251 |
</div>
|
252 |
<div class="modal-footer">
|
@@ -264,9 +267,26 @@
|
|
264 |
document.addEventListener('DOMContentLoaded', function () {
|
265 |
|
266 |
const role = sessionStorage.getItem('userRole');
|
267 |
-
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
fetchCompanies();
|
271 |
});
|
272 |
window.addEventListener('pageshow', function (event) {
|
@@ -285,10 +305,14 @@
|
|
285 |
placeholder: 'Select',
|
286 |
allowClear: true
|
287 |
});
|
|
|
|
|
288 |
// Show modal function
|
289 |
$('#add').on('click', function () {
|
290 |
const modalTitle = document.getElementById('addModalLabel');
|
291 |
modalTitle.textContent = 'Add Company Details';
|
|
|
|
|
292 |
$('#addModal').modal('show');
|
293 |
$('#save').show();
|
294 |
$('#saveupdate').hide();
|
@@ -310,7 +334,14 @@
|
|
310 |
$(document).on('click', '.btn-edit', function () {
|
311 |
const companyId = $(this).data('id');
|
312 |
console.log("company_id in edit", companyId);
|
313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
});
|
315 |
|
316 |
// Delete company
|
@@ -322,33 +353,56 @@
|
|
322 |
}
|
323 |
});
|
324 |
|
325 |
-
});
|
326 |
// View company details
|
327 |
function viewCompany(companyId) {
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
});
|
346 |
}
|
347 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
// Edit company details
|
349 |
-
function
|
|
|
350 |
const modalTitle = document.getElementById('addModalLabel');
|
351 |
modalTitle.textContent = 'Edit Company Details';
|
|
|
352 |
// Fetch company details by ID
|
353 |
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
|
354 |
$('#company_name').removeAttr('readonly');
|
@@ -362,8 +416,9 @@
|
|
362 |
$('#company_code').val(company.company_code);
|
363 |
$('#domain').val(company.domain);
|
364 |
$('#llm_tools').val(company.llm_tools.split(',')).trigger('change');
|
365 |
-
|
366 |
-
|
|
|
367 |
$('#addModal').modal('show');
|
368 |
|
369 |
// Update the save button to save the edited company
|
@@ -389,7 +444,7 @@
|
|
389 |
messageContainer.innerHTML = `
|
390 |
<div class='alert alert-danger'>
|
391 |
Company details deleted successfully.
|
392 |
-
<button class='close' onclick='dismissMessage()'>OK</button>
|
393 |
</div>`;
|
394 |
fetchCompanies(); // Refresh the table
|
395 |
},
|
@@ -404,7 +459,8 @@
|
|
404 |
company_name: $('#company_name').val(),
|
405 |
company_code: $('#company_code').val(),
|
406 |
domain: $('#domain').val(),
|
407 |
-
llm_tools: $('#llm_tools').val().join(',')
|
|
|
408 |
};
|
409 |
console.log("company_data", companyData);
|
410 |
|
@@ -419,7 +475,7 @@
|
|
419 |
messageContainer.innerHTML = `
|
420 |
<div class='alert alert-success'>
|
421 |
Company Data Updated successfully
|
422 |
-
<button class='close' onclick='dismissMessage()'>OK</button>
|
423 |
</div>`;
|
424 |
$('#addModal').modal('hide'); // Close the modal after saving
|
425 |
fetchCompanies();
|
@@ -431,7 +487,7 @@
|
|
431 |
messageContainer.innerHTML = `
|
432 |
<div class='alert alert-danger'>
|
433 |
No changes have been made to update company details.
|
434 |
-
<button class='close' onclick='dismissMessage()'>OK</button>
|
435 |
</div>`;
|
436 |
$('#addModal').modal('hide');
|
437 |
//alert('No changes have been made to update company details.');
|
@@ -451,14 +507,21 @@
|
|
451 |
const company_name = document.getElementById('company_name').value;
|
452 |
const company_code = document.getElementById('company_code').value;
|
453 |
const domain = document.getElementById('domain').value;
|
454 |
-
const llm_tools = $('#llm_tools').val();
|
|
|
|
|
455 |
|
456 |
// Prepare FormData
|
457 |
let formData = new FormData();
|
|
|
|
|
458 |
formData.append("company_name", company_name);
|
459 |
formData.append("company_code", company_code);
|
460 |
formData.append("domain", domain);
|
461 |
formData.append("llm_tools", llm_tools.join(','));
|
|
|
|
|
|
|
462 |
|
463 |
$.ajax({
|
464 |
type: "POST",
|
@@ -473,7 +536,7 @@
|
|
473 |
messageContainer.innerHTML = `
|
474 |
<div class='alert alert-success'>
|
475 |
Data saved successfully
|
476 |
-
<button class='close' onclick='dismissMessage()'>OK</button>
|
477 |
</div>`;
|
478 |
fetchCompanies(); // Refresh table data
|
479 |
|
@@ -514,7 +577,7 @@
|
|
514 |
company.domain,
|
515 |
company.llm_tools, // Join array of tools into a string
|
516 |
`<a href='#' class='btn btn-info btn-sm'onclick='viewCompany(${company.company_id})'><i class='fas fa-eye'></i></a>`,
|
517 |
-
`<a href='#' class='btn btn-warning btn-sm'onclick='
|
518 |
`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`
|
519 |
|
520 |
]).draw(false);
|
|
|
169 |
<div class="row mb-2">
|
170 |
<div class="col-12">
|
171 |
<div class="col-12 d-flex justify-content-end mb-3">
|
172 |
+
<button class="btn btn-primary" style="margin-bottom:-30px;position:fixed" id="add">Add</button>
|
|
|
173 |
</div>
|
174 |
</div>
|
175 |
+
<input type="hidden" id="userRole" name="userRole" value={{role}}>
|
176 |
<div class="row">
|
177 |
<div id="message-container" style="margin-left: 200px;width:600px;"></div>
|
178 |
</div>
|
|
|
180 |
</div>
|
181 |
</div>
|
182 |
<!-- Main content -->
|
183 |
+
<section class="content" id="startTable" style="display: none;">
|
184 |
<div class="container-fluid">
|
185 |
<div class="row">
|
186 |
<div class="col-12">
|
187 |
<div class="card">
|
188 |
<div class="card-body table-container">
|
189 |
+
<table id="companyTable" class="custom-select-lm table table-bordered table-striped">
|
|
|
190 |
<thead>
|
191 |
<tr>
|
192 |
<th>Sno</th>
|
|
|
246 |
Please select at least one LLM tool.
|
247 |
</div>
|
248 |
</div>
|
249 |
+
<div class="form-group">
|
250 |
+
<label for="domain">UserName<span class="text-danger">*</span></label>
|
251 |
+
<input type="text" class="form-control" id="username" name="username" required>
|
252 |
+
</div>
|
253 |
</form>
|
254 |
</div>
|
255 |
<div class="modal-footer">
|
|
|
267 |
document.addEventListener('DOMContentLoaded', function () {
|
268 |
|
269 |
const role = sessionStorage.getItem('userRole');
|
270 |
+
const company_id=sessionStorage.getItem('company_id');
|
271 |
+
console.log('Current role:', role); // Debug statement to check the role
|
272 |
+
document.getElementById('userRole').value = role;
|
273 |
+
$('#addModal').hide(); // Make sure this is called initially
|
274 |
+
|
275 |
+
if (role === 'superadmin') {
|
276 |
+
console.log("insidse compamy profile super admin");
|
277 |
+
|
278 |
+
$('#startTable').show();
|
279 |
+
$('#addModal').hide();
|
280 |
+
document.getElementById('add').style.display = 'block';
|
281 |
+
|
282 |
+
} else {
|
283 |
+
console.log("insidse company profile admin");
|
284 |
+
document.getElementById('add').style.display = 'none';
|
285 |
+
const modalTitle = document.getElementById('addModalLabel');
|
286 |
+
modalTitle.textContent = 'Company Details';
|
287 |
+
viewCompany(company_id);
|
288 |
+
|
289 |
+
}
|
290 |
fetchCompanies();
|
291 |
});
|
292 |
window.addEventListener('pageshow', function (event) {
|
|
|
305 |
placeholder: 'Select',
|
306 |
allowClear: true
|
307 |
});
|
308 |
+
|
309 |
+
});
|
310 |
// Show modal function
|
311 |
$('#add').on('click', function () {
|
312 |
const modalTitle = document.getElementById('addModalLabel');
|
313 |
modalTitle.textContent = 'Add Company Details';
|
314 |
+
console.log('Modal title after setting:', modalTitle.textContent); // This should log the new title
|
315 |
+
|
316 |
$('#addModal').modal('show');
|
317 |
$('#save').show();
|
318 |
$('#saveupdate').hide();
|
|
|
334 |
$(document).on('click', '.btn-edit', function () {
|
335 |
const companyId = $(this).data('id');
|
336 |
console.log("company_id in edit", companyId);
|
337 |
+
if (companyId)
|
338 |
+
{
|
339 |
+
const modalTitle = document.getElementById('addModalLabel');
|
340 |
+
modalTitle.textContent = 'Edit Company Details';
|
341 |
+
console.log('Modal title:', modalTitle.textContent);
|
342 |
+
|
343 |
+
Editcompany(companyId);
|
344 |
+
}
|
345 |
});
|
346 |
|
347 |
// Delete company
|
|
|
353 |
}
|
354 |
});
|
355 |
|
|
|
356 |
// View company details
|
357 |
function viewCompany(companyId) {
|
358 |
+
// Fetch company details by ID
|
359 |
+
const username = sessionStorage.getItem('username');
|
360 |
+
const modalTitle = document.getElementById('addModalLabel');
|
361 |
+
modalTitle.textContent = 'View Company Details';
|
362 |
+
|
363 |
+
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
|
364 |
+
// Set values and attributes for the form fields
|
365 |
+
$('#company_name').val(company.company_name).attr('readonly', 'readonly');
|
366 |
+
$('#company_code').val(company.company_code).attr('readonly', 'readonly');
|
367 |
+
$('#domain').val(company.domain).attr('readonly', 'readonly');
|
368 |
+
|
369 |
+
// Clear existing options in the dropdown
|
370 |
+
$('#llm_tools').empty();
|
371 |
+
|
372 |
+
// Add the options that are present in company.llm_tools
|
373 |
+
const availableOptions = {
|
374 |
+
'Database': 'Database',
|
375 |
+
'Static Documents': 'Static Documents',
|
376 |
+
'API': 'API'
|
377 |
+
};
|
378 |
+
|
379 |
+
if (Array.isArray(company.llm_tools)) {
|
380 |
+
company.llm_tools.forEach(tool => {
|
381 |
+
if (availableOptions[tool]) {
|
382 |
+
$('#llm_tools').append(new Option(availableOptions[tool], tool, true, true));
|
383 |
+
}
|
384 |
});
|
385 |
}
|
386 |
|
387 |
+
$('#llm_tools').prop('disabled', true); // Disable the dropdown
|
388 |
+
|
389 |
+
$('#username').val(username).attr('readonly', 'readonly'); // Set username field
|
390 |
+
|
391 |
+
// Show the modal with view details only
|
392 |
+
$('#saveupdate').hide();
|
393 |
+
$('#save').hide();
|
394 |
+
$('#addModal').modal('show');
|
395 |
+
}).fail(function () {
|
396 |
+
alert("Error retrieving company details.");
|
397 |
+
});
|
398 |
+
}
|
399 |
+
|
400 |
// Edit company details
|
401 |
+
function Editcompany(companyId) {
|
402 |
+
const username=sessionStorage.getItem('username');
|
403 |
const modalTitle = document.getElementById('addModalLabel');
|
404 |
modalTitle.textContent = 'Edit Company Details';
|
405 |
+
console.log('Modal title after setting:', modalTitle.textContent); // Should log "Edit Company Details"
|
406 |
// Fetch company details by ID
|
407 |
$.getJSON(`/api/getcompanydetails/${companyId}`, function (company) {
|
408 |
$('#company_name').removeAttr('readonly');
|
|
|
416 |
$('#company_code').val(company.company_code);
|
417 |
$('#domain').val(company.domain);
|
418 |
$('#llm_tools').val(company.llm_tools.split(',')).trigger('change');
|
419 |
+
$('#username').val(username).attr('readonly', 'readonly');// Disable the select input
|
420 |
+
|
421 |
+
//sessionStorage.setItem('llmTools', company.llm_tools); // Store as a string
|
422 |
$('#addModal').modal('show');
|
423 |
|
424 |
// Update the save button to save the edited company
|
|
|
444 |
messageContainer.innerHTML = `
|
445 |
<div class='alert alert-danger'>
|
446 |
Company details deleted successfully.
|
447 |
+
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
448 |
</div>`;
|
449 |
fetchCompanies(); // Refresh the table
|
450 |
},
|
|
|
459 |
company_name: $('#company_name').val(),
|
460 |
company_code: $('#company_code').val(),
|
461 |
domain: $('#domain').val(),
|
462 |
+
llm_tools: $('#llm_tools').val().join(','),
|
463 |
+
username: $('#username').val() // Assuming llm_tools is a multi-select
|
464 |
};
|
465 |
console.log("company_data", companyData);
|
466 |
|
|
|
475 |
messageContainer.innerHTML = `
|
476 |
<div class='alert alert-success'>
|
477 |
Company Data Updated successfully
|
478 |
+
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
479 |
</div>`;
|
480 |
$('#addModal').modal('hide'); // Close the modal after saving
|
481 |
fetchCompanies();
|
|
|
487 |
messageContainer.innerHTML = `
|
488 |
<div class='alert alert-danger'>
|
489 |
No changes have been made to update company details.
|
490 |
+
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
491 |
</div>`;
|
492 |
$('#addModal').modal('hide');
|
493 |
//alert('No changes have been made to update company details.');
|
|
|
507 |
const company_name = document.getElementById('company_name').value;
|
508 |
const company_code = document.getElementById('company_code').value;
|
509 |
const domain = document.getElementById('domain').value;
|
510 |
+
const llm_tools = $('#llm_tools').val();
|
511 |
+
const username=$('#username').val();
|
512 |
+
|
513 |
|
514 |
// Prepare FormData
|
515 |
let formData = new FormData();
|
516 |
+
const password="password";
|
517 |
+
const rolesave="admin";
|
518 |
formData.append("company_name", company_name);
|
519 |
formData.append("company_code", company_code);
|
520 |
formData.append("domain", domain);
|
521 |
formData.append("llm_tools", llm_tools.join(','));
|
522 |
+
formData.append("username",username);
|
523 |
+
formData.append("password",password);
|
524 |
+
formData.append("role",rolesave);
|
525 |
|
526 |
$.ajax({
|
527 |
type: "POST",
|
|
|
536 |
messageContainer.innerHTML = `
|
537 |
<div class='alert alert-success'>
|
538 |
Data saved successfully
|
539 |
+
<button class='close' style='font-size:medium;margin-top:6px;' onclick='dismissMessage()'>OK</button>
|
540 |
</div>`;
|
541 |
fetchCompanies(); // Refresh table data
|
542 |
|
|
|
577 |
company.domain,
|
578 |
company.llm_tools, // Join array of tools into a string
|
579 |
`<a href='#' class='btn btn-info btn-sm'onclick='viewCompany(${company.company_id})'><i class='fas fa-eye'></i></a>`,
|
580 |
+
`<a href='#' class='btn btn-warning btn-sm'onclick='Editcompany(${company.company_id})'><i class='fas fa-edit'></i></a>`,
|
581 |
`<a href='#' class='btn btn-danger btn-sm' onclick='deleteCompany(${company.company_id})'><i class='fas fa-trash'></i></a>`
|
582 |
|
583 |
]).draw(false);
|