Skip to content

Commit

Permalink
Merge pull request #7 from odinsy/refactor
Browse files Browse the repository at this point in the history
Subtasks and the work on appearance
  • Loading branch information
odinsy committed Dec 3, 2015
2 parents c9cd66d + 8b20dd3 commit d401c79
Show file tree
Hide file tree
Showing 51 changed files with 478 additions and 210 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
language: ruby
rvm:
- 2.2.2

before_script:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ gem 'simple_form'
gem 'aasm'
gem "default_value_for", "~> 3.0.0"
gem 'sorcery'
gem 'responders'

group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'fuubar'
gem 'bullet'
end

group :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'capybara'
gem 'selenium-webdriver'
gem 'database_cleaner'
end
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ GEM
bootstrap-sass-extras (0.0.6)
rails (>= 3.1.0)
builder (3.2.2)
bullet (4.14.9)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.9.0)
byebug (5.0.0)
columnize (= 0.9.0)
capybara (2.4.4)
Expand All @@ -58,6 +61,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
childprocess (0.5.7)
ffi (~> 1.0, >= 1.0.11)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
Expand All @@ -80,6 +85,7 @@ GEM
railties (>= 3.0.0)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.9.10)
fuubar (2.0.0)
rspec (~> 3.0)
ruby-progressbar (~> 1.4)
Expand Down Expand Up @@ -146,6 +152,8 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
Expand All @@ -168,6 +176,7 @@ GEM
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
ruby-progressbar (1.7.5)
rubyzip (1.1.7)
sass (3.4.14)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
Expand All @@ -178,6 +187,11 @@ GEM
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
selenium-webdriver (2.48.1)
childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0)
websocket (~> 1.0)
simple_form (3.1.0)
actionpack (~> 4.0)
activemodel (~> 4.0)
Expand Down Expand Up @@ -213,11 +227,13 @@ GEM
uglifier (2.7.1)
execjs (>= 0.3.0)
json (>= 1.8.0)
uniform_notifier (1.9.0)
web-console (2.1.3)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
websocket (1.2.2)
xpath (2.0.0)
nokogiri (~> 1.3)

Expand All @@ -228,6 +244,7 @@ DEPENDENCIES
aasm
bootstrap-sass
bootstrap-sass-extras
bullet
byebug
capybara
coffee-rails (~> 4.1.0)
Expand All @@ -239,9 +256,11 @@ DEPENDENCIES
jbuilder (~> 2.0)
jquery-rails
rails (= 4.2.1)
responders
rspec-rails
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
selenium-webdriver
simple_form
slim-rails
sorcery
Expand Down
8 changes: 0 additions & 8 deletions app/assets/stylesheets/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,3 @@ textarea {
.task-description {
min-height: 100px;
}
.subtask-title {
border-bottom: 1px solid #ddd;
padding: 5px !important;
}
.subtask-title ul,
ol {
margin: 5px;
}
1 change: 1 addition & 0 deletions app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class MainController < ApplicationController
layout 'main'

def index
redirect_to tasks_path if current_user
end

end
12 changes: 4 additions & 8 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ class ProjectsController < ApplicationController

def run
@project.run!
redirect_to projects_path
redirect_to :back
end

def complete
@project.complete!
redirect_to projects_path
redirect_to :back
end

def index
@projects = current_user.projects.active
end

def completed
@projects = current_user.projects.completed
end

def new
@project = current_user.projects.build
end
Expand All @@ -33,7 +29,7 @@ def edit
def create
@project = current_user.projects.create(project_params)
if @project.errors.empty?
redirect_to tasks_path
redirect_to @project
else
render 'new'
end
Expand All @@ -60,7 +56,7 @@ def find_project
end

def project_params
params.require(:project).permit(:title, :description, :scheduled, :deadline, tasks_attributes: [:title, :user_id])
params.require(:project).permit(:title, :description, :scheduled, :deadline)
end

end
8 changes: 8 additions & 0 deletions app/controllers/states_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class StatesController < ApplicationController

def completed
@tasks = current_user.tasks.completed
@projects = current_user.projects.completed
end

end
52 changes: 52 additions & 0 deletions app/controllers/subtasks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class SubtasksController < ApplicationController

before_action :find_subtask, only: [:edit, :update, :destroy, :run, :complete]

respond_to :html, :js

def run
@subtask.run!
@task = @subtask.task
respond_to do |format|
format.js { render 'subtasks' }
end
end

def complete
@subtask.complete!
@task = @subtask.task
respond_to do |format|
format.js { render 'subtasks' }
end
end

def create
@task = current_user.tasks.find(params[:task_id])
@subtask = @task.subtasks.create(subtask_params)
end

def edit
end

def update
end

def destroy
@task = @subtask.task
@subtask.destroy
respond_to do |format|
format.js { render 'subtasks' }
end
end

private

def subtask_params
params.require(:subtask).permit(:title, :user_id, :task_id).deep_merge!(user_id: current_user.id)
end

def find_subtask
@subtask = current_user.subtasks.find(params[:id])
end

end
72 changes: 45 additions & 27 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@ class TasksController < ApplicationController

before_action :find_task, only: [:show, :edit, :update, :destroy, :run, :complete]
rescue_from ActiveRecord::RecordNotFound, with: :invalid_task
respond_to :html, :js

def run
@task.run!
redirect_to :back
@project = @task.project
respond_to do |format|
format.html { redirect_to :back }
format.js { render 'tasks' }
end
end

def complete
@task.complete!
redirect_to :back
end

def index
@tasks = current_user.tasks.main.active.today
@project = @task.project
respond_to do |format|
format.html { redirect_to :back }
format.js { render 'tasks' }
end
end

def tomorrow
@tasks = current_user.tasks.main.active.tomorrow
@tasks = current_user.tasks.active.tomorrow
end

def scheduled
@tasks = current_user.tasks.main.active.scheduled
@tasks = current_user.tasks.active.scheduled
end

def waiting
@tasks = current_user.tasks.main.active.waiting
@tasks = current_user.tasks.active.waiting
end

def completed
@tasks = current_user.tasks.main.completed
def index
@tasks = current_user.tasks.active.today
end

def show
Expand All @@ -41,43 +46,47 @@ def new
end

def edit
session[:return_to] ||= request.referer
end

def create
@task = current_user.tasks.create(task_params)
if @task.project_id and @task.errors.empty?
redirect_to @task.project, notice: "Task created!"
elsif @task.project_id and @task.errors
redirect_to @task.project
elsif @task.errors.empty?
redirect_to tasks_path, notice: "Task created!"
else
render 'new', notice: "Invalid input!"
@task = current_user.tasks.create(task_params) do |t|
t.project = project if project_present
end
respond_to do |format|
if project_present
@project = @task.project
format.js
elsif @task.errors.empty?
format.html { redirect_to tasks_path, notice: "Task created!" }
else
format.html { render 'new', notice: "Could not save task" }
end
end
end

def update
@task.update_attributes(task_params)
if @task.errors.empty? || task_params[:subtasks_attributes]
redirect_to @task
if @task.errors.empty?
redirect_to session.delete(:return_to)
else
render 'edit'
end
end

def destroy
@task.destroy
if @task.parent_id?
redirect_to @task.parent
else
redirect_to :back
@project = @task.project
respond_to do |format|
format.html { redirect_to(:back) }
format.js { render 'tasks' }
end
end

private

def task_params
params.require(:task).permit(:title, :description, :scheduled, :deadline, :priority, :user_id, :project_id, subtasks_attributes: [:title, :user_id])
params.require(:task).permit(:title, :description, :scheduled, :deadline, :priority, :user_id, :project_id)
end

def find_task
Expand All @@ -88,4 +97,13 @@ def invalid_task
redirect_to tasks_path, notice: "Invalid task!"
end

def project
return unless project_present
Project.find(params[:project_id])
end

def project_present
params[:project_id].present?
end

end
18 changes: 18 additions & 0 deletions app/models/concerns/change_state.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module ChangeState

extend ActiveSupport::Concern

included do
aasm :column => 'state' do
state :active, :initial => true
state :completed
event :run do
transitions :from => :completed, :to => :active
end
event :complete do
transitions :from => :active, :to => :completed
end
end
end

end
Loading

0 comments on commit d401c79

Please sign in to comment.