-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LIMS-116: Summary page revamp (#606)
* updating .gitignore * adding frontend files and building backend * adding front end files and router files * create sidebar, filter options added, routes added * add routing to page,search bar and column selector * adding pagination continutation * adding csv, all columns, rest of filters * added descending and ascending * sidebar dropdown&changed data structure&hide row * cleaning up fixing jump bug * refactored backend mapped data * added expanding row * refactored favourites * refactored orderby filter * cleaned up code, added comments * added all params to watcher * added summary db connection * add routes to summary * add backend changes summarypage * changes to expandable sidebar, cleaning up fronte * clean up, add functions to get data * front end changes, group concat backend * remove summarypage code * fix pagination, timeout * delete old summary file * changed pagination in summary.php * changed backend to not include tot * fix refined cell c column * added ifsets to avoid undefined offset error * delete offset for output * change order of operands * change filters, fix operands * fix csv button * changed prop to propid * format beamlinename * change al,be,gamma * add selected columns summary * additional changes for selected columns * add multiple selections change expandable sidebar * redo routing, keep alive summary * fixes, change routing, results display, orderby * fixes to selected columns * format page to allow for customisation * area for potential formatting and fix to querypara * changes to regex, combobox multiple, and fomat * column select fix, resize pill fix, format inputs * Update api/src/Database/DatabaseConnectionFactory.php Co-authored-by: Guilherme Francisco <[email protected]> * Update client/src/js/modules/types/sp/menu.js Co-authored-by: Guilherme Francisco <[email protected]> * Update client/src/js/modules/types/saxs/menu.js Co-authored-by: Guilherme Francisco <[email protected]> * Update client/src/js/modules/types/pow/menu.js Co-authored-by: Guilherme Francisco <[email protected]> * Update client/src/js/modules/types/mx/menu.js Co-authored-by: Guilherme Francisco <[email protected]> * Update client/src/js/modules/types/em/menu.js Co-authored-by: Guilherme Francisco <[email protected]> * Update client/src/js/app/components/combo-box.vue Co-authored-by: Guilherme Francisco <[email protected]> * Update api/src/Database/DatabaseFactory.php Co-authored-by: John Holt <[email protected]> * Update api/src/TemplateParser.php Co-authored-by: Guilherme Francisco <[email protected]> * Code review changes: database conns, code tidy * add get started button --------- Co-authored-by: Guilherme Francisco <[email protected]> Co-authored-by: John Holt <[email protected]>
- Loading branch information
1 parent
1894d74
commit e0c0764
Showing
22 changed files
with
16,352 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
<?php | ||
|
||
namespace SynchWeb\Database\Type; | ||
|
||
use SqlFormatter; | ||
use SynchWeb\Database\DatabaseParent; | ||
|
||
class PureMySQL extends DatabaseParent { | ||
/** @var string */ | ||
protected $type = 'mysql'; | ||
/** @var string */ | ||
private $lastQuery = ''; // provide a way of retrieving the last query run - by storing the data - can then call getLastQuery() - primarily for testing | ||
/** @var array */ | ||
private $lastArgs = array(); | ||
/** @var bool */ | ||
private $transaction = False; | ||
/** @var int */ | ||
private $errors = 0; | ||
|
||
|
||
function __construct($conn) | ||
{ | ||
parent::__construct($conn); | ||
|
||
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // throw exceptions. | ||
|
||
if (mysqli_connect_errno()) | ||
{ | ||
$this->error('There was an error connecting to MySQL: ', htmlentities(mysqli_connect_errno())); | ||
} | ||
} | ||
|
||
// wsrep_sync_wait waits for cluster replication on a mariadb cluster | ||
function wait_rep_sync($state = false) | ||
{ | ||
# Empty - DatabaseFactory checks this exists | ||
} | ||
|
||
function start_transaction() | ||
{ | ||
$this->transaction = True; | ||
$this->conn->autocommit(False); | ||
} | ||
|
||
function end_transaction() | ||
{ | ||
if ($this->errors > 0) | ||
$this->conn->rollback(); | ||
else | ||
$this->conn->commit(); | ||
|
||
$this->conn->autocommit(True); | ||
$this->transaction = False; | ||
|
||
if ($this->errors > 0) | ||
$this->error('There was an error with MySQL', $this->conn->error . __LINE__); | ||
$this->errors = 0; | ||
} | ||
|
||
function paginate($query, $args = array()) | ||
{ | ||
// MySQL is Limit Start Row, Number | ||
// Oracle subselect is Start Row, End Row | ||
if (sizeof($args)) | ||
$args[sizeof($args) - 1] = $args[sizeof($args) - 1] - $args[sizeof($args) - 2]; | ||
return $this->pq("$query LIMIT ?,?", $args); | ||
} | ||
|
||
|
||
|
||
// return the last SQL query executed in fully expanded form (i.e. including binded params) - this is mainly for testing purposes (so ideally would not be part of the actual class...) | ||
function getLastQuery() | ||
{ | ||
echo '<br/>'; | ||
$sql = $this->lastQuery; | ||
for ($i = 1; $i < count($this->lastArgs); $i++) | ||
{ | ||
$val = $this->lastArgs[$i]; | ||
if (is_string($val)) | ||
{ | ||
$val = "'" . $val . "'"; | ||
} | ||
else if (is_null($val)) | ||
{ | ||
$val = 'null'; | ||
} | ||
$sql = preg_replace('/\?/', $val, $sql, 1); | ||
} | ||
$sql = preg_replace('/\\n/', '', $sql); // replace newlines | ||
return preg_replace('/\s\s+/', ' ', $sql); // remove excess spaces | ||
} | ||
|
||
function pq($query, $args = array(), $upperCaseKeys = true) | ||
{ | ||
|
||
if ($this->debug) | ||
{ | ||
print '<h1 class="debug">MySQL Debug</h1>'; | ||
print SqlFormatter::format($query); | ||
echo '<br/>'; | ||
} | ||
|
||
$stmt = $this->conn->prepare($query); | ||
|
||
if (!$stmt) | ||
{ | ||
if ($this->transaction) | ||
$this->errors++; | ||
else | ||
{ | ||
$err = mysqli_error($this->conn); | ||
$this->error('There was an error with MySQL', $err); | ||
return; | ||
} | ||
} | ||
|
||
if (sizeof($args)) | ||
{ | ||
$vtypes = array('NULL' => 'i', 'integer' => 'i', 'double' => 'd', 'string' => 's'); | ||
|
||
$strfs = ''; | ||
foreach ($args as $a) | ||
{ | ||
$t = gettype($a); | ||
$strfs .= $vtypes[$t]; | ||
} | ||
|
||
array_unshift($args, $strfs); | ||
call_user_func_array(array(&$stmt, 'bind_param'), $this->refs($args)); | ||
} | ||
|
||
$this->lastQuery = $query; | ||
$this->lastArgs = $args; | ||
if ($this->debug) | ||
{ | ||
print_r("Full SQL query: " . $this->getLastQuery()); | ||
} | ||
|
||
if (!$stmt->execute()) | ||
{ | ||
if ($this->transaction) | ||
$this->errors++; | ||
else | ||
{ | ||
$err = mysqli_error($this->conn); | ||
$this->error('There was an error with MySQL', $err); | ||
return; | ||
} | ||
} | ||
|
||
$data = array(); | ||
if (strpos($query, 'SELECT') !== false) | ||
{ | ||
$result = $stmt->get_result(); | ||
if ($result) | ||
{ | ||
if ($result->num_rows > 0) | ||
{ | ||
while ($row = $result->fetch_assoc()) | ||
{ | ||
$c = array(); | ||
// oracle inheritance ;( | ||
foreach ($row as $key => $val) | ||
{ | ||
if ($val !== null) | ||
{ | ||
if (gettype($val) == gettype(0.1)) | ||
$val = round($val, 5); | ||
$val = strval($val); | ||
} | ||
if ($upperCaseKeys) | ||
{ | ||
$key = strtoupper($key); | ||
} | ||
$c[$key] = $val; | ||
} | ||
array_push($data, $c); | ||
} | ||
} | ||
} | ||
} | ||
|
||
if ($this->debug) | ||
{ | ||
echo '<br/>'; | ||
print_r('row count: ' . sizeof($data)); | ||
echo '<br/>'; | ||
} | ||
|
||
// Need mysqlnd for this :( | ||
// $result = $stmt->get_result(); | ||
|
||
// $data = array(); | ||
|
||
// if ($result) { | ||
// if($result->num_rows > 0) { | ||
// while($row = $result->fetch_assoc()) { | ||
// array_push($data, array_change_key_case($row, CASE_UPPER)); | ||
// } | ||
// } | ||
// } | ||
|
||
$stmt->close(); | ||
|
||
return $data; | ||
} | ||
|
||
// Union multiple queries that take the same arguments and return the same columns | ||
// Query can optionally be wrapped, where :QUERY will be replaced with the inner query: | ||
// $wrapper = 'SELECT * FROM (:QUERY) GROUP BY id'; | ||
function union($queries, $args, $all = false, $wrapper = null) | ||
{ | ||
$nargs = sizeof($args); | ||
$all_args = array(); | ||
$union_kw = $all ? 'UNION ALL' : 'UNION'; | ||
foreach ($queries as $i => &$query) | ||
{ | ||
$offset = $i * $nargs; | ||
$query = preg_replace_callback('/\:(\d+)/', | ||
function ($mat) use ($offset) | ||
{ | ||
return ':' . (intval($mat[1]) + $offset); | ||
}, | ||
$query); | ||
$all_args = array_merge($all_args, $args); | ||
} | ||
|
||
$union = implode("\n$union_kw\n", $queries); | ||
if ($wrapper) | ||
{ | ||
$union = preg_replace('/:QUERY/', $union, $wrapper); | ||
} | ||
|
||
return $this->pq($union, $all_args); | ||
} | ||
|
||
private function refs($arr) | ||
{ | ||
$refs = array(); | ||
foreach ($arr as $key => $value) | ||
{ | ||
$refs[$key] = & $arr[$key]; | ||
} | ||
return $refs; | ||
} | ||
|
||
function read($field) | ||
{ | ||
return $field; | ||
} | ||
|
||
function id() | ||
{ | ||
return mysqli_insert_id($this->conn); | ||
} | ||
|
||
function close() | ||
{ | ||
if ($this->conn) | ||
$this->conn->close(); | ||
} | ||
} |
Oops, something went wrong.