Skip to content

Commit

Permalink
dragndrop working
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcjacobs committed Apr 24, 2020
1 parent bf21b4c commit 86e915f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/plan_courses.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the PlanCourses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/project4.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ table div, .dataTables_scrollHead, .dataTables_scrollHeadInner, .dataTables_scro
.fsuccess{
color: green;
}

#trash{
font-size: 64px;
}
17 changes: 17 additions & 0 deletions app/controllers/plan_courses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class PlanCoursesController < ApplicationController
#post
def create
@planCourse = PlanCourse.new
@planCourse.plan_id = Plan.where(name: params[:plan], user_id: params[:user])[0].id
@planCourse.course_id = Course.where(designator: params[:designator])[0].id
@planCourse.term = params[:term]
@planCourse.year = params[:year]
@planCourse.save!
end

#get
def index
@planCourse = PlanCourse.where(plan_id: Plan.where(name: params[:plan], user_id: params[:user])[0].id, course_id: Course.where(designator: params[:designator])[0].id)[0]
@planCourse.destroy();
end
end
2 changes: 2 additions & 0 deletions app/helpers/plan_courses_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module PlanCoursesHelper
end
29 changes: 27 additions & 2 deletions app/javascript/packs/myjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ window.hoverOverPlan = function(event){
}

window.dropOnPlan = function(event){
event.preventDefault();
event.target.children[1].innerHTML += "<li draggable='true' ondragstart='dragFromPlan(event)'>" + draggedCourse.designator + ": " + draggedCourse.name + "</li>";
if (draggedReqOrigin !== null){
draggedReqOrigin.hidden = true;
Expand All @@ -141,9 +142,33 @@ window.dropOnPlan = function(event){
draggedPlanOrigin.remove();
draggedPlanOrigin = null;
}

$.post("/plan_courses", {
plan: plan.plan_name,
user: plan.user.id,
designator: draggedCourse.designator,
term: event.target.children[0].children[0].innerText.split(" ")[0],
year: parseInt(event.target.children[0].children[0].innerText.split(" ")[1]),
});
draggedCourse = null;
}

window.hoverOverTrash = function(event){
event.preventDefault();
}

window.dropInTrash = function(event){
event.preventDefault();
if (draggedPlanOrigin !== null){
draggedPlanOrigin.remove();
draggedPlanOrigin = null;

$.get("/plan_courses", {
designator: draggedCourse.designator,
user: plan.user.id,
plan: plan.plan_name
});
}
draggedCourse = null;

}

class Course {
Expand Down
3 changes: 3 additions & 0 deletions app/views/plans/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<div class="container">
<div id="accordion">
</div>
<div id="trash" ondragover='hoverOverTrash(event)' ondrop='dropInTrash(event)'>
<i class="fa fa-trash" aria-hidden="true"></i>
</div>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do
root 'plans#index'
resources :plans
resources :plan_courses
devise_for :users, :controllers => {:registrations => 'registrations'}
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
7 changes: 7 additions & 0 deletions test/controllers/plan_courses_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class PlanCoursesControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end

0 comments on commit 86e915f

Please sign in to comment.