Skip to content
Snippets Groups Projects
Commit f00a65e0 authored by Takumaru Sekine's avatar Takumaru Sekine Committed by Yas Naoi
Browse files

Issue #3268479 by sekinet, yas: Fix the source_type not displaying correctly...

Issue #3268479 by sekinet, yas: Fix the source_type not displaying correctly when editing the K8s Launch Template
parent 5b20e8ef
No related branches found
No related tags found
6 merge requests!1759Issue #3356778: Release 5.1.1,!1679Issue #3349074: Fix the OpenStack Project create and edit form in SPA that "Member" cannot be saved due to a validation error,!1607Issue #3343582: Add the function to preview OpenStack stack in the SPA,!1032Issue #3284576: Release 5.0.0-alpha2,!832Issue #3274116: Refactor composer.json to use docomoinnovations/drupal-extension,!781Issue #3269930: Add a BDD test suite for checking no resources created by administrator
......@@ -7,14 +7,21 @@
updateSourcetypeOptions(mutation.target.value);
});
});
const tab_configuration_observer = new MutationObserver((mutations) => {
const tab_configuration_git_observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const className = mutation.target.className;
if (className.includes('vertical-tabs-pane')) {
// changed vertival tab.
updateSourcetypeOptions(
className.includes('active') ? 'git' : 'yml'
);
if (className.includes('vertical-tabs-pane') && className.includes('active')) {
// active git tab.
updateSourcetypeOptions('git');
}
});
});
const tab_configuration_yml_observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const className = mutation.target.className;
if (className.includes('vertical-tabs-pane') && className.includes('active')) {
// active yaml tab.
updateSourcetypeOptions('yml');
}
});
});
......@@ -25,13 +32,20 @@
attributeFilter: ['value']
}
);
tab_configuration_observer.observe(
tab_configuration_git_observer.observe(
document.querySelector('#edit-configuration-git'),
{
attributes: true,
attributeFilter: ['class']
}
);
tab_configuration_yml_observer.observe(
document.querySelector('#edit-configuration-yml'),
{
attributes: true,
attributeFilter: ['class']
}
);
const updateSourcetypeOptions = function (active_tab) {
if (!active_tab) {
......@@ -55,14 +69,14 @@
return true;
}
});
// When the yml tab is active, select yml.
// And when the git tab is active, select the value of old_git_source_type.
const source_type = active_tab.includes('yml') ? 'yml' : old_git_source_type;
$('#edit-field-source-type option').each(function () {
const source_type = $(this).val();
const item = $(this).val();
// When the yml tab is active, select yml.
// And when the git tab is active, select the value of field_source_type.
if ((active_tab.includes('git') && old_git_source_type === source_type)
|| ((active_tab.includes('yml') || field_source_type === 'yml')
&& source_type === 'yml')) {
if (item === source_type) {
$(this).prop('selected', 'selected');
return false;
}
......
......@@ -12,11 +12,7 @@
);
const changeTabBySourcetype = function () {
let $selected_source_type = '';
$('#edit-field-source-type option').each(function () {
$selected_source_type = $(this).prop('selected')
? $(this).val() : $selected_source_type;
});
const $selected_source_type = $("select[name='field_source_type']")[0].value;
const $source_type = $selected_source_type.includes('git') ? 'git' : 'yml';
$('[data-vertical-tabs-panes]').each(function () {
const $tab_tag = $(this).find('> details').length > 0 ? 'details' : 'div';
......
......@@ -867,13 +867,14 @@ function k8s_entity_view_alter(array &$build, EntityInterface $entity, EntityVie
|| empty($entity->get('field_is_metrics_server'))
? FALSE
: $entity->field_is_metrics_server->value;
$source_type = $entity->get('field_source_type')->getValue();
\Drupal::service('cloud')->reorderForm(
$build,
k8s_server_template_field_orders(
FALSE,
$is_metrics_server,
FALSE,
str_contains($source_type, 'Git')
str_contains($source_type[0]['value'], 'git')
)
);
$build['k8s']['cloud_context'] = $entity->cloud_context->view();
......@@ -901,8 +902,6 @@ function k8s_entity_view_alter(array &$build, EntityInterface $entity, EntityVie
}
$git_available = $k8s_service->isGitCommandAvailable();
$source_type = $entity->get('field_source_type')->getValue();
if (!$git_available && str_contains($source_type[0]['value'], 'git')) {
$messages = \Drupal::messenger()->messagesByType(\Drupal::messenger()::TYPE_ERROR);
$warning = t('A git command could not be found on the server. Install the git command and try again.');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment