Skip to content

Commit

Permalink
Add ability to generate report without uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
chris1984 committed Oct 17, 2023
1 parent 5bf9938 commit f542634
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions lib/foreman_inventory_upload/async/generate_report_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -18,7 +18,7 @@ def plan(base_folder, organization_id)
base_folder,
ForemanInventoryUpload.facts_archive_name(organization_id),
organization_id
)
) unless disconnected
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions webpack/ForemanInventoryUpload/Components/Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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 = {
exitCode,
logs,
completed,
restartProcess,
restartDisconnected,
error,
scheduled,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const ReportGenerate = ({
completed,
error,
restartProcess,
restartDisconnected,
toggleFullScreen,
scheduled,
}) => (
<TabContainer className="report-generate">
<TabHeader
exitCode={exitCode}
onRestart={restartProcess}
restartDisconnected={restartDisconnected}
toggleFullScreen={toggleFullScreen}
/>
<TabBody
Expand All @@ -39,6 +41,7 @@ ReportGenerate.propTypes = {
]),
completed: PropTypes.number,
error: PropTypes.string,
restartDisconnected: PropTypes.func,
restartProcess: PropTypes.func,
toggleFullScreen: PropTypes.func,
scheduled: PropTypes.string,
Expand All @@ -50,6 +53,7 @@ ReportGenerate.defaultProps = {
completed: 0,
error: null,
restartProcess: noop,
restartDisconnected: noop,
toggleFullScreen: noop,
scheduled: null,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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 downloadReports = noop;
export const error = null;
export const props = {
Expand All @@ -13,6 +14,7 @@ export const props = {
logs,
completed,
restartProcess,
restartDisconnected,
downloadReports,
error,
};
49 changes: 40 additions & 9 deletions webpack/ForemanInventoryUpload/Components/TabHeader/TabHeader.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Grid, Button, Icon } from 'patternfly-react';
import { Grid, Button, Icon, DropdownItem, Dropdown, DropdownToggle, DropdownToggleAction } from 'patternfly-react';
import { noop } from 'foremanReact/common/helpers';
import { sprintf, translate as __ } from 'foremanReact/common/I18n';
import { isExitCodeLoading } from '../../ForemanInventoryHelpers';
import './tabHeader.scss';

const TabHeader = ({ exitCode, onRestart, onDownload, toggleFullScreen }) => (
const onActionToggle = () => {
setIsActionOpen(prev => !prev);
};

const dropdownItems = [
<DropdownItem
aria-label="restart_disconnected"
ouiaId="restart_disconnected"
key="restart_disconnected"
component="button"
onClick={restartDisconnected}
isDisabled={isExitCodeLoading(exitCode)}
>
{__('Restart without uploading')}
</DropdownItem>,
];

const TabHeader = ({ exitCode, onRestart, onDownload, restartDisconnected, toggleFullScreen }) => (
<Grid.Row className="tab-header">
<Grid.Col sm={6}>
<p>{sprintf(__('Exit Code: %s'), exitCode)}</p>
</Grid.Col>
<Grid.Col sm={6}>
<div className="tab-action-buttons">
{onRestart ? (
<Button
bsStyle="primary"
onClick={onRestart}
disabled={isExitCodeLoading(exitCode)}
>
{__('Restart')}
</Button>
<Dropdown
aria-label="restart_dropdown"
ouiaId="restart_dropdown"
toggle={
<DropdownToggle
aria-label="restart_report_toggle"
ouiaId="restart_report_toggle"
splitButtonItems={[
<DropdownToggleAction key="action" aria-label="bulk_actions" onClick={onRestart}>
{__('Restart')}
</DropdownToggleAction>,
]}
splitButtonVariant="action"
toggleVariant="primary"
onToggle={onActionToggle}
isDisabled={isExitCodeLoading(exitCode)}
/>
}
isOpen={isActionOpen}
dropdownItems={dropdownItems}
/>
) : null}
{onDownload ? (
<Button onClick={onDownload}>
Expand Down

0 comments on commit f542634

Please sign in to comment.