Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review - DO NOT MERGE #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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
99 changes: 56 additions & 43 deletions public/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//GLOBAL VARIABLES
//Functions are at the bottom.

var editListModalButtonHtml =
var editListModalButtonHtml =
'<div class="col-md-12 addVerb">' +
' <button class="btn btn-success" id="addVerb">Add another verb</button>' +
'</div>';
Expand Down Expand Up @@ -47,6 +47,17 @@ $(document).ready(function() {
* j. Saving the updated list data
*/

// selected jQuery elements
var $je = $(".je")
var $tu = $(".tu")
var $il = $(".il")
var $nous = $(".nous")
var $vous = $(".vous")
var $ils = $(".ils")
var $tense = $(".tense")
var $tense = $(".tense")
var $present = $(".present")

// 1. MAIN PAGE JS:
if ($("#main-page").length >= 1) {
$("input.verb-search").keydown(function handler(event) {
Expand All @@ -56,6 +67,10 @@ $(document).ready(function() {
var family = infinitive.slice(infinitive.length-2, infinitive.length);
if (family === "er" || family === "re" || family === "ir") {
var url = "/api/verbname/" + infinitive;
// for kicks, let's display the current search in the URL Hash
// this one way of doing "front-end routing"
// bonus: make it bookmarkable / execute the search on pageload!
location.hash = "/verbs/search/" + infinitive; // e.g. http://example.com/#/verbs/search/aimer
$.ajax({
method: "GET",
url: url,
Expand Down Expand Up @@ -96,15 +111,15 @@ $(document).ready(function() {
success: function (data) {
// console.log(data);
tense = "present";
$(".je").text(data.tense.present.je);
$(".tu").text(data.tense.present.tu);
$(".il").text(data.tense.present.il);
$(".nous").text(data.tense.present.nous);
$(".vous").text(data.tense.present.vous);
$(".ils").text(data.tense.present.ils);
$(".tense").removeClass("btn-success");
$(".tense").addClass("btn-primary");
$(".present").addClass("btn-success");
$je.text(data.tense.present.je);
$tu.text(data.tense.present.tu);
$il.text(data.tense.present.il);
$nous.text(data.tense.present.nous);
$vous.text(data.tense.present.vous);
$ils.text(data.tense.present.ils);
$tense.removeClass("btn-success");
$tense.addClass("btn-primary");
$present.addClass("btn-success");
},
error: function (error) {
console.log("Present tense error: ", error);
Expand All @@ -122,14 +137,14 @@ $(document).ready(function() {
success: function (data) {
// console.log(data);
tense = "imparfait";
$(".je").text(data.tense.imparfait.je);
$(".tu").text(data.tense.imparfait.tu);
$(".il").text(data.tense.imparfait.il);
$(".nous").text(data.tense.imparfait.nous);
$(".vous").text(data.tense.imparfait.vous);
$(".ils").text(data.tense.imparfait.ils);
$(".tense").removeClass("btn-success");
$(".tense").addClass("btn-primary");
$je.text(data.tense.imparfait.je);
$tu.text(data.tense.imparfait.tu);
$il.text(data.tense.imparfait.il);
$nous.text(data.tense.imparfait.nous);
$vous.text(data.tense.imparfait.vous);
$ils.text(data.tense.imparfait.ils);
$tense.removeClass("btn-success");
$tense.addClass("btn-primary");
$(".imparfait").addClass("btn-success");
},
error: function (error) {
Expand All @@ -143,25 +158,25 @@ $(document).ready(function() {
$(".edit-tense.save").show();
$(".edit-tense.edit").hide();
$(".imparfait").hide();
$(".present").hide();
$present.hide();
tenseChangePrevent = 1;
var je = $("span.conjugation.je").text();
var tu = $("span.conjugation.tu").text();
var il = $("span.conjugation.il").text();
var nous = $("span.conjugation.nous").text();
var vous = $("span.conjugation.vous").text();
var ils = $("span.conjugation.ils").text();
$(".je").html("<input type='text' class='je'>");
$je.html("<input type='text' class='je'>");
$("input.je").val(je);
$(".tu").html("<input type='text' class='tu'>");
$tu.html("<input type='text' class='tu'>");
$("input.tu").val(tu);
$(".il").html("<input type='text' class='il'>");
$il.html("<input type='text' class='il'>");
$("input.il").val(il);
$(".nous").html("<input type='text' class='nous'>");
$nous.html("<input type='text' class='nous'>");
$("input.nous").val(nous);
$(".vous").html("<input type='text' class='vous'>");
$vous.html("<input type='text' class='vous'>");
$("input.vous").val(vous);
$(".ils").html("<input type='text' class='ils'>");
$ils.html("<input type='text' class='ils'>");
$("input.ils").val(ils);
});

Expand All @@ -170,7 +185,7 @@ $(document).ready(function() {
$(".edit-tense.edit").show();
$(".edit-tense.save").hide();
$(".imparfait").show();
$(".present").show();
$present.show();
tenseChangePrevent = 0;
id = $(".row.verb-conjugation").attr('id');
var je = $("input.je").val();
Expand Down Expand Up @@ -265,7 +280,7 @@ $(document).ready(function() {
$("span.new-verb.vous").html(vous);
$("span.new-verb.ils").html(ils);
});

$(".next-tense").click(function (event) {
$(".save-tense").show();
$(".next-tense").hide();
Expand Down Expand Up @@ -347,7 +362,7 @@ $(document).ready(function() {

//Gets all of the list information on page load
getLists();


$("#newList").submit(function (event) {
event.preventDefault();
Expand Down Expand Up @@ -407,7 +422,7 @@ $(document).ready(function() {
});

$("#editListModal").on("click", "#addVerb", function () {
//Removes the #addVerb button. It will be re-added to
//Removes the #addVerb button. It will be re-added to
//the bottom of the modal once a new verb has been added.
$(".addVerb").remove();
//Calls a function that adds a dropdown that is populated with the verbs
Expand Down Expand Up @@ -486,7 +501,7 @@ function renderConjugation(verb) {
if ($(".verb-conjugation")) {
$(".verb-conjugation").empty();
}
var conjugationGridHtml =
var conjugationGridHtml =
' <div class="row verb-conjugation" id="' + verb._id + '">' +
' <div class="col-md-6 col-md-offset-3">' +
' <div class="col-md-6 center bottom">' +
Expand All @@ -498,7 +513,7 @@ function renderConjugation(verb) {
' <span class="conjugation nous">' + verb.tense.present.nous + '</span>' +
' </div>' +
' <div class="col-md-6 center bottom">' +
' <h1>Tu</h1>' +
' <h1>Tu</h1>' +
' <span class="conjugation tu">' + verb.tense.present.tu + '</span>' +
' </div>' +
' <div class="col-md-6 bottom">' +
Expand Down Expand Up @@ -539,13 +554,11 @@ function renderConjugation(verb) {
function tenseChecker(tenseCount) {
if (tenseCount === 1) {
tense = "present";
$(".current-tense").text(tense);
return tense;
} else if (tenseCount === 2) {
tense = "imparfait";
$(".current-tense").text(tense);
return tense;
}
}
$(".current-tense").text(tense);
return tense;
}

//This function will need to be updated as more tenses are added.
Expand All @@ -560,15 +573,15 @@ function conjugateVerb(infinitive, tense) {
$("input.new-verb.nous").val(stem + "ons");
$("input.new-verb.vous").val(stem + "ez");
$("input.new-verb.ils").val(stem + "ent");

} else if (family === "re") {
$("input.new-verb.je").val(stem + "s");
$("input.new-verb.tu").val(stem + "s");
$("input.new-verb.il").val(stem);
$("input.new-verb.nous").val(stem + "ons");
$("input.new-verb.vous").val(stem + "ez");
$("input.new-verb.ils").val(stem + "ent");

} else if (family === "ir") {
$("input.new-verb.je").val(stem + "is");
$("input.new-verb.tu").val(stem + "is");
Expand All @@ -594,15 +607,15 @@ function conjugateVerb(infinitive, tense) {
$("input.new-verb.nous").val(stem + "ions");
$("input.new-verb.vous").val(stem + "iez");
$("input.new-verb.ils").val(stem + "aient");

} else if (family === "re") {
$("input.new-verb.je").val(stem + "ais");
$("input.new-verb.tu").val(stem + "ais");
$("input.new-verb.il").val(stem + "ait");
$("input.new-verb.nous").val(stem + "ions");
$("input.new-verb.vous").val(stem + "iez");
$("input.new-verb.ils").val(stem + "aient");

} else if (family === "ir") {
$("input.new-verb.je").val(stem + "issais");
$("input.new-verb.tu").val(stem + "issais");
Expand All @@ -626,7 +639,7 @@ function newVerbButtonCheck(tenseCount) {
}

function renderListData(list) {
var listHtml =
var listHtml =
"<div class='row list' id='" + list._id + "' data-list-name='" + list.name + "''>" +
" <div class='col-md-10 col-md-offset-1'>" +
" <div class='panel panel-default'>" +
Expand All @@ -652,7 +665,7 @@ function renderListData(list) {
" <button class='btn btn-primary edit-list'>Edit List</button>" +
" <button class='btn btn-info quiz-launch'>Quiz me!</button>" +
" <button class='btn btn-danger delete-list'>Delete List</button>" +
" </div>" +
" </div>" +
" </div>" +
" </div>" +
"</div>";
Expand All @@ -674,7 +687,7 @@ function listOfVerbsToEdit(verb) {
}

function renderVerbDropDownMenu() {
var dropDownMenuHtml =
var dropDownMenuHtml =
' <div class="form-group drop-down">' +
' <label class="col-md-4 control-label" for="verbs">Select a new verb:</label>' +
' <div class="col-md-3 col-md-offset-1">' +
Expand Down
8 changes: 7 additions & 1 deletion public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,10 @@ span input {

#quiz {
text-align: center;
}
}

@media all and (max-width: 991px){
.center {
border-right: 0px; /* remove vertical borders from verb grid */
}
}
62 changes: 44 additions & 18 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ app.get('/lists', function homepage (req, res) {

app.get('/api/verbs', function verbList (req, res) {
db.Verb.find({}, function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});

app.post('/api/verbs', function newVerb (req, res) {
db.Verb.create(req.body, function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});
Expand All @@ -53,22 +59,31 @@ app.post('/api/verbs', function newVerb (req, res) {
// searching by infinitive
app.get('/api/verbname/:infinitive', function verbList (req, res) {
db.Verb.find(req.params, function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});

//searching by infinitive ID
app.get('/api/verbid/:_id', function verbList (req, res) {
db.Verb.findById(req.params, function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});

app.put('/api/verbid/:_id', function updateVerb (req, res) {
db.Verb.findById(req.params, function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
var selectedTense = req.body.tense;
var updatedVerb = success;
//Checks to see whether anything has actually been changed. If there is a difference, it will save it.
Expand All @@ -90,43 +105,54 @@ app.put('/api/verbid/:_id', function updateVerb (req, res) {

app.get('/api/list', function listsList (req, res) {
db.List.find({}).populate('verbs').exec(function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});

app.get('/api/list/:_id', function getListData (req, res) {
db.List.findById(req.params._id).populate('verbs').exec(function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});

app.put('/api/list/:_id', function updateListData (req, res) {
db.List.findById(req.params._id, function (err, foundList) {
var updatedList = foundList;
updatedList.name = req.body.name;
updatedList.description = req.body.description;
updatedList.verbs = req.body.verbs;
updatedList.save(function (err, savedList) {
res.send(updatedList);
});
// http://mongoosejs.com/docs/api.html#query_Query-findOneAndUpdate
db.List.findOneAndUpdate({_id: req.params._id}, req.body, function (err, updatedList) {
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(updatedList);
});
});

app.post('/api/list', function newList (req, res) {
db.List.create(req.body, function (err, success) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send(success);
});
});

app.delete('/api/list/:_id', function removeList (req, res) {
db.List.remove(req.params, function (err) {
if (err) { return console.log(err); }
if (err) {
console.log(err)
return res.status(404).json({errors: ["Bad Thing", err.message]})
}
res.send("List deleted.");
});
});

// listen on port 3000
app.listen(process.env.PORT || 3000);
app.listen(process.env.PORT || 3000);