From 04f5413d76b8282a62b3001f913775e35d37209b Mon Sep 17 00:00:00 2001 From: jimi Date: Thu, 10 Nov 2011 17:15:18 -0600 Subject: [PATCH] Continue progress of task list - add routes for managing tasks - move task listing to partial - add css styling --- main.rb | 16 ++++++++++++++-- public/styles.css | 36 ++++++++++++++++++++++++++++++++++++ views/index.haml | 5 ++--- views/task.haml | 13 +++++++++++-- 4 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 public/styles.css diff --git a/main.rb b/main.rb index aa93081..d9a2fc3 100644 --- a/main.rb +++ b/main.rb @@ -19,11 +19,23 @@ get '/' do end post '/' do - Task.create name: params[:task] + Task.create params[:task] + redirect '/' +end + +delete '/task/:id' do + Task.get(params[:id]).destroy + redirect '/' +end + +put '/task/:id' do + task = Task.get params[:id] + task.completed_at = task.completed_at.nil? ? Time.now : nil + task.save redirect '/' end get '/:task' do @task = params[:task].split('-').join(' ').capitalize - haml :task + # haml :task end diff --git a/public/styles.css b/public/styles.css new file mode 100644 index 0000000..f97a30c --- /dev/null +++ b/public/styles.css @@ -0,0 +1,36 @@ +.completed{ + text-decoration: line-through; + } +.tasks{ + padding:0; + list-style:none; + width:400px; + } +.task{ + position:relative; + padding:2px 0 2px 28px; + border-bottom: dotted 1px #ccc; +} +form.update{ + position:absolute; + bottom:2px; + left:0; + } +form.update input{ + background:white; + color:gray; + padding:0 2px; + border:none; + cursor:pointer; +} +.tasks li.completed form.update input{ + color:#47FD6B; + } +form.delete{ + display:inline; + } +form.delete input{ + background:none; + cursor:pointer; + border:none; + } diff --git a/views/index.haml b/views/index.haml index e913608..aa3bf04 100644 --- a/views/index.haml +++ b/views/index.haml @@ -1,8 +1,7 @@ -%h2 My Tasks %form{ action: '/', method: "POST" } - %input{ type: "text", name: "task" } + %input{ type: "text", name: "task[name]" } %input.button{ type: "submit", value: "New Task >>" } %h2 My Tasks %ul.tasks - @tasks.each do |task| - %li.task= task.name + = render(:haml, :task, locals: { task: task }) diff --git a/views/task.haml b/views/task.haml index a96bb7a..6491de8 100644 --- a/views/task.haml +++ b/views/task.haml @@ -1,2 +1,11 @@ -%h2 My Tasks -= @task +%li[task]{ class: (task.completed_at.nil? ? "" : "completed") } + = task.name + %form.update(action="/task/#{task.id}" method="POST") + %input{ type: 'hidden', name: '_method', value: 'PUT' } + -if task.completed_at.nil? + %input{type: 'submit', value: '−', title: 'Complete Task'} + -else + %input{type: 'submit', value: '✓', title: 'Uncomplete Task'} + %form.delete(action="/task/#{task.id}" method="POST") + %input(type="hidden" name="_method" value="DELETE") + %input(type="submit" value="✗" title="Delete Task")