diff --git a/main.rb b/main.rb index d9a2fc3..5e9350a 100644 --- a/main.rb +++ b/main.rb @@ -9,17 +9,24 @@ class Task property :id, Serial property :name, String, required: true property :completed_at, DateTime + belongs_to :list +end +class List + include DataMapper::Resource + property :id, Serial + property :name, String, required: true + has n, :tasks, :constraint => :destroy end DataMapper.finalize get '/' do - @tasks = Task.all + @lists = List.all(:order => [:name]) haml :index end -post '/' do - Task.create params[:task] +post '/:id' do + List.get(params[:id]).tasks.create params['task'] redirect '/' end @@ -39,3 +46,13 @@ get '/:task' do @task = params[:task].split('-').join(' ').capitalize # haml :task end + +post '/new/list' do + List.create params['list'] + redirect '/' +end + +delete '/list/:id' do + List.get(params[:id]).destroy + redirect '/' +end diff --git a/public/styles.css b/public/styles.css index f97a30c..c4a1d97 100644 --- a/public/styles.css +++ b/public/styles.css @@ -4,7 +4,6 @@ .tasks{ padding:0; list-style:none; - width:400px; } .task{ position:relative; @@ -34,3 +33,14 @@ form.delete input{ cursor:pointer; border:none; } +.lists{ + padding:0; + list-style:none; + overflow:hidden; + } +.list{ + float: left; + width:23%; + margin:0 1%; + border-top:solid 5px #ccc; + } diff --git a/views/index.haml b/views/index.haml index aa3bf04..e65c0d9 100644 --- a/views/index.haml +++ b/views/index.haml @@ -1,7 +1,6 @@ -%form{ action: '/', method: "POST" } - %input{ type: "text", name: "task[name]" } - %input.button{ type: "submit", value: "New Task >>" } -%h2 My Tasks -%ul.tasks - - @tasks.each do |task| - = render(:haml, :task, locals: { task: task }) +%form{ action: '/new/list', method: "POST" } + %input{ type: "text", name: "list[name]" } + %input.button{ type: "submit", value: "+ List" } +%ul.lists + - @lists.each do |list| + = render(:haml, :list, locals: { list: list }) diff --git a/views/list.haml b/views/list.haml new file mode 100644 index 0000000..d01a485 --- /dev/null +++ b/views/list.haml @@ -0,0 +1,10 @@ +%li.list + %h2= list.name + %form.new(action="/#{list.id}" method="POST") + %input(type="text" name="task[name]") + %ul.tasks + - list.tasks.each do |task| + = render(:haml, :task, locals: { task: task }) + %form.destroy(action="/list/#{list.id}" method="POST") + %input(type="hidden" name="_method" value="DELETE") + %input(type="submit" value="✗")