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

NYS-14920, Openleg custom module refactor, part 2 #82

Closed
wants to merge 20 commits into from
Closed
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
1,005 changes: 496 additions & 509 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions config/sync/nys_openleg_api.settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
base_path: /legislation/laws
log_level: 7
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
arguments: ['nys_bill_notifications']
bill_notifications.processor:
class: Drupal\nys_bill_notifications\Service\UpdatesProcessor
arguments: ['@logger.channel.bill_notifications', '@config.factory', '@manager.openleg_api', '@entity_type.manager', '@bill_notifications.test_manager', '@nys_subscriptions.queue_manager']
arguments: ['@logger.channel.bill_notifications', '@config.factory', '@openleg_api', '@entity_type.manager', '@bill_notifications.test_manager', '@nys_subscriptions.queue_manager']
bill_notifications.test_manager:
class: Drupal\nys_bill_notifications\Service\BillTestManager
parent: default_plugin_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Drupal\Core\State\State;
use Drupal\nys_bill_notifications\Service\UpdatesProcessor;
use Drupal\nys_openleg\Api\Request;
use Drupal\nys_openleg_api\Request;
use Drush\Commands\DrushCommands;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function getFullPrint(): string {
* This indicates the time at which this update was last processed
* by OpenLeg. It can change over time.
*
* @see \Drupal\nys_openleg\Api\Request::OPENLEG_TIME_FULL
* @see \Drupal\nys_openleg_api\Request::OPENLEG_TIME_FULL
*/
public function getProcessed(): string {
return $this->update->processedDateTime;
Expand All @@ -84,7 +84,7 @@ public function getProcessed(): string {
* This indicates the time at which the update was officially published
* by LBDC. It should remain constant over time.
*
* @see \Drupal\nys_openleg\Api\Request::OPENLEG_TIME_FULL
* @see \Drupal\nys_openleg_api\Request::OPENLEG_TIME_FULL
*/
public function getSourceTime(): string {
return $this->update->sourceDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Logger\LoggerChannel;
use Drupal\node\Entity\Node;
use Drupal\nys_openleg\Api\ResponsePluginBase;
use Drupal\nys_openleg\Service\ApiManager;
use Drupal\nys_openleg_api\ResponsePluginInterface;
use Drupal\nys_openleg_api\Service\Api;
use Drupal\nys_subscriptions\Entity\Subscription;
use Drupal\nys_subscriptions\SubscriptionQueue;
use Drupal\nys_subscriptions\SubscriptionQueueInterface;
Expand Down Expand Up @@ -37,9 +37,9 @@ class UpdatesProcessor {
/**
* NYS Openleg API Manager service.
*
* @var \Drupal\nys_openleg\Service\ApiManager
* @var \Drupal\nys_openleg_api\Service\Api
*/
protected ApiManager $apiManager;
protected Api $apiManager;

/**
* The plugin manager for bill notification update tests.
Expand Down Expand Up @@ -67,7 +67,7 @@ class UpdatesProcessor {
*
* @throws \Drupal\nys_subscriptions\Exception\SubscriptionQueueNotRegistered
*/
public function __construct(LoggerChannel $logger, ConfigFactory $config, ApiManager $apiManager, EntityTypeManager $entityTypeManager, BillTestManager $tester, SubscriptionQueueManager $queueManager) {
public function __construct(LoggerChannel $logger, ConfigFactory $config, Api $apiManager, EntityTypeManager $entityTypeManager, BillTestManager $tester, SubscriptionQueueManager $queueManager) {
$this->logger = $logger;
$this->config = $config->get('nys_bill_notifications.settings');
$this->apiManager = $apiManager;
Expand Down Expand Up @@ -106,13 +106,11 @@ public function getBasePrintFromUpdate(object $update): string {
* @param array $params
* Query string parameters to add to the API request.
*
* @return \Drupal\nys_openleg\Api\ResponsePluginBase
* @return \Drupal\nys_openleg_api\ResponsePluginBase
* The Response object from Openleg.
*/
protected function retrieveUpdates(mixed $time_from, mixed $time_to, array $params = []): ResponsePluginBase {
return $this->apiManager->getRequest('bill')
->setParams(['detail' => 'true'] + $params)
->retrieveUpdates($time_from, $time_to);
protected function retrieveUpdates(mixed $time_from, mixed $time_to, array $params = []): ResponsePluginInterface {
return $this->apiManager->getUpdates('bill', $time_from, $time_to, ['detail' => 'true'] + $params);
}

/**
Expand Down Expand Up @@ -160,7 +158,7 @@ protected function loadBillNode(string $print_num): ?Node {
*/
$ret = (count($nodes) == 1) ? current($nodes) : NULL;
}
catch (\Throwable $e) {
catch (\Throwable) {
$ret = NULL;
}
return $ret;
Expand All @@ -178,7 +176,7 @@ protected function loadTerm(int $id): ?Term {
->getStorage('taxonomy_term')
->load($id);
}
catch (\Throwable $e) {
catch (\Throwable) {
$ret = NULL;
}
return $ret;
Expand Down Expand Up @@ -247,6 +245,8 @@ protected function compileEvents(array $results): array {
* The bill receiving the updates.
* @param \Drupal\taxonomy\Entity\Term $term
* The term representing the lineage root of the bill.
*
* @throws \Exception
*/
public function queueEvents(array $results, Node $bill, Term $term): void {
// Ensure the primary_event is populated.
Expand Down Expand Up @@ -296,6 +296,8 @@ public function queueEvents(array $results, Node $bill, Term $term): void {
*
* @return array
* An array of all match results, keyed by bill print number.
*
* @throws \Exception
*/
public function process(mixed $time_from = 0, mixed $time_to = 0, array $params = []): array {
// Get the updates based on the requested time range.
Expand All @@ -317,6 +319,8 @@ public function process(mixed $time_from = 0, mixed $time_to = 0, array $params
* An array, keyed by bill print number, with each element being an array
* of MatchResults (one results per update block). Each MatchResult may
* have multiple matching tests.
*
* @throws \Exception
*/
public function processResults(array $matches): void {
// For each bill, there could be multiple updates, each with their own test
Expand Down
19 changes: 14 additions & 5 deletions web/modules/custom/nys_openleg/assets/nys_openleg.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
.nys-openleg-config-warning {
background-color: darkred;
color: yellow;
padding: 0.5em 1.5em;
width: fit-content;
}

.path-legislation main.l-row--main {
padding: 20px 0;
}
Expand Down Expand Up @@ -327,12 +334,14 @@
}

#nys-openleg-search-form button.search__submit {
position: relative;
top: 3px;
width: 15%;
line-height: 1em;
padding: 0.6em;
margin-left: 1em;
margin-right: 0;
width: 15%;
background-color: #008CBA !important;
border-color: #007095 !important;
background-color: #008CBA;
color: #ffffff;
}

#nys-openleg-search-form button.search__submit:hover {
Expand Down Expand Up @@ -426,4 +435,4 @@
.nys-openleg-history-container .form-item-history select {
margin: 0 0 0 1em;
}
}
}
26 changes: 13 additions & 13 deletions web/modules/custom/nys_openleg/assets/nys_openleg.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(function ($, Drupal, once) {
Drupal.behaviors.nys_openleg = {
attach: function (context, settings) {
once('nys_openleg', '.search-title', context).forEach(
function (element) {
$(element).on(
'click', function (e) {
$(e.target).closest('form').toggleClass('open');
}
);
}
);
}
};
Drupal.behaviors.nys_openleg = {
attach: function (context, settings) {
once('nys_openleg', '.search-title', context).forEach(
function (element) {
$(element).on(
'click', function (e) {
$(e.target).closest('form').toggleClass('open');
},
);
},
);
},
};
})(jQuery, Drupal, once);
4 changes: 3 additions & 1 deletion web/modules/custom/nys_openleg/nys_openleg.info.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: 'NYS Openleg'
description: "A service to call NYS OpenLeg API"
description: "Enables browsing laws via NYS OpenLeg API"
package: NYSenate
core_version_requirement: ^9 || ^10
type: module
configure: nys_openleg.config
dependencies:
- nys_openleg_api:nys_openleg_api
4 changes: 4 additions & 0 deletions web/modules/custom/nys_openleg/nys_openleg.links.task.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nys_openleg.browsing_tab:
title: "OpenLeg Browsing"
route_name: nys_openleg.config
base_route: nys_openleg_api.config
16 changes: 12 additions & 4 deletions web/modules/custom/nys_openleg/nys_openleg.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Module nys_openleg.
*/

use Drupal\nys_openleg_api\Plugin\OpenlegApi\Response\ResponseSearch;

/**
* Implements hook_theme().
*/
Expand Down Expand Up @@ -64,7 +66,10 @@ function nys_openleg_theme(): array {
],
],
'nys_openleg_not_found' => [
'variables' => ['additional' => NULL],
'variables' => [
'browse_url' => '',
'additional' => NULL,
],
],
];
}
Expand All @@ -74,7 +79,8 @@ function nys_openleg_theme(): array {
*/
function nys_openleg_preprocess_block__nys_blocks_bythe_numbers(&$variables): void {
$content = $variables['elements']['content'];
$variables['facts_title'] = $content['#first_year'] . '-' . $content['#second_year'] . ' by the numbers';
$variables['facts_title'] = $content['#first_year'] . '-' .
$content['#second_year'] . ' by the numbers';

$legislative_session = date("Y", strtotime("now"));
if (($legislative_session % 2) == 0) {
Expand All @@ -100,7 +106,7 @@ function nys_openleg_preprocess_block__nys_blocks_bythe_numbers(&$variables): vo
];

// Get Openleg results. Any error means zero records.
/** @var \Drupal\nys_openleg\Service\ApiManager $openApiService */
/** @var \Drupal\nys_openleg_api\Service\Api $openApiService */
$openApiService = Drupal::service('manager.openleg_api');
foreach ($variables['facts'] as &$v) {
$v['link'] = '/search/legislation?type=bill&session_year=' .
Expand All @@ -109,7 +115,9 @@ function nys_openleg_preprocess_block__nys_blocks_bythe_numbers(&$variables): vo
' AND status.statusType:' . $v['statusType'];
try {
$result = $openApiService->getSearch('bill', $search);
$v['statistic'] = $result->getTotal();
$v['statistic'] = ($result instanceof ResponseSearch)
? $result->total()
: 0;
}
catch (Throwable) {
$v['statistic'] = 0;
Expand Down
4 changes: 2 additions & 2 deletions web/modules/custom/nys_openleg/nys_openleg.routing.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
nys_openleg.config:
path: /admin/config/nys_openleg
path: /admin/config/nys_openleg_api/browsing
defaults:
_form: '\Drupal\nys_openleg\Form\ConfigForm'
_title: "NYS Open Legislation Configuration"
_title: "NYS OpenLeg Browsing Configuration"
requirements:
_permission: 'administer site configuration'

Expand Down
15 changes: 0 additions & 15 deletions web/modules/custom/nys_openleg/nys_openleg.services.yml

This file was deleted.

Loading
Loading