Permalink
Browse files

Add tasks, completed tasks MVCs; random task view; task saves if done

  • Loading branch information...
1 parent 9388218 commit 05888658ef7a866b436e8550935450517a097e4d @joemerante joemerante committed May 22, 2012
Showing with 629 additions and 1 deletion.
  1. +3 −0 app/assets/javascripts/completed_tasks.js.coffee
  2. +3 −0 app/assets/javascripts/tasks.js.coffee
  3. +3 −0 app/assets/stylesheets/completed_tasks.css.scss
  4. +56 −0 app/assets/stylesheets/scaffolds.css.scss
  5. +3 −0 app/assets/stylesheets/tasks.css.scss
  6. +97 −0 app/controllers/completed_tasks_controller.rb
  7. +85 −0 app/controllers/tasks_controller.rb
  8. +2 −0 app/helpers/completed_tasks_helper.rb
  9. +2 −0 app/helpers/tasks_helper.rb
  10. +3 −0 app/models/completed_task.rb
  11. +9 −0 app/models/task.rb
  12. +1 −0 app/models/user.rb
  13. +33 −0 app/views/completed_tasks/_form.html.erb
  14. +6 −0 app/views/completed_tasks/edit.html.erb
  15. +29 −0 app/views/completed_tasks/index.html.erb
  16. +5 −0 app/views/completed_tasks/new.html.erb
  17. +25 −0 app/views/completed_tasks/show.html.erb
  18. +1 −0 app/views/devise/_links.erb
  19. +25 −0 app/views/tasks/_form.html.erb
  20. +6 −0 app/views/tasks/edit.html.erb
  21. +27 −0 app/views/tasks/index.html.erb
  22. +5 −0 app/views/tasks/new.html.erb
  23. +15 −0 app/views/tasks/show.html.erb
  24. +7 −0 config/routes.rb
  25. +10 −0 db/migrate/20120521214235_create_tasks.rb
  26. +10 −0 db/migrate/20120521214603_create_completed_tasks.rb
  27. +16 −1 db/schema.rb
  28. +13 −0 test/fixtures/completed_tasks.yml
  29. +9 −0 test/fixtures/tasks.yml
  30. +49 −0 test/functional/completed_tasks_controller_test.rb
  31. +49 −0 test/functional/tasks_controller_test.rb
  32. +7 −0 test/unit/completed_task_test.rb
  33. +4 −0 test/unit/helpers/completed_tasks_helper_test.rb
  34. +4 −0 test/unit/helpers/tasks_helper_test.rb
  35. +7 −0 test/unit/task_test.rb
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
@@ -0,0 +1,3 @@
+// Place all the styles related to the Completed_Tasks controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,56 @@
+body {
+ background-color: #fff;
+ color: #333;
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px; }
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px; }
+
+a {
+ color: #000;
+ &:visited {
+ color: #666; }
+ &:hover {
+ color: #fff;
+ background-color: #000; } }
+
+div {
+ &.field, &.actions {
+ margin-bottom: 10px; } }
+
+#notice {
+ color: green; }
+
+.field_with_errors {
+ padding: 2px;
+ background-color: red;
+ display: table; }
+
+#error_explanation {
+ width: 450px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 0;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+ h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ margin-bottom: 0px;
+ background-color: #c00;
+ color: #fff; }
+ ul li {
+ font-size: 12px;
+ list-style: square; } }
@@ -0,0 +1,3 @@
+// Place all the styles related to the Tasks controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
@@ -0,0 +1,97 @@
+class CompletedTasksController < ApplicationController
+ # GET /completed_tasks
+ # GET /completed_tasks.json
+ def index
+ @completed_tasks = CompletedTask.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @completed_tasks }
+ end
+ end
+
+ # GET /completed_tasks/1
+ # GET /completed_tasks/1.json
+ def show
+ @completed_task = CompletedTask.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @completed_task }
+ end
+ end
+
+ def completed
+ @user = current_user
+ task_id = session[:task_id]
+ CompletedTask.create!(:user_id => current_user.id, :task_id => task_id, :completed => TRUE)
+ redirect_to tasks_path
+ end
+
+ # GET /completed_tasks/new
+ # GET /completed_tasks/new.json
+ def new
+ # if user_signed_in?
+ # @user = current_user
+ # @findrandom = Task.find(params[:id])
+ # @completed_task = CompletedTask.create!(:user_id => @user.user_id, :task_id => @findrandom, :completed => yes)
+ # #will the created_at and updated_at get populated automatically in the new completed task?
+ # else
+ # redirect_to(new_user_registration_path)
+ # end
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @completed_task }
+ end
+ end
+
+ # GET /completed_tasks/1/edit
+ def edit
+ @completed_task = CompletedTask.find(params[:id])
+ end
+
+ # POST /completed_tasks
+ # POST /completed_tasks.json
+ def create
+ @completed_task = CompletedTask.new(params[:completed_task])
+
+ respond_to do |format|
+ if @completed_task.save
+ format.html { redirect_to @completed_task, notice: 'Completed task was successfully created.' }
+ format.json { render json: @completed_task, status: :created, location: @completed_task }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @completed_task.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /completed_tasks/1
+ # PUT /completed_tasks/1.json
+ def update
+ @completed_task = CompletedTask.find(params[:id])
+
+ respond_to do |format|
+ if @completed_task.update_attributes(params[:completed_task])
+ format.html { redirect_to @completed_task, notice: 'Completed task was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @completed_task.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /completed_tasks/1
+ # DELETE /completed_tasks/1.json
+ def destroy
+ @completed_task = CompletedTask.find(params[:id])
+ @completed_task.destroy
+
+ respond_to do |format|
+ format.html { redirect_to completed_tasks_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,85 @@
+class TasksController < ApplicationController
+ # GET /tasks
+ # GET /tasks.json
+
+ def index
+ # @tasks = Task.all
+ @random = Task.random
+ session[:task_id] = @random.id
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @tasks }
+ end
+ end
+
+ # GET /tasks/1
+ # GET /tasks/1.json
+ def show
+ @task = Task.find(params[:id])
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @task }
+ end
+ end
+
+ # GET /tasks/new
+ # GET /tasks/new.json
+ def new
+ @task = Task.new
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @task }
+ end
+ end
+
+ # GET /tasks/1/edit
+ def edit
+ @task = Task.find(params[:id])
+ end
+
+ # POST /tasks
+ # POST /tasks.json
+ def create
+ @task = Task.new(params[:task])
+
+ respond_to do |format|
+ if @task.save
+ format.html { redirect_to @task, notice: 'Task was successfully created.' }
+ format.json { render json: @task, status: :created, location: @task }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @task.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /tasks/1
+ # PUT /tasks/1.json
+ def update
+ @task = Task.find(params[:id])
+
+ respond_to do |format|
+ if @task.update_attributes(params[:task])
+ format.html { redirect_to @task, notice: 'Task was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @task.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /tasks/1
+ # DELETE /tasks/1.json
+ def destroy
+ @task = Task.find(params[:id])
+ @task.destroy
+
+ respond_to do |format|
+ format.html { redirect_to tasks_url }
+ format.json { head :no_content }
+ end
+ end
+end
+
+
@@ -0,0 +1,2 @@
+module CompletedTasksHelper
+end
@@ -0,0 +1,2 @@
+module TasksHelper
+end
@@ -0,0 +1,3 @@
+class CompletedTask < ActiveRecord::Base
+ attr_accessible :completed, :remind, :task_id, :user_id
+end
View
@@ -0,0 +1,9 @@
+class Task < ActiveRecord::Base
+ attr_accessible :difficulty, :task
+ has_many :users
+
+ def self.random
+ ids = connection.select_all("SELECT id from tasks")
+ find(ids[rand(ids.length)]["id"].to_i) unless ids.blank?
+ end
+end
View
@@ -1,6 +1,7 @@
class User < ActiveRecord::Base
# to have many ways to authenticate into a single user account, add this line and a related controller and model
has_many :authentications
+ has_many :tasks
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable
@@ -0,0 +1,33 @@
+<%= form_for(@completed_task) do |f| %>
+ <% if @completed_task.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@completed_task.errors.count, "error") %> prohibited this completed_task from being saved:</h2>
+
+ <ul>
+ <% @completed_task.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :user_id %><br />
+ <%= f.text_field :user_id %>
+ </div>
+ <div class="field">
+ <%= f.label :task_id %><br />
+ <%= f.text_field :task_id %>
+ </div>
+ <div class="field">
+ <%= f.label :completed %><br />
+ <%= f.text_field :completed %>
+ </div>
+ <div class="field">
+ <%= f.label :remind %><br />
+ <%= f.date_select :remind %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing completed_task</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @completed_task %> |
+<%= link_to 'Back', completed_tasks_path %>
@@ -0,0 +1,29 @@
+<h1>Listing completed_tasks</h1>
+
+<table>
+ <tr>
+ <th>User</th>
+ <th>Task</th>
+ <th>Completed</th>
+ <th>Remind</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @completed_tasks.each do |completed_task| %>
+ <tr>
+ <td><%= completed_task.user_id %></td>
+ <td><%= completed_task.task_id %></td>
+ <td><%= completed_task.completed %></td>
+ <td><%= completed_task.remind %></td>
+ <td><%= link_to 'Show', completed_task %></td>
+ <td><%= link_to 'Edit', edit_completed_task_path(completed_task) %></td>
+ <td><%= link_to 'Destroy', completed_task, confirm: 'Are you sure?', method: :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Completed task', new_completed_task_path %>
@@ -0,0 +1,5 @@
+<h1>New completed_task</h1>
+
+<%=# render 'form' %>
+
+<%= link_to 'Back', completed_tasks_path %>
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>User:</b>
+ <%= @completed_task.user_id %>
+</p>
+
+<p>
+ <b>Task:</b>
+ <%= @completed_task.task_id %>
+</p>
+
+<p>
+ <b>Completed:</b>
+ <%= @completed_task.completed %>
+</p>
+
+<p>
+ <b>Remind:</b>
+ <%= @completed_task.remind %>
+</p>
+
+
+<%= link_to 'Edit', edit_completed_task_path(@completed_task) %> |
+<%= link_to 'Back', completed_tasks_path %>
@@ -20,6 +20,7 @@
<%- if devise_mapping.omniauthable? %>
+ <%# display Sign in with Google instead of google_oauth2 in sign up link %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%- if (provider.to_s == "google_oauth2" ) %>
<%= provider_icon "google_oauth2" %>
Oops, something went wrong.

0 comments on commit 0588865

Please sign in to comment.