Skip to content

Commit

Permalink
Merge pull request Chore-Swap#90 from sarahlessner/sarah-branch-10
Browse files Browse the repository at this point in the history
cleaned up some comments and excess console logs commented out, added…
  • Loading branch information
sarahlessner committed Aug 25, 2017
2 parents 9302e13 + c8a2a96 commit 2af3a4d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 48 deletions.
6 changes: 4 additions & 2 deletions assets/js/exchange_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ $(document).ready(function() {
// console.log($(this).parent().children()[2]);
$($(this).parent().children()[2]).slideToggle();
});
//on click for delete button to call delete offer function

$(document).on("click", '.delete-offer-btn', function(){
event.preventDefault();
deleteOffer(parseInt(this.value));
});

//function to remove an offer - called by on click
//also called by condition of removal of all wanteds for the offer
function deleteOffer(offerid) {
$.ajax({
method: "DELETE",
Expand All @@ -88,7 +90,7 @@ $(document).ready(function() {
.done(displayUserOffers);
console.log("delete offered button what are you?", offerid);
};

//function to remove a wanted item on click
$(document).on("click", '.delete-wanted-btn', function(){
event.preventDefault();
// alert(($(this).parent().parent()).toString());
Expand Down
39 changes: 21 additions & 18 deletions assets/js/match_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ $(document).ready(function() {
// $("#main_results").append("<p>" + "calculating perfect matches..." + "<p>");
$("#main_results").append('<img src="https://loading.io/spinners/color-bar/lg.colorful-progress-loader.gif"/>');
console.log("running displayPerfect");
//TODO: Enable ID from local storage for 'production'
var userid = localStorage.userid;
// var userid = 1;
//TODO: figure out where UserId param ought to come
//from the page redirect/data

$.get("/homepage/perfectmatch/" + userid, function(data) {
$("#main_results").empty();
console.log("PERFECT MATCH", data);
if (data.length === 0) {
// console.log("sorry, no matches here");
//if there aren't any matches - display images
$("#main_results").append('<img id="no_matches" src="../img/sorry.png"/>')
.append('<h3 style="color:#4e638a">No Matches Found. Adding more skills can help!</h3>')
.append('<button id="add_button2">Add another skill?</button>')
} else {
//match display logic - put match name/skills matching to the page
//include email for sending and photo for user
for (var i = 0; i < data.length; i++) {
//block user from seeing their own matches
if (isNotCurrentUser(data[i][0].User.id, localStorage.userid)) {

var email = data[i][0].User.email;
Expand All @@ -57,7 +58,8 @@ $(document).ready(function() {
}
});
};

//function to display offer matches to the user - those offering what the user wants
//regardless of if the user is offering something they want in return
function displayOfferMatch() {
// $(".da_tabs").removeClass("active");
// $(this).addClass("active");
Expand All @@ -67,14 +69,17 @@ $(document).ready(function() {
var userid = localStorage.userid;
$.get("/homepage/offermatch/" + userid, function(data) {
$("#main_results").empty();
//if no offer matches
// console.log("OK Match", data);
if(data.length === 0){
$("#main_results").append('<img id="no_matches" src="../img/sorry.png"/>')
.append('<h3 style="color:#4e638a">No Matches Found. Adding more skills can help!</h3>')
.append('<button id="add_button2">Add another skill?</button>')
} else{
//display offer matches - name, photo, skills, etc
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
//block user from seeing their own matches
if (isNotCurrentUser(data[i][j].User.id, localStorage.userid)) {

var email = data[i][j].User.email;
Expand All @@ -94,7 +99,7 @@ $(document).ready(function() {
'<a href="mailto:'+email+'?Subject=Wanna%20Swap?" target="_top" class="mailto"><button class="match_buttons">Contact</button></a>' +
'</div>' +
'</div>';

//append matches to page
$("#main_results").append(offer_match_html);
}
}
Expand All @@ -112,45 +117,46 @@ $(document).ready(function() {

$.get("/alloffersbyskill", function(data) {
$("#main_results").empty();
// NOTE: this is a dummy email for now, but we need to fetch it from
//the back end later
// var email = "studentskillswap@gmail.com";
// console.log(data);

// console.log("All Skills Joined w Offers", data);
//create a button for each skill
for (var i = 0; i < data.length; i++) {
console.log("data", data[i]);

//set added div to false for each offer
var addedDiv = false;
var $skills;

for (var j = 0; j < data[i].length; j++) {
//get each users email
var email = data[i][j].User.email;
// console.log(data[i]);
//make sure use doesn't see their own matches
if (isNotCurrentUser(data[i][j].User.id, localStorage.userid)) {
//check if no div was already added for the skill
if (!addedDiv) {
$skills = $('<div class="all_skills"></div>');
$skills.append($('<h3>' + data[i][0].Skill.skill_name + '</h3>'));
addedDiv = true;
}

//display users offering that skill
var user_html = '<div class="all_users">' +
'<h4>' + data[i][j].User.name + '</h4>' +
'<img class="all_users_pics" src="' + data[i][j].User.photo + '"/>' +
'<a href="mailto:'+email+'?Subject=Wanna%20Swap?" target="_top" class="mailto"><button class="all_users_buttons">Contact</button></a>' +
'</div>';

//append each user offering the skill to div for that skill
$skills.append(user_html);
}
}
//append skills div to page
$("#main_results").append($skills);


}

});
};

//on clicks that also trigger each function
$("#perfectmatch").on("click", displayPerfect);
$("#offermatch").on("click", displayOfferMatch);
$("#offersbyskill").on("click", displayOffersBySkill);
Expand All @@ -160,15 +166,12 @@ $(document).ready(function() {
}

//broke this function out just to try my hand at testing
"use strict";
//but then learned it's not test-able
var isNotCurrentUser = function(matchid, userid) {
if (matchid != userid) {
return true;
}
};
//for testing
// module.exports = isNotCurrentUser;
//document.ready end


});
14 changes: 7 additions & 7 deletions controllers/add_skills_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var SAVED_OFFER_ID;
var wanted_skill_ids;

module.exports = function(app) {

//route to add skills page and get all of the skills from skills table
app.get("/signin", function(req, res) {

db.Skill.findAll({}).then(function(data) {
Expand All @@ -19,12 +19,12 @@ module.exports = function(app) {
});
});


//post a swap - creates an offer first
app.post("/newexchange", function(req, res) {

var temp = req.body.offereds.offer;
offered_skill_id = temp;
console.log("Offered skill ids is " + temp);
// console.log("Offered skill ids is " + temp);

db.Offered.findOrCreate({
where: {
Expand All @@ -35,10 +35,10 @@ module.exports = function(app) {
SkillId: parseInt(temp),
UserId: parseInt(req.body.offereds.userid)
}

//once the offer is created
}).then(function(offerskill) {
// INSERT THE 2ND THINGY THAT CREATED THE WANTEDS
console.log("added offered skill", offerskill[1]);
// use the offer id to populate wanted table along with skill and user
// console.log("added offered skill", offerskill[1]);
var created = offerskill[1];


Expand All @@ -64,7 +64,7 @@ module.exports = function(app) {
//TODO: pass some kind of message to the front end so the user is alerted
//that they are trying to create a dupe offer
if (!created) {
console.log("you're already offering that item");
// console.log("you're already offering that item");
res.send({direction: "signin",
reply: "You already have this offer!"});
} else {
Expand Down
12 changes: 6 additions & 6 deletions controllers/update_skills_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const db = require(path.join(__dirname,".." ,"models"));

module.exports = function(app) {
//all app.gets, post, etc need to live here

//get all the users current offers and then the things they want for those offers
app.get("/update-skills/:currentUser", function(req, res) {
db.Offered
.findAll({
Expand All @@ -14,7 +14,7 @@ module.exports = function(app) {
},
include: [{ model: db.Skill }]
})
.then(function(useroffers) {
.then(function(useroffers) { // returns all the users offers
// console.log("USER OFFERS FROM UPDATE", useroffers);
// console.log("SKILLZ", useroffers[0].Skill.skill_name);
Promise.all(
Expand All @@ -27,23 +27,23 @@ module.exports = function(app) {
},
include: [{ model: db.Skill }]
})
)).then(wanted => {
)).then(wanted => { // returns all the things they want per each offer
// TODO Math `useroffers` with `values` (combining 2 arrays)
res.json({useroffers: useroffers, wanted:wanted});
res.json({useroffers: useroffers, wanted:wanted}); // send over 2 arrays of objects
// console.log(JSON.stringify({useroffers: useroffers, values:values}))
});
});
//end of app.get
});

//delete offer route
app.delete("/update-skills/offers/:offerId", function(req, res) {
db.Offered.destroy({
where: {id: req.params.offerId}
}).then(function(deleteoffer) {
res.json(deleteoffer);
});
});

//delete wanted route
app.delete("/update-skills/wanteds/:wantedId", function(req, res) {
db.Wanted.destroy({
where: {id: req.params.wantedId}
Expand Down
15 changes: 0 additions & 15 deletions test/match_display_test.js

This file was deleted.

0 comments on commit 2af3a4d

Please sign in to comment.