diff --git a/css/cloud_config_location.css b/css/cloud_config_location.css index 88fb583..a98a39e 100644 --- a/css/cloud_config_location.css +++ b/css/cloud_config_location.css @@ -11,6 +11,10 @@ use.aws_ec2 { stroke: #ec912d; } +use.aws_ec2.own_location { + fill: #ec912d; +} + use.aws_ec2:hover { fill: #ec912d; } @@ -20,6 +24,10 @@ use.k8s { stroke: #326de6; } +use.k8s.own_location { + fill: #326de6; +} + use.k8s:hover { fill: #326de6; } @@ -29,20 +37,36 @@ use.openstack { stroke: #ed1e48; } +use.openstack.own_location { + fill: #ed1e48; +} + use.openstack:hover { fill: #ed1e48; } -.own_location { - stroke-width:5px; +use.multiple { + fill: #9fd5a2; + stroke: #68c16c; +} + +use.multiple.own_location { + fill: #68c16c; } +use.multiple:hover { + fill: #68c16c; +} + +.tooltip { + background-color: #68c16c; + color: #ffffff; +} .tooltip a { color: #ffffff; font-size: 1.1em; } .tooltip a:hover { - font-weight: bold; color: #ffffff; } \ No newline at end of file diff --git a/js/cloud_config_location.js b/js/cloud_config_location.js index 4e91f91..da68123 100644 --- a/js/cloud_config_location.js +++ b/js/cloud_config_location.js @@ -22,12 +22,6 @@ g_pointer.append('path') .attr('d', 'M0-49c7.7,0,14,6.3,14,14.1c0,8,0,8.1-14,32.8c-14-24.7-14-24.9-14-32.8C-14-42.7-7.7-49,0-49 M0-50c-8.3,0-15,6.8-15,15.1 S-15-26.5,0,0c15-26.5,15-26.5,15-34.9S8.3-50,0-50L0-50z'); - svg.append('g') - .attr('id', 'own_location_pointer') - .append('use') - .attr('href', '#pointer') - .attr('transform', 'scale(1.3)'); - let projection = d3.geoMercator() .scale(width / 2 / Math.PI) .translate([width / 2, height * 3 / 5]) @@ -50,8 +44,6 @@ .append('div') .style('opacity', 0) .attr('class', 'tooltip') - .style('background-color', '#68c16c') - .style('color', '#ffffff') .style('font-size', '0.8em') .style('border-radius', '5px') .style('padding', '5px') @@ -106,14 +98,6 @@ .on('mouseover', mouseover) .on('mouseleave', mouseleave) .attr('href', '#pointer') - .attr('href', function (d) { - if (d.OwnLocation) { - return '#own_location_pointer'; - } - else { - return '#pointer'; - } - }) .attr('x', function (d) { return projection([d.Longitude, d.Latitude])[0]; }) diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php b/modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php index 252480d..6f35f2c 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php @@ -668,46 +668,34 @@ class AwsCloudAdminSettings extends ConfigFormBase { '#header_columns' => 5, ]; foreach ($region as $key => $value) { - $form['location']['aws_cloud_region_locations'][] = [ + $form['location']['aws_cloud_region_locations'][$key] = [ ['data' => ['#markup' => "$value"]], - [ - 'data' => [ - '#type' => 'select', - '#options' => $country_options, - '#name' => "aws_cloud_region_locations[$key][country]", - '#default_value' => $location[$key]['country'], - '#attributes' => ['autocomplete' => 'off'], - ], + 'country' => [ + '#type' => 'select', + '#options' => $country_options, + '#default_value' => $location[$key]['country'], + '#attributes' => ['autocomplete' => 'off'], ], - [ - 'data' => [ - '#type' => 'textfield', - '#size' => 30, - '#default_value' => $location[$key]['city'], - '#name' => "aws_cloud_region_locations[$key][city]", - ], + 'city' => [ + '#type' => 'textfield', + '#size' => 30, + '#default_value' => $location[$key]['city'], ], - [ - 'data' => [ - '#type' => 'number', - '#default_value' => $location[$key]['latitude'], - '#max' => '90', - '#min' => '-90', - '#scale' => 6, - '#step' => 'any', - '#name' => "aws_cloud_region_locations[$key][latitude]", - ], + 'latitude' => [ + '#type' => 'number', + '#default_value' => $location[$key]['latitude'], + '#max' => '90', + '#min' => '-90', + '#scale' => 6, + '#step' => 'any', ], - [ - 'data' => [ - '#type' => 'number', - '#default_value' => $location[$key]['longitude'], - '#max' => '180', - '#min' => '-180', - '#scale' => 6, - '#step' => 'any', - '#name' => "aws_cloud_region_locations[$key][longitude]", - ], + 'longitude' => [ + '#type' => 'number', + '#default_value' => $location[$key]['longitude'], + '#max' => '180', + '#min' => '-180', + '#scale' => 6, + '#step' => 'any', ], ]; } diff --git a/src/Controller/CloudConfigLocationController.php b/src/Controller/CloudConfigLocationController.php index 082a75b..c6c8d6e 100644 --- a/src/Controller/CloudConfigLocationController.php +++ b/src/Controller/CloudConfigLocationController.php @@ -142,6 +142,7 @@ class CloudConfigLocationController extends ControllerBase { $url = Url::fromUri("internal:" . $alias); $params = $url->getRouteParameters(); + $cloud_context = NULL; if (isset($params['cloud_context'])) { $cloud_context = $params['cloud_context']; } @@ -152,19 +153,38 @@ class CloudConfigLocationController extends ControllerBase { $config = $this->config('aws_cloud.settings'); $aws_location = $config->get('aws_cloud_region_locations'); + $regions = []; foreach ($cloud_configs ?: [] as $cloud_config) { if (isset($cloud_config)) { $this->cloudConfigPluginManager->setCloudContext($cloud_config->getCloudContext()); $route = $this->cloudConfigPluginManager->getInstanceCollectionTemplateName(); + $region_id = NULL; + + if (isset($cloud_config->field_location_longitude) && !empty($cloud_config->field_location_longitude->value) + && isset($cloud_config->field_location_latitude) && !empty($cloud_config->field_location_latitude->value) + && (!isset($cloud_config->field_region) || empty($cloud_config->field_region->value))) { + + foreach ($aws_location as $id => $location) { + if ($cloud_config->field_location_latitude->value === $location['latitude'] + &&$cloud_config->field_location_longitude->value === $location['longitude']) { + $region_id = $id; + break; + } + } + } + + if (isset($cloud_config->field_region) && !empty($cloud_config->field_region->value) + && isset($aws_location) && isset($aws_location[$cloud_config->field_region->value]) + && isset($aws_location[$cloud_config->field_region->value])) { + $region_id = $cloud_config->field_region->value; + } - if ($cloud_config->bundle() === 'aws_ec2' - && isset($cloud_config->field_region) && !empty($cloud_config->field_region->value) - && isset($aws_location) && isset($aws_location[$cloud_config->field_region->value])) { - if (!isset($regions[$cloud_config->field_region->value])) { - $region = $aws_location[$cloud_config->field_region->value]; - $regions[$cloud_config->field_region->value] = [ + if (isset($region_id)) { + if (!isset($regions[$region_id])) { + $region = $aws_location[$region_id]; + $regions[$region_id] = [ 'Type' => $cloud_config->bundle(), 'Country' => $region['country'], 'City' => $region['city'], @@ -172,18 +192,29 @@ class CloudConfigLocationController extends ControllerBase { 'Longitude' => $region['longitude'], ]; } - $regions[$cloud_config->field_region->value]['Items'][] = [ + if ($regions[$region_id]['Type'] !== $cloud_config->bundle()) { + $regions[$region_id]['Type'] = 'multiple'; + } + $regions[$region_id]['Items'][] = [ 'Name' => $cloud_config->getName(), 'Url' => Url::fromRoute($route, ['cloud_context' => $cloud_config->getCloudContext()])->toString(), ]; if (isset($cloud_context) && $cloud_config->getCloudContext() === $cloud_context) { - $regions[$cloud_config->field_region->value]['OwnLocation'] = TRUE; + $regions[$region_id]['OwnLocation'] = TRUE; } } elseif (isset($cloud_config->field_location_country) && !empty($cloud_config->field_location_country->value) && isset($cloud_config->field_location_city) && !empty($cloud_config->field_location_city->value) && isset($cloud_config->field_location_longitude) && !empty($cloud_config->field_location_longitude->value) && isset($cloud_config->field_location_latitude) && !empty($cloud_config->field_location_latitude->value)) { + + foreach ($aws_location as $region => $location) { + if ($cloud_config->field_location_latitude->value == $location['latitude'] + &&$cloud_config->field_location_longitude->value == $location['longitude']) { + $cloud_config->set('field_region', $region); + break; + } + } $response[] = [ 'Type' => $cloud_config->bundle(), 'Country' => $country_allowed_values[$cloud_config->field_location_country->value], @@ -205,8 +236,15 @@ class CloudConfigLocationController extends ControllerBase { $regions_value = array_values($regions); $response = array_merge($response, $regions_value); } + foreach ($response as $idx => $values) { + if (isset($values['OwnLocation']) && $values['OwnLocation'] === TRUE) { + unset($response[$idx]); + $response[] = $values; + break; + } + } - return new JsonResponse($response); + return new JsonResponse(array_values($response)); }