From f5426344279fdd8acf1e6b84c18781f57ad68e72 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 17 Oct 2023 13:52:12 -0400 Subject: [PATCH] Add ability to generate report without uploading --- .../inventory_upload/report_actions.rb | 2 +- .../reports_controller.rb | 3 +- .../async/generate_report_job.rb | 4 +- .../AccountList/AccountListActions.js | 34 +++++++++++++ .../Components/Dashboard/index.js | 4 +- .../ReportGenerate/ReportGenerate.fixtures.js | 2 + .../ReportGenerate/ReportGenerate.js | 4 ++ .../ReportUpload/ReportUpload.fixtures.js | 2 + .../Components/TabHeader/TabHeader.js | 49 +++++++++++++++---- 9 files changed, 89 insertions(+), 15 deletions(-) diff --git a/app/controllers/concerns/inventory_upload/report_actions.rb b/app/controllers/concerns/inventory_upload/report_actions.rb index e40dd367..cc7d87e3 100644 --- a/app/controllers/concerns/inventory_upload/report_actions.rb +++ b/app/controllers/concerns/inventory_upload/report_actions.rb @@ -10,7 +10,7 @@ def initialize(**params) end end - def start_report_generation(organization_id) + def start_report_generation(organization_id, disconnected) ForemanTasks.async_task(ForemanInventoryUpload::Async::GenerateReportJob, ForemanInventoryUpload.generated_reports_folder, organization_id) end diff --git a/app/controllers/foreman_inventory_upload/reports_controller.rb b/app/controllers/foreman_inventory_upload/reports_controller.rb index 20bc72e6..37d7e35e 100644 --- a/app/controllers/foreman_inventory_upload/reports_controller.rb +++ b/app/controllers/foreman_inventory_upload/reports_controller.rb @@ -21,8 +21,9 @@ def last def generate organization_id = params[:organization_id] + disconnected = params[:disconnected] - start_report_generation(organization_id) + start_report_generation(organization_id, disconnected) render json: { action_status: 'success', diff --git a/lib/foreman_inventory_upload/async/generate_report_job.rb b/lib/foreman_inventory_upload/async/generate_report_job.rb index b0bef3fc..af0c3b3e 100644 --- a/lib/foreman_inventory_upload/async/generate_report_job.rb +++ b/lib/foreman_inventory_upload/async/generate_report_job.rb @@ -5,7 +5,7 @@ def self.output_label(label) "report_for_#{label}" end - def plan(base_folder, organization_id) + def plan(base_folder, organization_id, disconnected) sequence do super( GenerateReportJob.output_label(organization_id), @@ -18,7 +18,7 @@ def plan(base_folder, organization_id) base_folder, ForemanInventoryUpload.facts_archive_name(organization_id), organization_id - ) + ) unless disconnected end end diff --git a/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js b/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js index 2bdfcc13..9e63ebaf 100644 --- a/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js +++ b/webpack/ForemanInventoryUpload/Components/AccountList/AccountListActions.js @@ -40,6 +40,40 @@ export const stopAccountStatusPolling = pollingProcessID => dispatch => { }); }; +export const restartDisconnected = (accountID, activeTab) => async dispatch => { + let processController = null; + let processStatusName = null; + let disconnected = true + + if (activeTab === 'uploading') { + processController = 'uploads'; + processStatusName = 'upload_report_status'; + } else { + processController = 'reports'; + processStatusName = 'generate_report_status'; + } + + try { + await API.post(inventoryUrl(`${accountID}/${processController}`)); + dispatch({ + type: INVENTORY_PROCESS_RESTART, + payload: { + accountID, + disconnected, + processStatusName, + }, + }); + } catch (error) { + dispatch( + addToast({ + sticky: true, + type: 'error', + message: error.message, + }) + ); + } +}; + export const restartProcess = (accountID, activeTab) => async dispatch => { let processController = null; let processStatusName = null; diff --git a/webpack/ForemanInventoryUpload/Components/Dashboard/index.js b/webpack/ForemanInventoryUpload/Components/Dashboard/index.js index 00db12c9..41e6f273 100644 --- a/webpack/ForemanInventoryUpload/Components/Dashboard/index.js +++ b/webpack/ForemanInventoryUpload/Components/Dashboard/index.js @@ -2,7 +2,7 @@ import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import * as actions from './DashboardActions'; -import { restartProcess } from '../AccountList/AccountListActions'; +import { restartProcess, restartDisconnected } from '../AccountList/AccountListActions'; import reducer from './DashboardReducer'; import Dashboard from './Dashboard'; @@ -25,7 +25,7 @@ const mapStateToProps = (state, { accountID }) => ({ // map action dispatchers to props const mapDispatchToProps = dispatch => - bindActionCreators({ ...actions, restartProcess }, dispatch); + bindActionCreators({ ...actions, restartProcess, restartDisconnected }, dispatch); // export reducers export const reducers = { dashboard: reducer }; diff --git a/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js b/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js index 87b293ed..87e6f84e 100644 --- a/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js +++ b/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.fixtures.js @@ -4,6 +4,7 @@ export const exitCode = 'exit 0'; export const logs = ['No running process']; export const completed = 0; export const restartProcess = noop; +export const restartDisconnected = noop; export const error = null; export const scheduled = '2019-08-21T16:14:16.520+03:00'; export const props = { @@ -11,6 +12,7 @@ export const props = { logs, completed, restartProcess, + restartDisconnected, error, scheduled, }; diff --git a/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js b/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js index 31dffea7..8c1db96d 100644 --- a/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js +++ b/webpack/ForemanInventoryUpload/Components/ReportGenerate/ReportGenerate.js @@ -12,6 +12,7 @@ const ReportGenerate = ({ completed, error, restartProcess, + restartDisconnected, toggleFullScreen, scheduled, }) => ( @@ -19,6 +20,7 @@ const ReportGenerate = ({ ( +const onActionToggle = () => { + setIsActionOpen(prev => !prev); +}; + +const dropdownItems = [ + + {__('Restart without uploading')} + , +]; + +const TabHeader = ({ exitCode, onRestart, onDownload, restartDisconnected, toggleFullScreen }) => (

{sprintf(__('Exit Code: %s'), exitCode)}

@@ -14,13 +31,27 @@ const TabHeader = ({ exitCode, onRestart, onDownload, toggleFullScreen }) => (
{onRestart ? ( - + + {__('Restart')} + , + ]} + splitButtonVariant="action" + toggleVariant="primary" + onToggle={onActionToggle} + isDisabled={isExitCodeLoading(exitCode)} + /> + } + isOpen={isActionOpen} + dropdownItems={dropdownItems} + /> ) : null} {onDownload ? (