Commit 4e09a16d authored by xiaohua guan's avatar xiaohua guan Committed by Yas Naoi
Browse files

Issue #3164969 by Xiaohua Guan, yas: Add an "Item per page" option in K8s admin settings menu

parent 11ccfd6e
Loading
Loading
Loading
Loading
+35
Changes for cloud.module: 35 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -322,3 +322,38 @@ function cloud_modules_installed($modules) {
  $cloud_service = Drupal::getContainer()->get('cloud');
  $cloud_service->initGeocoder();
}

/**
 * Get the views items per page.
 *
 * @return array
 *   Array of page items.
 */
function cloud_get_views_items_options() {
  return [
    10 => '10',
    15 => '15',
    20 => '20',
    25 => '25',
    50 => '50',
    100 => '100',
  ];
}

/**
 * Update the configuration of view.
 *
 * @param string $view_name
 *   The name of view.
 * @param array $options
 *   The key and value array of view configuration.
 */
function cloud_update_views_configuration($view_name, array $options) {
  $config_factory = \Drupal::configFactory();
  $view = $config_factory->getEditable($view_name);

  foreach ($options ?: [] as $key => $value) {
    $view->set($key, $value);
  }
  $view->save(TRUE);
}
+3 −3
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.install: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -724,7 +724,7 @@ function aws_cloud_update_8133() {
    'views.view.aws_volume',
  ];

  $items_per_page = aws_cloud_get_views_items_options();
  $items_per_page = cloud_get_views_items_options();
  $options = [
    'display.default.display_options.pager.options.items_per_page' => 50,
    'display.default.display_options.pager.options.expose.items_per_page' => TRUE,
@@ -733,7 +733,7 @@ function aws_cloud_update_8133() {
  ];

  foreach ($views ?: [] as $view_name) {
    aws_cloud_update_views_configuration($view_name, $options);
    cloud_update_views_configuration($view_name, $options);
  }
}

@@ -820,7 +820,7 @@ function aws_cloud_update_8139() {
  ];

  foreach ($views ?: [] as $view_name) {
    aws_cloud_update_views_configuration($view_name, $options);
    cloud_update_views_configuration($view_name, $options);
  }
}

−35
Changes for modules/cloud_service_providers/aws_cloud/aws_cloud.module: 0 added lines, 35 removed lines.
Original line number Diff line number Diff line
@@ -3743,24 +3743,6 @@ function aws_cloud_ini_file_path($cloud_context) {
  return aws_cloud_ini_directory() . "/cloud_config_{$cloud_context}.ini";
}

/**
 * Update the configuration of view.
 *
 * @param string $view_name
 *   The name of view.
 * @param array $options
 *   The key and value array of view configuration.
 */
function aws_cloud_update_views_configuration($view_name, array $options) {
  $config_factory = \Drupal::configFactory();
  $view = $config_factory->getEditable($view_name);

  foreach ($options ?: [] as $key => $value) {
    $view->set($key, $value);
  }
  $view->save(TRUE);
}

/**
 * Get the reimport interval.
 *
@@ -3771,23 +3753,6 @@ function aws_cloud_get_reimport_interval() {
  return 86400;
}

/**
 * Get the views items per page.
 *
 * @return array
 *   Array of page items.
 */
function aws_cloud_get_views_items_options() {
  return [
    10 => '10',
    15 => '15',
    20 => '20',
    25 => '25',
    50 => '50',
    100 => '100',
  ];
}

/**
 * Implements hook_views_pre_view().
 */
+5 −39
Changes for modules/cloud_service_providers/aws_cloud/src/Form/Config/AwsCloudAdminSettings.php: 5 added lines, 39 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\aws_cloud\Form\Config;

use Drupal\aws_cloud\Service\Pricing\PricingService;
use Drupal\cloud\Plugin\cloud\config\CloudConfigPluginManagerInterface;
use Drupal\cloud\Traits\CloudFormTrait;
use Drupal\Component\Utility\Html;
use Drupal\Core\Config\Config;
use Drupal\Core\Config\ConfigFactoryInterface;
@@ -21,6 +22,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 */
class AwsCloudAdminSettings extends ConfigFormBase {

  use CloudFormTrait;

  /**
   * The file system service.
   *
@@ -143,7 +146,7 @@ class AwsCloudAdminSettings extends ConfigFormBase {

    $form['views']['pager_options']['aws_cloud_view_items_per_page'] = [
      '#type' => 'select',
      '#options' => aws_cloud_get_views_items_options(),
      '#options' => cloud_get_views_items_options(),
      '#title' => $this->t('Items per page'),
      '#description' => $this->t('Number of items to display on each page in views.'),
      '#default_value' => $config->get('aws_cloud_view_items_per_page'),
@@ -391,50 +394,13 @@ class AwsCloudAdminSettings extends ConfigFormBase {
    $config->save();

    if (!empty($views_settings)) {
      $this->updateViewsPagerOptions($views_settings);
      $this->updateViewsPagerOptions('aws_cloud', $views_settings);
    }

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

  }

  /**
   * Update views pager options.
   *
   * @param array $views_settings
   *   The key and value array of views pager options.
   */
  private function updateViewsPagerOptions(array $views_settings) {
    $views = [
      'views.view.aws_cloud_key_pair',
      'views.view.aws_cloud_elastic_ip',
      'views.view.aws_cloud_image',
      'views.view.aws_cloud_instance',
      'views.view.aws_cloud_network_interface',
      'views.view.aws_cloud_security_group',
      'views.view.aws_cloud_snapshot',
      'views.view.aws_cloud_volume',
    ];

    $options = [];
    foreach ($views_settings ?: [] as $key => $value) {
      $view_key = str_replace('aws_cloud_view_', '', $key);
      if (strpos($view_key, 'expose_') !== FALSE) {
        $view_key = str_replace('expose_', 'expose.', $view_key);
        if ($value) {
          $items_per_page = aws_cloud_get_views_items_options();
          $options['display.default.display_options.pager.options.expose.items_per_page_options'] = implode(',', $items_per_page);
          $options['display.default.display_options.pager.options.expose.items_per_page_options_all'] = TRUE;
        }
      }
      $options["display.default.display_options.pager.options.$view_key"] = $value;

    }
    foreach ($views ?: [] as $view_name) {
      aws_cloud_update_views_configuration($view_name, $options);
    }
  }

  /**
   * Judge whether cache should be cleaned or not.
   *
+2
Changes for modules/cloud_service_providers/k8s/config/install/k8s.settings.yml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -4,3 +4,5 @@ k8s_update_resource_storage_queue_cron_time: 3600
k8s_update_cost_storage_queue_cron_time: 60
k8s_keep_resource_storage_time_range: 2
k8s_yaml_file_extensions: 'yaml yml'
k8s_view_items_per_page: 50
k8s_view_expose_items_per_page: true
Loading