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

Issue #3167104 by yas, Xiaohua Guan: Refactor K8s admin settings form

parent 7b977fd7
No related branches found
No related tags found
No related merge requests found
...@@ -85,9 +85,23 @@ class K8sAdminSettings extends ConfigFormBase { ...@@ -85,9 +85,23 @@ class K8sAdminSettings extends ConfigFormBase {
*/ */
public function buildForm(array $form, FormStateInterface $form_state) { public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('k8s.settings'); $config = $this->config('k8s.settings');
$form['k8s_js_refresh_interval'] = [
$form['views'] = [
'#type' => 'details',
'#title' => $this->t('Views'),
'#open' => TRUE,
'#description' => $this->t("Note that selecting the default option will overwrite View's settings."),
];
$form['views']['refresh_options'] = [
'#type' => 'details',
'#title' => $this->t('Refresh options'),
'#open' => TRUE,
];
$form['views']['refresh_options']['k8s_js_refresh_interval'] = [
'#type' => 'number', '#type' => 'number',
'#title' => 'UI Refresh Interval', '#title' => 'View refresh interval',
'#description' => $this->t('Refresh UI (Charts and etc) at periodical intervals.'), '#description' => $this->t('Refresh UI (Charts and etc) at periodical intervals.'),
'#default_value' => $config->get('k8s_js_refresh_interval'), '#default_value' => $config->get('k8s_js_refresh_interval'),
'#min' => 1, '#min' => 1,
...@@ -95,89 +109,88 @@ class K8sAdminSettings extends ConfigFormBase { ...@@ -95,89 +109,88 @@ class K8sAdminSettings extends ConfigFormBase {
'#field_suffix' => 'seconds', '#field_suffix' => 'seconds',
]; ];
$form['k8s_update_resources_queue_cron_time'] = [ $form['views']['refresh_options']['k8s_update_pricing_data_cache'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow pricing data to be updated during rendering of K8s blocks.'),
'#description' => $this->t('This allows the pricing data to be updated if not found in cache. Turning this on could result in performance issues if there are many regions to update.'),
'#default_value' => $config->get('k8s_update_pricing_data_cache'),
];
$form['views']['pager_options'] = [
'#type' => 'details',
'#title' => $this->t('Pager options'),
'#open' => TRUE,
];
$form['views']['pager_options']['k8s_view_expose_items_per_page'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow user to control the number of items displayed in views.'),
'#default_value' => $config->get('k8s_view_expose_items_per_page'),
'#description' => $this->t('When enabled, an "Items per page" dropdown listbox is shown.'),
];
$form['views']['pager_options']['k8s_view_items_per_page'] = [
'#type' => 'select',
'#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('k8s_view_items_per_page'),
];
$form['cron'] = [
'#type' => 'details',
'#title' => $this->t('Cron'),
'#open' => TRUE,
];
$form['cron']['k8s_update_resources_queue_cron_time'] = [
'#type' => 'number', '#type' => 'number',
'#title' => 'Update Resources Queue Cron Time', '#title' => 'Update resources every',
'#description' => $this->t('The cron time for queue update resources.'), '#description' => $this->t('Run cron to process queue to update resources.'),
'#default_value' => $config->get('k8s_update_resources_queue_cron_time'), '#default_value' => $config->get('k8s_update_resources_queue_cron_time'),
'#min' => 1, '#min' => 1,
'#max' => 9999, '#max' => 9999,
'#field_suffix' => 'seconds', '#field_suffix' => 'seconds',
]; ];
$form['k8s_update_cost_storage_queue_cron_time'] = [ $form['cron']['k8s_update_cost_storage_queue_cron_time'] = [
'#type' => 'number', '#type' => 'number',
'#title' => 'Update Cost Storage Queue Cron Time', '#title' => 'Update cost storage every',
'#description' => $this->t('The cron time for queue update cost storage.'), '#description' => $this->t('Run cron to process queue to update cost storage.'),
'#default_value' => $config->get('k8s_update_cost_storage_queue_cron_time'), '#default_value' => $config->get('k8s_update_cost_storage_queue_cron_time'),
'#min' => 1, '#min' => 1,
'#max' => 9999, '#max' => 9999,
'#field_suffix' => 'seconds', '#field_suffix' => 'seconds',
]; ];
$form['k8s_update_resource_storage_queue_cron_time'] = [ $form['cron']['k8s_update_resource_storage_queue_cron_time'] = [
'#type' => 'number', '#type' => 'number',
'#title' => 'Update Resource Storage Queue Cron Time', '#title' => 'Update resource storage every',
'#description' => $this->t('The cron time for queue update resource storage.'), '#description' => $this->t('Run cron to process queue to update resource storage.'),
'#default_value' => $config->get('k8s_update_resource_storage_queue_cron_time'), '#default_value' => $config->get('k8s_update_resource_storage_queue_cron_time'),
'#min' => 1, '#min' => 1,
'#max' => 9999, '#max' => 9999,
'#field_suffix' => 'seconds', '#field_suffix' => 'seconds',
]; ];
$form['k8s_keep_resource_storage_time_period'] = [ $form['cron']['k8s_keep_resource_storage_time_period'] = [
'#type' => 'number', '#type' => 'number',
'#title' => 'The time range to keep resources data.', '#title' => 'The time range to keep resources data',
'#description' => $this->t('The time range to keep resources data of all namespaces.'), '#description' => $this->t('The time period to keep resources data of all namespaces.'),
'#default_value' => $config->get('k8s_keep_resource_storage_time_period'), '#default_value' => $config->get('k8s_keep_resource_storage_time_period'),
'#min' => 1, '#min' => 1,
'#max' => 12, '#max' => 12,
'#field_suffix' => 'month', '#field_suffix' => 'month',
]; ];
$form['k8s_cloud_config_icon'] = [ $form['launch_templates'] = [
'#type' => 'managed_file',
'#title' => $this->t('K8s Cloud Config Icon'),
'#default_value' => [
'fids' => $config->get('k8s_cloud_config_icon'),
],
'#description' => $this->t('Upload an image to represent K8s.'),
'#upload_location' => 'public://images/icons',
'#upload_validators' => [
'file_validate_is_image' => [],
],
];
$form['views'] = [
'#type' => 'details', '#type' => 'details',
'#title' => $this->t('Views'), '#title' => $this->t('Launch Templates'),
'#open' => TRUE, '#open' => TRUE,
'#description' => $this->t("Note that selecting the default option will overwrite View's settings."),
];
$form['views']['pager_options'] = [
'#type' => 'details',
'#title' => $this->t('Pager options'),
'#open' => TRUE,
];
$form['views']['pager_options']['k8s_view_expose_items_per_page'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow user to control the number of items displayed in views.'),
'#default_value' => $config->get('k8s_view_expose_items_per_page'),
'#description' => $this->t('When enabled, an "Items per page" dropdown listbox is shown.'),
];
$form['views']['pager_options']['k8s_view_items_per_page'] = [
'#type' => 'select',
'#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('k8s_view_items_per_page'),
]; ];
$extensions = str_replace(' ', ', ', $config->get('k8s_yaml_file_extensions')); $extensions = str_replace(' ', ', ', $config->get('k8s_yaml_file_extensions'));
$form['k8s_yaml_file_extensions'] = [ $form['launch_templates']['k8s_yaml_file_extensions'] = [
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('Allowed YAML file extensions'), '#title' => $this->t('Allowed YAML file extensions'),
'#default_value' => $extensions, '#default_value' => $extensions,
...@@ -188,11 +201,23 @@ class K8sAdminSettings extends ConfigFormBase { ...@@ -188,11 +201,23 @@ class K8sAdminSettings extends ConfigFormBase {
'#required' => TRUE, '#required' => TRUE,
]; ];
$form['k8s_update_pricing_data_cache'] = [ $form['icon'] = [
'#type' => 'checkbox', '#type' => 'details',
'#title' => $this->t('Allow pricing data to be updated during rendering of K8s Blocks.'), '#title' => $this->t('Icon'),
'#description' => $this->t('This allows the pricing data to be updated if not found in cache. Turning this on could result in performance issues if there are many regions to update.'), '#open' => TRUE,
'#default_value' => $config->get('k8s_update_pricing_data_cache'), ];
$form['icon']['k8s_cloud_config_icon'] = [
'#type' => 'managed_file',
'#title' => $this->t('K8s cloud service provider icon'),
'#default_value' => [
'fids' => $config->get('k8s_cloud_config_icon'),
],
'#description' => $this->t('Upload an image to represent K8s.'),
'#upload_location' => 'public://images/icons',
'#upload_validators' => [
'file_validate_is_image' => [],
],
]; ];
return parent::buildForm($form, $form_state); return parent::buildForm($form, $form_state);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment