Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/alaashafaee/Coolsoft-14 i…
Browse files Browse the repository at this point in the history
…nto C4_Husseny_297_Edit_track_of_a_problem_4.2
  • Loading branch information
AbdullRahman ElHusseini committed Apr 24, 2014
2 parents 9fed0b2 + 85740f0 commit f9ef9ee
Show file tree
Hide file tree
Showing 35 changed files with 783 additions and 288 deletions.
4 changes: 2 additions & 2 deletions tutor/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ gem 'rails', '4.0.4'
gem 'devise'

# File uploading
gem 'carrierwave'
gem 'rmagick'
# gem 'carrierwave'
# gem 'rmagick'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Expand Down
8 changes: 0 additions & 8 deletions tutor/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ GEM
arel (4.0.2)
bcrypt (3.1.7)
builder (3.1.4)
carrierwave (0.10.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
json (>= 1.7)
mime-types (>= 1.16)
chronic (0.10.2)
coffee-rails (4.0.1)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -101,7 +96,6 @@ GEM
json (~> 1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
rmagick (2.13.2)
sass (3.2.19)
sass-rails (4.0.3)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -155,7 +149,6 @@ PLATFORMS
ruby

DEPENDENCIES
carrierwave
coffee-rails (~> 4.0.0)
composite_primary_keys (~> 6.0.1)
devise
Expand All @@ -164,7 +157,6 @@ DEPENDENCIES
jquery-rails (~> 3.1.0)
json_builder (= 3.1.0)
rails (= 4.0.4)
rmagick
sass-rails (~> 4.0.2)
sdoc
sqlite3
Expand Down
Binary file added tutor/app/assets/images/add_buttom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutor/app/assets/images/add_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tutor/app/assets/images/delete_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
256 changes: 256 additions & 0 deletions tutor/app/assets/javascripts/solutions_constraints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
//# Place all the behaviors and hooks related to the matching controller here.
//# All this logic will automatically be available in application.js.
//# You can use CoffeeScript in this file: http://coffeescript.org/

var type = new Array();
var param_name = new Array();
var var_type = new Array();
var var_name = new Array();

//# [Add Solutions' constraints - Story 4.14]
//# Description: Adds the parameters from the text_fields to array
//# Parameters: none
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function add_params(field) {
var tmp_type = document.getElementById("params_type").value;
var tmp_name = document.getElementById("params_name").value;
if (tmp_name != "" && tmp_type != "") {
document.getElementById("params_type").style.border= "";
document.getElementById("params_name").style.border= "";
type[type.length] = tmp_type;
document.getElementById("params_type").value = "";
param_name[param_name.length] = tmp_name;
document.getElementById("params_name").value = "";
document.getElementById("parameter").innerHTML = "<h3>Paramters Constraints</h3><table>";
for (var i = 0; i < type.length; i++) {
$('#parameter').append("<tr>");
$('#parameter').append("<td width = \"10px\"></td>");
$('#parameter').append("<td><label>"+type[i]+"</label></td>");
$('#parameter').append("<td width = \"10px\"></td>");
$('#parameter').append("<td><label>"+param_name[i]+"</label></td>");
$('#parameter').append("<td width = \"20px\"></td>");
$('#parameter').append("<td><img alt=\"delete buttom\" id=\"params_"+i+"\" \
onclick=\"remove_params(this);\" src=\"/assets/delete_button.png\" \
style=\"width:8%;height:8%;margin_top:10px;;cursor:pointer\"></td>");
$('#parameter').append("</tr>");
}
$('#parameter').append("</table>");
}
else {
if (tmp_name == "" && tmp_type == "") {
document.getElementById("params_type").style.border= "red 1px solid";
document.getElementById("params_name").style.border= "red 1px solid";
}
else if(tmp_name == "") {
document.getElementById("params_type").style.border= "";
document.getElementById("params_name").style.border= "red 1px solid";
}
else{
document.getElementById("params_type").style.border= "red 1px solid";
document.getElementById("params_name").style.border= "";
}
}
}

//# [Add Solutions' constraints - Story 4.14]
//# Description: removes selected variable from method Contraints
//# Parameters: none
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function remove_params(field) {
var index = field.id.split("_")[1];
type.splice(index,1);
param_name.splice(index,1);
document.getElementById("parameter").innerHTML = "<h3>Paramters Constraints</h3><table>";
if(type.length == 0) {
$('#parameter').append("No paramter");
}
for (var i = 0; i < type.length; i++) {
$('#parameter').append("<tr>");
$('#parameter').append("<td width = \"10px\"></td>");
$('#parameter').append("<td><label>"+type[i]+"</label></td>");
$('#parameter').append("<td width = \"10px\"></td>");
$('#parameter').append("<td><label>"+param_name[i]+"</label></td>");
$('#parameter').append("<td width = \"20px\"></td>");
$('#parameter').append("<td><img alt=\"delete buttom\" id=\"params_"+i+"\" \
onclick=\"remove_params(this);\" src=\"/assets/delete_button.png\" \
style=\"width:8%;height:8%;margin_top:10px;;cursor:pointer\"></td>");
$('#parameter').append("</tr>");
}
$('#parameter').append("</table>");
}

//# [Add Solutions' constraints - Story 4.14]
//# Description: Adds the parameters from the text_fields to array
//# Parameters: none
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function add_variable(field) {
var tmp_type = document.getElementById("variable_type").value;
var tmp_name = document.getElementById("variable_name").value;
if (tmp_name != "" && tmp_type != "") {
document.getElementById("variable_type").style.border= "";
document.getElementById("variable_name").style.border= "";
var_type[var_type.length] = tmp_type;
document.getElementById("variable_type").value = "";
var_name[var_name.length] = tmp_name;
document.getElementById("variable_name").value = "";
document.getElementById("variable").innerHTML = "<h3>Variables Constraints</h3><table>";
for (var i = 0; i < var_type.length; i++) {
$('#variable').append("<tr>");
$('#variable').append("<td width = \"10px\"></td>");
$('#variable').append("<td><label>"+var_type[i]+"</label></td>");
$('#variable').append("<td width = \"10px\"></td>");
$('#variable').append("<td><label>"+var_name[i]+"</label></td>");
$('#variable').append("<td width = \"20px\"></td>");
$('#variable').append("<td><img alt=\"delete buttom\" id=\"params_"+i+"\" \
onclick=\"remove_variable(this);\" src=\"/assets/delete_button.png\" \
style=\"width:8%;height:8%;margin_top:10px;;cursor:pointer\"></td>");
$('#variable').append("</tr>");
}
$('#variable').append("</table>");
}
else {
if (tmp_name == "" && tmp_type == "") {
document.getElementById("variable_type").style.border= "red 1px solid";
document.getElementById("variable_name").style.border= "red 1px solid";
}
else if(tmp_name == "") {
document.getElementById("variable_type").style.border= "";
document.getElementById("variable_name").style.border= "red 1px solid";
}
else {
document.getElementById("variable_type").style.border= "red 1px solid";
document.getElementById("variable_name").style.border= "";
}
}
}

//# [Add Solutions' constraints - Story 4.14]
//# Description: removes selected variable from Variable Contraints
//# Parameters: none
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function remove_variable(field) {
var index = field.id.split("_")[1];
var_type.splice(index,1);
var_name.splice(index,1);
document.getElementById("variable").innerHTML = "<h3>Variables Constraints</h3><table>";
if(var_type.length == 0) {
$('#variable').append("No Variables");
}
for (var i = 0; i < var_type.length; i++) {
$('#variable').append("<tr>");
$('#variable').append("<td width = \"10px\"></td>");
$('#variable').append("<td><label>"+var_type[i]+"</label></td>");
$('#variable').append("<td width = \"10px\"></td>");
$('#variable').append("<td><label>"+var_name[i]+"</label></td>");
$('#variable').append("<td width = \"20px\"></td>");
$('#variable').append("<td><img alt=\"delete buttom\" id=\"params_"+i+"\" \
onclick=\"remove_params(this);\" src=\"/assets/delete_button.png\" \
style=\"width:8%;height:8%;margin_top:10px;;cursor:pointer\"></td>");
$('#variable').append("</tr>");
}
$('#variable').append("</table>");
}

//# [Add Solutions' constraints - Story 4.14]
//# Description: for showing the error massages for the user
//# Parameters:
//# errorArray: array of Errors,for multi error massage show
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function showErrorMessage(arrayOfErrors) {
for (var i = 0; i < arrayOfErrors.length; i++) {
$("#errors").append("<div class=\"alert alert-danger\">"+arrayOfErrors[i]+"</div>");
};
}

//# [Add Solutions' constraints - Story 4.14]
//# Description: Validates Data before sending it to the Server side
//# Parameters:
//# method_cons: Hash containting the Method parameters
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function testingValidation(errorArray,method,name) {
if (type.length == 0 &&
var_type.length == 0 &&
method == 0 &&
name == 0) {
errorArray.push("Can not submit an empty Data,\
Try filling either Method Constraint for Variable Constraint");
return false;
};
if (type.length > 0) {
if (method == "" && name == "") {
document.getElementById("_constrain_method_return").style.border= "red 1px solid";
document.getElementById("_constrain_method_name").style.border= "red 1px solid";
errorArray.push("Enter method name and return type ..");
}
};
if(method == "" && name != "") {
document.getElementById("_constrain_method_name").style.border= "";
document.getElementById("_constrain_method_return").style.border= "red 1px solid";
errorArray.push("Enter method return type ..");
}
else if(name == "" && method != "") {
document.getElementById("_constrain_method_name").style.border= "red 1px solid";
document.getElementById("_constrain_method_return").style.border= "";
errorArray.push("Enter method name ..");
}
return errorArray.length == 0;
}

//# [Add Solutions' constraints - Story 4.14]
//# Description: submits via ajax to the controller
//# Parameters: none
//# Returns: none
//# Author: Ahmed Mohamed Magdi
function submitParams() {
$("#errors").html("");
errorArray = new Array();
var hash_p = new Array();
var hash_v = new Array();
method = $('#_constrain_method_return').val()
name = $('#_constrain_method_name').val()
if (!testingValidation(errorArray,method,name)) {
showErrorMessage(errorArray);
return;
};
for (var i = 0; i < type.length; i++) {
hash_p.push({
type: type[i] ,
name: param_name[i]
});
};
for (var i = 0; i < type.length; i++) {
hash_v.push({
type: var_type[i] ,
name: var_name[i]
});
};
$.ajax({
type: "POST",
url: "/solutions_constraints",
data:{
parameter_constraint: hash_p,
variable_constraint: hash_v,
method_return: method,
method_name: name
},
success: function(data) {
if (data) {
alert("Data have been Added successfully");
window.location = window.location
}
else {
alert("Data messigin/incorrect !");
}
},
datatype: "JSON",
error: function() {
alert("Failed to Add Constraints, Check again");
}
});
}
7 changes: 7 additions & 0 deletions tutor/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
margin-bottom:70px;
width:78%;
margin-left:1%;
min-width:500px;
overflow:scroll;
position:static;
}

.footer {
Expand All @@ -46,4 +49,8 @@

.button-devise {
margin-top: 10px;
}

.home {
overflow:scroll;
}
3 changes: 3 additions & 0 deletions tutor/app/assets/stylesheets/solutions_constraints.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the solutionsConstraints controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
19 changes: 19 additions & 0 deletions tutor/app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,24 @@ def new
end
end

# [Remove Problem - Story 4.18]
# This action takes the problem id, remove it from the database
# and then redirects the user to the show page of the track that had the problem
# with a "Problem successfully Deleted" message.
# Parameters:
# params[:id]: The current problem's id
# Returns:
# flash[:notice]: A message indicating the success of the deletion
# Author: Ahmed Atef
def destroy
@track = Problem.find_by_id(params[:id]).track_id
if Problem.find_by_id(params[:id]).destroy
flash[:notice] = "Problem successfully Deleted"
redirect_to(:controller => 'tracks',
:action => 'show' ,:id => @track)
end
end

# [Edit Problem - 4.5]
# Update the problem's title, description or track
# Parameters:
Expand Down Expand Up @@ -196,4 +214,5 @@ def done
def problem_params
params.require(:Problem).permit(:title, :description, :track_id)
end

end
Loading

0 comments on commit f9ef9ee

Please sign in to comment.