Skip to content

Commit

Permalink
Issue alaashafaee#424 conditions for submit button
Browse files Browse the repository at this point in the history
  • Loading branch information
LinKassem committed May 18, 2014
1 parent a7ef398 commit ec608e9
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tutor/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ GEM
tzinfo (~> 0.3.37)
acts_as_list (0.4.0)
activerecord (>= 3.0)
addressable (2.3.6)
ansi (1.4.3)
arbre (1.0.1)
activesupport (>= 3.0.0)
Expand All @@ -59,6 +60,7 @@ GEM
json (>= 1.7)
mime-types (>= 1.16)
chronic (0.10.2)
cocoon (1.2.6)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -86,6 +88,7 @@ GEM
has_scope (0.6.0.rc)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
hashie (2.0.5)
hashr (0.0.22)
hike (1.2.3)
i18n (0.6.9)
Expand All @@ -110,9 +113,18 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
metainspector (1.15.4)
addressable (~> 2.3.4)
nokogiri (~> 1.5)
open_uri_redirections (~> 0.1.0)
rash (~> 0.4.0)
mime-types (1.25.1)
mini_portile (0.6.0)
minitest (4.7.5)
multi_json (1.9.2)
nokogiri (1.6.2.1)
mini_portile (= 0.6.0)
open_uri_redirections (0.1.4)
orm_adapter (0.5.0)
polyamorous (1.0.0)
activerecord (>= 3.0)
Expand Down Expand Up @@ -141,6 +153,8 @@ GEM
activesupport (>= 3.0)
i18n
polyamorous (~> 1.0.0)
rash (0.4.0)
hashie (~> 2.0.0)
rdoc (4.1.1)
json (~> 1.4)
responders (1.0.0)
Expand Down Expand Up @@ -224,13 +238,15 @@ DEPENDENCIES
activeadmin!
acts_as_list
carrierwave
cocoon
coffee-rails (~> 4.0.0)
composite_primary_keys (~> 6.0.1)
devise
foreman
jbuilder (~> 1.2)
jquery-rails (~> 3.1.0)
json_builder (= 3.1.0)
metainspector (= 1.15.4)
rails (= 4.0.4)
rmagick
rspec-rails (~> 3.0.0.beta)
Expand Down
33 changes: 33 additions & 0 deletions tutor/app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ def show
else
render ('public/404')
end
if student_signed_in?
student_id = current_student.id
end
@submitted_problems = []
@all_problems_submitted = false
@problems.each do |p|
@submitted_problems = @submitted_problems +
Solution.where("student_id = ? AND problem_id = ? AND problem_type = ?",
student_id, p.id, "AssignmentProblem")
end
if @submitted_problems.size == @problems.size &&
@assignment.due_date > Date.today
@all_problems_submitted = true
end
end

# [View List Of Assignments - Story 4.24]
Expand All @@ -36,4 +50,23 @@ def edit
@can_edit||= @course.can_edit(current_teaching_assistant)
end
end

def submit
@assignment = Assignment.find_by_id(params[:id])
if student_signed_in?
student_id = current_student.id
end
#@assignment = Assignment.find_by_id(params[:id])
@problems = @assignment.problems
@submitted_problems = []
@all_problems_submitted = false
@problems.each do |p|
@submitted_problems = @submitted_problems +
Solution.where("student_id = ? AND problem_id = ?", student_id, p.id)
end
if @submitted_problems.size == @problems.size
@all_problems_submitted = true
end
end

end
7 changes: 7 additions & 0 deletions tutor/app/views/assignments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,11 @@
<% if @can_edit %>
<%= link_to "Edit assignment", { :controller => 'assignments',
:action => 'edit', :id => @assignment.id }, class: "btn btn-info" %>
<% end %>
<% if !@can_edit %>
<% if @all_problems_submitted %>
<%= link_to "Submit Assignment", { :controller => 'assignments',
:action => 'submit', :id => @assignment.id },
class: "btn btn-info" %>
<% end %>
<% end %>
6 changes: 6 additions & 0 deletions tutor/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
get 'destroy_problem'
end

resources :assignments do
member do
get 'submit'
end
end

# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
Expand Down

0 comments on commit ec608e9

Please sign in to comment.