Skip to content

Commit

Permalink
Certificate added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronaq13 committed Mar 26, 2017
1 parent a3028bb commit b8c4cbd
Show file tree
Hide file tree
Showing 19 changed files with 278 additions and 178 deletions.
13 changes: 13 additions & 0 deletions .byebug_history
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
c
dc.user_id
current_user.id
c
u_id
dc.user_id
c_id
dc.course_id
c
c_id
c
current_user.id
tmpCourse.id
c
params[:course_id]
c
changeVideo()
Expand Down
306 changes: 142 additions & 164 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ end
gem 'devise'
gem 'omniauth-facebook'
gem 'yt', '~> 0.28.0'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'autoprefixer-rails'
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.4)
autoprefixer-rails (6.7.7.1)
execjs
bcrypt (3.1.11)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
bootstrap-sass (3.2.0.2)
sass (~> 3.2)
builder (3.2.3)
byebug (9.0.6)
coffee-rails (4.1.1)
Expand Down Expand Up @@ -178,6 +182,8 @@ PLATFORMS
ruby

DEPENDENCIES
autoprefixer-rails
bootstrap-sass (~> 3.2.0)
byebug
coffee-rails (~> 4.1.0)
devise
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@



$(document).ready(function(){

function subSignInFunc(){
alert("Please Sign in first!!");
}
Expand All @@ -40,7 +40,7 @@ $(document).ready(function(){
}
}

});




Expand Down
16 changes: 15 additions & 1 deletion app/controllers/student_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,29 @@ def unsubscribeCourse
def doneVideo
dv = DoneVideo.new
dv.user_id = current_user.id
dv.link = params[:link]
dv.link_key = params[:link]
dv.save

return redirect_to '/doingCourse/'+params[:course_id]

end

def accomplishment

end

def addingDoneCourse
if current_user.done_courses.where(course_id: params[:course_id])
return redirect_to '/accomplishment'
else
dc = DoneCourse.new
dc.user_id = current_user.id
dc.course_id = params[:course_id]
dc.save
return redirect_to '/accomplishment'
end

end


end
24 changes: 24 additions & 0 deletions app/helpers/student_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
module StudentHelper

def courseIsDone(c_id,u_id)

# DoneCourse.all.each do |dc|
#
# if(dc.user_id === u_id)
# if (dc.course_id === c_id)
#
# return true
# else
# return false
# end
# else
# return false
# end
# end
user = User.find(u_id)
if user.done_courses.find_by(course_id: c_id)
return true
else
return false
end
end

end
3 changes: 3 additions & 0 deletions app/models/done_course.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class DoneCourse < ActiveRecord::Base
has_many :users
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class User < ActiveRecord::Base

has_many :subscribes
has_many :courses , through: :subscribes

has_many :done_courses


end
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<button class="dropbtn"><i class="fa fa-user-circle-o fa-lg" aria-hidden="true"></i>&nbsp;<%= value%></button>
<div class="dropdown-content" style="left:0;">
<a href="/myCourses">My Courses</a>
<a href="/accomplishment/<%= current_user.id.to_s %>">Accomplishment</a>
<a href="/accomplishment">Accomplishment</a>
<a href="/profile">Profile</a>
<a href="/settings">Settings</a>
<a href="/users/sign_out" data-method="DELETE">Log Out</a>
Expand Down
5 changes: 5 additions & 0 deletions app/views/student/accomplishment.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%current_user.done_courses.each do |dc|%>
<% course = Course.find(dc.course_id) %>
<h1><%= course.title %></h1>
<img src=<%= course.image %> alt="photo" width="400px">
<%end%>
5 changes: 3 additions & 2 deletions app/views/student/doingCourse.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
frame.setAttribute('src', '<%= course.teaser_video %>');"><p>Intro</p></div>
<% numOfVideos = 0
numOfDone = 0 %>

<%course.videos.each do |c|%>
<%numOfVideos += 1%>
<div style="display: flex;">
Expand All @@ -26,7 +27,7 @@
courseIsDone = false
DoneVideo.all.each do |dv|
if dv.user_id == current_user.id
if dv.link == c.link.split('/')[-1]
if dv.link_key == c.link.split('/')[-1]
courseIsDone = true
end
end
Expand All @@ -50,7 +51,7 @@
<md-card>
<%if numOfVideos == numOfDone %>
<h1 style="margin-bottom: 10px;">Course Complete</h1>
<a style="margin-bottom: 30px;" href="/accomplishment/<%= current_user.id.to_s%>">See Certificate</a>
<a style="margin-bottom: 30px;" href="/addingDoneCourse/<%= params[:course_id].to_s %>">See Certificate</a>
<%end%>

<iframe id="videoFrame" src=<%= course.teaser_video %> width="420" height=300">
Expand Down
23 changes: 19 additions & 4 deletions app/views/student/myCourses.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= current_user.id %>
<%courseDone = false%>

<md-card>
<h2>Subscribed Courses</h2>

Expand Down Expand Up @@ -26,12 +28,25 @@
<div style="display: flex; align-items: center;">

<img class="controllingWidthOfImage" src=<%= tmpCourse.image%> alt="photo" onclick="location.href=<%=doingCourseURL%>;">
<div style="display: flex;flex-direction: column;">
<div style="display: flex;flex-direction: column;">

<p style="margin-left: 20px;"><%= tmpCourse.short_summay%></p>
<button style="margin-left: 20px; width: 100px;" onclick="unsubscribeConfirmation(<%= tmpCourse.id %>);">Un-subscribe</button>
<p style="margin-left: 20px;"><%= tmpCourse.short_summay%></p>
</div>
<%if courseIsDone(tmpCourse.id,current_user.id) %>
<div style="display: flex; margin-left: 20px;margin-top: 20px;">
<i class="fa fa-check" aria-hidden="true"></i>
<p>You have completed this course</p>
</div>

<%else%>
<button style="margin-left: 20px; width: 100px;" onclick="unsubscribeConfirmation(<%= tmpCourse.id %>);">Un-subscribe</button>
<%end%>
<md-progress-linear md-mode="determinate" value="50"></md-progress-linear>
</div>
</div>
</md-card>
<%end%>
Expand Down
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
get '/unsubscribeCourse/:id' => 'student#unsubscribeCourse'
post '/changeSettings' => 'student#changeSettings'
get '/doneVideo/:link/:course_id' => 'student#doneVideo'

get '/accomplishment' => 'student#accomplishment'
get '/addingDoneCourse/:course_id' => 'student#addingDoneCourse'

#--------------Teacher------------------#

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170325154011_change_column_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeColumnName < ActiveRecord::Migration
def change
rename_column :done_videos, :link, :link_key
end
end
10 changes: 10 additions & 0 deletions db/migrate/20170325160613_create_done_courses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateDoneCourses < ActiveRecord::Migration
def change
create_table :done_courses do |t|
t.integer :user_id
t.integer :course_id

t.timestamps null: false
end
end
end
11 changes: 9 additions & 2 deletions 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: 20170325142508) do
ActiveRecord::Schema.define(version: 20170325160613) do

create_table "courses", force: :cascade do |t|
t.string "category"
Expand All @@ -32,9 +32,16 @@
t.integer "teacher_id"
end

create_table "done_courses", force: :cascade do |t|
t.integer "user_id"
t.integer "course_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "done_videos", force: :cascade do |t|
t.integer "user_id"
t.string "link"
t.string "link_key"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/done_courses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
user_id: 1
course_id: 1

two:
user_id: 1
course_id: 1
7 changes: 7 additions & 0 deletions test/models/done_course_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class DoneCourseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit b8c4cbd

Please sign in to comment.