Skip to content

Commit

Permalink
refactor: move API usage files to API folders
Browse files Browse the repository at this point in the history
Keeping the dashboard and usage graph service
files for APIs in the Admin folder would have
created the need for additional parameters and
control flow logic in the exportUsageData method
which both Admin usage data CSV export and API
usage data CSV export relied on. Additionally,
the resulting class names do not follow the same
naming conventions (<serviceName>_Dashboard and
<serviceName>_UsageGraphs) as the rest of Aspen.

This refactor provides a separation of concerns by
replacing services/Admin/APIUsageDashboard.php and
services/Admin/APIUsageGraphs.php with
services/API/Dashboard.php and
services/API/UsageGraphs.

In doing so, it also fixes an issue where only the
csv file for 'runPendingDatabaseUpdates' could be
downloaded.

Test plan:

1) Log in to Aspen as an Admin
2) In Aspen Administration > System Reports, open
API Usage Dashboard. Notice the title of the links
match their section and header.
3) For each API and for each of their stats, open
their usage graph page. Notice that the data
matches the data on the dashboard, both in the raw
data table and on the graph. Also notice that the
tilte of the graph match its section and header in
the dashboard.
4) Click 'Export to CSV' (bottom left of the page)
to check that the downloaded file's contents match
those of the raw data table and that its name
includes the stat name.

Run through this plan before applying the patch,
and notice that the CSV export only works for
'runPendingDatabaseUpdates'. After the patch, it
is expected to work for any usage graph.
  • Loading branch information
Chloe070196 committed Oct 9, 2024
1 parent f5746df commit 1d4edb6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<h3 class="dashboardCategoryLabel">{$method}{' '} {* No translation needed *}
<a href="/Admin/APIUsageGraphs?stat={$method}&instance={$selectedInstance}" title="{translate text="{$moduleName} Graph" inAttribute="true" isAdminFacing=true}">
<a href="/API/UsageGraphs?stat={$method}&instance={$selectedInstance}" title="{translate text="{$moduleName}: {$method} Graph" inAttribute="true" isAdminFacing=true}">
<i class="fas fa-chart-line"></i>
</a>
</h3>
Expand Down
10 changes: 10 additions & 0 deletions code/web/services/API/AJAX.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
require_once ROOT_DIR . '/JSON_Action.php';

class API_AJAX extends JSON_Action {
public function exportUsageData() {
require_once ROOT_DIR . '/services/API/UsageGraphs.php';
$aspenUsageGraph = new API_UsageGraphs();
$aspenUsageGraph->buildCSV();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_once ROOT_DIR . '/services/Admin/Dashboard.php';
require_once ROOT_DIR . '/sys/SystemLogging/APIUsage.php';

class Admin_APIUsageDashboard extends Admin_Dashboard {
class API_UsageDashboard extends Admin_Dashboard {
function launch() {
global $interface;

Expand All @@ -24,7 +24,7 @@ function launch() {

$interface->assign('statsByModule', $statsByModule);

$this->display('api_usage_dashboard.tpl', 'Aspen Usage Dashboard');
$this->display('dashboard.tpl', 'Aspen Usage Dashboard');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_once ROOT_DIR . '/services/Admin/Admin.php';
require_once ROOT_DIR . '/sys/SystemLogging/APIUsage.php';

class Admin_APIUsageGraphs extends Admin_Admin
class API_UsageGraphs extends Admin_Admin
{
function launch()
{
Expand All @@ -17,15 +17,15 @@ function launch()
}

$title = 'Aspen Discovery API Usage Graph';
$interface->assign('section', 'Admin');
$interface->assign('section', 'API');
$interface->assign('showCSVExportButton', true);
$interface->assign('graphTitle', $title);
$this->assignGraphSpecificTitle($stat);
$this->getAndSetInterfaceDataSeries($stat, $instanceName);
$interface->assign('stat', $stat);
$interface->assign('propName', 'exportToCSV');
$title = $interface->getVariable('graphTitle');
$this->display('usage-graph.tpl', $title);
$this->display('../Admin/usage-graph.tpl', $title);
}
function getBreadcrumbs(): array
{
Expand Down
15 changes: 2 additions & 13 deletions code/web/services/Admin/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -1664,20 +1664,9 @@ public function copyMenuLinks() {
return $result;
}

/* Aspen API Usage and general Aspen usage use the same graph template and AJAX file,
but different services.
This is reflected in the following control flow
*/
public function exportUsageData() {
$stat = $_REQUEST['stat'];

if ($stat == 'runPendingDatabaseUpdates') {
require_once ROOT_DIR . '/services/Admin/APIUsageGraphs.php';
$aspenUsageGraph = new Admin_APIUsageGraphs();
} else {
require_once ROOT_DIR . '/services/Admin/UsageGraphs.php';
$aspenUsageGraph = new Admin_UsageGraphs();
}
require_once ROOT_DIR . '/services/Admin/UsageGraphs.php';
$aspenUsageGraph = new Admin_UsageGraphs();
$aspenUsageGraph->buildCSV();
}
}
2 changes: 1 addition & 1 deletion code/web/sys/Account/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3640,7 +3640,7 @@ public function getAdminActions() {
'View Dashboards',
'View System Reports',
]);
$sections['system_reports']->addAction(new AdminAction('API Usage Dashboard', 'API Usage Report for Aspen Discovery.', '/Admin/APIUsageDashboard'), [
$sections['system_reports']->addAction(new AdminAction('API Usage Dashboard', 'API Usage Report for Aspen Discovery.', '/API/UsageDashboard'), [
'View Dashboards',
'View System Reports',
]);
Expand Down

0 comments on commit 1d4edb6

Please sign in to comment.