Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
#250 Process button
Browse files Browse the repository at this point in the history
  • Loading branch information
damianprzygodzki committed Feb 23, 2017
1 parent ed469e5 commit 668cfcf
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 35 deletions.
12 changes: 8 additions & 4 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,12 @@ export function attachFileAction(windowType, docId, data){

// PROCESS ACTIONS

export function createProcess(processType, viewId, type, ids) {
export function createProcess(processType, viewId, type, ids, tabId, rowId) {
let pid = null;
return (dispatch) =>
dispatch(getProcessData(processType, viewId, type, ids)).then(response => {
dispatch(
getProcessData(processType, viewId, type, ids, tabId, rowId)
).then(response => {
const preparedData = parseToDisplay(response.data.parameters);
pid = response.data.pinstanceId;
if (preparedData.length === 0) {
Expand Down Expand Up @@ -434,7 +436,7 @@ export function handleProcessResponse(response, type, id, successCallback) {
}
}

function getProcessData(processId, viewId, type, ids) {
function getProcessData(processId, viewId, type, ids, tabId, rowId) {
return () => axios.post(
config.API_URL +
'/process/' + processId,
Expand All @@ -445,7 +447,9 @@ function getProcessData(processId, viewId, type, ids) {
} : {
processId: processId,
documentId: Array.isArray(ids) ? ids[0] : ids,
documentType: type
documentType: type,
tabId: tabId,
rowId: rowId
}
);
}
Expand Down
61 changes: 39 additions & 22 deletions src/components/app/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import {
handleProcessResponse
} from '../../actions/WindowActions';


class Modal extends Component {
constructor(props) {
super(props);

const {
dispatch, windowType, dataId, tabId, rowId, modalType, selected,
relativeType, isAdvanced, modalViewId
rowId
} = this.props;

this.state = {
Expand All @@ -29,25 +27,7 @@ class Modal extends Component {
pending: false
}

switch(modalType){
case 'window':
dispatch(
createWindow(windowType, dataId, tabId, rowId, true, isAdvanced)
).catch(() => {
this.handleClose();
});
break;
case 'process':
//processid, viewId, docType, id or ids
dispatch(
createProcess(
windowType, modalViewId, relativeType, dataId ? [dataId] : selected
)
).catch(() => {
this.handleClose();
});
break;
}
this.init();
}

componentDidMount() {
Expand All @@ -68,6 +48,43 @@ class Modal extends Component {
modalContent && modalContent.removeEventListener('scroll', this.handleScroll);
}

componentDidUpdate (prevProps) {
const {
windowType
} = this.props;

if(prevProps.windowType !== windowType){
this.init();
}
}

init = () => {
const {
dispatch, windowType, dataId, tabId, rowId, modalType, selected,
relativeType, isAdvanced, modalViewId
} = this.props;

switch(modalType){
case 'window':
dispatch(
createWindow(windowType, dataId, tabId, rowId, true, isAdvanced)
).catch(() => {
this.handleClose();
});
break;
case 'process':
dispatch(
createProcess(
windowType, modalViewId, relativeType, dataId ? [dataId] : selected,
tabId, rowId
)
).catch(() => {
this.handleClose();
});
break;
}
}

handleClose = () => {
const {closeCallback} = this.props;
const {isNew} = this.state;
Expand Down
28 changes: 20 additions & 8 deletions src/components/widget/MasterWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { connect } from 'react-redux';

import {
patch,
updateProperty
updateProperty,
openModal
} from '../../actions/WindowActions';

import RawWidget from './RawWidget';
Expand All @@ -29,16 +30,16 @@ class MasterWidget extends Component {
updated: true
}), () => {
this.timeout = setTimeout(() => {
this.setState(Object.assign({}, this.state, {
this.setState({
updated: false
}))
})
}, 1000);
}
)
}else{
this.setState(Object.assign({}, this.state, {
this.setState({
edited: false
}));
});
}
}
}
Expand Down Expand Up @@ -107,9 +108,9 @@ class MasterWidget extends Component {
}

setEditedFlag = (edited) => {
this.setState(Object.assign({}, this.state, {
this.setState({
edited: edited
}));
});
}

validatePrecision = (value) => {
Expand All @@ -130,13 +131,22 @@ class MasterWidget extends Component {
}
}

handleProcess = (
caption, buttonProcessId, tabId, rowId, dataId
) => {
const {dispatch} = this.props;

dispatch(
openModal(caption, buttonProcessId, 'process', tabId, rowId, false, false)
);
}

render() {
const {
caption, widgetType, fields, windowType, type, noLabel,
widgetData, dataId, rowId, tabId, icon, gridAlign, isModal, entity,
handleBackdropLock, tabIndex, dropdownOpenCallback, autoFocus, fullScreen,
disabled
disabled, buttonProcessId
} = this.props;

const {updated} = this.state;
Expand All @@ -155,6 +165,7 @@ class MasterWidget extends Component {
gridAlign={gridAlign}
handlePatch={this.handlePatch}
handleChange={this.handleChange}
handleProcess={this.handleProcess}
updated={updated}
isModal={isModal}
setEditedFlag={this.setEditedFlag}
Expand All @@ -167,6 +178,7 @@ class MasterWidget extends Component {
autoFocus={autoFocus}
fullScreen={fullScreen}
disabled={disabled}
buttonProcessId={buttonProcessId}
/>
)
}
Expand Down
28 changes: 27 additions & 1 deletion src/components/widget/RawWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,24 @@ class RawWidget extends Component {
this.handlePatch(widgetField, value, id);
}

handleProcess = () => {
const {
handleProcess, buttonProcessId, tabId, rowId, dataId, windowType,
caption
} = this.props;

handleProcess && handleProcess(
caption, buttonProcessId, tabId, rowId, dataId, windowType
);
}

renderWidget = () => {
const {
handleChange, updated, isModal, filterWidget, filterId, id, range,
onHide, handleBackdropLock, subentity, subentityId, tabIndex, viewId,
dropdownOpenCallback, autoFocus, fullScreen, widgetType, fields,
windowType, dataId, type, widgetData, rowId, tabId, icon, gridAlign,
entity, onShow, disabled
entity, onShow, disabled, caption
} = this.props;

const {isEdited} = this.state;
Expand Down Expand Up @@ -511,6 +522,21 @@ class RawWidget extends Component {
{widgetData[0].value[Object.keys(widgetData[0].value)[0]]}
</button>
)
case 'ProcessButton':
return (
<button
className={
'btn btn-sm btn-meta-primary ' +
(gridAlign ? 'text-xs-' + gridAlign + ' ' : '') +
(widgetData[0].readonly || disabled ? 'tag-disabled disabled ' : '')
}
onClick={this.handleProcess}
tabIndex={fullScreen ? -1 : tabIndex}
ref={c => this.rawWidget = c}
>
{caption}
</button>
)
case 'ActionButton':
return (
<ActionButton
Expand Down

0 comments on commit 668cfcf

Please sign in to comment.