-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4043b88
commit 256bf45
Showing
29 changed files
with
506 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
*.log |
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,21 @@ | ||
{ | ||
"name": "backend", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/loader.js", | ||
"scripts": { | ||
"dev": "nodemon", | ||
"production": "pm2 start src/loader.js --name todo-app" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"body-parser": "^1.15.2", | ||
"express": "^4.14.0", | ||
"mongoose": "^4.7.0", | ||
"node-restful": "^0.2.5", | ||
"nodemon": "^1.11.0", | ||
"pm2": "^2.1.5" | ||
} | ||
} |
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,10 @@ | ||
const restful = require('node-restful') | ||
const mongoose = restful.mongoose | ||
|
||
const todoSchema = new mongoose.Schema({ | ||
description: { type: String, required: true }, | ||
done: { type: Boolean, required: true, default: false }, | ||
createdAt: { type: Date, default: Date.now } | ||
}) | ||
|
||
module.exports = restful.model('Todo', todoSchema) |
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,6 @@ | ||
const Todo = require('./todo') | ||
|
||
Todo.methods(['get', 'post', 'put', 'delete']) | ||
Todo.updateOptions({new: true, runValidators: true}) | ||
|
||
module.exports = Todo |
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,6 @@ | ||
module.exports = function(req, res, next) { | ||
res.header('Access-Control-Allow-Origin', '*') | ||
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE') | ||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept') | ||
next() | ||
} |
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,3 @@ | ||
const mongoose = require('mongoose') | ||
mongoose.Promise = global.Promise | ||
module.exports = mongoose.connect('mongodb://localhost/todo') |
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,12 @@ | ||
const express = require('express') | ||
|
||
module.exports = function(server) { | ||
|
||
// API Routes | ||
const router = express.Router() | ||
server.use('/api', router) | ||
|
||
// TODO Routes | ||
const todoService = require('../api/todo/todoService') | ||
todoService.register(router, '/todos') | ||
} |
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,16 @@ | ||
const port = 3003 | ||
|
||
const bodyParser = require('body-parser') | ||
const express = require('express') | ||
const server = express() | ||
const allowCors = require('./cors') | ||
|
||
server.use(bodyParser.urlencoded({ extended: true })) | ||
server.use(bodyParser.json()) | ||
server.use(allowCors) | ||
|
||
server.listen(port, function() { | ||
console.log(`BACKEND is running on port ${port}.`) | ||
}) | ||
|
||
module.exports = server |
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,3 @@ | ||
const server = require('./config/server') | ||
require('./config/database') | ||
require('./config/routes')(server) |
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,2 @@ | ||
node_modules | ||
*.log |
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,38 @@ | ||
{ | ||
"name": "frontend", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"dev": "webpack-dev-server --progress --colors --inline --hot", | ||
"production": "webpack --progress -p" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"axios": "^0.15.3", | ||
"babel-core": "^6.22.1", | ||
"babel-loader": "^6.2.10", | ||
"babel-plugin-react-html-attrs": "^2.0.0", | ||
"babel-plugin-transform-object-rest-spread": "^6.22.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"babel-preset-react": "^6.22.0", | ||
"bootstrap": "^3.3.7", | ||
"css-loader": "^0.26.1", | ||
"extract-text-webpack-plugin": "^1.0.1", | ||
"file-loader": "^0.9.0", | ||
"font-awesome": "^4.7.0", | ||
"react": "^15.4.2", | ||
"react-dom": "^15.4.2", | ||
"react-redux": "^5.0.2", | ||
"react-router": "^3.0.2", | ||
"redux": "^3.6.0", | ||
"redux-multi": "^0.1.12", | ||
"redux-promise": "^0.5.3", | ||
"redux-thunk": "^2.2.0", | ||
"style-loader": "^0.13.1", | ||
"webpack": "^1.14.0", | ||
"webpack-dev-server": "^1.16.2" | ||
} | ||
} |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset='utf-8'> | ||
<meta name='viewport' content='width=device-width, initial-scale=1'> | ||
<title>Todo App</title> | ||
<link rel='stylesheet' href='app.css'> | ||
</head> | ||
<body> | ||
<div id="app" class='container'></div> | ||
<script src='app.js'></script> | ||
</body> | ||
</html> |
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,15 @@ | ||
import React from 'react' | ||
import PageHeader from '../template/pageHeader' | ||
|
||
export default props => ( | ||
<div> | ||
<PageHeader name='Sobre' small='Nós'></PageHeader> | ||
|
||
<h2>Nossa História</h2> | ||
<p>Lorem ipsum dolor sit amet...</p> | ||
<h2>Missão e Visão</h2> | ||
<p>Lorem ipsum dolor sit amet...</p> | ||
<h2>Imprensa</h2> | ||
<p>Lorem ipsum dolor sit amet...</p> | ||
</div> | ||
) |
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,20 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import { applyMiddleware, createStore } from 'redux' | ||
import { Provider } from 'react-redux' | ||
|
||
import promise from 'redux-promise' | ||
import multi from 'redux-multi' | ||
import thunk from 'redux-thunk' | ||
|
||
import App from './main/app' | ||
import reducers from './main/reducers' | ||
|
||
const devTools = window.__REDUX_DEVTOOLS_EXTENSION__ | ||
&& window.__REDUX_DEVTOOLS_EXTENSION__() | ||
const store = applyMiddleware(thunk, multi, promise)(createStore)(reducers, devTools) | ||
ReactDOM.render( | ||
<Provider store={store}> | ||
<App /> | ||
</Provider> | ||
, document.getElementById('app')) |
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,14 @@ | ||
import 'modules/bootstrap/dist/css/bootstrap.min.css' | ||
import 'modules/font-awesome/css/font-awesome.min.css' | ||
import '../template/custom.css' | ||
|
||
import React from 'react' | ||
import Menu from '../template/menu' | ||
import Routes from './routes' | ||
|
||
export default props => ( | ||
<div className='container'> | ||
<Menu /> | ||
<Routes /> | ||
</div> | ||
) |
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,8 @@ | ||
import { combineReducers } from 'redux' | ||
import todoReducer from '../todo/todoReducer' | ||
|
||
const rootReducer = combineReducers({ | ||
todo: todoReducer | ||
}) | ||
|
||
export default rootReducer |
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,13 @@ | ||
import React from 'react' | ||
import { Router, Route, Redirect, hashHistory } from 'react-router' | ||
|
||
import Todo from '../todo/todo' | ||
import About from '../about/about' | ||
|
||
export default props => ( | ||
<Router history={hashHistory}> | ||
<Route path='/todos' component={Todo} /> | ||
<Route path='/about' component={About} /> | ||
<Redirect from='*' to='/todos' /> | ||
</Router> | ||
) |
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,16 @@ | ||
.btn { | ||
margin-right: 5px; | ||
} | ||
|
||
.markedAsDone { | ||
text-decoration: line-through; | ||
color: #777; | ||
} | ||
|
||
.tableActions { | ||
width: 105px; | ||
} | ||
|
||
.todoForm { | ||
padding-bottom: 60px; | ||
} |
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,24 @@ | ||
import React, { Component } from 'react' | ||
|
||
export default class Grid extends Component { | ||
toCssClasses(numbers) { | ||
const cols = numbers ? numbers.split(' ') : [] | ||
let classes = '' | ||
|
||
if(cols[0]) classes += `col-xs-${cols[0]}` | ||
if(cols[1]) classes += ` col-sm-${cols[1]}` | ||
if(cols[2]) classes += ` col-md-${cols[2]}` | ||
if(cols[3]) classes += ` col-lg-${cols[3]}` | ||
|
||
return classes | ||
} | ||
|
||
render() { | ||
const gridClasses = this.toCssClasses(this.props.cols || 12) | ||
return ( | ||
<div className={gridClasses}> | ||
{this.props.children} | ||
</div> | ||
) | ||
} | ||
} |
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,11 @@ | ||
import React from 'react' | ||
import If from './if' | ||
|
||
export default props => ( | ||
<If test={!props.hide}> | ||
<button className={'btn btn-'+ props.style} | ||
onClick={props.onClick}> | ||
<i className={'fa fa-'+ props.icon}></i> | ||
</button> | ||
</If> | ||
) |
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,9 @@ | ||
import React from 'react' | ||
|
||
export default props => { | ||
if(props.test) { | ||
return props.children | ||
} else { | ||
return false | ||
} | ||
} |
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,20 @@ | ||
import React from 'react' | ||
|
||
export default props => ( | ||
<nav className='navbar navbar-inverse bg-inverse'> | ||
<div className='container'> | ||
<div className='navbar-header'> | ||
<a className='navbar-brand' href='#'> | ||
<i className='fa fa-calendar-check-o'></i> TodoApp | ||
</a> | ||
</div> | ||
|
||
<div id='navbar' className='navbar-collapse collapse'> | ||
<ul className="nav navbar-nav"> | ||
<li><a href='#/todos'>Tarefas</a></li> | ||
<li><a href='#/about'>Sobre</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</nav> | ||
) |
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,7 @@ | ||
import React from 'react' | ||
|
||
export default props => ( | ||
<header className='page-header'> | ||
<h2>{props.name} <small>{props.small}</small></h2> | ||
</header> | ||
) |
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,13 @@ | ||
import React from 'react' | ||
|
||
import PageHeader from '../template/pageHeader' | ||
import TodoForm from './todoForm' | ||
import TodoList from './todoList' | ||
|
||
export default props => ( | ||
<div> | ||
<PageHeader name='Tarefas' small='Cadastro'></PageHeader> | ||
<TodoForm /> | ||
<TodoList /> | ||
</div> | ||
) |
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,50 @@ | ||
import axios from 'axios' | ||
|
||
const URL = 'http://localhost:3003/api/todos' | ||
|
||
export const changeDescription = event => ({ | ||
type: 'DESCRIPTION_CHANGED', | ||
payload: event.target.value | ||
}) | ||
|
||
export const search = () => { | ||
return (dispatch, getState) => { | ||
const description = getState().todo.description | ||
const search = description ? `&description__regex=/${description}/` : '' | ||
const request = axios.get(`${URL}?sort=-createdAt${search}`) | ||
.then(resp => dispatch({type: 'TODO_SEARCHED', payload: resp.data})) | ||
} | ||
} | ||
|
||
export const add = (description) => { | ||
return dispatch => { | ||
axios.post(URL, { description }) | ||
.then(resp => dispatch(clear())) | ||
.then(resp => dispatch(search())) | ||
} | ||
} | ||
|
||
export const markAsDone = (todo) => { | ||
return dispatch => { | ||
axios.put(`${URL}/${todo._id}`, { ...todo, done: true }) | ||
.then(resp => dispatch(search())) | ||
} | ||
} | ||
|
||
export const markAsPending = (todo) => { | ||
return dispatch => { | ||
axios.put(`${URL}/${todo._id}`, { ...todo, done: false }) | ||
.then(resp => dispatch(search())) | ||
} | ||
} | ||
|
||
export const remove = (todo) => { | ||
return dispatch => { | ||
axios.delete(`${URL}/${todo._id}`) | ||
.then(resp => dispatch(search())) | ||
} | ||
} | ||
|
||
export const clear = () => { | ||
return [{ type: 'TODO_CLEAR' }, search()] | ||
} |
Oops, something went wrong.