Skip to content

Commit

Permalink
Apenas conteúdo teórico no roteiro
Browse files Browse the repository at this point in the history
  • Loading branch information
goveiat committed Dec 12, 2018
1 parent 0f29677 commit dad5e3f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "site",
"version": "0.1.5",
"version": "0.1.6",
"private": true,
"dependencies": {
"antd": "^3.8.1",
Expand Down
12 changes: 11 additions & 1 deletion src/Anatomp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ class Anatomp extends Component {

onSelectRoteiro = (partes, model) => {

const roteiro = this.state.options.listaRoteiros.find(r => r._id == model.roteiro)
const extra = roteiro ? {
options: {
...this.state.options,
listaPecasGenericas: roteiro.pecasGenericas
}
} : {};


this.setState({
model: {
...this.state.model,
Expand All @@ -246,7 +255,8 @@ class Anatomp extends Component {
referenciaRelativa: getModelReferenciaRelativa()
}]
}))
}
},
...extra
})
}

Expand Down
11 changes: 8 additions & 3 deletions src/Roteiro/FormGeral.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, Fragment } from 'react';

import { Form, Input, Select, Row, Col } from 'antd';
import { Form, Input, Select, Row, Col, Checkbox } from 'antd';

import { listaIdiomas } from '../utils/mock';

Expand All @@ -17,7 +17,7 @@ const props = {
wrapperCol: { span: 14 },
}

const FormGeral = ({ nome, curso, disciplina, proposito, erros, onChange, idioma, generalidades, onOpenSnackbar }) => {
const FormGeral = ({ nome, curso, disciplina, somentePratica, onChangeSomentePratica, erros, onChange, idioma, generalidades, onOpenSnackbar }) => {

const _erros = {
idioma: erros.campos.indexOf('idioma'),
Expand Down Expand Up @@ -65,7 +65,7 @@ const FormGeral = ({ nome, curso, disciplina, proposito, erros, onChange, idioma
help={erros.msgs[_erros.curso] || ''}
label='Curso'
>
<Input value={curso} onChange={e => onChange('curso')(e.target.value)} />
<Input value={curso} onChange={e => onChange('curso')(e.target.value)} />
</FormItem>
</Col>
<Col span={5}>
Expand All @@ -82,6 +82,11 @@ const FormGeral = ({ nome, curso, disciplina, proposito, erros, onChange, idioma
<Generalidades defaultValue={generalidades} onOpenSnackBar={onOpenSnackbar} onChange={onChange('generalidades')} placeholder='Generalidade sobre o assunto da aula' />
</FormItem>
</Col>
<Col span={24}>
<FormItem>
<Checkbox checked={somentePratica} onChange={e => onChangeSomentePratica(e.target.checked)}>Somente conteúdo prático</Checkbox>
</FormItem>
</Col>
{/* <Col span={12}>
<FormItem
validateStatus={_erros.proposito != -1 ? 'error' : ''}
Expand Down
43 changes: 27 additions & 16 deletions src/Roteiro/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@ class Roteiro extends Component {
pecas: [],
pecasFlat: [],
conteudoExpandido: [],
somentePratica: false
}

componentDidMount() {
const model = Maybe(this.props.history).bind(h => h.location).bind(l => l.state).maybe(false, s => s.model);

if(model){
this.setState({model: {
...model,
idioma: model.idioma._id,
partes: [],
conteudo: {
selected: [],
original: [],
filtrado: []
}
}})
this.setState({
somentePratica: model.conteudos.length == 0,
model: {
...model,
idioma: model.idioma._id,
partes: [],
conteudo: {
selected: [],
original: [],
filtrado: []
}
}
})
}

this.onGetData(false)
Expand All @@ -59,7 +63,7 @@ class Roteiro extends Component {

componentWillUpdate(nextProps, nextState){
if((JSON.stringify(this.state.model) != JSON.stringify(nextState.model)) && this.props.onChange){
this.props.onChange(nextState.model)
this.props.onChange({...nextState.model, somentePratica: nextState.somentePratica})
}
}

Expand All @@ -70,7 +74,7 @@ class Roteiro extends Component {

render() {
const {erros, loading} = this.props;
const { model, pecas, conteudoExpandido } = this.state;
const { model, pecas, conteudoExpandido, somentePratica } = this.state;

return (
<div style={{padding: 24}}>
Expand All @@ -80,14 +84,14 @@ class Roteiro extends Component {
</div>
<Collapse bordered={false} defaultActiveKey={['geral', 'partes', 'teoria']} >
<Panel className='anatome-panel' header={<Header loading={loading} error={this.checkError(['idioma', 'nome', 'curso', 'disciplina'])} contentQ={<p>....</p>} title="Informações gerais do roteiro" />} key='geral'>
<FormGeral onOpenSnackbar={this.props.onOpenSnackbar} erros={erros} onChange={this.onChange} {...model} />
<FormGeral somentePratica={somentePratica} onChangeSomentePratica={this.onChangeSomentePratica} onOpenSnackbar={this.props.onOpenSnackbar} erros={erros} onChange={this.onChange} {...model} />
</Panel>
<Panel className='anatome-panel' header={<Header loading={loading} error={this.checkError(['partes'])} contentQ={<p>....</p>} title="Conhecimento Prático (CP)" />} key='partes'>
<FormPecas onUpdatePecas={this.onGetData} pecas={pecas} erros={erros} onChange={this.onChange} {...model} />
</Panel>
<Panel className='anatome-panel' header={<Header loading={loading} error={this.checkError(['conteudo'])} contentQ={<p>....</p>} title="Conhecimento Teórico (CT)" />} key='teoria'>
{!somentePratica && <Panel className='anatome-panel' header={<Header loading={loading} error={this.checkError(['conteudo'])} contentQ={<p>....</p>} title="Conhecimento Teórico (CT)" />} key='teoria'>
<FormTeoria erros={erros} onChange={this.onChangeConteudoRoteiro} {...model.conteudo} partes={model.partes} conteudoExpandido={conteudoExpandido} />
</Panel>
</Panel>}
</Collapse>
{
this.props.match && (
Expand All @@ -101,8 +105,15 @@ class Roteiro extends Component {
)
}

onChangeSomentePratica = somentePratica => this.setState({somentePratica}, () => {
if(this.props.onChange){
this.props.onChange({...this.state.model, somentePratica})
}
})

onSubmit = () => {
onSaveRoteiro(this.props.onOpenSnackbar, this.props.onSetAppState, this.state.model, ret => {
const {somentePratica} = this.state;
onSaveRoteiro(this.props.onOpenSnackbar, this.props.onSetAppState, {...this.state.model, somentePratica}, ret => {
this.props.onOpenSnackbar(`O roteiro ${this.state.model.nome} foi salvo com sucesso!`, 'success');
this.props.onPush('/')
})
Expand Down
12 changes: 7 additions & 5 deletions src/Roteiro/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const uuidv4 = require('uuid/v4');


export const onValidate = model => {
const { nome, curso, disciplina, conteudo, partes, idioma } = model;
const { nome, curso, disciplina, conteudo, partes, idioma, somentePratica } = model;
let campos = [], msgs = []

if (idioma == '') {
Expand Down Expand Up @@ -31,9 +31,11 @@ export const onValidate = model => {
msgs = [...msgs, 'Inclua ao menos uma parte no roteiro'];
}

if (conteudo.selected.length == 0) {
campos = [...campos, 'conteudo'];
msgs = [...msgs, 'Inclua ao menos um conteúdo no roteiro'];
if(!somentePratica){
if (conteudo.selected.length == 0) {
campos = [...campos, 'conteudo'];
msgs = [...msgs, 'Inclua ao menos um conteúdo no roteiro'];
}
}

return { campos, msgs }
Expand All @@ -53,7 +55,7 @@ export const onSave = (onOpenSnackbar, onSetAppState, model, cb = false) => {
onSetAppState({ loading: true })
const body = {
...model,
conteudos: model.conteudo.selected.map(ct => (ct._id))
conteudos: model.somentePratica ? [] : model.conteudo.selected.map(ct => (ct._id))
}

const _request = model._id != null ? request(`roteiro/${model._id}`, { method: 'PUT', body: JSON.stringify(body) }) : request('roteiro', { method: 'POST', body: JSON.stringify({...body, _id: uuidv4()}) })
Expand Down

0 comments on commit dad5e3f

Please sign in to comment.