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

g0.135 Resolve problems and bring code to standard #136

Merged
merged 43 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7a2b290
Fixes TripalCultivatePhenotypesSettingsController
reynoldtan Dec 24, 2024
ff8597b
Fixes TripalCulticatePhenotypesOntologySettingsForm
reynoldtan Dec 24, 2024
cadf6e4
Fixes TripalCultivatePhenotypesRSettingsForm
reynoldtan Dec 24, 2024
7a00089
Fixes TripalCultivatePhenotypesWatermarkSettingsForm
reynoldtan Dec 24, 2024
f70257a
Fixes ConfigOntologyTermsTest
reynoldtan Dec 26, 2024
b6e9215
Fixes ConfigRRulesTest
reynoldtan Dec 31, 2024
ae68d6c
Fixes ConfigWatermarkTest
reynoldtan Dec 31, 2024
fb2832b
Fixes InstallTest
reynoldtan Dec 31, 2024
97fcd4d
Fixes failed test
reynoldtan Jan 2, 2025
b8fc933
Fixes ConfigRRulesFormTest
reynoldtan Jan 2, 2025
8c61576
Revises ServiceGenusOntologyTest
reynoldtan Jan 3, 2025
27975cd
Revises ServiceGenusProjectTest
reynoldtan Jan 3, 2025
96377c8
Revises ServiceTermTest
reynoldtan Jan 6, 2025
69fdec6
Fixes TripalCultivatePhenotypesGenusOntologyService
reynoldtan Jan 8, 2025
1e6605d
Fixes TripalCultivatePhenotypesGenusProjectService
reynoldtan Jan 8, 2025
344d2e6
Fixes TripalCultivatePhenotypesTermsService
reynoldtan Jan 8, 2025
2100fdf
Fixes TripalCultivatePhenotypesTraitsService @TODO: automated test
reynoldtan Jan 8, 2025
da16d64
Fixes PhenotypeImporterTestTrait
reynoldtan Jan 8, 2025
258bba5
Fixes core module files
reynoldtan Jan 8, 2025
f3ca0c3
Merge branch '4.x' into g0.135-resolveProblemsAndBringToStandard
reynoldtan Jan 13, 2025
156cde0
Update trpcultivate_phenotypes/src/Service/TripalCultivatePhenotypesT…
reynoldtan Jan 17, 2025
1ac3e42
Updates term service outdated doc block config name references and ap…
Jan 17, 2025
16345d8
Applied Traits service dock block revisions
Jan 17, 2025
dce3696
Update trpcultivate_phenotypes/src/Controller/TripalCultivatePhenotyp…
reynoldtan Jan 17, 2025
2de031f
Update trpcultivate_phenotypes/src/Service/TripalCultivatePhenotypesG…
reynoldtan Jan 17, 2025
fc6c9f5
Update trpcultivate_phenotypes/src/Service/TripalCultivatePhenotypesG…
reynoldtan Jan 17, 2025
a570691
Fixes failed test in watermark-config
Jan 17, 2025
18d4ddf
Update trpcultivate_phenotypes/src/Service/TripalCultivatePhenotypesT…
reynoldtan Jan 20, 2025
38a9096
Update trpcultivate_phenotypes/tests/src/Kernel/ServiceGenusOntologyT…
reynoldtan Jan 20, 2025
7aa24e0
Update trpcultivate_phenotypes/tests/src/Kernel/ServiceGenusProjectTe…
reynoldtan Jan 20, 2025
62804fa
Update trpcultivate_phenotypes/tests/src/Kernel/ServiceTermTest.php
reynoldtan Jan 20, 2025
d6acc15
Update trpcultivate_phenotypes/tests/src/Traits/PhenotypeImporterTest…
reynoldtan Jan 20, 2025
ba2e2f2
Update trpcultivate_phenotypes/tests/src/Unit/ConfigRRulesFormTest.php
reynoldtan Jan 20, 2025
8dee00b
Update trpcultivate_phenotypes/tests/src/Unit/ConfigWatermarkFormTest…
reynoldtan Jan 20, 2025
a3c19da
Update trpcultivate_phenotypes/trpcultivate_phenotypes.install
reynoldtan Jan 20, 2025
272843a
Update trpcultivate_phenotypes/src/Service/TripalCultivatePhenotypesG…
reynoldtan Jan 20, 2025
a006f61
Fixes minor problems
reynoldtan Jan 20, 2025
adf01ee
Merge branch '4.x' into g0.135-resolveProblemsAndBringToStandard
reynoldtan Jan 20, 2025
312a094
Fix watermark form unit test and create kernel test version
reynoldtan Jan 22, 2025
233d39e
Fixes minor inconsistency in submit form test
reynoldtan Jan 23, 2025
5c42d31
Update trpcultivate_phenotypes/tests/src/Unit/ConfigWatermarkFormTest…
reynoldtan Jan 24, 2025
14376a2
Reword short description text of defineGenusOtology() method
reynoldtan Jan 24, 2025
f737158
Merge branch 'g0.135-resolveProblemsAndBringToStandard' of https://gi…
reynoldtan Jan 24, 2025
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
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
<?php

/**
* @file
* Controller to display a dashboard page that houses links and descriptions
* to configuration pages.
*/

namespace Drupal\trpcultivate_phenotypes\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Class definition TripalCultivatePhenotypesSettingsController.
*
* Controller to display a dashboard page that houses links and descriptions
* to configuration pages.
*/
class TripalCultivatePhenotypesSettingsController extends ControllerBase {

/**
* Returns a markup of details (fieldset) where the
* the title of the element is the configuration section and
* expanding each will reveal a short description.
* Module hander service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $module_handler;

/**
* Constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->module_handler = $module_handler;
}

/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('module_handler')
);
}

/**
* Provides an administrative list of phenotypes configuration pages.
*
* @return array
* A render array consisting of a details element for each configuration
* page where the title is the configuration section and the contents
* include a short description plus a link.
*/
public function loadPage() {
// Quick enabled or disabled status of sub-phenotypes modules
// and report to dashboard.
$moduleHandler = \Drupal::service('module_handler');
// Quick enabled or disabled status of sub-phenotypes modules and report
// to dashboard.
$status_message = 'Tripal Cultivate Phenotypes Modules Status: ';

foreach(['trpcultivate_phenoshare', 'trpcultivate_phenocollect'] as $m) {
$is_enabled = ($moduleHandler->moduleExists($m)) ? 'is enabled' : 'is disabled';
foreach (['trpcultivate_phenoshare', 'trpcultivate_phenocollect'] as $m) {
$is_enabled = ($this->module_handler->moduleExists($m)) ? 'is enabled' : 'is disabled';
$status_message .= '*' . $m . ' ' . $is_enabled . ' ';
}

$url = Url::fromUri('internal:/admin/modules');
$link = Link::fromTextAndUrl('Manage Modules', $url)
->toString();

$this->messenger()->addStatus($this->t($status_message . '- @manage', ['@manage' => $link]));

$this->messenger()->addStatus($status_message . ' - ' . $link);

// Describe R Rules configuration:
$url = Url::fromRoute('trpcultivate_phenotypes.settings_r');
Expand Down Expand Up @@ -90,4 +116,5 @@ public function loadPage() {

return $element;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$link_to_docs = Link::fromTextAndUrl($this->t('Tripal 4 User Guide'), $url)
->toString();

$placeholder_values = [
'@tripaljobs' => $link_to_jobs,
'@tripaldocs' => $link_to_docs,
];
$config_warning = $this->t('Tripal Cultivate Phenotypes module requires controlled vocabulary terms and genus records
used for creating terms and genus-ontology module configuration. If you already know how to execute a Tripal Job,
please proceed with the Tripal Job Id number for Tripal Job titled: Tripal Cultivate Phenotypes: Install Ontology and Terms
(@tripaljobs), otherwise, please visit @tripaldocs to learn more about Tripal Jobs.', ['@tripaljobs' => $link_to_jobs, '@tripaldocs' => $link_to_docs]);
(@tripaljobs), otherwise, please visit @tripaldocs to learn more about Tripal Jobs.', $placeholder_values);

$this->messenger()->addWarning($config_warning);
return $form;
Expand Down Expand Up @@ -325,9 +329,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
// Render each term as autocomplete field element.
foreach ($this->config_vars['terms'] as $config => $prop) {
// Field description.
$describe = $this->t($prop['help_text']);
$describe = $prop['help_text'];
// Field placeholder and title text.
$placeholder = $title = $this->t(ucwords($prop['name']));
$placeholder = $title = ucwords($prop['name']);
// Field default value.
$config_value = $this->service_terms->getTermId($config);
$default_value = ChadoCVTermAutocompleteController::formatCVterm($config_value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
<?php

/**
* @file
* Construct form to manage and configure R Transformation rules.
*/

namespace Drupal\trpcultivate_phenotypes\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Class definition TripalCultivatePhenotypesRSettingsForm.
*
* Construct form to manage and configure R Transformation rules.
*/
class TripalCultivatePhenotypesRSettingsForm extends ConfigFormBase {
const SETTINGS = 'trpcultivate_phenotypes.settings';

/**
* {@inheritdoc}
*/
Expand All @@ -30,26 +27,26 @@ protected function getEditableConfigNames() {
return [
static::SETTINGS,
];
}
/**
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config(static::SETTINGS);
$config_r = 'trpcultivate.phenotypes.r_config.';

$form['description'] = [
'#markup' => $this->t('Tripal Cultivate Phenotypes supports R language for statistical computing by providing
syntactically valid version of trait or values. Use R Transformation Rules configuration page to define
standard transformation rules to apply to trait or string when converting to R version.')
syntactically valid version of trait or values. Use R Transformation Rules configuration page to define
standard transformation rules to apply to trait or string when converting to R version.'),
];

$form['words'] = [
'#type' => 'textarea',
'#title' => $this->t('List of words to remove'),
'#default_value' => implode(',', $config->get($config_r . 'words')),
'#description' => $this->t('Separate each word entry with a comma character.
'#description' => $this->t('Separate each word entry with a comma character.
Words must at least be 2 characters or more.'),
'#required' => TRUE,
];
Expand All @@ -58,7 +55,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textarea',
'#title' => $this->t('List of special characters to remove'),
'#default_value' => implode(',', $config->get($config_r . 'chars')),
'#description' => $this->t('Separate each character entry with a comma character.
'#description' => $this->t('Separate each character entry with a comma character.
Characters must be 1 character only.'),
'#required' => TRUE,
];
Expand All @@ -67,12 +64,11 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textarea',
'#title' => $this->t('Match word and replace with'),
'#default_value' => implode(',', $config->get($config_r . 'replace')),
'#description' => $this->t('Separate match and replace pairs with a comma character.
'#description' => $this->t('Separate match and replace pairs with a comma character.
Use match = replace pattern for each combination.'),
'#required' => TRUE,
];



return parent::buildForm($form, $form_state);
}

Expand All @@ -82,33 +78,33 @@ public function buildForm(array $form, FormStateInterface $form_state) {
public function validateForm(array &$form, FormStateInterface $form_state) {
// Words: words must be at least 2 characters long.
if ($words = $form_state->getValue('words')) {
foreach(explode(',', $words) as $word) {
foreach (explode(',', $words) as $word) {
if (empty($word) || !preg_match('/\w{2,}/', $word)) {
$form_state->setErrorByName('word', $this->t('Could not save rule.
Empty or invalid word: @word added to the list.', ['@word' => $word]));
}
}
}

// Special characters: 1 character only, excluding comma symbol since
// it is used as delimiter.
if ($chars = $form_state->getValue('chars')) {
foreach(explode(',', $chars) as $char) {
foreach (explode(',', $chars) as $char) {
if (empty($char) || $char == ',' || !preg_match('/\W{1}/', $char)) {
$form_state->setErrorByName('chars', $this->t('Could not save rule.
Empty or invalid special characters: @char added to the list.', ['@char' => $char]));
Empty or invalid special characters: @char added to the list.', ['@char' => $char]));
}
}
}

// Match and replace: match = replace pattern, excluding comma symbol since
// it is used as delimiter.
if ($replaces = $form_state->getValue('replace')) {
foreach(explode(',', $replaces) as $replace) {
foreach (explode(',', $replaces) as $replace) {
if (empty($replace) || !preg_match('/^[^,]+\s{1}[=]\s{1}[^,]+$/', $replace)) {
$form_state->setErrorByName('replace', $this->t('Could not save rule.
Empty or invalid match and replace: @replace added to the list.', ['@replace' => $replace]));
}
$form_state->setErrorByName('replace', $this->t('Could not save rule.
Empty or invalid match and replace: @replace added to the list.', ['@replace' => $replace]));
}
}
}
}
Expand All @@ -118,8 +114,8 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config_r = 'trpcultivate.phenotypes.r_config.';
// Configuration in field are string, convert to array to match

// Configuration in field are string, convert to array to match
// configuration schema data type.
$this->configFactory->getEditable(static::SETTINGS)
->set($config_r . 'words', explode(',', $form_state->getValue('words')))
Expand All @@ -129,4 +125,5 @@ public function submitForm(array &$form, FormStateInterface $form_state) {

return parent::submitForm($form, $form_state);
}
}

}
Loading
Loading