add stats, and add history import details
This commit is contained in:
@@ -28,6 +28,8 @@
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css">
|
||||
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
|
||||
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-beta.1/css/select2.min.css" rel="stylesheet" />
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-beta.1/js/select2.min.js"></script>
|
||||
|
||||
<style>
|
||||
.width-100 {
|
||||
@@ -230,7 +232,8 @@
|
||||
data: null,
|
||||
className: 'dt-center',
|
||||
render: function(data, type, row) {
|
||||
return '<button class="btn btn-sm btn-primary show-synonyms" data-id="' + row.idanalysisvocabulary + '">Show Synonyms</button>';
|
||||
return '<button class="btn btn-sm btn-primary show-synonyms" data-id="' + row.idanalysisvocabulary + '">Show Synonyms</button>' +
|
||||
' <button class="btn btn-sm btn-danger show-compounds" data-id="' + row.idanalysisvocabulary + '">Show Compounds</button>';
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -393,6 +396,233 @@
|
||||
Swal.fire('Error', 'Please enter a synonym.', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// Show compounds and allow editing of compounds
|
||||
// Show compounds and allow editing of compounds
|
||||
$('#analysisTable').on('click', '.show-compounds', function() {
|
||||
var tr = $(this).closest('tr');
|
||||
var row = table.row(tr);
|
||||
var analysisId = $(this).data('id');
|
||||
|
||||
if (row.child.isShown()) {
|
||||
row.child.hide();
|
||||
tr.removeClass('shown');
|
||||
} else {
|
||||
$.ajax({
|
||||
url: 'get_compounds.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
id: analysisId
|
||||
},
|
||||
success: function(response) {
|
||||
var compounds = JSON.parse(response);
|
||||
var childTable = '<table class="table table-custom"><tr><th>Compound Name</th><th>CAS</th><th>Actions</th></tr>';
|
||||
|
||||
if (compounds.length > 0) {
|
||||
$.each(compounds, function(index, compound) {
|
||||
childTable += '<tr>' +
|
||||
'<td>' + compound.namecompoundsvocabulary + '</td>' +
|
||||
'<td>' + compound.cascompoundvocabulary + '</td>' +
|
||||
'<td><button class="btn btn-danger delete-compound" data-id="' + compound.idcompoundsvocabulary + '" data-analysis-id="' + analysisId + '">Delete</button></td></tr>';
|
||||
});
|
||||
} else {
|
||||
|
||||
childTable += '<tr><td colspan="3">No compounds found</td></tr>';
|
||||
}
|
||||
|
||||
// Add row for adding a new compound
|
||||
childTable += '<tr><td>New</td>' +
|
||||
'<td><select class="form-control new-compound-select" data-id="' + analysisId + '"></select></td>' +
|
||||
'<td><button class="btn btn-success add-compound" data-id="' + analysisId + '">Add</button></td></tr>';
|
||||
|
||||
childTable += '</table>';
|
||||
|
||||
row.child(childTable).show();
|
||||
tr.addClass('shown');
|
||||
|
||||
// Load compound options into the select dropdown with Select2
|
||||
$.ajax({
|
||||
url: 'get_compounds_list.php',
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
var compoundsList = JSON.parse(data);
|
||||
var select = tr.next().find('.new-compound-select');
|
||||
|
||||
// Aggiungi un'opzione iniziale per indicare di selezionare un composto
|
||||
select.append('<option value="" disabled selected>Select a compound...</option>');
|
||||
|
||||
// Popola il select con le opzioni
|
||||
$.each(compoundsList, function(index, compound) {
|
||||
var option = new Option(compound.text, compound.id, false, false);
|
||||
select.append(option);
|
||||
});
|
||||
|
||||
// Inizializza Select2 dopo aver popolato il select
|
||||
select.select2({
|
||||
placeholder: "Select a compound...",
|
||||
width: 'resolve',
|
||||
allowClear: true
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Error', 'Error loading compounds list.', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$('#analysisTable').on('click', '.add-compound', function() {
|
||||
var analysisId = $(this).data('id');
|
||||
var compoundId = $(this).closest('tr').find('.new-compound-select').val();
|
||||
var tr = $(this).closest('tr').prev(); // Trova la riga principale dell'analisi
|
||||
var row = table.row(tr);
|
||||
|
||||
if (compoundId) {
|
||||
$.ajax({
|
||||
url: 'add_compound.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
analysis_id: analysisId,
|
||||
compound_id: compoundId
|
||||
},
|
||||
success: function(response) {
|
||||
var jsonResponse = JSON.parse(response);
|
||||
if (jsonResponse.success) {
|
||||
Swal.fire('Success', 'New compound has been added successfully!', 'success');
|
||||
|
||||
// Ricarica solo la lista dei composti nel child table senza chiudere
|
||||
reloadChildCompounds(analysisId, row);
|
||||
} else {
|
||||
Swal.fire('Error', jsonResponse.error || 'There was a problem adding the compound.', 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Swal.fire('Error', 'Please select a compound.', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// Funzione per ricaricare il child table dei composti
|
||||
function reloadChildCompounds(analysisId, row) {
|
||||
$.ajax({
|
||||
url: 'get_compounds.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
id: analysisId
|
||||
},
|
||||
success: function(response) {
|
||||
var compounds = JSON.parse(response);
|
||||
var childTable = '<table class="table table-custom"><tr><th>Compound Name</th><th>CAS</th><th>Actions</th></tr>';
|
||||
|
||||
if (compounds.length > 0) {
|
||||
$.each(compounds, function(index, compound) {
|
||||
childTable += '<tr>' +
|
||||
'<td>' + compound.namecompoundsvocabulary + '</td>' +
|
||||
'<td>' + compound.cascompoundvocabulary + '</td>' +
|
||||
'<td><button class="btn btn-danger delete-compound" data-id="' + compound.idcompoundsvocabulary + '" data-analysis-id="' + analysisId + '">Delete</button></td></tr>';
|
||||
});
|
||||
} else {
|
||||
childTable += '<tr><td colspan="3">No compounds found</td></tr>';
|
||||
}
|
||||
|
||||
// Aggiungi una riga per aggiungere un nuovo composto
|
||||
childTable += '<tr><td>New</td>' +
|
||||
'<td><select class="form-control new-compound-select" data-id="' + analysisId + '"></select></td>' +
|
||||
'<td><button class="btn btn-success add-compound" data-id="' + analysisId + '">Add</button></td></tr>';
|
||||
|
||||
childTable += '</table>';
|
||||
|
||||
// Ricarica il contenuto del child row con il nuovo contenuto
|
||||
row.child(childTable).show();
|
||||
|
||||
// Carica le opzioni dei composti nella tendina con Select2
|
||||
$.ajax({
|
||||
url: 'get_compounds_list.php',
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
var compoundsList = JSON.parse(data);
|
||||
var select = row.child().find('.new-compound-select');
|
||||
|
||||
// Aggiungi un'opzione iniziale per indicare di selezionare un composto
|
||||
select.append('<option value="" disabled selected>Select a compound...</option>');
|
||||
|
||||
// Popola il select con le opzioni
|
||||
$.each(compoundsList, function(index, compound) {
|
||||
var option = new Option(compound.text, compound.id, false, false);
|
||||
select.append(option);
|
||||
});
|
||||
|
||||
// Inizializza Select2 dopo aver popolato il select
|
||||
select.select2({
|
||||
placeholder: "Select a compound...",
|
||||
width: 'resolve',
|
||||
allowClear: true
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Error', 'Error loading compounds list.', 'error');
|
||||
}
|
||||
});
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Handle delete compound
|
||||
$('#analysisTable').on('click', '.delete-compound', function() {
|
||||
var compoundId = $(this).data('id');
|
||||
var analysisId = $(this).data('analysis-id');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Are you sure?',
|
||||
text: 'This will delete the compound.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Yes, delete it!',
|
||||
cancelButtonText: 'Close Window'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.ajax({
|
||||
url: 'delete_compound.php',
|
||||
type: 'POST',
|
||||
data: {
|
||||
analysis_id: analysisId, // Invia l'ID dell'analisi
|
||||
compound_id: compoundId // Invia l'ID del composto
|
||||
},
|
||||
success: function(response) {
|
||||
var jsonResponse = JSON.parse(response);
|
||||
if (jsonResponse.success) {
|
||||
Swal.fire('Deleted!', 'The compound has been deleted.', 'success');
|
||||
table.ajax.reload(); // Reload DataTables
|
||||
} else {
|
||||
Swal.fire('Error', jsonResponse.error || 'There was a problem deleting the compound.', 'error');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire('Error', 'Server communication error.', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<!-- plugin JS -->
|
||||
|
||||
Reference in New Issue
Block a user