Permalink
Browse files

Fix some bugs

  • Loading branch information...
1 parent 9156b86 commit e8b79bde25fb9143d0b94e32943f508cfd14e67b @SamuelHassine SamuelHassine committed Jan 11, 2017
@@ -54,6 +54,10 @@ export const redirectToScenario = (exerciseId) => (dispatch) => {
dispatch(push('/private/exercise/' + exerciseId + '/scenario'))
}
+export const redirectToEvent = (exerciseId, eventId) => (dispatch) => {
+ dispatch(push('/private/exercise/' + exerciseId + '/scenario/' + eventId))
+}
+
export const redirectToChecks = (exerciseId) => (dispatch) => {
dispatch(push('/private/exercise/' + exerciseId + '/checks'))
}
@@ -57,7 +57,9 @@ class AddUsers extends Component {
}
addUser(user) {
- this.setState({users: R.append(user, this.state.users)})
+ if( !this.props.audienceUsersIds.includes(user.user_id) && !this.state.users.includes(user) ) {
+ this.setState({users: R.append(user, this.state.users)})
+ }
}
removeUser(user) {
@@ -307,8 +307,8 @@ const filterInjectsPending = (state, ownProps) => {
const exerciseId = ownProps.params.exerciseId
let injectsFilterAndSorting = R.pipe(
R.values,
- R.filter(n => n.inject_exercise === exerciseId && n.inject_status.status_name === 'PENDING'),
- R.sort((a, b) => a.inject_date > b.inject_date)
+ R.sort((a, b) => a.inject_date > b.inject_date),
+ R.filter(n => n.inject_exercise === exerciseId && n.inject_status.status_name === 'PENDING')
)
return injectsFilterAndSorting(injects)
}
@@ -326,12 +326,12 @@ const filterInjectsProcessed = (state, ownProps) => {
const exerciseId = ownProps.params.exerciseId
let injectsFilterAndSorting = R.pipe(
R.values,
+ R.sort((a, b) => a.inject_date < b.inject_date),
R.filter(n => n.inject_exercise === exerciseId && (
n.inject_status.status_name === 'SUCCESS' ||
n.inject_status.status_name === 'ERROR' ||
n.inject_status.status_name === 'PARTIAL')
- ),
- R.sort((a, b) => a.inject_date < b.inject_date)
+ )
)
return injectsFilterAndSorting(injects)
}
@@ -9,10 +9,11 @@ const styles = {
},
'title': {
fontSize: '16px',
- fontWeight: '500'
+ fontWeight: '500',
+ margin: '0px 0px 10px 0px'
},
'story': {
-
+ textAlign: 'justify'
}
}
@@ -9,10 +9,11 @@ const styles = {
},
'title': {
fontSize: '16px',
- fontWeight: '500'
+ fontWeight: '500',
+ margin: '0px 0px 10px 0px'
},
'story': {
-
+ textAlign: 'justify'
}
}
@@ -0,0 +1,49 @@
+import React, {Component, PropTypes} from 'react'
+import {reduxForm, change} from 'redux-form'
+import R from 'ramda'
+import {SelectField} from '../../../../../components/SelectField'
+import {MenuItemLink} from '../../../../../components/menu/MenuItem'
+import {i18nRegister} from '../../../../../utils/Messages'
+
+i18nRegister({
+ fr: {
+ 'Incident': 'Incident'
+ }
+})
+
+const validate = values => {
+ const errors = {}
+ const requiredFields = ['incident_id']
+ requiredFields.forEach(field => {
+ if (!values[field]) {
+ errors[field] = 'Required'
+ }
+ })
+ return errors
+}
+
+class CopyForm extends Component {
+ render() {
+ return (
+ <form onSubmit={this.props.handleSubmit(this.props.onSubmit)}>
+ <SelectField label="Incident" name="incident_id" fullWidth={true}>
+ {R.values(this.props.incidents).map(data => {
+ return (<MenuItemLink key={data.incident_id} value={data.incident_id} label={data.incident_title}/>)
+ })}
+ </SelectField>
+ </form>
+ )
+ }
+}
+
+CopyForm.propTypes = {
+ error: PropTypes.string,
+ pristine: PropTypes.bool,
+ submitting: PropTypes.bool,
+ onSubmit: PropTypes.func.isRequired,
+ handleSubmit: PropTypes.func,
+ change: PropTypes.func,
+ incidents: PropTypes.array
+}
+
+export default reduxForm({form: 'CopyForm', validate}, null, {change})(CopyForm)
@@ -12,7 +12,6 @@ import {Icon} from '../../../../../components/Icon'
import {MenuItemLink, MenuItemButton} from "../../../../../components/menu/MenuItem"
import {Step, Stepper, StepLabel,} from '../../../../../components/Stepper'
import {updateIncident, deleteIncident, selectIncident} from '../../../../../actions/Incident'
-import {fetchSubobjectives} from '../../../../../actions/Subobjective'
import IncidentForm from './IncidentForm'
import IncidentSubobjectives from './IncidentSubobjectives'
@@ -58,10 +57,6 @@ class IncidentPopover extends Component {
}
}
- componentDidMount() {
- this.props.fetchSubobjectives(this.props.exerciseId);
- }
-
handlePopoverOpen(event) {
event.stopPropagation()
this.setState({openPopover: true, anchorEl: event.currentTarget})
@@ -141,7 +136,7 @@ class IncidentPopover extends Component {
exerciseId={this.props.exerciseId}
eventId={this.props.eventId}
onChange={this.onSubobjectivesChange.bind(this)}
- subobjectives={R.values(this.props.subobjectives)}
+ subobjectives={this.props.subobjectives}
incidentSubobjectivesIds={this.props.incidentSubobjectivesIds}
/>
)
@@ -216,14 +211,13 @@ IncidentPopover.propTypes = {
incident: PropTypes.object,
incident_types: PropTypes.object,
incidentSubobjectivesIds: PropTypes.array,
- subobjectives: PropTypes.object
+ subobjectives: PropTypes.array
}
const select = (state) => {
return {
incident_types: state.referential.entities.incident_types,
- subobjectives: state.referential.entities.subobjectives,
}
}
-export default connect(select, {fetchSubobjectives, updateIncident, deleteIncident, selectIncident})(IncidentPopover)
+export default connect(select, {updateIncident, deleteIncident, selectIncident})(IncidentPopover)
@@ -228,6 +228,7 @@ class Index extends Component {
<div>
<div style={styles.title}>{incident.incident_title}</div>
<IncidentPopover exerciseId={exerciseId} eventId={eventId} incident={incident}
+ subobjectives={this.props.subobjectives}
incidentSubobjectivesIds={incident.incident_subobjectives.map(i => i.subobjective_id)}
incident_types={this.props.incident_types}/>
<div style={styles.subobjectives}>{incident.incident_subobjectives.length} <T>linked subobjective(s)</T></div>
@@ -278,6 +279,7 @@ class Index extends Component {
injectAudiencesIds={inject_audiences.map(a => a.audience_id)}
audiences={this.props.audiences}
inject_types={this.props.inject_types}
+ incidents={this.props.allIncidents}
/>
}
primaryText={
@@ -340,6 +342,7 @@ Index.propTypes = {
inject_types: PropTypes.object,
injects: PropTypes.object,
subobjectives: PropTypes.array,
+ allIncidents: PropTypes.array,
fetchAudiences: PropTypes.func,
fetchSubobjectives: PropTypes.func,
fetchEvents: PropTypes.func,
@@ -399,7 +402,8 @@ const select = (state, ownProps) => {
subobjectives,
injects: state.referential.entities.injects,
incident_types: state.referential.entities.incident_types,
- inject_types: state.referential.entities.inject_types
+ inject_types: state.referential.entities.inject_types,
+ allIncidents: R.values(state.referential.entities.incidents),
}
}
@@ -41,9 +41,11 @@ class InjectAudiences extends Component {
}
addAudience(audienceId) {
- let audiencesIds = R.append(audienceId, this.state.audiencesIds)
- this.setState({audiencesIds: audiencesIds})
- this.submitAudiences(audiencesIds)
+ if (!this.state.audiencesIds.includes(audienceId)) {
+ let audiencesIds = R.append(audienceId, this.state.audiencesIds)
+ this.setState({audiencesIds: audiencesIds})
+ this.submitAudiences(audiencesIds)
+ }
}
removeAudience(audienceId) {
@@ -13,11 +13,13 @@ import {IconButton, FlatButton} from '../../../../../components/Button'
import {Icon} from '../../../../../components/Icon'
import {MenuItemLink, MenuItemButton} from "../../../../../components/menu/MenuItem"
import {Step, Stepper, StepLabel,} from '../../../../../components/Stepper'
-import {fetchIncident} from '../../../../../actions/Incident'
-import {fetchInjectTypes, updateInject, deleteInject} from '../../../../../actions/Inject'
+import {fetchIncident, selectIncident} from '../../../../../actions/Incident'
+import {redirectToEvent} from '../../../../../actions/Application'
+import {fetchInjectTypes, addInject, updateInject, deleteInject} from '../../../../../actions/Inject'
import InjectForm from './InjectForm'
import InjectContentForm from './InjectContentForm'
import InjectAudiences from './InjectAudiences'
+import CopyForm from './CopyForm'
const styles = {
[ Constants.INJECT_EXEC ]: {
@@ -54,6 +56,7 @@ class InjectPopover extends Component {
openPopover: false,
openDisable: false,
openEnable: false,
+ openCopy: false,
type: undefined,
stepIndex: 0,
finished: false,
@@ -86,7 +89,7 @@ class InjectPopover extends Component {
onContentSubmit(data) {
let injectData = this.state.injectData
- if( this.state.injectAttachments.length > 0 ) {
+ if (this.state.injectAttachments.length > 0) {
data.attachments = this.state.injectAttachments
}
injectData.inject_content = JSON.stringify(data)
@@ -182,6 +185,41 @@ class InjectPopover extends Component {
this.setState({stepIndex: 2, finished: true})
}
+ handleOpenCopy() {
+ this.setState({openCopy: true})
+ this.handlePopoverClose()
+ }
+
+ handleCloseCopy() {
+ this.setState({openCopy: false})
+ }
+
+ submitFormCopy() {
+ this.refs.copyForm.submit()
+ }
+
+ onCopySubmit(data) {
+ let incident = R.find(a => a.incident_id === data.incident_id)(this.props.incidents)
+ let new_inject = R.pipe(
+ R.dissoc('inject_id'),
+ R.dissoc('inject_event'),
+ R.dissoc('inject_exercise'),
+ R.dissoc('inject_incident'),
+ R.dissoc('inject_status'),
+ R.dissoc('inject_user'),
+ R.dissoc('inject_users_number'),
+ R.assoc('inject_title', this.props.inject.inject_title + ' (copy)')
+ )(this.props.inject)
+
+ this.props.addInject(this.props.exerciseId, incident.incident_event.event_id, data.incident_id, new_inject).then(() => {
+ this.props.fetchIncident(this.props.exerciseId, incident.incident_event.event_id, data.incident_id).then(() => {
+ this.props.redirectToEvent(this.props.exerciseId, incident.incident_event.event_id)
+ })
+ })
+ this.props.selectIncident(this.props.exerciseId, incident.incident_event.event_id, data.incident_id)
+ this.handleCloseCopy()
+ }
+
getStepContent(stepIndex, initialValues) {
switch (stepIndex) {
case 0:
@@ -237,7 +275,8 @@ class InjectPopover extends Component {
render() {
const editActions = [
<FlatButton label="Cancel" primary={true} onTouchTap={this.handleCloseEdit.bind(this)}/>,
- <FlatButton label={this.state.stepIndex === 2 ? "Update" : "Next"} primary={true} onTouchTap={this.submitFormEdit.bind(this)}/>,
+ <FlatButton label={this.state.stepIndex === 2 ? "Update" : "Next"} primary={true}
+ onTouchTap={this.submitFormEdit.bind(this)}/>,
]
const deleteActions = [
<FlatButton label="Cancel" primary={true} onTouchTap={this.handleCloseDelete.bind(this)}/>,
@@ -251,6 +290,10 @@ class InjectPopover extends Component {
<FlatButton label="Cancel" primary={true} onTouchTap={this.handleCloseEnable.bind(this)}/>,
<FlatButton label="Enable" primary={true} onTouchTap={this.submitEnable.bind(this)}/>,
]
+ const copyActions = [
+ <FlatButton label="Cancel" primary={true} onTouchTap={this.handleCloseCopy.bind(this)}/>,
+ <FlatButton label="Copy" primary={true} onTouchTap={this.submitFormCopy.bind(this)}/>,
+ ]
let initPipe = R.pipe(
R.assoc('inject_date', dateFormat(R.path(['inject', 'inject_date'], this.props))),
@@ -269,6 +312,7 @@ class InjectPopover extends Component {
onRequestClose={this.handlePopoverClose.bind(this)}>
<Menu multiple={false}>
<MenuItemLink label="Edit" onTouchTap={this.handleOpenEdit.bind(this)}/>
+ <MenuItemLink label="Copy" onTouchTap={this.handleOpenCopy.bind(this)}/>
{inject_enabled ?
<MenuItemButton label="Disable" onTouchTap={this.handleOpenDisable.bind(this)}/> :
<MenuItemButton label="Enable" onTouchTap={this.handleOpenEnable.bind(this)}/>}
@@ -322,6 +366,15 @@ class InjectPopover extends Component {
actions={enableActions}>
<T>Do you want to enable this inject?</T>
</Dialog>
+ <Dialog title="Copy" modal={false}
+ open={this.state.openCopy}
+ onRequestClose={this.handleCloseCopy.bind(this)}
+ actions={copyActions}>
+ <CopyForm ref="copyForm"
+ incidents={this.props.incidents}
+ onSubmit={this.onCopySubmit.bind(this)}
+ onSubmitSuccess={this.handleCloseCopy.bind(this)}/>
+ </Dialog>
</div>
)
}
@@ -335,12 +388,24 @@ InjectPopover.propTypes = {
inject: PropTypes.object,
injectAudiencesIds: PropTypes.array,
fetchIncident: PropTypes.func,
+ addInject: PropTypes.func,
updateInject: PropTypes.func,
deleteInject: PropTypes.func,
+ redirectToEvent: PropTypes.func,
+ selectIncident: PropTypes.func,
inject_types: PropTypes.object,
children: PropTypes.node,
initialAttachments: PropTypes.array,
- type: PropTypes.string
+ type: PropTypes.string,
+ incidents: PropTypes.array
}
-export default connect(null, {fetchIncident, fetchInjectTypes, updateInject, deleteInject})(InjectPopover)
+export default connect(null, {
+ fetchIncident,
+ fetchInjectTypes,
+ addInject,
+ updateInject,
+ deleteInject,
+ redirectToEvent,
+ selectIncident
+})(InjectPopover)
@@ -1,5 +1,6 @@
import React, {PropTypes, Component} from 'react'
import R from 'ramda'
+import Theme from '../../../../../components/Theme'
import {i18nRegister} from '../../../../../utils/Messages'
import {T} from '../../../../../components/I18n'
@@ -20,6 +21,7 @@ i18nRegister({
const styles = {
'container': {
+ color: Theme.palette.textColor,
padding: '10px 0px 10px 0px'
}
}
@@ -23,7 +23,8 @@ export const i18n = {
'Search': 'Rechercher',
'Required': 'Obligatoire',
'Close': 'Fermer',
- 'Export to XLS': 'Exporter en XLS'
+ 'Export to XLS': 'Exporter en XLS',
+ 'Copy': 'Copier'
},
en: {
'TECHNICAL': 'Technique',

0 comments on commit e8b79bd

Please sign in to comment.