Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 75 additions & 3 deletions app/controllers/assignment_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,93 @@
class AssignmentController < ApplicationController
def new
@course = Course.find(params[:course_id])
end

def show
@course = Course.find(params[:course_id])
@assignment = Assignment.find(params[:id])
end

def index

@course = Course.find(params[:course_id])
@assignments = @course.assignments
end

def new
def create
@course = Course.find(params[:course_id])
@assignment = @course.assignments.new(assignment_params)
unless @assignment.valid?
@assignment.destroy
flash[:alert] = "Missing required fields"
redirect_to new_course_assignment_path and return
else
@template = Project.find_by_name(params[:assignment][:template])
if params[:assignment][:template] != "" and not @template
@assignment.destroy
flash[:alert] = "Invalid template project"
redirect_to new_course_assignment_path and return
else
@assignment.template_id = @template ? @template.id : ""
end
@assignment.save
flash[:notice] = "Assignment #{@assignment.title} successfully created"
redirect_to course_assignment_index_path(@course)
end
end

def edit
@course = Course.find(params[:course_id])
@assignment = Assignment.find(params[:id])
@template = @assignment.template_id ? Project.find(@assignment.template_id).title : ""
end

def create
def update
@assignment = Assignment.find(params[:id])
@assignment.update_attributes(assignment_params)
unless @assignment.valid?
flash[:notice] = "Missing required fields"
redirect_to edit_course_assignment_path(@assignment) and return
end
@template = Project.find_by_name(params[:assignment][:template])
if params[:assignment][:template] != "" and not @template
@assignment.destroy
flash[:alert] = "Invalid template project"
redirect_to edit_course_assignment_path(id: @assignment.id) and return
else
@assignment.template_id = @template ? @template.id : ""
end
@assignment.save
flash[:notice] = "#{@assignment.title} was successfully updated."
redirect_to course_assignment_path(id: @assignment.id)
end

def destroy
@course = Course.find(params[:course_id])
@assignment = Assignment.find(params[:id])
@assignment.destroy
flash[:notice] = "Assignment '#{@assignment.title}' deleted."
redirect_to course_assignment_index_path(@course)
end

def submit
@assignment = Assignment.find(params[:id])
@project = current_user.projects.where(:name => params[:submition][:project]).first
if @project
@submission = Submission.create(@project.attributes.except('id', 'type'))
@submission.update_attributes(assignment_id: @assignment.id)
@submission.save
@submission.add_users(@project.users)
flash[:notice] = "Project successfully submited"
redirect_to course_assignment_path(id: @assignment.id)
else
flash[:alert] = "Invalid Project"
redirect_to course_assignment_path(id: @assignment.id)
end
end

private

def assignment_params
params.require(:assignment).permit(:title, :description, :start_time, :deadline)
end
end
5 changes: 5 additions & 0 deletions app/controllers/course_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def unenroll
redirect_to course_path(@course)
end

def assignments
@course = Course.find(params[:id])
@assignments = @course.assignments
end

def new
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def show

def index
@user = User.find(params[:id])
@projects = (@user == current_user) ? @user.projects.includes(:users) : @user.public_projects
@projects = (@user == current_user) ? @user.projects.includes(:users).select{|project| project.type==nil} : @user.public_projects
end

def new
Expand Down
5 changes: 4 additions & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class Project < ActiveRecord::Base
has_and_belongs_to_many :users, join_table: 'user_projects'
has_many :comments
belongs_to :assignment

validates :name, presence: true
after_update :remove_users

Expand All @@ -29,3 +28,7 @@ def add_users(users)
users.each { |user| self.users << user }
end
end

class Submission < Project

end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def public_projects
# Input: User (self)
# Output: Array of public project the User has worked on

self.projects.includes(:users).select{|project| project.privacy=='Public'}
self.projects.includes(:users).select{|project| project.privacy=='Public'; project.type==''}
end

def self.validate_emails(emails)
Expand Down
33 changes: 33 additions & 0 deletions app/views/assignment/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%h1 Edit Assignment


=form_tag course_assignment_path(id: @assignment.id), :method => :put do
.form-group
= label :assignment, :title, 'Title', :required => true
%br
=text_field :assignment, 'title', :value => @assignment.title

.form-group
=label :assignment, :description, 'Description'
%br
=text_field :assignment, 'description', :value => @assignment.description

.form-group
= label :assignment, :template, 'Project Starter File'
%br
= text_field :assignment, :template, :value => @template

.form-group
= label :assignment, :start_time, 'Start time'
%br
= date_select :assignment, :start_time, :value => @assignment.start_time

.form-group
= label :assignment, :deadline, 'Deadline'
%br
= date_select :assignment, :deadline, :value => @assignment.deadline

.form-group
=submit_tag 'Update Course'

= button_to 'Delete', course_path(@assignment), method: :delete, data: {confirm: "Are you sure?"}
23 changes: 23 additions & 0 deletions app/views/assignment/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

-# in app/views/course/assignments.html.haml

%h2 Assignments for #{@course.title}

%table{:class => "table table-hover"}
%thead
%tr
%th Assignment Title
%th Description
%th Due Date
%tbody
- @assignments.each do |assignment|
%tr
%td= link_to assignment.title, course_assignment_path(id: assignment.id)
%td= assignment.description
%td= assignment.deadline

-if (@course.teachers.include?(current_user))
= link_to 'New Assignment', new_course_assignment_path

%br
= link_to 'Back to Course Details', course_path(@course)
31 changes: 31 additions & 0 deletions app/views/assignment/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
%h1 Create New Assignment

= form_tag course_assignment_index_path do

.form-group
= label :assignment, :title, 'Title'
%br
= text_field :assignment, 'title', :required => true

.form-group
= label :assignment, :description, 'Description'
%br
= text_field :assignment, :description

.form-group
= label :assignment, :template, 'Project Starter File'
%br
= text_field :assignment, :template

.form-group
= label :assignment, :start_time, 'Start time'
%br
= date_select :assignment, :start_time

.form-group
= label :assignment, :deadline, 'Deadline'
%br
= date_select :assignment, :deadline

.form-group
= submit_tag 'Create Assignment'
41 changes: 41 additions & 0 deletions app/views/assignment/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

-# in app/views/course/show.html.haml

%h2 Details about #{@assignment.title}

%ul#details
%li
Description:
= @assignment.description
%li
Deadline:
= @assignment.deadline
%li
Starter Code:
= link_to @assignment.template.name, project_path(@assignment.template)

-if !(@course.teachers.include?(current_user))
-if @course.students.include?(current_user)
= form_tag submit_assignment_path do
.form-group
=label :submition, :project, 'Project Title'
%br
=text_field :submition, 'project'

= submit_tag 'Submit from assignment'

-else
%table{:class => "table table-hover"}
%thead
%tr
%th Submission
%th User(s)
%tbody
- @assignment.submissions.each do |project|
%tr
%td= link_to project.name, project_path(project)
%td= project.all_users

= link_to 'Edit', edit_course_assignment_path(id: @assignment.id)
= button_to 'Delete', course_assignment_path(id: @assignment.id), :method => :delete, :confirm => 'Are you sure?'
= link_to 'Back to Course', course_path(@course)
1 change: 1 addition & 0 deletions app/views/course/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
-else
= link_to 'Edit', edit_course_path(@course)
= button_to 'Delete', course_path(@course), :method => :delete, :confirm => 'Are you sure?'
= link_to 'Assignments', course_assignment_index_path(@course)
= link_to 'Back to User list', user_index_path
8 changes: 7 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
post '/project/:id', to: 'project#comment', as: 'project_comment'

# '/course/'
resources :course
resources :course do
resources :assignment
end
post '/course/:id/enroll' => 'course#enroll', :as => :course_enroll
post '/course/:id/unenroll' => 'course#unenroll', :as => :course_unenroll
# get '/course/:id/assignments/:assignment_id' => 'assignment#show', as: 'show_assignment'
# get '/course/:id/assignments/new' => 'assignment#new', as: 'new_assignment'
# post '/course/:id/assignments/new', to: 'assignment#create', as: 'create_assignment'
post '/course/:course_id/assignments/:id' => 'assignment#submit', as: 'submit_assignment'
end
Binary file modified db/development.sqlite3
Binary file not shown.
5 changes: 5 additions & 0 deletions db/migrate/20150609044654_adding_typeto_project.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddingTypetoProject < ActiveRecord::Migration
def change
add_column :projects, :type, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150427192508) do
ActiveRecord::Schema.define(version: 20150609044654) do

create_table "assignments", force: :cascade do |t|
t.integer "course_id"
Expand Down Expand Up @@ -60,6 +60,7 @@
t.string "description"
t.string "privacy"
t.integer "assignment_id"
t.string "type"
end

create_table "user_conversations", id: false, force: :cascade do |t|
Expand Down
Loading