cleanup & bugfix for DisplayRowAs (formerly RowClass option), added source preview, added focused mode, moved view processing to bottom
This commit is contained in:
parent
50bf5bead3
commit
e44526aa5a
324
pages/run.php
324
pages/run.php
@ -14,13 +14,15 @@
|
|||||||
$strInput = substr($strInput, strlen($strQueryDir) + 1);
|
$strInput = substr($strInput, strlen($strQueryDir) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$strFind = shell_exec("find files/sql | grep -Ei \"\.sql$\"");
|
$strFind = shell_exec("find {$strQueryDir} | grep -Ei \"\.sql$\"");
|
||||||
$varFiles = explode("\n", $strFind);
|
$varFiles = explode("\n", $strFind);
|
||||||
$varFiles = array_filter($varFiles);
|
$varFiles = array_filter($varFiles);
|
||||||
|
|
||||||
array_walk($varFiles, "removeQueryDir");
|
array_walk($varFiles, "removeQueryDir");
|
||||||
|
|
||||||
$strSelection = implode("/", Request::getArgs());
|
$strSelection = implode("/", Request::getArgs());
|
||||||
|
$strQueryPath = "{$strQueryDir}/{$strSelection}";
|
||||||
|
$strQueryView = null;
|
||||||
|
|
||||||
$varInputs = [[]];
|
$varInputs = [[]];
|
||||||
$varRows = null;
|
$varRows = null;
|
||||||
@ -31,8 +33,9 @@
|
|||||||
|
|
||||||
if ($strSelection !== null && strlen($strSelection) > 0)
|
if ($strSelection !== null && strlen($strSelection) > 0)
|
||||||
{
|
{
|
||||||
$strSelection = urldecode($strSelection);
|
$strSelection = urldecode($strSelection);
|
||||||
$strFileData = file_get_contents("{$strQueryDir}/{$strSelection}");
|
$strFileDataSource = file_get_contents("{$strQueryDir}/{$strSelection}");
|
||||||
|
$strFileData = $strFileDataSource;
|
||||||
|
|
||||||
// Translate occurrences of {{ Date: next monday }} into yyyy-MM-dd format:
|
// Translate occurrences of {{ Date: next monday }} into yyyy-MM-dd format:
|
||||||
// Can be used in string literals or default values in comments!
|
// Can be used in string literals or default values in comments!
|
||||||
@ -158,21 +161,12 @@
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$varRows = $c->query("{$strQueryDir}/{$strSelection}", $varPosted);
|
$varRows = $c->query($strQueryPath, $varPosted);
|
||||||
$strView = "files/views/{$strSelection}.php";
|
$strQueryView = "{$strQueryPath}.php";
|
||||||
|
|
||||||
// Allow returning the data as JSON for APIs, maybe:
|
// Allow returning the data as JSON for APIs, maybe:
|
||||||
if (strtolower($strFormat) == "json")
|
if (strtolower($strFormat) == "json")
|
||||||
Respond::json($varRows);
|
Respond::json($varRows);
|
||||||
|
|
||||||
// Load a custom view if there is one:
|
|
||||||
if (file_exists($strView))
|
|
||||||
{
|
|
||||||
ob_clean();
|
|
||||||
require $strView;
|
|
||||||
ob_end_flush();
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception $x)
|
catch (Exception $x)
|
||||||
{
|
{
|
||||||
@ -190,16 +184,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fancier title processing:
|
// Fancier title processing:
|
||||||
$strTitle = null;
|
$strTitle = "Select Report";
|
||||||
|
|
||||||
|
if ($strSelection !== null && strlen($strSelection) > 0)
|
||||||
|
$strTitle = $strSelection;
|
||||||
|
|
||||||
if (array_key_exists("title", $varOptions))
|
if (array_key_exists("title", $varOptions))
|
||||||
$strTitle = $varOptions["title"];
|
$strTitle = $varOptions["title"];
|
||||||
|
|
||||||
$strTitle = $strTitle ?? $strSelection ?? "Report";
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if (array_key_exists("scale", $varOptions)): ?>
|
<?php if (array_key_exists("scale", $varOptions)): ?>
|
||||||
<style>
|
<style>
|
||||||
table {
|
#visible-data {
|
||||||
font-size: <?= $varOptions["scale"]; ?>em;
|
font-size: <?= $varOptions["scale"]; ?>em;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
@ -220,6 +216,14 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="navbar navbar-expand bg-light navbar-light d-print-none" id="title-navbar">
|
||||||
|
<div class="container-fluid justify-content-between">
|
||||||
|
<div class="d-inline-flex align-items-center">
|
||||||
|
<span class="navbar-brand"><?= $strTitle; ?></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="page" id="page-input">
|
<div class="page" id="page-input">
|
||||||
<div class="container my-3">
|
<div class="container my-3">
|
||||||
|
|
||||||
@ -245,7 +249,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<div class="mb-3">
|
<div class="mb-3" data-report-chooser="1">
|
||||||
<label>Choose Query</label>
|
<label>Choose Query</label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
<span class="input-group-text"><i class="fa fa-fw fa-folder"></i></span>
|
||||||
@ -352,7 +356,16 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label>Actions</label>
|
<label>Actions</label>
|
||||||
<div>
|
<div>
|
||||||
<a class="btn btn-primary" onclick="fnSubmit(this);"><i class="fa fa-fw fa-server me-1"></i> Execute</a>
|
<?php if ($strSelection !== null && strlen($strSelection) > 0): ?>
|
||||||
|
<?php
|
||||||
|
$strButtonLabel = $varOptions["buttonlabel"] ?? "Execute";
|
||||||
|
$strButtonClass = $varOptions["buttonclass"] ?? "btn-primary";
|
||||||
|
$strButtonIcon = $varOptions["buttonicon"] ?? "fa-server";
|
||||||
|
?>
|
||||||
|
<a class="btn <?= $strButtonClass; ?> me-1" onclick="fnSubmit(this);"><i class="fa fa-fw <?= $strButtonIcon; ?> me-1"></i> <?= $strButtonLabel; ?></a>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<a class="btn btn-outline-secondary me-1" href="<?= Request::getPath(); ?>"><i class="fa fa-fw fa-arrow-rotate-left me-1"></i> Reset</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -380,10 +393,18 @@
|
|||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if (count($varDirectories)): ?>
|
<?php if (count($varDirectories)): ?>
|
||||||
<div class="col-md-6">
|
<div class="col-md-6" data-report-chooser="1">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label>Directories</label>
|
<label>Directories</label>
|
||||||
<div class="">
|
<div class="">
|
||||||
|
|
||||||
|
<div class="border p-3">
|
||||||
|
<a class="link-underline link-underline-opacity-0" href="/run">
|
||||||
|
<i class="fa fa-fw fa-home me-2"></i>
|
||||||
|
Home
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php foreach ($varDirectories as $d => $a): ?>
|
<?php foreach ($varDirectories as $d => $a): ?>
|
||||||
|
|
||||||
<div class="border p-3">
|
<div class="border p-3">
|
||||||
@ -401,6 +422,30 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<?php if ($strSelection !== null && strlen($strSelection) > 0): ?>
|
||||||
|
<?php if (array_key_exists("sourcepreview", $varOptions)): ?>
|
||||||
|
<style>
|
||||||
|
#source-preview {
|
||||||
|
line-height: 1em;
|
||||||
|
font-family: monospace;
|
||||||
|
min-height: 2in;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label>Source</label>
|
||||||
|
<div class="w-100">
|
||||||
|
<textarea class="w-100 border-0 bg-light p-3" id="source-preview" readonly><?= $strFileDataSource; ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -414,10 +459,10 @@
|
|||||||
foreach ($varRow1 as $k => $v)
|
foreach ($varRow1 as $k => $v)
|
||||||
$varColumns[] = $k;
|
$varColumns[] = $k;
|
||||||
|
|
||||||
$strRowClass = null;
|
$strDisplayRowAs = null;
|
||||||
if (array_key_exists("rowclass", $varOptions))
|
if (array_key_exists("displayrowas", $varOptions))
|
||||||
if (preg_match("/^col\-/i", $varOptions["rowclass"]))
|
if (preg_match("/^col\-/i", $varOptions["displayrowas"]))
|
||||||
$strRowClass = $varOptions["rowclass"];
|
$strDisplayRowAs = $varOptions["displayrowas"];
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="d-none d-print-block">
|
<div class="d-none d-print-block">
|
||||||
@ -443,71 +488,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php if ($strRowClass !== null): ?>
|
<div id="visible-data">
|
||||||
|
<?php if ($strDisplayRowAs !== null): ?>
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row my-3">
|
<div class="row my-3">
|
||||||
<?php foreach ($varRows as $r): ?>
|
|
||||||
<div class="<?= $strRowClass; ?>">
|
|
||||||
|
|
||||||
<table class="table table-sm table-striped table-bordered">
|
|
||||||
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th class="bg-black text-white"><?= $varColumns[0]; ?></th>
|
|
||||||
<th class="bg-black text-white"><?= $r[$varColumns[0]]; ?></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
|
|
||||||
|
|
||||||
<?php foreach ($varColumns as $col): ?>
|
|
||||||
<?php
|
|
||||||
// Hide columns that begin with underscore:
|
|
||||||
if ($col[0] == "_")
|
|
||||||
continue;
|
|
||||||
?>
|
|
||||||
|
|
||||||
<tr>
|
|
||||||
<td><?= $col; ?></td>
|
|
||||||
<td><?= $r[$col]; ?></td>
|
|
||||||
</tr>
|
|
||||||
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
$(function() {
|
|
||||||
$("#export-csv-button")
|
|
||||||
.first()
|
|
||||||
.addClass("d-none");
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<?php else: ?>
|
|
||||||
|
|
||||||
<div class="table-responsive">
|
|
||||||
<table class="table table-sm table-striped table-bordered w-100" id="table">
|
|
||||||
<thead class="sticky-top">
|
|
||||||
<tr>
|
|
||||||
<?php foreach ($varColumns as $col): ?>
|
|
||||||
<?php
|
|
||||||
// Hide columns that begin with underscore:
|
|
||||||
if ($col[0] == "_")
|
|
||||||
continue;
|
|
||||||
?>
|
|
||||||
<th class="text-nowrap sorting"><?= $col; ?> <?php DataTable::sortIcon(); ?></th>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
<?php foreach ($varRows as $r): ?>
|
<?php foreach ($varRows as $r): ?>
|
||||||
<?php
|
<?php
|
||||||
// Allow SQL data to control row classes with _row_class column:
|
// Allow SQL data to control row classes with _row_class column:
|
||||||
@ -517,38 +501,121 @@
|
|||||||
|
|
||||||
$strNextCellClass = "";
|
$strNextCellClass = "";
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<div class="<?= $strDisplayRowAs; ?>">
|
||||||
|
|
||||||
|
<table class="table table-sm table-striped table-bordered">
|
||||||
|
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="bg-black text-white"><?= $varColumns[0]; ?></th>
|
||||||
|
<th class="bg-black text-white"><?= $r[$varColumns[0]]; ?></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
|
||||||
|
|
||||||
|
<?php foreach ($varColumns as $col): ?>
|
||||||
|
<?php
|
||||||
|
$strCellClass = "";
|
||||||
|
|
||||||
|
if (strlen($strRowClass) > 0)
|
||||||
|
$strCellClass = $strRowClass;
|
||||||
|
|
||||||
|
if (strlen($strNextCellClass) > 0)
|
||||||
|
$strCellClass = $strNextCellClass;
|
||||||
|
|
||||||
|
// Allow SQL data to controll next cell class with _next_cell_class column:
|
||||||
|
if (preg_match("/^_next_cell_class/i", $col))
|
||||||
|
$strNextCellClass = $r[$col];
|
||||||
|
|
||||||
|
// Hide columns that begin with underscore:
|
||||||
|
if ($col[0] == "_")
|
||||||
|
continue;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td><?= $col; ?></td>
|
||||||
|
<td class="<?= $strCellClass; ?>"><?= $r[$col]; ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<?php $strNextCellClass = ""; ?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("#export-csv-button")
|
||||||
|
.first()
|
||||||
|
.addClass("d-none");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php else: ?>
|
||||||
|
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-sm table-striped table-bordered w-100" id="table">
|
||||||
|
<thead class="sticky-top">
|
||||||
<tr>
|
<tr>
|
||||||
<?php foreach ($varColumns as $col): ?>
|
<?php foreach ($varColumns as $col): ?>
|
||||||
<?php
|
<?php
|
||||||
$strCellClass = "";
|
|
||||||
|
|
||||||
if (strlen($strRowClass) > 0)
|
|
||||||
$strCellClass = $strRowClass;
|
|
||||||
|
|
||||||
if (strlen($strNextCellClass) > 0)
|
|
||||||
$strCellClass = $strNextCellClass;
|
|
||||||
|
|
||||||
// Allow SQL data to controll next cell class with _next_cell_class column:
|
|
||||||
if (preg_match("/^_next_cell_class/i", $col))
|
|
||||||
$strNextCellClass = $r[$col];
|
|
||||||
|
|
||||||
// Hide columns that begin with underscore:
|
// Hide columns that begin with underscore:
|
||||||
if ($col[0] == "_")
|
if ($col[0] == "_")
|
||||||
continue;
|
continue;
|
||||||
?>
|
?>
|
||||||
|
<th class="text-nowrap sorting"><?= $col; ?> <?php DataTable::sortIcon(); ?></th>
|
||||||
<td class="<?= $strCellClass; ?>"><?= $r[$col]; ?></td>
|
|
||||||
|
|
||||||
<?php
|
|
||||||
$strNextCellClass = "";
|
|
||||||
?>
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
</thead>
|
||||||
</tbody>
|
|
||||||
</table>
|
<tbody>
|
||||||
</div>
|
<?php foreach ($varRows as $r): ?>
|
||||||
<?php endif; ?>
|
<?php
|
||||||
|
// Allow SQL data to control row classes with _row_class column:
|
||||||
|
$strRowClass = "";
|
||||||
|
if (array_key_exists("_row_class", $r))
|
||||||
|
$strRowClass = $r["_row_class"];
|
||||||
|
|
||||||
|
$strNextCellClass = "";
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<?php foreach ($varColumns as $col): ?>
|
||||||
|
<?php
|
||||||
|
$strCellClass = "";
|
||||||
|
|
||||||
|
if (strlen($strRowClass) > 0)
|
||||||
|
$strCellClass = $strRowClass;
|
||||||
|
|
||||||
|
if (strlen($strNextCellClass) > 0)
|
||||||
|
$strCellClass = $strNextCellClass;
|
||||||
|
|
||||||
|
// Allow SQL data to controll next cell class with _next_cell_class column:
|
||||||
|
if (preg_match("/^_next_cell_class/i", $col))
|
||||||
|
$strNextCellClass = $r[$col];
|
||||||
|
|
||||||
|
// Hide columns that begin with underscore:
|
||||||
|
if ($col[0] == "_")
|
||||||
|
continue;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<td class="<?= $strCellClass; ?>"><?= $r[$col]; ?></td>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
$strNextCellClass = "";
|
||||||
|
?>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -596,6 +663,11 @@
|
|||||||
fnShowPage("#page-output");
|
fnShowPage("#page-output");
|
||||||
$("#table").exportCSV({name: "<?= $strSelection; ?>"});
|
$("#table").exportCSV({name: "<?= $strSelection; ?>"});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
fnGetRowAsQueryString = function()
|
||||||
|
{
|
||||||
|
|
||||||
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -607,6 +679,15 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<?php DataTable::js("#table"); ?>
|
<?php DataTable::js("#table"); ?>
|
||||||
|
|
||||||
|
<?php if (array_key_exists("outputonly", $varOptions)): ?>
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$(".navbar").addClass("d-none");
|
||||||
|
// $("#title-navbar").removeClass("d-none");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
@ -636,3 +717,20 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (array_key_exists("focusinput", $varOptions)): ?>
|
||||||
|
<script>
|
||||||
|
$(function() {
|
||||||
|
$("[data-report-chooser='1']").addClass("d-none");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Load a custom view if there is one:
|
||||||
|
if ($strQueryView !== null)
|
||||||
|
if (file_exists($strQueryView))
|
||||||
|
require $strQueryView;
|
||||||
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user