Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnvanbreda committed Jan 13, 2023
2 parents aec1c52 + 8084950 commit 67dd975
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 54 deletions.
2 changes: 1 addition & 1 deletion easy_login/easy_login.info.yml
Expand Up @@ -2,7 +2,7 @@ name: 'Easy login'
description: 'Configures Drupal login to integrate with Indicia.'
core: 8.x
core_version_requirement: ^8 || ^9
version: "8.7.2"
version: "8.13.0"
package: "Indicia"
type: module
dependencies:
Expand Down
12 changes: 6 additions & 6 deletions easy_login/easy_login.module
Expand Up @@ -139,9 +139,8 @@ function easy_login_allowed_taxon_groups() {
}
return $groups;
}
else {
return [];
}
// Needs to return something otherwise crashes Layout Builder.
return [t('None available')];
}

/**
Expand Down Expand Up @@ -170,7 +169,8 @@ function easy_login_allowed_locations() {
}
return $locations;
}
return [];
// Needs to return something otherwise crashes Layout Builder.
return [t('None available')];
}

/**
Expand Down Expand Up @@ -382,9 +382,9 @@ function easy_login_synchronise_account_to_warehouse($account) {
if (!empty($requests)) {
global $base_url;
\Drupal::messenger()->addMessage(t('Why not tell us ' .
implode(' ' . t('and') . ' ', $requests) .
implode(' ' . t('and') . ' ', $requests) .
' to help us tailor the system to your needs? ' .
'You can fill this information in on your <a href="' . $base_url .
'You can fill this information in on your <a href="' . $base_url .
'/user/' . $account->uid->value . '/edit">user preferences</a>.'
));
}
Expand Down
4 changes: 4 additions & 0 deletions indicia_blocks/css/es_blocks.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion indicia_blocks/css/es_blocks.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion indicia_blocks/indicia_blocks.info.yml
Expand Up @@ -2,7 +2,7 @@ name: 'Indicia blocks'
description: 'A collection of handy blocks for interacting with Indicia data.'
core: 8.x
core_version_requirement: ^8 || ^9
version: "8.x-6.0"
version: "8.13.0"
package: "Indicia"
type: module
dependencies:
Expand Down
6 changes: 5 additions & 1 deletion indicia_blocks/scss/es_blocks.scss
@@ -1,7 +1,11 @@
#indicia-es-totals-block-container {
font-size: 150%;
display: table;
width: 100%;
margin-bottom: 8px;
> div {
padding: 0 2px;
padding: 0 2px;
display: table-cell;
> div {
/* hide till loaded */
opacity: 0;
Expand Down
22 changes: 22 additions & 0 deletions indicia_blocks/src/Plugin/Block/IndiciaBlockBase.php
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\UserInterface;

/**
* Base class for providing Indicia blocks with permissions.
Expand Down Expand Up @@ -53,4 +54,25 @@ public function blockAccess(AccountInterface $account) {
}
}

/**
* Returns the warehouse user ID to filter a block's data to.
*
* The returned ID is either the current user's, or if on a profile view
* page then the ID of the viewed user is returned.
*
* @return int
* Warehouse user ID.
*/
protected function getWarehouseUserId() {
$profileUser = \Drupal::routeMatch()->getParameter('user');
if ($profileUser instanceof UserInterface) {
// On a profile view page, so use the profile being viewed.
return $profileUser->field_indicia_user_id->value;
}
else {
// For other pages, use the current user.
return hostsite_get_user_field('indicia_user_id');
}
}

}
48 changes: 43 additions & 5 deletions indicia_blocks/src/Plugin/Block/IndiciaEsRecentRecordsBlock.php
Expand Up @@ -24,22 +24,37 @@ public function blockForm($form, FormStateInterface $form_state) {
// Retrieve existing configuration for this block.
$config = $this->getConfiguration();

// Add a form field to the existing block configuration form.
// Option to exclude sensitive records.
$form['sensitive_records'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include sensitive records'),
'#description' => $this->t('Unless this box is ticked, sensitive records are completely excluded.'),
'#default_value' => isset($config['sensitive_records']) ? $config['sensitive_records'] : 0,
];

// Add a form field to the existing block configuration form.
// Option to exclude unverified records.
$form['unverified_records'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include unverified records'),
'#description' => $this->t('Unless this box is ticked, unverified (pending) records are completely excluded.'),
'#default_value' => isset($config['unverified_records']) ? $config['unverified_records'] : 0,
];

// Option to limit to current user.
$form['limit_to_user'] = [
'#type' => 'checkbox',
'#title' => $this->t("Limit to current user's records"),
'#description' => $this->t('If ticked, only records for the current user are shown.'),
'#default_value' => isset($config['limit_to_user']) ? $config['limit_to_user'] : 0,
];

$form['cache_timeout'] = [
'#type' => 'number',
'#title' => $this->t('Cache timeout'),
'#description' => $this->t('Minimum number of seconds that the data request will be cached for, resulting in faster loads times.'),
'#default_value' => isset($config['cache_timeout']) ? $config['cache_timeout'] : 300,
];

return $form;
}

Expand All @@ -51,21 +66,31 @@ public function blockSubmit($form, FormStateInterface $form_state) {
// Save our custom settings when the form is submitted.
$this->setConfigurationValue('sensitive_records', $form_state->getValue('sensitive_records'));
$this->setConfigurationValue('unverified_records', $form_state->getValue('unverified_records'));
$this->setConfigurationValue('limit_to_user', $form_state->getValue('limit_to_user'));
$this->setConfigurationValue('cache_timeout', $form_state->getValue('cache_timeout'));
}

/**
* {@inheritdoc}
*/
public function build() {
iform_load_helpers(['ElasticsearchReportHelper']);
\ElasticsearchReportHelper::enableElasticsearchProxy();
$enabled = \ElasticsearchReportHelper::enableElasticsearchProxy();
if (!$enabled) {
global $indicia_templates;
return [
'#markup' => str_replace('{message}', $this->t('Service unavailable.'), $indicia_templates['warningBox']),
];
}
$config = $this->getConfiguration();
$location = hostsite_get_user_field('location');
$groups = hostsite_get_user_field('taxon_groups', FALSE, TRUE);
$fields = [
'id',
'taxon.accepted_name',
'taxon.vernacular_name',
'taxon.taxon_rank',
'taxon.taxon_rank_sort_order',
'event.date_start',
'event.date_end',
'event.recorded_by',
Expand All @@ -77,7 +102,7 @@ public function build() {
$options = [
'id' => 'src-IndiciaEsRecentRecordsBlock',
'size' => 10,
'proxyCacheTimeout' => 300,
'proxyCacheTimeout' => isset($config['cache_timeout']) ? $config['cache_timeout'] : 300,
'filterPath' => $filterPath,
'initialMapBounds' => TRUE,
'sort' => ['id' => 'desc'],
Expand Down Expand Up @@ -109,14 +134,25 @@ public function build() {
'value' => 'false',
];
}
// Other record filters.
if (empty($config['unverified_records'])) {
$options['filterBoolClauses']['must'][] = [
'query_type' => 'term',
'field' => 'identification.verification_status',
'value' => 'V',
];
}
if (!empty($config['limit_to_user'])) {
$warehouseUserId = $this->getWarehouseUserId();
if (empty($warehouseUserId)) {
// Not linked to the warehouse so force report to be blank.
$warehouseUserId = -9999;
}
$options['filterBoolClauses']['must'][] = [
'query_type' => 'term',
'field' => 'metadata.created_by_id',
'value' => $warehouseUserId,
];
}

$r = \ElasticsearchReportHelper::source($options);
// Totally exclude sensitive records.
Expand All @@ -132,6 +168,7 @@ public function build() {
'#attached' => [
'library' => [
'indicia_blocks/es-blocks',
'iform/fancybox',
],
],
'#cache' => [
Expand All @@ -149,4 +186,5 @@ public function build() {
public function getCacheMaxAge() {
return 0;
}

}
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\indicia_blocks\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Render\Markup;

/**
Expand All @@ -22,13 +21,20 @@ class IndiciaEsRecentRecordsMapBlock extends IndiciaBlockBase {
*/
public function build() {
iform_load_helpers(['ElasticsearchReportHelper']);
\ElasticsearchReportHelper::enableElasticsearchProxy();
$enabled = \ElasticsearchReportHelper::enableElasticsearchProxy();
if (!$enabled) {
global $indicia_templates;
return [
'#markup' => str_replace('{message}', $this->t('Service unavailable.'), $indicia_templates['warningBox']),
];
}
$r = \ElasticsearchReportHelper::leafletMap([
'layerConfig' => [
'recent-records' => [
'title' => $this->t('Recent records'),
'source' => 'src-IndiciaEsRecentRecordsBlock',
'forceEnabled' => TRUE,
'labels' => 'hover',
],
],
]);
Expand All @@ -54,4 +60,5 @@ public function build() {
public function getCacheMaxAge() {
return 0;
}

}

0 comments on commit 67dd975

Please sign in to comment.