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 11, 2024
2 parents bdaaacc + 00f9880 commit dc7467b
Show file tree
Hide file tree
Showing 23 changed files with 2,102 additions and 358 deletions.
639 changes: 496 additions & 143 deletions ElasticsearchProxyHelper.php

Large diffs are not rendered by default.

36 changes: 32 additions & 4 deletions ElasticsearchReportHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class ElasticsearchReportHelper {
'caption' => 'Submitted on',
'description' => 'Date the record was submitted.',
],
'metadata.licence_code' => [
'caption' => 'Licence',
'description' => 'Code for the licence that applies to the record.',
],
'metadata.website.id' => [
'caption' => 'Website ID',
'description' => 'Unique ID of the website the record was submitted from.',
Expand Down Expand Up @@ -686,6 +690,7 @@ public static function groupIntegration(array $options) {
if (empty($group_id) && $options['missingGroupIdBehaviour'] !== 'showAll') {
hostsite_show_message(lang::get('The link you have followed is invalid.'), 'warning', TRUE);
hostsite_goto_page('<front>');
return '';
}
require_once 'prebuilt_forms/includes/groups.php';
$member = group_authorise_group_id($group_id, $options['readAuth']);
Expand All @@ -708,6 +713,7 @@ public static function groupIntegration(array $options) {
if (!count($groups)) {
hostsite_show_message(lang::get('The link you have followed is invalid.'), 'warning', TRUE);
hostsite_goto_page('<front>');
return '';
}
$group = $groups[0];
if ($options['showGroupSummary']) {
Expand Down Expand Up @@ -1141,7 +1147,7 @@ public static function filterSummary(array $options) {

helper_base::$late_javascript .= <<<JS
$('#es-filter-summary').idcFilterSummary('populate');
$('.es-filter-param, .user-filter, .permissions-filter, .standalone-quality-filter select').change(function () {
$('.es-filter-param, .user-filter, .permissions-filter, .standalone-quality-filter select,.standalone-media-filter select').change(function () {
// Update any summary output
$('#es-filter-summary').idcFilterSummary('populate');
});
Expand All @@ -1151,6 +1157,25 @@ public static function filterSummary(array $options) {
return self::getControlContainer('filterSummary', $options, json_encode([]), $html);
}

/**
* Output a selector for presence of media.
*
* Mirrors the 'quality - records and photos' drop-down in standardParams
* control.
*
* @return string
* Select HTML.
*
* @link https://indicia-docs.readthedocs.io/en/latest/site-building/iform/helpers/elasticsearch-report-helper.html#elasticsearchreporthelper-mediafilter
*/
public static function mediaFilter(array $options) {
require_once 'prebuilt_forms/includes/report_filters.php';
$options = array_merge([
'standalone' => TRUE,
], $options);
return media_filter_control($options['readAuth'], $options);
}

/**
* Output a selector for record status.
*
Expand All @@ -1166,9 +1191,9 @@ public static function statusFilters(array $options) {
$options = array_merge([
'sharing' => 'reporting',
'elasticsearch' => TRUE,
'standalone' => TRUE,
], $options);

return status_control($options['readAuth'], $options);
return status_filter_control($options['readAuth'], $options);
}

/**
Expand Down Expand Up @@ -2418,7 +2443,10 @@ private static function convertValueToFilterList($report, array $params, $output
// Build a hidden input which causes filtering to this list.
$keys = [];
foreach ($listEntries as $row) {
$keys[] = $row[$outputField];
if ($row[$outputField]) {
// Don't want nulls as they break ES terms filters.
$keys[] = $row[$outputField];
}
}
return str_replace('"', '&quot;', json_encode($keys));
}
Expand Down
2 changes: 1 addition & 1 deletion data_entry_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5846,7 +5846,6 @@ public static function multiple_places_species_checklist($options) {
'Incorrect configuration - multiple_places_species_checklist requires a @include_sref_handler_jsspatialSystem option.',
$indicia_templates['messageBox']
);
return;
}
// The ID must be done here so it can be accessed by both the species grid and the buttons.
$code = rand(0, 1000);
Expand All @@ -5864,6 +5863,7 @@ public static function multiple_places_species_checklist($options) {
self::includeSrefHandlerJs([$options['spatialSystem'] => '']);
$r = '';
if (isset($options['sample_method_id'])) {
require_once 'prebuilt_forms/includes/form_generation.php';
$sampleAttrs = self::getMultiplePlacesSpeciesChecklistSubsampleAttrs($options);
foreach ($sampleAttrs as &$attr) {
$attr['fieldname'] = "sc:n::$attr[fieldname]";
Expand Down
29 changes: 23 additions & 6 deletions helper_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ public static function getTranslations(array $strings) {
* * brc_charts
* * bigr
* * d3
* * html2canvas
*/
public static function add_resource($resource) {
// Ensure indiciaFns is always the first resource added.
Expand Down Expand Up @@ -1280,6 +1281,27 @@ public static function get_resources() {
'https://unpkg.com/[email protected]/dist/bigr.min.umd.js',
],
],
'html2canvas' => [
'javascript' => [
'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js',
],
],
'brc_atlas_e' => [
'deps' => [
'd3_v7',
],
'stylesheets' => [
'https://cdn.jsdelivr.net/gh/biologicalrecordscentre/[email protected]/dist/brcatlas_e.umd.css',
],
'javascript' => [
'https://cdn.jsdelivr.net/gh/biologicalrecordscentre/[email protected]/dist/brcatlas_e.umd.min.js',
],
],
'd3_v7' => [
'javascript' => [
'https://d3js.org/d3.v7.min.js',
],
],
];
}
return self::$resource_list;
Expand Down Expand Up @@ -2367,6 +2389,7 @@ public static function getIndiciaData() {
'buttonDefaultClass' => $indicia_templates['buttonDefaultClass'],
'buttonHighlightedClass' => $indicia_templates['buttonHighlightedClass'],
'buttonSmallClass' => 'btn-xs',
'jQueryValidateErrorClass' => $indicia_templates['error_class'],
];
self::$indiciaData['formControlClass'] = $indicia_templates['formControlClass'];
self::$indiciaData['inlineErrorClass'] = $indicia_templates['error_class'];
Expand Down Expand Up @@ -3271,12 +3294,6 @@ private static function apply_error_template($error, $fieldname) {
* * **report** - Path to the report file to use when loading data from a
* report, e.g. "library/occurrences/explore_list", excluding the .xml
* extension.
* * **orderby** - Optional. For a non-default sort order, provide the
* field name to sort by. Can be comma separated to sort by several
* fields in descending order of precedence.
* * **sortdir** - Optional. Specify ASC or DESC to define ascending or
* descending sort order respectively. Can be comma separated if several
* sort fields are specified in the orderby parameter.
* * **extraParams** - Array of extra URL parameters to send with the web
* service request. Should include key value pairs for the field filters
* (for table data) or report parameters (for the report data) as well as
Expand Down
78 changes: 60 additions & 18 deletions import_helper_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public static function importer($options) {
self::$indiciaData['importChunkUrl'] = $options['importChunkUrl'];
self::$indiciaData['getErrorFileUrl'] = $options['getErrorFileUrl'];
self::$indiciaData['write'] = $options['writeAuth'];
self::$indiciaData['advancedFields'] = $options['advancedFields'];
$nextImportStep = empty($_POST['next-import-step']) ? 'fileSelectForm' : $_POST['next-import-step'];
self::$indiciaData['step'] = $nextImportStep;
switch ($nextImportStep) {
Expand Down Expand Up @@ -779,10 +780,13 @@ private static function mappingsForm(array $options) {
$lang = [
'columnInImportFile' => lang::get('Column in import file'),
'destinationDatabaseField' => lang::get('Destination database field'),
'display' => lang::get('Display'),
'instructions' => lang::get($options['mappingsFormIntro']),
'next' => lang::get('Next step'),
'requiredFields' => lang::get('Required fields'),
'requiredFieldsInstructions' => lang::get($options['requiredFieldsIntro']),
'standardFieldsOnly' => lang::get('standard fields'),
'standardAndAdvancedFields' => lang::get('standard and advanced fields'),
'title' => lang::get('Map import columns to destination database fields'),
];
self::addLanguageStringsToJs('import_helper_2', [
Expand Down Expand Up @@ -843,6 +847,11 @@ private static function mappingsForm(array $options) {
return <<<HTML
<h3>$lang[title]</h3>
<p>$lang[instructions]</p>
<div class="inline field-type-selector">
<span>$lang[display]</span>
<label class="radio-inline auto"><input type="radio" name="field-type-toggle" value="standard" checked> $lang[standardFieldsOnly]</label>
<label class="radio-inline auto"><input type="radio" name="field-type-toggle" value="advanced"> $lang[standardAndAdvancedFields]</label>
</div>
<form method="POST">
<div class="row">
<div class="col-md-8">
Expand Down Expand Up @@ -908,42 +917,74 @@ private static function getAvailableDbFieldsAsOptions(array $options, array $ava
$shortGroupLabels[$optGroup] = lang::get("optionGroup-$fieldParts[0]-shortLabel");
}
// Find variants of field names for auto matching.
$alts = [];
switch ($field) {
case 'occurrence:comment':
$alts = ['comment', 'comments', 'notes'];
break;

case 'occurrence:external_key':
$alts = ['recordkey', 'ref', 'referenceno', 'referencenumber'];
break;

case 'occurrence:fk_taxa_taxon_list':
$alts = ['commonname', 'scientificname', 'species', 'speciesname', 'taxon', 'taxonname', 'vernacular'];
break;

case 'occurrence:fk_taxa_taxon_list:search_code':
$alts = ['searchcode','tvk','taxonversionkey'];
break;

case 'sample:date':
$alt = ' data-alt="eventdate"';
$alts = ['eventdate'];
break;

case 'sample:entered_sref':
$alt = ' data-alt="gridref,gridreference,spatialref,spatialreference,mapref,mapreference"';
$alts = ['gridref', 'gridreference', 'spatialref', 'spatialreference', 'mapref', 'mapreference', 'coords', 'coordinates'];
break;

case 'sample:location_name':
$alt = ' data-alt="location,site,sitename"';
$alts = ['location', 'site', 'sitename'];
break;

case 'sample:recorder_names':
$alt = ' data-alt="recorder,recordername,recordernames"';
break;

case 'occurrence:fk_taxa_taxon_list':
$alt = ' data-alt="species,speciesname,taxon,taxonname,scientificname"';
$alts = ['recorder', 'recordername', 'recordernames'];
break;

default:
$alt = '';
}
// Also use caption to pick up custom attributes.
if (substr($field, 3, 5) === 'Attr:') {
switch (preg_replace('/[^a-z]/', '', strtolower($caption))) {
case 'recorder':
case 'recordername':
case 'recordernames':
$alt = ' data-alt="recorder,recordername,recordernames"';
break;
// Matching variations for some potential custom attribute captions.
if (preg_match('/(.+) \(.+\)/', $caption, $matches)) {
// Strip anything in brackets from caption we are checking.
$captionSimplified = preg_replace('/[^a-z]/', '', strtolower($matches[1]));
}
else {
$captionSimplified = preg_replace('/[^a-z]/', '', strtolower($caption));
}
$customAttrVariations = [
['abundance', 'count', 'qty', 'quantity'],
['vc', 'vicecounty', 'vicecountynumber'],
['recorder', 'recordername', 'recordernames', 'recorders'],
['determinedby', 'determiner', 'identifiedby', 'identifier'],
['lifestage','stage'],
];
foreach ($customAttrVariations as $variationSet) {
if (in_array(strtolower($captionSimplified), $variationSet)) {
unset($variationSet[array_search($captionSimplified, $variationSet)]);
$alts = array_merge($alts, $variationSet);
}
}
$translatedCaption = lang::get($caption);
$colsByGroup[$optGroup][$translatedCaption] = "<option value=\"$field\" data-untranslated=\"$caption\"$alt>$translatedCaption</option>";
// Build the data attribute.
$alt = empty($alts) ? '' : ' data-alt="' . implode(',', $alts) . '"';
// Translation can be a precise term keyed by the field name, or a loose
// term keyed off the caption.
$translatedCaption = lang::get($field);
if ($translatedCaption === $field) {
$translatedCaption = lang::get($caption);
}
$advanced = in_array($field, $options['advancedFields']) ? ' class="advanced" ' : '';
$colsByGroup[$optGroup][$translatedCaption] = "<option value=\"$field\"$advanced data-untranslated=\"$caption\"$alt>$translatedCaption</option>";
}
$optGroupHtmlList = ["<option value=\"\">- $lang[notImported] -</option>"];
foreach ($colsByGroup as $thisColOptionGroup => $optionsList) {
Expand Down Expand Up @@ -1589,6 +1630,7 @@ private static function clearTemplateCache(array $options) {
'extraParams' => $options['readAuth'] + [
'entity' => $options['entity'],
'created_by_id' => hostsite_get_user_field('indicia_user_id'),
'orderby' => 'title',
],
]);
}
Expand Down
10 changes: 9 additions & 1 deletion lang/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
// Default labels for various database fields.
'occurrence:taxa_taxon_list_id' => 'Species',
'sample:date' => 'Date',
'sample:entered_sref' => 'Spatial Reference',
'sample:entered_sref' => 'Spatial reference',
'sample:entered_sref_system' => 'Spatial reference system',

// Spatial reference systems.
'sref:OSGB' => 'British National Grid',
Expand Down Expand Up @@ -98,6 +99,13 @@
'Click to Filter Occ_id' => 'Select records by record ID',
'Click to Filter Quality' => 'Select records based on quality criteria such as verification status or presence of photos',
'Click to Filter Source' => 'Select records based on source website, survey or input form',

// Data cleaner rules.
'ancillary_species failed' => 'Rarity check failed',
'identification_difficulty failed' => 'ID difficulty check failed',
'period failed' => 'Year range check failed',
'period_within_year failed' => 'Date range check failed',
'without_polygon failed' => 'Distribution check failed',
];

// Some bigger bits of text better handled with HEREDOC.
Expand Down
18 changes: 15 additions & 3 deletions lang/import_helper_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
TXT;

$default_terms['import2mappingsFormIntro'] = <<<TXT
Select which database field each of your import file's columns should be mapped to. Any columns in your file that do not have matches can be set to "- not imported -".
Select which database field each of your import file's columns should be mapped to. Any columns in
your file that do not need to be imported, or that have no matches, should be set to
“- not imported -“.<br><br>
By default this page shows all the “standard” attributes that will be sufficient for typical
biological record formats. If needed you can add “advanced” attributes to the list - these provide
additional options but are not always straightforward to use.
TXT;

$default_terms['import2lookupMatchingFormIntro'] = <<<TXT
Expand Down Expand Up @@ -82,8 +88,14 @@
$default_terms['optionGroup-sample-shortLabel'] = 'Sample';
$default_terms['optionGroup-sample_medium-shortLabel'] = 'Sample media';
$default_terms['optionGroup-smpAttr-shortLabel'] = 'Sample attributes';
// Improved field name captions.
$default_terms['occurrence:comment'] = 'Occurrence comment';
$default_terms['occurrence:external_key'] = 'External record ID';
$default_terms['location:external_key'] = 'External location ID';
$default_terms['sample:comment'] = 'Sample comment';
$default_terms['sample:external_key'] = 'External sample ID';
$default_terms['sample:record_status'] = 'Sample verification status';

$default_terms['Deleted'] = 'Deleted (for existing records)';
$default_terms['External key'] = 'External key (your reference)';
$default_terms['Id'] = 'ID (primary key for existing records)';
$default_terms['Taxa taxon list (lookup in database)'] = 'Species or taxon name';
$default_terms['Taxa taxon list (lookup)'] = 'Species or taxon name';
Loading

0 comments on commit dc7467b

Please sign in to comment.