diff --git a/app/controllers/api/v2/hosts_bulk_actions_controller.rb b/app/controllers/api/v2/hosts_bulk_actions_controller.rb index 75e816ef7c8..e609d17b081 100644 --- a/app/controllers/api/v2/hosts_bulk_actions_controller.rb +++ b/app/controllers/api/v2/hosts_bulk_actions_controller.rb @@ -40,25 +40,25 @@ def build if missed_hosts.empty? if reboot process_response(true, { :message => n_("%s host set to build and rebooting.", - "%s hosts set to build and rebooting.", @hosts.count) % @hosts.count }) + "%s hosts set to build and rebooting.", + @hosts.count) % @hosts.count, + }) else process_response(true, { :message => n_("Built %s host", - "Built %s hosts", @hosts.count) % @hosts.count }) + "Built %s hosts", @hosts.count) % @hosts.count }) end + elsif reboot + render_error(:bulk_hosts_error, :status => :unprocessable_entity, + :locals => { :message => n_("Failed to build and reboot %s host", + "Failed to build and reboot %s hosts", missed_hosts.count) % missed_hosts.count, + :failed_host_ids => missed_hosts.map(&:id), + }) else - if reboot - render_error(:bulk_hosts_error, :status => :unprocessable_entity, - :locals => { :message => n_("Failed to build and reboot %s host", - "Failed to build and reboot %s hosts", missed_hosts.count) % missed_hosts.count, - :failed_host_ids => missed_hosts.map(&:id) - }) - else - render_error(:bulk_hosts_error, :status => :unprocessable_entity, - :locals => { :message => n_("Failed to build %s host", - "Failed to build %s hosts", missed_hosts.count) % missed_hosts.count, - :failed_host_ids => missed_hosts.map(&:id) - }) - end + render_error(:bulk_hosts_error, :status => :unprocessable_entity, + :locals => { :message => n_("Failed to build %s host", + "Failed to build %s hosts", missed_hosts.count) % missed_hosts.count, + :failed_host_ids => missed_hosts.map(&:id), + }) end end end @@ -93,16 +93,16 @@ def rebuild_config failed_host_ids.uniq! if failed_host_ids.blank? process_response(true, { :message => n_("Rebuilt configuration for %s host", - "Rebuilt configuration for %s hosts", - @hosts.count) % @hosts.count }) + "Rebuilt configuration for %s hosts", + @hosts.count) % @hosts.count }) else render_error(:bulk_hosts_error, :status => :unprocessable_entity, :locals => { :message => n_("Failed to rebuild configuration for %s host", - "Failed to rebuild configuration for %s hosts", - failed_host_ids.count) % failed_host_ids.count, - :failed_host_ids => failed_host_ids + "Failed to rebuild configuration for %s hosts", + failed_host_ids.count) % failed_host_ids.count, + :failed_host_ids => failed_host_ids, } - ) + ) end end end diff --git a/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js b/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js index 9fdee3b7cb6..3bcc13d40a6 100644 --- a/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js +++ b/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/BulkBuildHostModal.js @@ -14,7 +14,6 @@ import { addToast } from '../../../ToastsList/slice'; import { actionTypeGenerator } from '../../../../redux/API/APIActionTypeGenerator'; import { translate as __ } from '../../../../common/I18n'; import { urlWithSearch } from '../../../../common/urlHelpers'; -import { HOSTS_PATH } from '../../../../routes/Hosts/constants'; import { STATUS } from '../../../../constants'; import { selectAPIStatus } from '../../../../redux/API/APISelectors'; @@ -40,32 +39,33 @@ const BulkBuildHostModal = ({ closeModal(); }; - const search_link = ({ query, message, baseUrl }) => { - console.log({baseUrl}); + const searchLink = ({ query, message, baseUrl }) => { return { - children: message, - href: urlWithSearch(baseUrl, query), - } + children: message, + href: urlWithSearch(baseUrl, query), + }; }; - const handleError = ({response}) => { - console.log({response}) + const handleError = ({ response }) => { handleModalClose(); - const { FAILURE } = actionTypeGenerator( - HOST_BUILD_KEY - ); + const { FAILURE } = actionTypeGenerator(HOST_BUILD_KEY); const data = response.data.error; - const query = `id ^ (${data.failed_host_ids.join(",")})`; + const query = `id ^ (${data.failed_host_ids.join(',')})`; const hostsBaseUrl = foremanUrl('new/hosts'); dispatch( - addToast({ type: 'danger', - link: search_link({query, - message: __('Failed Hosts'), - baseUrl: hostsBaseUrl}), - message: data.message, key: FAILURE }) - ); - } + addToast({ + type: 'danger', + link: searchLink({ + query, + message: __('Failed hosts'), + baseUrl: hostsBaseUrl, + }), + message: data.message, + key: FAILURE, + }) + ); + }; const handleSave = () => { const requestBody = { included: { diff --git a/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/actions.js b/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/actions.js index cdec6c086b0..c62d9e8e09c 100644 --- a/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/actions.js +++ b/webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/buildHosts/actions.js @@ -1,35 +1,18 @@ import { translate as __ } from '../../../../common/I18n'; -import { API_OPERATIONS, APIActions } from '../../../../redux/API'; +import { APIActions } from '../../../../redux/API'; import { foremanUrl } from '../../../../common/helpers'; -export const HOST_BUILD_KEY = "HOST_BUILD_KEY"; + +export const HOST_BUILD_KEY = 'HOST_BUILD_KEY'; export const bulkBuildHosts = (params, handleSuccess, handleError) => { - const errorToast = ({ message }) => message; const url = foremanUrl(`/api/v2/hosts/bulk/build`); return APIActions.put({ key: HOST_BUILD_KEY, url, - successToast: (response) => response.data.message, + successToast: response => response.data.message, handleSuccess, handleError, params, }); }; - - // dispatch( - // APIActions.put({ - // url: `/api/hosts/${hostId}/parameters/${param.id}`, - // key: `${param.id}-EDIT`, - // params: { - // name, - // value, - // parameter_type: type, - // hidden_value: isHide, - // }, - // successToast: () => sprintf(__('Edited parameter %s'), name), - // ...APIActionsProps, - // }) - - - export default bulkBuildHosts;