Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIMS-116: Summary page revamp #606

Merged
merged 60 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c513eae
updating .gitignore
NKatti2011 Aug 31, 2022
aa88518
adding frontend files and building backend
NKatti2011 Sep 8, 2022
7a8bef5
adding front end files and router files
NKatti2011 Sep 8, 2022
3a845c4
create sidebar, filter options added, routes added
NKatti2011 Sep 30, 2022
dae770f
add routing to page,search bar and column selector
NKatti2011 Oct 12, 2022
30a11f6
adding pagination continutation
NKatti2011 Oct 14, 2022
d5647b7
adding csv, all columns, rest of filters
NKatti2011 Oct 18, 2022
0e25f7f
added descending and ascending
NKatti2011 Oct 20, 2022
fe7aa9d
sidebar dropdown&changed data structure&hide row
NKatti2011 Oct 28, 2022
61cd46d
cleaning up fixing jump bug
NKatti2011 Oct 31, 2022
a6f2e03
refactored backend mapped data
NKatti2011 Nov 7, 2022
0c653fb
added expanding row
NKatti2011 Nov 9, 2022
2dd0635
refactored favourites
NKatti2011 Nov 11, 2022
4029b12
refactored orderby filter
NKatti2011 Nov 12, 2022
057a173
cleaned up code, added comments
NKatti2011 Nov 14, 2022
e11c096
added all params to watcher
NKatti2011 Nov 21, 2022
80a1243
added summary db connection
NKatti2011 Apr 28, 2023
8435157
Merge branch 'feature/update-summary-page' into feature/LIMS-116/summ…
NKatti2011 Apr 28, 2023
d5aa01d
add routes to summary
NKatti2011 Apr 28, 2023
c2677ca
add backend changes summarypage
NKatti2011 May 10, 2023
c190eae
changes to expandable sidebar, cleaning up fronte
NKatti2011 May 10, 2023
5ddf4e4
clean up, add functions to get data
NKatti2011 May 15, 2023
2ec323f
front end changes, group concat backend
NKatti2011 May 17, 2023
fbf85d2
remove summarypage code
NKatti2011 May 17, 2023
b948e24
fix pagination, timeout
NKatti2011 May 17, 2023
d974761
delete old summary file
NKatti2011 May 17, 2023
0c24e40
changed pagination in summary.php
NKatti2011 May 17, 2023
ae5a069
changed backend to not include tot
NKatti2011 May 17, 2023
7c99a68
fix refined cell c column
NKatti2011 May 17, 2023
175d622
added ifsets to avoid undefined offset error
NKatti2011 May 19, 2023
4efd2eb
delete offset for output
NKatti2011 May 19, 2023
568dfcd
change order of operands
NKatti2011 May 19, 2023
123a67c
change filters, fix operands
NKatti2011 May 19, 2023
a92adb1
fix csv button
NKatti2011 May 19, 2023
539e330
changed prop to propid
NKatti2011 May 19, 2023
ad02e6f
format beamlinename
NKatti2011 May 19, 2023
6a10597
change al,be,gamma
NKatti2011 May 19, 2023
fd7a37d
add selected columns summary
NKatti2011 May 31, 2023
bf7c5c2
additional changes for selected columns
NKatti2011 May 31, 2023
cc6c7d6
add multiple selections change expandable sidebar
NKatti2011 Jun 13, 2023
90a84f0
redo routing, keep alive summary
NKatti2011 Jun 13, 2023
481c7b8
fixes, change routing, results display, orderby
NKatti2011 Jun 15, 2023
a982f5a
fixes to selected columns
NKatti2011 Jun 15, 2023
78139d9
format page to allow for customisation
NKatti2011 Jun 16, 2023
03852ee
area for potential formatting and fix to querypara
NKatti2011 Jun 16, 2023
a203317
changes to regex, combobox multiple, and fomat
NKatti2011 Jun 28, 2023
1f43806
Merge branch 'prerelease' into feature/LIMS-116/summary-page-revamp
NKatti2011 Jun 28, 2023
4d24658
column select fix, resize pill fix, format inputs
NKatti2011 Jun 29, 2023
1796b70
Update api/src/Database/DatabaseConnectionFactory.php
NKatti2011 Jul 10, 2023
ad6e222
Update client/src/js/modules/types/sp/menu.js
NKatti2011 Jul 10, 2023
e0a1ba1
Update client/src/js/modules/types/saxs/menu.js
NKatti2011 Jul 10, 2023
9e9a0a9
Update client/src/js/modules/types/pow/menu.js
NKatti2011 Jul 10, 2023
c8e2093
Update client/src/js/modules/types/mx/menu.js
NKatti2011 Jul 10, 2023
9c1cfb1
Update client/src/js/modules/types/em/menu.js
NKatti2011 Jul 10, 2023
b0c67f5
Update client/src/js/app/components/combo-box.vue
NKatti2011 Jul 10, 2023
4caa014
Update api/src/Database/DatabaseFactory.php
NKatti2011 Jul 10, 2023
e07cb2a
Update api/src/TemplateParser.php
NKatti2011 Jul 10, 2023
3a8967e
Code review changes: database conns, code tidy
NKatti2011 Jul 12, 2023
6ffdf48
Merge branch 'feature/LIMS-116/summary-page-revamp' of https://github…
NKatti2011 Jul 12, 2023
5b6db21
add get started button
NKatti2011 Jul 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
$isb = array('user' => 'user', 'pass' => 'pass', 'db' => 'localhost/ispyb');
$dbtype = 'mysql';

# Summary Database credentials
######### DELETE if not using connection.
$summarydbconfig = array('user' => 'user', 'pass' => 'pass', 'db' => 'localhost/ispyb');
$ifsummary = true;

# Encoded JWT key, used to sign and check validaty of jwt tokens
# - Create one of these using /api/authenticate/key
# This can be changed to invalidate all currently active tokens
Expand Down
12 changes: 10 additions & 2 deletions api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function setupApplication($mode): Slim
global $motd, $authentication_type, $cas_url, $cas_sso, $package_description,
$facility_courier_countries, $facility_courier_countries_nde,
$dhl_enable, $dhl_link, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone,
$valid_components, $enabled_container_types;
$valid_components, $enabled_container_types, $ifsummary;
$app->contentType('application/json');
$app->response()->body(json_encode(array(
'motd' => $motd,
Expand All @@ -86,7 +86,8 @@ function setupApplication($mode): Slim
'preset_proposal' => $preset_proposal,
'timezone' => $timezone,
'valid_components' => $valid_components,
'enabled_container_types' => $enabled_container_types
'enabled_container_types' => $enabled_container_types,
'ifsummary' => $ifsummary
)));
});
return $app;
Expand All @@ -101,6 +102,13 @@ function setupDependencyInjectionContainer($app)
return $db;
});

$app->container->singleton('dbsummary', function () use ($app): DatabaseParent {
$dbFactory = new DatabaseFactory(new DatabaseConnectionFactory());
$db = $dbFactory->get("summary");
$db->set_app($app);
return $db;
});

$app->container->singleton('authData', function () use ($app) {
return new AuthenticationData($app->container['db']);
});
Expand Down
11 changes: 11 additions & 0 deletions api/src/Database/DatabaseConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class DatabaseConnectionFactory
public function get($databaseType)
{
global $isb;
global $summarydbconfig;

if (!$databaseType) {
error_log('Database type variable, dbtype, is not specified in config.php - defaulting to MySql.');
Expand All @@ -24,6 +25,16 @@ public function get($databaseType)
$conn = new \mysqli($host, $isb['user'], $isb['pass'], $dbn, $port);
$conn->set_charset("utf8mb4");
}
elseif ($databaseType == 'PureMySQL') {
$port = array_key_exists('port', $summarydbconfig) ? $summarydbconfig['port'] : null;
NKatti2011 marked this conversation as resolved.
Show resolved Hide resolved
if (!$port) {
$port = ini_get("mysqli.default_port");
}
list($host, $dbn) = explode('/', $summarydbconfig['db']);
$conn = new \mysqli($host, $summarydbconfig['user'], $summarydbconfig['pass'], $dbn, $port);
$conn->set_charset("utf8mb4");
}


if ($conn == null) {
Utils::returnError("Database Configuration Error", "Database connection for type '$databaseType' does not exist.");
Expand Down
27 changes: 15 additions & 12 deletions api/src/Database/DatabaseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class DatabaseFactory
// Value is class name in SynchWeb\Database\Type namespace.
// Key is lower case representation of class name.
public $database_types = array(
'mysql' => 'MySQL'
'mysql' => ["dbClassName" =>'MySQL', "dataConnectionName" => 'MySQL'],
'summary' => ["dbClassName" =>'PureMySQL', "dataConnectionName" => 'PureMySQL']
);

function __construct($databaseConnectionFactory)
Expand All @@ -19,25 +20,27 @@ function __construct($databaseConnectionFactory)

private $databaseConnectionFactory;

public function get()
{
// Global variable is named $dbtype in config.php.
global $dbtype;
$database_type = $dbtype;
public function get($databaseType = null)
{
if ( $databaseType == null) {
// Global variable is named $dbtype in config.php.
global $dbtype;
$databaseType = $dbtype;
}

if (!$database_type) {
if (!$databaseType) {
error_log('Database type variable, dbtype, is not specified in config.php - defaulting to MySql.');
$database_type = 'MySQL';
}

// Determine fully-qualified class name of database class corresponding to $database_type.
if (key_exists(strtolower($database_type), $this->database_types)) {
$dbClassName = $this->database_types[strtolower($database_type)];
if (key_exists(strtolower($databaseType), $this->database_types)) {
$dbType = $this->database_types[strtolower($databaseType)];

$full_class_name = 'SynchWeb\\Database\\Type\\' . $dbClassName;
$full_class_name = 'SynchWeb\\Database\\Type\\' . $dbType["dbClassName"];;

if (class_exists($full_class_name)) {
$conn = $this->databaseConnectionFactory->get($dbClassName);
$conn = $this->databaseConnectionFactory->get($dbType["dataConnectionName"]);
return new $full_class_name($conn);
}
else {
Expand All @@ -46,7 +49,7 @@ public function get()

}
else {
error_log("Database type '$database_type' not configured.");
error_log("Database type '$databaseType' not configured.");
}
return null;
}
Expand Down
262 changes: 262 additions & 0 deletions api/src/Database/Type/PureMySQL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
<?php
NKatti2011 marked this conversation as resolved.
Show resolved Hide resolved

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();
}
}
Loading
Loading