fix dashboard to API
This commit is contained in:
parent
7a4491c037
commit
748e7a04bc
@ -5,8 +5,6 @@ use CodeIgniter\Router\RouteCollection;
|
||||
/**
|
||||
* @var RouteCollection $routes
|
||||
*/
|
||||
$routes->get('/', 'Dashboard::index');
|
||||
$routes->get('/dashboard/viewAccess/(:any)', 'Dashboard::viewAccess/$1');
|
||||
|
||||
// Tubes
|
||||
$routes->get('/tubes/collect/(:any)/(:any)', 'Tubes::collect/$1/$2');
|
||||
@ -18,10 +16,15 @@ $routes->get('/tubes/unreceiveAll/(:any)', 'Tubes::unreceiveAll/$1');
|
||||
$routes->post('/tubes/comment/(:any)/(:any)', 'Tubes::comment/$1/$2');
|
||||
|
||||
// Pages
|
||||
$routes->get('/', 'Pages::dashboard_index');
|
||||
$routes->get('/userroles/', 'Pages::userroles_index');
|
||||
$routes->get('/users/', 'Pages::users_index');
|
||||
$routes->get('/changePass/', 'Pages::changePass');
|
||||
|
||||
$routes->get('/dashboard/viewAccess/(:any)', 'Dashboard::viewAccess/$1');
|
||||
// Dashboard
|
||||
$routes->get('/api/dashboard/index', 'Dashboard::index');
|
||||
|
||||
// DICT_TESTS
|
||||
$routes->get('/dict_tests/', 'Dict_tests::index');
|
||||
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
class Dashboard extends BaseController {
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
|
||||
public function index(): string {
|
||||
class Dashboard extends ResourceController {
|
||||
protected $format = 'json';
|
||||
|
||||
public function index() {
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "select top 50 sr.COLLECTIONDATE, sr.SP_ACCESSNUMBER, sr.HOSTORDERNUMBER, p.PATNUMBER, p.NAME,
|
||||
TESTS=stuff(( select ', '+'('+T.SP_TESTCODE+')' from
|
||||
@ -50,9 +52,9 @@ end STATS
|
||||
order by sr.COLLECTIONDATE desc";
|
||||
$query = $db->query($sql);
|
||||
$results = $query->getResultArray();
|
||||
$data['data'] = $results;
|
||||
|
||||
return view('dashboard', $data);
|
||||
$data['data'] = $results;
|
||||
return $this->respond($data,200);
|
||||
}
|
||||
|
||||
public function viewAccess($accessnumber): string {
|
||||
|
||||
@ -4,6 +4,10 @@ namespace App\Controllers;
|
||||
|
||||
class Pages extends BaseController {
|
||||
|
||||
public function dashboard_index() {
|
||||
return view('dashboard');
|
||||
}
|
||||
|
||||
public function userroles_index(): string {
|
||||
return view('userroles_index');
|
||||
}
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
<?= $this->extend('layouts/main.php') ?>
|
||||
|
||||
<?= $this->section('content') ?>
|
||||
<style>
|
||||
#table_dashboard tr { cursor: pointer; }
|
||||
</style>
|
||||
|
||||
<!--
|
||||
<div class="d-flex justify-content-between p-0">
|
||||
@ -91,9 +88,9 @@
|
||||
-->
|
||||
|
||||
<div class="card border-0">
|
||||
<div class="body-card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="table_dashboard" class="table">
|
||||
<table id="myTable" class="table">
|
||||
<thead>
|
||||
<tr >
|
||||
<th>Order</th>
|
||||
@ -105,28 +102,7 @@
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$i = 1;
|
||||
foreach ($data as $row) {
|
||||
$colldate = $row['COLLECTIONDATE'];
|
||||
$colldate = substr($colldate,0,10);
|
||||
$patnumber = $row['PATNUMBER'];
|
||||
$patnumber = substr($patnumber,-16);
|
||||
$accessnumber = $row['SP_ACCESSNUMBER'];
|
||||
?>
|
||||
<tr class="table-row viewAccess" data-bs-toggle="modal" data-bs-target="#modal" data-access='<?=$accessnumber;?>'>
|
||||
<td class="text-start text-nowrap"><?=$colldate;?></td>
|
||||
<td class="text-start text-nowrap"><?=$patnumber;?></td>
|
||||
<td class="text-start"><?=$row['NAME'];?></td>
|
||||
<td class="text-start"><?=$accessnumber;?></td>
|
||||
<td class="text-start"><?=$row['HOSTORDERNUMBER'];?></td>
|
||||
<td class="text-start"><?=$row['TESTS'];?></td>
|
||||
<td class="bg-orange text-center align-middle">Pending</td>
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<tbody id="table-body">
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@ -144,18 +120,41 @@
|
||||
|
||||
<?= $this->section('script') ?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#table_dashboard').DataTable({
|
||||
order: [],
|
||||
pageLength: 25
|
||||
var tb = $('#mytable').DataTable();
|
||||
index();
|
||||
function index() {
|
||||
let url = '<?=base_url('');?>api/dashboard/index';
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
$("#table-body").html("");
|
||||
var data = response['data'];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
colldate = data[i].COLLECTIONDATE.substr(0,10);
|
||||
patnumber = data[i].PATNUMBER.substr(-16,16);
|
||||
accessnumber = data[i].SP_ACCESSNUMBER;
|
||||
patname = data[i].NAME;
|
||||
hon = data[i].HOSTORDERNUMBER;
|
||||
tests = data[i].TESTS;
|
||||
let datarow = '<tr class="align-middle">' +
|
||||
'<td>' + colldate + '</td> <td>' + patnumber + '</td> <td>' + accessnumber + '</td> <td>' + patname + '</td> <td>' + hon + '</td> <td>' + tests + '</td>' +
|
||||
"<td role='button' class='bg-orange text-center align-middle' onclick='viewAccess("+accessnumber+")'>Pending</td>"
|
||||
'</tr>';
|
||||
$("#table-body").append(datarow);
|
||||
}
|
||||
tb.ajax.reload();
|
||||
},
|
||||
error: function(response) { console.log(response.responseJSON); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$('.viewAccess').on('click',function(){
|
||||
const access = $(this).data('access');
|
||||
$('.modal-content').load('<?=base_url();?>dashboard/viewAccess/'+access, function(){
|
||||
function viewAccess(access) {
|
||||
let url = '<?=base_url();?>dashboard/viewAccess/'+access;
|
||||
$('.modal-content').load(url, function(){
|
||||
$('#modal').modal('show');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
<?= $this->endSection() ?>
|
||||
@ -59,7 +59,7 @@ span.badge { cursor:pointer; }
|
||||
<span class='badge text-bg-warning' onclick='uncollect($sampletype, $accessnumber)'>Un-Coll.</span>
|
||||
<span class='badge text-bg-primary' onclick='unreceive($sampletype, $accessnumber)'>Un-Rec.</span>
|
||||
</td> ";
|
||||
echo "<td id='comment$sampletype'>$comment <i class='bi bi-pencil-square' onclick='comment($sampletype, $accessnumber, \"$sampletext\", \"$comment\")'></i></td>";
|
||||
echo "<td id='comment$sampletype'>$comment <i class='bi bi-pencil-square' role='button' onclick='comment($sampletype, $accessnumber, \"$sampletext\", \"$comment\")'></i></td>";
|
||||
echo " </tr>";
|
||||
}
|
||||
?>
|
||||
@ -88,8 +88,9 @@ function collect(sample, access) {
|
||||
const url = '<?=base_url();?>tubes/collect/'+access+'/'+sample;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
$("#coll"+sample).prop("checked", true);
|
||||
//console.log(data);
|
||||
//$("#coll"+sample).prop("checked", true);
|
||||
viewAccess(access);
|
||||
})
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
}
|
||||
@ -98,8 +99,9 @@ function collectAll(access) {
|
||||
const url = '<?=base_url();?>tubes/collectAll/'+access;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
$('input[id^="coll"]').prop('checked', true);
|
||||
//console.log(data);
|
||||
//$('input[id^="coll"]').prop('checked', true);
|
||||
viewAccess(access);
|
||||
})
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
|
||||
@ -110,8 +112,9 @@ function uncollect(sample, access) {
|
||||
const url = '<?=base_url();?>tubes/uncollect/'+access+'/'+sample;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
$("#coll"+sample).prop("checked", false);
|
||||
//console.log(data);
|
||||
//$("#coll"+sample).prop("checked", false);
|
||||
viewAccess(access);
|
||||
})
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
|
||||
@ -121,8 +124,9 @@ function uncollectAll(access) {
|
||||
const url = '<?=base_url();?>tubes/uncollectAll/'+access;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
$('input[id^="coll"]').prop('checked', false);
|
||||
//console.log(data);
|
||||
//$('input[id^="coll"]').prop('checked', false);
|
||||
viewAccess(access);
|
||||
})
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
}
|
||||
@ -132,8 +136,9 @@ function unreceive(sample, access) {
|
||||
const url = '<?=base_url();?>tubes/unreceive/'+access+'/'+sample;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
$("#recv"+sample).prop("checked", false);
|
||||
//console.log(data);
|
||||
//$("#recv"+sample).prop("checked", false);
|
||||
viewAccess(access);
|
||||
})
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
|
||||
@ -143,8 +148,9 @@ function unreceiveAll(access) {
|
||||
const url = '<?=base_url();?>tubes/unreceiveAll/'+access;
|
||||
fetch(url)
|
||||
.then(data => {
|
||||
console.log(data);
|
||||
$('input[id^="recv"]').prop('checked', false);
|
||||
//console.log(data);
|
||||
//$('input[id^="recv"]').prop('checked', false);
|
||||
viewAccess(access);
|
||||
})
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
}
|
||||
@ -152,16 +158,16 @@ function unreceiveAll(access) {
|
||||
function comment(sample, access, sampletext, comments) {
|
||||
const url = '<?=base_url();?>tubes/comment/'+access+'/'+sample;
|
||||
let comment = prompt('Comment for sample '+sampletext, comments);
|
||||
if(comment) {
|
||||
$('#comment'+sample).html(comment +"<i class='bi bi-pencil-square' onclick='comment("+ sample +", "+ access +', "'+sampletext+'", "'+comment+'")\'></i>');
|
||||
//$('#comment'+sample).html(comment +"<i class='bi bi-pencil-square' onclick='comment("+ sample +", "+ access +', "'+sampletext+'", "'+comment+'")\'></i>');
|
||||
fetch(url, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ comment : comment }),
|
||||
headers: { "Content-type": "application/json; charset=UTF-8" }
|
||||
}).then(data => {
|
||||
//console.log(data);
|
||||
viewAccess(access);
|
||||
})
|
||||
.then(data => console.log(data))
|
||||
.catch(error => { console.error('Error:',error); });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user