forked from git-ankit/MovieRecommender
-
Notifications
You must be signed in to change notification settings - Fork 4
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 #17 from adipai/ui-branch
improve ui and integrate with sendMail api
- Loading branch information
Showing
6 changed files
with
259 additions
and
195 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
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,188 @@ | ||
$(document).ready(function () { | ||
$(function () { | ||
$("#searchBox").autocomplete({ | ||
source: function (request, response) { | ||
$.ajax({ | ||
type: "POST", | ||
url: "http://localhost:5000/search", | ||
dataType: "json", | ||
cache: false, | ||
data: { | ||
q: request.term, | ||
}, | ||
success: function (data) { | ||
//alert(data); | ||
// console.log(data); | ||
response(data); | ||
}, | ||
error: function (jqXHR, textStatus, errorThrown) { | ||
console.log(textStatus + " " + errorThrown); | ||
}, | ||
}); | ||
}, | ||
select: function (event, ui) { | ||
var ulList = $("#selectedMovies"); | ||
// Check if the value already exists in the list | ||
if (ulList.find('li:contains("' + ui.item.value + '")').length > 0) { | ||
$("#searchBox").val(""); | ||
return false; | ||
} | ||
|
||
var li = $("<li class='list-group-item'/>") | ||
.text(ui.item.value) | ||
.appendTo(ulList); | ||
$("#searchBox").val(""); | ||
return false; | ||
}, | ||
|
||
// changed the min-length for searching movies from 2 to 1 | ||
minLength: 1, | ||
}); | ||
}); | ||
|
||
$("#predict").click(function () { | ||
var movie_list = []; | ||
|
||
$("#selectedMovies li").each(function () { | ||
movie_list.push($(this).text()); | ||
}); | ||
|
||
var movies = { movie_list: movie_list }; | ||
|
||
// Clear the existing recommendations | ||
$("#predictedMovies").empty(); | ||
|
||
// if movies list empty then throw an error box saying select atleast 1 movie!! | ||
if (movie_list.length == 0) { | ||
alert("Select atleast 1 movie!!"); | ||
} | ||
|
||
$.ajax({ | ||
type: "POST", | ||
url: "/predict", | ||
dataType: "json", | ||
contentType: "application/json;charset=UTF-8", | ||
traditional: "true", | ||
cache: false, | ||
data: JSON.stringify(movies), | ||
success: function (response) { | ||
var ulList = $("#predictedMovies"); | ||
var i = 0; | ||
response["recommendations"].forEach((element) => { | ||
var diventry = $("<div/>"); | ||
var fieldset = $("<fieldset/>", { id: i }).css("border", "0"); | ||
var li = $("<li/>").text(element); | ||
var radios = $(` | ||
<table class='table'> | ||
<tr> | ||
<td class='radio-inline'> | ||
<label><input type='radio' name="${i}" value='1'>Dislike</label> | ||
</td> | ||
<td class='radio-inline'> | ||
<label><input type='radio' name="${i}" value='2'>Yet to watch</label> | ||
</td> | ||
<td class='radio-inline'> | ||
<label><input type='radio' name="${i}" value='3'>Like</label> | ||
</td> | ||
</tr> | ||
</table> | ||
`); | ||
|
||
diventry.append(li); | ||
diventry.append(radios); | ||
fieldset.append(diventry); | ||
ulList.append(fieldset); | ||
i += 1; | ||
}); | ||
|
||
// var li = $('<li/>').text() | ||
console.log("->", response["recommendations"]); | ||
}, | ||
error: function (error) { | ||
console.log("ERROR ->" + error); | ||
}, | ||
}); | ||
}); | ||
|
||
var FeedbackData; | ||
|
||
$("#feedback").click(function () { | ||
notifyMeButton = document.getElementById("checkbox"); | ||
notifyMeButton.disabled = false; | ||
var myForm = $("fieldset"); | ||
var data = {}; | ||
var labels = { | ||
1: "Dislike", | ||
2: "Yet to watch", | ||
3: "Like", | ||
}; | ||
var error = false; // Flag to track errors | ||
|
||
for (var i = 0; i < myForm.length; i++) { | ||
var input = $("#" + i) | ||
.find("div") | ||
.find("input:checked")[0]; | ||
var movieName = $("#" + i) | ||
.find("div") | ||
.find("li")[0].innerText; | ||
|
||
if (!input) { | ||
// If no selection is made, set error flag to true and break the loop | ||
error = true; | ||
break; | ||
} | ||
|
||
data[movieName] = labels[input.value]; | ||
} | ||
|
||
if (error) { | ||
// Display an error message if there are missing selections | ||
alert("Please select a feedback for all movies."); | ||
return; // Exit the function without making the AJAX call | ||
} | ||
|
||
console.log(data); | ||
FeedbackData = data; | ||
localStorage.setItem("fbData", JSON.stringify(data)); | ||
console.log(localStorage.getItem("fbData")); | ||
$.ajax({ | ||
type: "POST", | ||
url: "/feedback", | ||
dataType: "json", | ||
contentType: "application/json;charset=UTF-8", | ||
traditional: "true", | ||
cache: false, | ||
data: JSON.stringify(data), | ||
success: function (response) { | ||
window.location.href = "/success"; | ||
console.log("Success"); | ||
}, | ||
error: function (error) { | ||
console.log("ERROR ->" + error); | ||
}, | ||
}); | ||
}); | ||
|
||
$("#notifyButton").click(function () { | ||
data = JSON.parse(localStorage.getItem("fbData")); | ||
var emailString = $("#emailField").val(); | ||
data.email = emailString; | ||
$.ajax({ | ||
type: "POST", | ||
url: "/sendMail", | ||
dataType: "json", | ||
contentType: "application/json;charset=UTF-8", | ||
traditional: "true", | ||
cache: false, | ||
data: JSON.stringify(data), | ||
success: function (response) { | ||
localStorage.removeItem("fbData"); | ||
console.log(response); | ||
}, | ||
error: function (error) { | ||
console.log("ERROR ->" + error); | ||
localStorage.removeItem("fbData"); | ||
}, | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.