Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Test #39

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# production
/build

#
*.swp

# misc
.DS_Store
.env.local
Expand Down
Empty file added backend/todo/__init__ 2.py
Empty file.
3 changes: 3 additions & 0 deletions backend/todo/admin 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions backend/todo/apps 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class TodoConfig(AppConfig):
name = 'todo'
28 changes: 28 additions & 0 deletions backend/todo/migrations/0003_auto_20191009_1311 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.5 on 2019-10-09 13:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('todo', '0002_todo_done'),
]

operations = [
migrations.AddField(
model_name='todo',
name='date',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='todo',
name='month',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='todo',
name='year',
field=models.IntegerField(default=2019),
),
]
28 changes: 28 additions & 0 deletions backend/todo/migrations/0003_auto_20191009_1311.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.5 on 2019-10-09 13:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('todo', '0002_todo_done'),
]

operations = [
migrations.AddField(
model_name='todo',
name='date',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='todo',
name='month',
field=models.IntegerField(default=1),
),
migrations.AddField(
model_name='todo',
name='year',
field=models.IntegerField(default=2019),
),
]
Empty file.
9 changes: 9 additions & 0 deletions backend/todo/models 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.db import models

class Todo(models.Model):
title = models.CharField(max_length=120)
content = models.TextField()
done = models.BooleanField(default=False)
year = models.IntegerField(default=2019)
month = models.IntegerField(default=1)
date = models.IntegerField(default=1)
3 changes: 3 additions & 0 deletions backend/todo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ class Todo(models.Model):
title = models.CharField(max_length=120)
content = models.TextField()
done = models.BooleanField(default=False)
year = models.IntegerField(default=2019)
month = models.IntegerField(default=1)
date = models.IntegerField(default=1)
3 changes: 3 additions & 0 deletions backend/todo/tests 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions backend/todo/urls 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path

from . import views

urlpatterns = [
path('', views.index),
path('<int:id>', views.index),
]
73 changes: 73 additions & 0 deletions backend/todo/views 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseBadRequest, JsonResponse
from django.views.decorators.csrf import csrf_exempt

import json

from .models import Todo

@csrf_exempt
def index(request, id=None):
if request.method == 'GET':
if id is None:
# get all
todo_all_list = list(Todo.objects.all().values())
return JsonResponse(todo_all_list, safe=False)
else:
try:
todo = Todo.objects.get(id=id)
response_dict = {
'id': todo.id,
'title': todo.title,
'content': todo.content,
'year': todo.year,
'month': todo.month,
'date': todo.date,
'done': todo.done,
}
return JsonResponse(response_dict, safe=False)
except KeyError as e:
return HttpResponseBadRequest('TodoID does not exist: {}'.format(id))
if request.method == 'POST':
try:
body = request.body.decode()
title = json.loads(body)['title']
content = json.loads(body)['content']
dueDate = json.loads(body)['dueDate']
except (KeyError, JSONDecodeError) as e:
return HttpResponseBadRequest()
todo = Todo(title=title, content=content,
year=dueDate['year'], month=dueDate['month'],
date=dueDate['date'], done=False)
todo.save()
response_dict = {
'id': todo.id,
'title': todo.title,
'content': todo.content,
'year': todo.year,
'month': todo.month,
'date': todo.date,
'done': todo.done,
}
return HttpResponse(json.dumps(response_dict), status=201)
elif request.method == 'DELETE':
if id is None:
return HttpResponseBadRequest('TodoID is not specified.')
try:
todo = Todo.objects.get(id=id)
todo.delete()
except KeyError as e:
return HttpResponseBadRequest('TodoID does not exist: {}'.format(id))
return HttpResponse(status=204)
elif request.method == 'PUT':
if id is None:
return HttpResponseBadRequest('TodoID is not specified.')
try:
todo = Todo.objects.get(id=id)
todo.done = not todo.done
todo.save()
return HttpResponse(status=204)
except KeyError as e:
return HttpResponseBadRequest('TodoID does not exist: {}'.format(id))
else:
return HttpResponseNotAllowed(['GET', 'POST', 'DELETE', 'PUT'])
11 changes: 10 additions & 1 deletion backend/todo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def index(request, id=None):
'id': todo.id,
'title': todo.title,
'content': todo.content,
'year': todo.year,
'month': todo.month,
'date': todo.date,
'done': todo.done,
}
return JsonResponse(response_dict, safe=False)
Expand All @@ -30,14 +33,20 @@ def index(request, id=None):
body = request.body.decode()
title = json.loads(body)['title']
content = json.loads(body)['content']
dueDate = json.loads(body)['dueDate']
except (KeyError, JSONDecodeError) as e:
return HttpResponseBadRequest()
todo = Todo(title=title, content=content, done=False)
todo = Todo(title=title, content=content,
year=dueDate['year'], month=dueDate['month'],
date=dueDate['date'], done=False)
todo.save()
response_dict = {
'id': todo.id,
'title': todo.title,
'content': todo.content,
'year': todo.year,
'month': todo.month,
'date': todo.date,
'done': todo.done,
}
return HttpResponse(json.dumps(response_dict), status=201)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"react-router-dom": "^5.0.1",
"react-scripts": "3.1.1",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"semantic-ui-react": "^0.88.1"
},
"scripts": {
"start": "react-scripts start",
Expand Down
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import './App.css';

import TodoList from './containers/TodoList/TodoList';
import TodoCalendar from './containers/TodoCalendar/TodoCalendar';
import RealDetail from './containers/TodoList/RealDetail/RealDetail';
import NewTodo from './containers/TodoList/NewTodo/NewTodo';

Expand All @@ -14,12 +15,13 @@ function App(props) {
<div className="App" >
<Switch>
<Route path='/todos' exact render={() => <TodoList title="My TODOs!" />} />
<Route path='/calendar' exact component={TodoCalendar} />
<Route path='/todos/:id' exact component={RealDetail} />
<Route path='/new-todo' exact component={NewTodo} />
<Redirect exact from='/' to='todos' />
<Route render={() => <h1>Not Found</h1>} />
</Switch>
</div >
</div>
</ConnectedRouter>
);
}
Expand Down
20 changes: 20 additions & 0 deletions src/components/Calendar/Calendar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.cell .date {
font-size: 20px;
}

.todoTitle {
cursor: pointer;
}

.notdone {
color: blue;
}

.done {
text-decoration: line-through;
color: #adb5bd;
}

.sunday {
color: red;
}
87 changes: 87 additions & 0 deletions src/components/Calendar/Calendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React, { Component } from 'react';
import { Table } from 'semantic-ui-react'

import './Calendar.css';

const CALENDAR_HEADER = (
<Table.Header>
<Table.Row>
<Table.HeaderCell className="sunday">Sun</Table.HeaderCell>
<Table.HeaderCell>Mon</Table.HeaderCell>
<Table.HeaderCell>Tue</Table.HeaderCell>
<Table.HeaderCell>Wed</Table.HeaderCell>
<Table.HeaderCell>Thu</Table.HeaderCell>
<Table.HeaderCell>Fri</Table.HeaderCell>
<Table.HeaderCell>Sat</Table.HeaderCell>
</Table.Row>
</Table.Header>
);

const renderCalenderBody = (dates, todos, clickDone) => {
let i = 0;
const rows = [];
for (let week=0; week<5; week++){
let day = 0; // Sunday

let row = [];
for (let day=0; day<7; day++) {
const date = dates[i];
if (date !== undefined && day === date.getDay()) {
row.push(
<Table.Cell className={`cell ${day === 0 && 'sunday'}`} key={7*week+day}>
<div className="date">{date.getDate()}</div>
{
todos.filter(todo => {
return todo.year === date.getFullYear() &&
todo.month === date.getMonth() &&
todo.date === date.getDate();
}).map(todo => {
return (
<div
key={todo.id}
className={`todoTitle ${todo.done ? 'done':'notdone'}`}
onClick={() => clickDone(todo.id)}>
{todo.title}
</div>
)
})
}
</Table.Cell>
)
i++;
} else {
row.push(<Table.Cell key={7*week+day}> </Table.Cell>)
}
}
rows.push(row);
}

return (
<Table.Body>
{rows.map((row, i) => (<Table.Row key={i}>{row}</Table.Row>))}
</Table.Body>
);
}

const renderCalendar = (dates, todos, clickDone) => (
<Table striped style={{"height": "600px", "width": "600px"}}>
{CALENDAR_HEADER}
{renderCalenderBody(dates, todos, clickDone)}
</Table>
)

const Calendar = (props) => {
const dates = [];
const year = props.year;
const month = props.month - 1;
let date = 1;
let maxDate = (new Date(year, month + 1, 0)).getDate();

for (let date=1; date<=maxDate; date++) {
dates.push(new Date(year, month, date));
}

return renderCalendar(dates, props.todos, props.clickDone);
}

export default Calendar
8 changes: 7 additions & 1 deletion src/components/Todo/Todo.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@
margin-left: 1rem;
color: orange;
font-weight: 800;
}
}

.Todo .due {
flex: 1;
text-align: left;
word-break: break-all;
}
1 change: 1 addition & 0 deletions src/components/Todo/Todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Todo = (props) => {
{props.title}
</div>
{props.done && <div className="done-mark">&#x2713;</div>}
<div className="due"> due: {props.year}.{props.month+1}.{props.date} </div>
<button onClick={props.clickDone}
className={(props.done) ? "undoneButton" : "doneButton"}>
{(props.done) ? 'Undone' : 'Done'}</button>
Expand Down
10 changes: 10 additions & 0 deletions src/containers/TodoCalendar/TodoCalendar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.link{
text-align: left;
}

.header {
text-align: left;
font-size: 40px;
margin-left: 10rem;
font-weight: bold;
}
Loading