Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ composer require drupal/rl
drush en rl
```

### Plotly.js Library (Required for Charts)

The RL module uses Plotly.js for experiment charts. Install it via Composer using
[Asset Packagist](https://asset-packagist.org):

```bash
# Add Asset Packagist repository (if not already configured)
composer config repositories.asset-packagist composer https://asset-packagist.org

# Install the Composer plugin for npm assets (if not already installed)
composer require oomphinc/composer-installers-extender
composer config extra.installer-types --json '["npm-asset"]'
composer config extra.installer-paths.web/libraries/\{\$name\} --json '["type:npm-asset"]'

# Install Plotly.js
composer require npm-asset/plotly.js-dist-min:^2.35
```

This installs the library to `web/libraries/plotly.js-dist-min/`.

### Post-Installation: Verify rl.php Access

The RL module includes a `.htaccess` file that allows direct access to
Expand Down
4 changes: 2 additions & 2 deletions rl.install
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ function rl_requirements($phase) {

if ($phase == 'runtime') {
// Check if Plotly.js library is installed.
$plotly_path = DRUPAL_ROOT . '/libraries/plotly.js-dist-min/plotly.min.js';
if (!file_exists($plotly_path)) {
$library_finder = \Drupal::service('library.libraries_directory_file_finder');
if (!$library_finder->find('plotly.js-dist-min/plotly.min.js')) {
$requirements['rl_plotly_library'] = [
'title' => t('RL: Plotly.js library'),
'severity' => REQUIREMENT_ERROR,
Expand Down
24 changes: 22 additions & 2 deletions src/Controller/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\rl\Controller;

use Drupal\Component\Utility\Html;
use Drupal\Core\Asset\LibrariesDirectoryFileFinder;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Link;
Expand Down Expand Up @@ -70,6 +71,13 @@ class ReportsController extends ControllerBase {
*/
protected RequestStack $requestStack;

/**
* The libraries directory file finder.
*
* @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder
*/
protected LibrariesDirectoryFileFinder $libraryFinder;

/**
* Constructs a ReportsController object.
*
Expand All @@ -87,15 +95,18 @@ class ReportsController extends ControllerBase {
* The snapshot storage.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_finder
* The libraries directory file finder.
*/
public function __construct(ExperimentDataStorageInterface $experiment_storage, DateFormatterInterface $date_formatter, ExperimentDecoratorManager $decorator_manager, RendererInterface $renderer, ArmDataValidator $arm_data_validator, SnapshotStorageInterface $snapshot_storage, RequestStack $request_stack) {
public function __construct(ExperimentDataStorageInterface $experiment_storage, DateFormatterInterface $date_formatter, ExperimentDecoratorManager $decorator_manager, RendererInterface $renderer, ArmDataValidator $arm_data_validator, SnapshotStorageInterface $snapshot_storage, RequestStack $request_stack, LibrariesDirectoryFileFinder $library_finder) {
$this->experimentStorage = $experiment_storage;
$this->dateFormatter = $date_formatter;
$this->decoratorManager = $decorator_manager;
$this->renderer = $renderer;
$this->armDataValidator = $arm_data_validator;
$this->snapshotStorage = $snapshot_storage;
$this->requestStack = $request_stack;
$this->libraryFinder = $library_finder;
}

/**
Expand All @@ -114,7 +125,8 @@ public static function create(ContainerInterface $container): static {
$container->get('renderer'),
$container->get('rl.arm_data_validator'),
$container->get('rl.snapshot_storage'),
$container->get('request_stack')
$container->get('request_stack'),
$container->get('library.libraries_directory_file_finder')
);
}

Expand Down Expand Up @@ -243,6 +255,14 @@ public function experimentDetailTitle($experiment_id) {
* A render array.
*/
public function experimentDetail($experiment_id) {
// Check if Plotly.js library is installed.
if (!$this->libraryFinder->find('plotly.js-dist-min/plotly.min.js')) {
$status_url = Url::fromRoute('system.status')->toString();
$this->messenger()->addWarning($this->t('Charts require the Plotly.js library. See <a href="@url">Status report</a> for installation instructions.', [
'@url' => $status_url,
]));
}

// Get experiment totals from storage.
$experiment_totals = $this->experimentStorage->getExperimentTotals($experiment_id);

Expand Down