-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from alaashafaee/create_track_4.1_2
@MussabElDash Merging user story: Create track 4.1
- Loading branch information
Showing
7 changed files
with
376 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# [Create Track - Story 4.1] | ||
# Create new Select List | ||
# Parameters: | ||
# value: The list to be created | ||
# Author: Mussab ElDash | ||
@change = (value) -> | ||
v = document.getElementById("second") | ||
v.innerHTML = value | ||
return | ||
|
||
# [Create Track - Story 4.1] | ||
# alert will be shown with value | ||
# Parameters: | ||
# value: The message to be alerted | ||
# Author: Mussab ElDash | ||
@show = (value) -> | ||
alert value | ||
return | ||
|
||
# [Create Track - Story 4.1] | ||
# sends ajax post request to the server to get all | ||
# the problems of the track with id track_id | ||
# then send the result to showProblems function | ||
# that will put the result in a list | ||
# Parameters: | ||
# track_id: The id of the track of the requested problems | ||
# Author: Mussab ElDash | ||
@getProblems = (track_id) -> | ||
$.ajax | ||
type: "POST" | ||
url: "/tracks/" + track_id + "/getProblems" | ||
datatype: "json" | ||
success: (data) -> | ||
showProblems data | ||
return | ||
return | ||
|
||
# [Create Track - Story 4.1] | ||
# show the recieved set of problems in the select list | ||
# Parameters: | ||
# datas: List of problems to be shown | ||
# Author: Mussab ElDash | ||
showProblems = (datas) -> | ||
inner = "<input name='Problem[id][]' | ||
type='hidden' value='' /> | ||
<select id='ProblemsSel' | ||
multiple='multiple' | ||
name='Problem[id][]' | ||
onchange='' size='15' | ||
style='width:250px;align='center'>" | ||
for data in datas | ||
opt = "<option value='" + data.id + "'>" | ||
opt+= data.title + "</option>" | ||
inner += opt | ||
inner += "</select>" | ||
document.getElementById("second").innerHTML = inner | ||
return | ||
|
||
# [Create Track - Story 4.1] | ||
# triggers the visibilty of the create track form | ||
# Author: Mussab ElDash | ||
@newTrack = -> | ||
create = document.getElementById("create_track") | ||
if create.hidden is true | ||
create.hidden = false | ||
else | ||
create.hidden = true | ||
return | ||
|
||
# [Create Track - Story 4.1] | ||
# Returns: The id of the selected track | ||
# Author: Mussab ElDash | ||
getSelectedTrackId = -> | ||
tracks = document.getElementById("tracksSel") | ||
tracks.options[tracks.selectedIndex].value | ||
|
||
# [Create Track - Story 4.1] | ||
# Returns: The id of the selected problem | ||
# Author: Mussab ElDash | ||
getSelectedProblemId = -> | ||
problems = document.getElementById("problemsSel") | ||
problems.options[problems.selectedIndex].value | ||
|
||
# [Create Track - Story 4.1] | ||
# this function is called when the page finishes loading | ||
# selects the first track in the track list | ||
# and focuses on the track list | ||
# Author: Mussab ElDash | ||
jQuery -> | ||
getProblems getSelectedTrackId() | ||
document.getElementById("tracksSel").focus() | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
class TracksController < ApplicationController | ||
|
||
# [Create Track - Story 4.1] | ||
# shows the tracks of the topic with id :id | ||
# show 404 page if there is no topic with such id | ||
# This Action should be put in the future in the | ||
# Topic controller | ||
# Parameters: | ||
# id: The id of the topic | ||
# Returns: The view of the requested topic | ||
# Author: Mussab ElDash | ||
def show | ||
boool = flash[:notice] != "Successfully created..." | ||
boool&&=flash[:notice] != "The required Fields are missing" | ||
if boool | ||
flash[:notice]= nil | ||
end | ||
id = params[:id] | ||
@topic = Topic.find_by_id(id) | ||
if @topic | ||
@course = @topic.course | ||
@tracks = @topic.tracks | ||
else | ||
render ('public/404') | ||
end | ||
end | ||
|
||
# [Create Track - Story 4.1] | ||
# render a json file with a set of problems of the track with id :id | ||
# Parameters: | ||
# id: The id of the Track | ||
# Returns: The list of the requested problems in json file | ||
# Author: Mussab ElDash | ||
def getProblems | ||
id = params[:id] | ||
track = Track.find(id) | ||
problems = track.problems | ||
render json: problems | ||
end | ||
|
||
# [Create Track - Story 4.1] | ||
# creates a new track with the passed parameters | ||
# if the parameters is valid a flash that it was save will show | ||
# and if not not a flash will show that there are fields missing | ||
# Parameters: | ||
# topic_id: The id of the topic to connect the track to | ||
# title: The title of the track to be created | ||
# difficulty: The difficulty of the track to be created | ||
# Returns: The same page that wants to create the Track | ||
# Author: Mussab ElDash | ||
def create | ||
t = Track.new(permitCreate) | ||
if t.save | ||
flash[:notice] = "Successfully created..." | ||
redirect_to :back | ||
else | ||
flash[:notice] = "The required Fields are missing" | ||
redirect_to :back | ||
end | ||
end | ||
|
||
# [Create Track - Story 4.1] | ||
# permits the passed parameters | ||
# Parameters: | ||
# topic_id: The id of the topic to connect the track to | ||
# title: The title of the track to be created | ||
# difficulty: The difficulty of the track to be created | ||
# Returns: The permited params | ||
# Author: Mussab ElDash | ||
def permitCreate | ||
params.require(:Track).permit(:topic_id , :title , :difficulty) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<%@title = @course.name + '#'+ @topic.title%> | ||
<h1><%=@title%></h1> | ||
<table align="center"> | ||
<tr> | ||
<td align="center">Tracks</td> | ||
<td align="center">Problems</td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<!-- List of all tracks of the selected topic | ||
visit /tracks/:id where id is the id of the topic | ||
that route I used until we decide on a correct route --> | ||
<%=select(:Track , :id , | ||
@tracks.collect{|t|[t.title , t.id]}, | ||
{selected: @tracks.first ? @tracks.first.id : 0} , | ||
:multiple => true , :style => "width:250px;align='center'" , | ||
:onchange => "getProblems(this.value)" , | ||
:size => 15 , :id => "tracksSel")%> | ||
</td> | ||
|
||
<!-- Here will be the list of problems | ||
of the track selected in the previous list --> | ||
<td id="second" align="center"> | ||
<%=select(:Track , :id , {}, {} , | ||
:multiple => true , :style => "width:250px;align='center'" , | ||
:onchange => "getProblems(this.value)" , | ||
:size => 15 , :id => "problemsSel")%> | ||
</td> | ||
</tr> | ||
<tr> | ||
<!-- Here is a buttons to create and edit problems | ||
and tracks but for now | ||
the create button of tracks is the only button that works | ||
other buttons only shows an alert --> | ||
<td align="center"> | ||
<button onclick="newTrack()">New</button> | ||
<button onclick="show('Course')">Edit</button> | ||
</td> | ||
<td align="center"> | ||
<button onclick="show('Problem')">Edit</button> | ||
<button onclick="alert('hello')">New</button> | ||
</td> | ||
</tr> | ||
</table> | ||
<br> | ||
|
||
<!-- thats a form for creating a track which is intially hidden 7 | ||
until the new button clicked --> | ||
<div align="center" ><%=flash[:notice]%></div><br> | ||
<div align="center" id="create_track" hidden=true> | ||
<%= form_for :Track , url: {action: "create"}, | ||
html: {class: "nifty_form"} do |f| %> | ||
<label>Title :</label> | ||
<%= f.text_field :title %> <br> | ||
<label>Difficulty :</label> | ||
<%= f.number_field :difficulty %> <br> | ||
<%= f.submit "Create" %> <br> | ||
<%= f.hidden_field :topic_id , :value => params[:id]%> | ||
<% end %></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,60 @@ | ||
Tutor::Application.routes.draw do | ||
# The priority is based upon order of creation: first created -> highest priority. | ||
# See how all your routes lay out with "rake routes". | ||
|
||
# You can have the root of your site routed with "root" | ||
root 'site#index' | ||
|
||
# Example of regular route: | ||
# get 'products/:id' => 'catalog#view' | ||
|
||
# Example of named route that can be invoked with purchase_url(id: product.id) | ||
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | ||
|
||
# Example resource route (maps HTTP verbs to controller actions automatically): | ||
# resources :products | ||
|
||
# Example resource route with options: | ||
# resources :products do | ||
# member do | ||
# get 'short' | ||
# post 'toggle' | ||
# end | ||
# | ||
# collection do | ||
# get 'sold' | ||
# end | ||
# end | ||
|
||
# Example resource route with sub-resources: | ||
# resources :products do | ||
# resources :comments, :sales | ||
# resource :seller | ||
# end | ||
|
||
# Example resource route with more complex sub-resources: | ||
# resources :products do | ||
# resources :comments | ||
# resources :sales do | ||
# get 'recent', on: :collection | ||
# end | ||
# end | ||
|
||
# Example resource route with concerns: | ||
# concern :toggleable do | ||
# post 'toggle' | ||
# end | ||
# resources :posts, concerns: :toggleable | ||
# resources :photos, concerns: :toggleable | ||
|
||
# Example resource route within a namespace: | ||
# namespace :admin do | ||
# # Directs /admin/products/* to Admin::ProductsController | ||
# # (app/controllers/admin/products_controller.rb) | ||
# resources :products | ||
# end | ||
resources :tracks do | ||
post 'getProblems' , on: :member | ||
end | ||
# The priority is based upon order of creation: first created -> highest priority. | ||
# See how all your routes lay out with "rake routes". | ||
|
||
# You can have the root of your site routed with "root" | ||
root 'site#index' | ||
|
||
# Example of regular route: | ||
# get 'products/:id' => 'catalog#view' | ||
|
||
# Example of named route that can be invoked with purchase_url(id: product.id) | ||
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | ||
|
||
# Example resource route (maps HTTP verbs to controller actions automatically): | ||
# resources :products | ||
|
||
# Example resource route with options: | ||
# resources :products do | ||
# member do | ||
# get 'short' | ||
# post 'toggle' | ||
# end | ||
# | ||
# collection do | ||
# get 'sold' | ||
# end | ||
# end | ||
|
||
# Example resource route with sub-resources: | ||
# resources :products do | ||
# resources :comments, :sales | ||
# resource :seller | ||
# end | ||
|
||
# Example resource route with more complex sub-resources: | ||
# resources :products do | ||
# resources :comments | ||
# resources :sales do | ||
# get 'recent', on: :collection | ||
# end | ||
# end | ||
|
||
# Example resource route with concerns: | ||
# concern :toggleable do | ||
# post 'toggle' | ||
# end | ||
# resources :posts, concerns: :toggleable | ||
# resources :photos, concerns: :toggleable | ||
|
||
# Example resource route within a namespace: | ||
# namespace :admin do | ||
# # Directs /admin/products/* to Admin::ProductsController | ||
# # (app/controllers/admin/products_controller.rb) | ||
# resources :products | ||
# end | ||
end | ||
|
Binary file not shown.
Oops, something went wrong.