Skip to content

Commit

Permalink
Ajustes gerais: ref. rel, inserção lista...
Browse files Browse the repository at this point in the history
  • Loading branch information
goveiat committed Dec 10, 2018
1 parent d08a1cc commit 2280fdf
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 59 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.2",
"version": "0.1.3",
"private": true,
"dependencies": {
"antd": "^3.8.1",
Expand Down
45 changes: 38 additions & 7 deletions src/Anatom/ListaPeca.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Card, Input, List, Button, Tooltip, Spin, Icon, Collapse, Table } from 'antd';
import { Card, Input, Modal, Button, Tooltip, Spin, Icon, Collapse, Table } from 'antd';
import { withAppContext } from '../context'

import { request, norm, Maybe } from '../utils/data'
Expand Down Expand Up @@ -41,6 +41,8 @@ const Crud = ({ onEdit, onDelete }) => {
class Main extends Component {

state = {
toDelete: null,
open: false,
pecas: [],
originais: {
pecas: [],
Expand All @@ -53,7 +55,7 @@ class Main extends Component {

render() {
const { loading, history } = this.props;
const { pecas } = this.state;
const { pecas, open } = this.state;

return (
<div style={{padding: 24}}>
Expand Down Expand Up @@ -85,7 +87,7 @@ class Main extends Component {
title: '',
key: 'action',
width: 100,
render: (text, item) => <Crud onEdit={() => history.push({pathname: '/peca/editar/' + item._id, state: {model: item}})} onDelete={this.onDelete(item._id)} />,
render: (text, item) => <Crud onEdit={() => history.push({pathname: '/peca/editar/' + item._id, state: {model: item}})} onDelete={this.onShowDelete(item)} />,
}
]}
pagination={{ style: { textAlign: 'center', width: '100%' } }}
Expand All @@ -94,17 +96,42 @@ class Main extends Component {
/>
</Panel>
</Collapse>
<Modal
title={'Excluir conteúdo da peça'}
visible={open}
okText='Excluir'
onOk={this.onDelete}
cancelText='Cancelar'
onCancel={this.onClose}
okButtonProps={{ loading }}
cancelButtonProps={{ loading }}
>
{this.onGetBody()}
</Modal>
</div>
)
}

onGetBody = () => {
const {toDelete} = this.state;
if(toDelete !== null){
return <div>Deseja realmente excluir o conteúdo da peça <span style={{fontWeight: 'bold'}}>{toDelete.nome}</span>?</div>
}else{
return null;
}
}

onShowDelete = toDelete => () => {
this.setState({ open: true, toDelete })
}

onClose = () => this.setState({ open: false, toDelete: null })

onFilter = attr => val => {
const list = this.state.originais[attr];

const _val = norm(val);

console.log(list)

const _list = list.filter(p => {
return (
norm(p.nome).indexOf(_val) != -1 ||
Expand Down Expand Up @@ -147,10 +174,11 @@ class Main extends Component {
})
}

onDelete = id => () => {
onDelete = () => {
this.props.onSetAppState({loading: true})
this.props.onOpenSnackbar('Aguarde...', 'loading');

const id = this.state.toDelete._id;

request('peca/'+id, {method: 'DELETE'})
.then(ret => {
Expand All @@ -165,7 +193,10 @@ class Main extends Component {
const msg = typeof e == 'string' ? e : 'Não foi possível excluir a peça selecionada';
this.props.onOpenSnackbar(msg);
})
.finally(() => this.props.onSetAppState({loading: false}))
.finally(() => {
this.onClose()
this.props.onSetAppState({loading: false})
})
}

}
Expand Down
51 changes: 45 additions & 6 deletions src/Anatom/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Input, List, Button, Tooltip, Spin, Icon, Collapse, Table, Popover } from 'antd';
import { Input, Modal, Button, Tooltip, Spin, Icon, Collapse, Table, Popover } from 'antd';
import { withAppContext } from '../context'

import { request, norm } from '../utils/data'
Expand Down Expand Up @@ -75,6 +75,9 @@ class Main extends Component {
state = {
anatomp: [],
roteiros: [],
open: false,
toDelete: null,
resourceToDelete: '',
originais: {
anatomp: [],
roteiros: []
Expand All @@ -87,7 +90,7 @@ class Main extends Component {

render() {
const { loading, history } = this.props;
const { anatomp, roteiros } = this.state;
const { anatomp, roteiros, open, resourceToDelete } = this.state;

return (
<div style={{ padding: 24 }}>
Expand Down Expand Up @@ -141,7 +144,7 @@ class Main extends Component {
title: '',
key: 'action',
width: 100,
render: (text, item) => <Crud onEdit={() => history.push({ pathname: '/roteiro/editar/' + item._id, state: { model: item } })} onDelete={this.onDelete('roteiro', item._id)} />,
render: (text, item) => <Crud onEdit={() => history.push({ pathname: '/roteiro/editar/' + item._id, state: { model: item } })} onDelete={this.onShowDelete('roteiro', item)} />,
}
]}
rowKey='_id'
Expand Down Expand Up @@ -184,7 +187,7 @@ class Main extends Component {
title: '',
key: 'action',
width: 100,
render: (text, item) => <Crud onEdit={() => history.push({ pathname: '/mapeamento/editar/' + item._id, state: { model: item } })} onDelete={this.onDelete('anatomp', item._id)} />,
render: (text, item) => <Crud onEdit={() => history.push({ pathname: '/mapeamento/editar/' + item._id, state: { model: item } })} onDelete={this.onShowDelete('anatomp', item)} />,
}
]}
rowKey='_id'
Expand All @@ -193,10 +196,40 @@ class Main extends Component {
/>
</Panel>
</Collapse>
<Modal
title={`Excluir ${resourceToDelete == 'anatomp' ? 'roteiro setado' : 'conteúdo do roteiro'}`}
visible={open}
okText='Excluir'
onOk={this.onDelete}
cancelText='Cancelar'
onCancel={this.onClose}
okButtonProps={{ loading }}
cancelButtonProps={{ loading }}
>
{this.onGetBody()}
</Modal>
</div>
)
}

onGetBody = () => {
const {toDelete, resourceToDelete} = this.state;
if(toDelete !== null){
return <div>Deseja realmente excluir o {resourceToDelete == 'anatomp' ? 'roteiro setado' : 'conteúdo do roteiro'} <span style={{fontWeight: 'bold'}}>{toDelete.nome}</span>?</div>
}else{
return null;
}
}

onShowDelete = (resourceToDelete, toDelete) => () => {
this.setState({ open: true, toDelete, resourceToDelete })
}

onClose = () => this.setState({ open: false }, () => {
this.setState({toDelete: null, resourceToDelete: ''})
})


onGetData = () => {
const { onOpenSnackbar, onSetAppState } = this.props;

Expand Down Expand Up @@ -226,10 +259,13 @@ class Main extends Component {
}


onDelete = (model, id) => () => {
onDelete = () => {
this.props.onSetAppState({ loading: true })
this.props.onOpenSnackbar('Aguarde...', 'loading');

const model = this.state.resourceToDelete;
const id = this.state.toDelete._id;

const nome = model == 'roteiro' ? 'Conteúdo do roteiro' : 'Roteiro setado';

request(model + '/' + id, { method: 'DELETE' })
Expand All @@ -245,7 +281,10 @@ class Main extends Component {
const msg = typeof e == 'string' ? e : 'Não foi possível excluir o ' + nome.toLowerCase() + ' selecionado';
this.props.onOpenSnackbar(msg);
})
.finally(() => this.props.onSetAppState({ loading: false }))
.finally(() => {
this.onClose()
this.props.onSetAppState({ loading: false })
})
}


Expand Down
54 changes: 32 additions & 22 deletions src/Anatomp/FormLocalizacao.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,54 @@ import TextArea from 'antd/lib/input/TextArea';
const FormItem = Form.Item;
const Option = Select.Option

const Label = ({ children }) => (
<div style={{ color: '#000000d1', marginBottom: 5, marginTop: 15 }}>
{children}
</div>
)

const Num = ({ value, onChange, label }) => (
<FormItem label={label}>
<TextArea autosize style={{ width: '100%' }} value={value} onChange={e => onChange(e.target.value)} />
</FormItem>
<TextArea autosize style={{ width: '100%' }} value={value} onChange={e => onChange(e.target.value)} />
)



class FormLocalizacao extends Component {

render() {

const { model, onChange, partes } = this.props;
const { model, onChange, partes, item } = this.props;

const {
referenciaParaReferenciado,
referenciadoParaReferencia,
referencia
} = model

const sel = partes.find(p => p._id == referencia);
const nomeSel = sel ? sel.nome : '[Referência a selecionar]';

return (
<Form layout="vertical">
<FormItem label="Parte referenciada por:">
<Select
notFoundContent='Nenhuma parte foi encontrada'
style={{ width: '100%' }}
placeholder="Parte anatômica"
value={referencia}
optionFilterProp="children"
onChange={v => {
onChange('referencia')(v)
}}
>
{partes.map(({ nome, _id }) => <Option value={_id} key={_id}>{nome}</Option>)}
</Select>
</FormItem>
<Num label="Da referência para o referenciado:" value={referenciaParaReferenciado} onChange={onChange('referenciaParaReferenciado')} />
<Num label="Do referenciado para a referência:" value={referenciadoParaReferencia} onChange={onChange('referenciadoParaReferencia')} />
</Form>
<div layout="vertical" style={{ padding: 0 }}>
<Label>A parte <span style={{ fontWeight: 'bold' }}>{item.parte.nome}</span> é referenciada pela parte:</Label>
<Select
showSearch
notFoundContent='Nenhuma parte foi encontrada'
style={{ width: '100%' }}
placeholder="Parte anatômica"
value={referencia}
optionFilterProp="children"
onChange={v => {
onChange('referencia')(v)
}}
>
{partes.map(({ nome, _id }) => <Option value={_id} key={_id}>{nome}</Option>)}
</Select>
<Label>A parte <span style={{ fontWeight: 'bold' }}>{item.parte.nome}</span> em relação à parte <span style={{ fontWeight: 'bold' }}>{nomeSel}</span> está localizada:</Label>
<Num value={referenciaParaReferenciado} onChange={onChange('referenciaParaReferenciado')} />
<Label>A parte <span style={{ fontWeight: 'bold' }}>{nomeSel}</span> em relação à parte <span style={{ fontWeight: 'bold' }}>{item.parte.nome}</span> está localizada:</Label>
<Num value={referenciadoParaReferencia} onChange={onChange('referenciadoParaReferencia')} />
</div>
)
}
}
Expand Down
Loading

0 comments on commit 2280fdf

Please sign in to comment.