-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from EmmanuelDemey/master
Zenika
- Loading branch information
Showing
18 changed files
with
4,541 additions
and
4,091 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,6 @@ yarn-debug.log* | |
yarn-error.log* | ||
|
||
/swagger | ||
.cache | ||
.cache | ||
cypress/videos | ||
cypress/screenshots |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
226 changes: 226 additions & 0 deletions
226
src/js/components/operations/document/edition/edition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
import React, { Component } from 'react'; | ||
import PageSubtitle from 'js/components/shared/page-subtitle'; | ||
import PageTitle from 'js/components/shared/page-title'; | ||
import D from 'js/i18n'; | ||
import { goBack } from 'js/utils/redirection'; | ||
import NoteFlag from 'js/components/shared/note-flag/note-flag'; | ||
import PropTypes from 'prop-types'; | ||
import EditorMarkdown from 'js/components/shared/editor-html/editor-markdown'; | ||
import Button from 'js/components/shared/button'; | ||
import { validate } from 'js/components/operations/document/edition/validation'; | ||
const defaultDocument = { | ||
labelLg1: '', | ||
labelLg2: '', | ||
descriptionLg1: '', | ||
descriptionLg2: '', | ||
url: '', | ||
lang: '', | ||
}; | ||
class OperationsDocumentationEdition extends Component { | ||
static propTypes = { | ||
document: PropTypes.object.isRequired, | ||
langs: PropTypes.object.isRequired, | ||
saveDocument: PropTypes.func.isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
document: { | ||
...defaultDocument, | ||
...props.document, | ||
}, | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
this.setState({ | ||
document: { | ||
...defaultDocument, | ||
...nextProps.document, | ||
}, | ||
}); | ||
} | ||
|
||
onChange = e => { | ||
this.setState({ | ||
document: { | ||
...this.state.document, | ||
[e.target.id]: e.target.value, | ||
}, | ||
}); | ||
}; | ||
onSubmit = () => { | ||
this.props.saveDocument( | ||
this.state.document, | ||
(id = this.state.document.id) => { | ||
this.props.history.push(`/operations/document/${id}`); | ||
} | ||
); | ||
}; | ||
|
||
render() { | ||
const { | ||
langs: { lg1, lg2 }, | ||
} = this.props; | ||
const { document } = this.state; | ||
const isEditing = !!document.id; | ||
|
||
const errors = validate(document); | ||
|
||
return ( | ||
<div className="container editor-container"> | ||
{isEditing && ( | ||
<React.Fragment> | ||
<PageTitle | ||
title={this.props.document.labelLg1} | ||
context="operations" | ||
/> | ||
{this.props.document.labelLg2 && ( | ||
<PageSubtitle | ||
subTitle={this.props.document.labelLg2} | ||
context="operations" | ||
/> | ||
)} | ||
</React.Fragment> | ||
)} | ||
|
||
<div className="row btn-line"> | ||
<Button | ||
action={goBack(this.props, '/operations/documents')} | ||
label={ | ||
<React.Fragment> | ||
<span | ||
className="glyphicon glyphicon-floppy-remove" | ||
aria-hidden="true" | ||
/> | ||
<span> {D.btnCancel}</span> | ||
</React.Fragment> | ||
} | ||
context="operations" | ||
/> | ||
|
||
<div className="col-md-8 centered"> | ||
<div | ||
style={{ visibility: errors.errorMessage ? 'visible' : 'hidden' }} | ||
className="alert alert-danger bold" | ||
role="alert" | ||
> | ||
{/* HACK: if no content, the line height is set to 0 and the rest | ||
of the page moves a little */} | ||
{errors.errorMessage || ( | ||
<span style={{ whiteSpace: 'pre-wrap' }}> </span> | ||
)} | ||
</div> | ||
</div> | ||
<Button | ||
action={this.onSubmit} | ||
label={ | ||
<React.Fragment> | ||
<span | ||
className="glyphicon glyphicon-floppy-disk" | ||
aria-hidden="true" | ||
/> | ||
<span> {D.btnSave}</span> | ||
</React.Fragment> | ||
} | ||
context="operations" | ||
disabled={errors.errorMessage} | ||
/> | ||
</div> | ||
<form> | ||
<div className="row"> | ||
<div className="col-md-6 form-group"> | ||
<label htmlFor="prefLabelLg1"> | ||
<NoteFlag text={D.title} lang={lg1} /> | ||
<span className="boldRed">*</span> | ||
</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="labelLg1" | ||
value={document.labelLg1} | ||
onChange={this.onChange} | ||
aria-invalid={errors.fields.labelLg1} | ||
/> | ||
</div> | ||
<div className="col-md-6 form-group"> | ||
<label htmlFor="prefLabelLg2"> | ||
<NoteFlag text={D.title} lang={lg2} /> | ||
<span className="boldRed">*</span> | ||
</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="labelLg2" | ||
value={document.labelLg2} | ||
onChange={this.onChange} | ||
aria-invalid={errors.fields.labelLg2} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col-md-6 form-group"> | ||
<label htmlFor="abstractLg1"> | ||
<NoteFlag text={D.descriptionTitle} lang={lg1} /> | ||
</label> | ||
<EditorMarkdown | ||
text={document.descriptionLg1} | ||
handleChange={value => | ||
this.onChange({ target: { value, id: 'descriptionLg1' } }) | ||
} | ||
/> | ||
</div> | ||
<div className="col-md-6 form-group"> | ||
<label htmlFor="abstractLg2"> | ||
<NoteFlag text={D.descriptionTitle} lang={lg2} /> | ||
</label> | ||
<EditorMarkdown | ||
text={document.descriptionLg2} | ||
handleChange={value => | ||
this.onChange({ target: { value, id: 'descriptionLg2' } }) | ||
} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col-md-12 form-group"> | ||
<label htmlFor="url"> | ||
<NoteFlag text={D.titleLink} lang={lg1} /> | ||
<span className="boldRed">*</span> | ||
</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="url" | ||
value={document.url} | ||
onChange={this.onChange} | ||
aria-invalid={errors.fields.url} | ||
/> | ||
</div> | ||
</div> | ||
<div className="row"> | ||
<div className="col-md-12 form-group"> | ||
<label htmlFor="lang"> | ||
<NoteFlag text={D.langTitle} lang={lg1} /> | ||
<span className="boldRed">*</span> | ||
</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="lang" | ||
value={document.lang} | ||
onChange={this.onChange} | ||
aria-invalid={errors.fields.lang} | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
); | ||
// TODO n'afficher que l'URL pour les liens | ||
// TODO ajouter un select pour savoir si c'est un lien ou un document qu'on souhaite creer | ||
} | ||
} | ||
|
||
export default OperationsDocumentationEdition; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { Component } from 'react'; | ||
import { withRouter } from 'react-router-dom'; | ||
import loadDocument, { | ||
saveDocument, | ||
} from 'js/actions/operations/documents/item'; | ||
import * as select from 'js/reducers'; | ||
import { connect } from 'react-redux'; | ||
import buildExtract from 'js/utils/build-extract'; | ||
import Loading from 'js/components/shared/loading'; | ||
import DocumentationEdition from 'js/components/operations/document/edition/edition'; | ||
import { getCurrentDocument } from 'js/reducers/operations/selector'; | ||
|
||
const extractId = buildExtract('id'); | ||
|
||
class OperationsDocumentationEditionContainer extends Component { | ||
componentDidMount() { | ||
if (!this.props.document.id && this.props.id) { | ||
this.props.loadDocument(this.props.id); | ||
} | ||
} | ||
render() { | ||
if (!this.props.document) | ||
return <Loading textType="loading" context="operations" />; | ||
if (this.props.operationsAsyncTask) | ||
return <Loading textType="saving" context="operations" />; | ||
return <DocumentationEdition {...this.props} />; | ||
} | ||
} | ||
|
||
const mapDispatchToProps = { | ||
loadDocument, | ||
saveDocument, | ||
}; | ||
|
||
export const mapStateToProps = (state, ownProps) => { | ||
const id = extractId(ownProps); | ||
const document = id ? getCurrentDocument(state) : {}; | ||
const langs = select.getLangs(state); | ||
return { | ||
id, | ||
document, | ||
langs, | ||
operationsAsyncTask: state.operationsAsyncTask, | ||
}; | ||
}; | ||
|
||
export default withRouter( | ||
connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(OperationsDocumentationEditionContainer) | ||
); |
18 changes: 18 additions & 0 deletions
18
src/js/components/operations/document/edition/validation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import D from 'js/i18n'; | ||
|
||
export function validate(document) { | ||
let errorMessage = ''; | ||
if (!document.labelLg1 || !document.labelLg2) | ||
errorMessage = D.requiredPrefLabel; | ||
if (!document.url) errorMessage = D.requiredUrl; //TODO only for the likn | ||
if (!document.lang) errorMessage = D.requiredLang; | ||
return { | ||
fields: { | ||
prefLabelLg1: !document.labelLg1, | ||
prefLabelLg2: !document.labelLg2, | ||
url: !document.url, //TODO seulement pour les liens | ||
lang: !document.lang, | ||
}, | ||
errorMessage, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.