Skip to content

Commit

Permalink
Merge pull request #55 from sebthedev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Sebastian Hallum Clarke committed Apr 20, 2017
2 parents e6c4c05 + 278f10b commit e123ba6
Show file tree
Hide file tree
Showing 20 changed files with 791 additions and 393 deletions.
16 changes: 14 additions & 2 deletions controllers/api.js
Expand Up @@ -340,7 +340,7 @@ router.get('/course/:id', function (req, res) {
}, {
scores: 1,
semester: 1
}).sort({'semester': -1}).limit(1).populate({
}).sort({'semester': -1}).populate({
path: 'comments',
options: {
sort: {
Expand Down Expand Up @@ -405,9 +405,21 @@ router.get('/course/:id', function (req, res) {
let useOldEvaluations = queryCourse.scoresFromPreviousSemester || !queryCourse.hasOwnProperty('scores') || queryCourse.hasOwnProperty('scores') && queryCourse.scores === {}

// Insert into the queryCourse the evaluation data for the most recent semester for which evaluations exist
if (useOldEvaluations && mostRecentEvaluations.length === 1) {
if (useOldEvaluations && mostRecentEvaluations.length > 0) {
queryCourse.evaluations = mostRecentEvaluations[0].toObject()

// If there exist evaluations for a semester of this course taught by this instructor, use those evaluations instead
if (typeof (queryCourse.scoresFromPreviousSemesterSemester) === 'number') {
mostRecentEvaluations.find(function (thisPastSemesterCourse) {
if (thisPastSemesterCourse.semester._id === queryCourse.scoresFromPreviousSemesterSemester) {
queryCourse.evaluations = thisPastSemesterCourse.toObject()
return true
} else {
return false
}
})
}

// Note if the user has previously up-voted this comment
for (var commentIndex in queryCourse.evaluations.comments) {
queryCourse.evaluations.comments[commentIndex].voted = queryCourse.evaluations.comments[commentIndex].voters.indexOf(req.app.get('user')._id) > -1
Expand Down
7 changes: 5 additions & 2 deletions importers/insertMostRecentScoreIntoUnevaluatedSemesters.js
Expand Up @@ -40,7 +40,8 @@ courseModel.find({
}
}, {
'scores.Overall Quality of the Course': 1,
courseID: 1
courseID: 1,
'semester': 1
}).sort({_id: -1}).limit(1).exec())

// Find the most recent Overall Quality of the Course score taught by this instructor
Expand All @@ -58,7 +59,8 @@ courseModel.find({
instructors: course.instructors[0]._id
}, {
'scores.Overall Quality of the Course': 1,
courseID: 1
courseID: 1,
'semester': 1
}).sort({_id: -1}).limit(1).exec())
}

Expand All @@ -80,6 +82,7 @@ courseModel.find({
scores: {
'Overall Quality of the Course': mostRecentCourseWithRatings[0].scores['Overall Quality of the Course']
},
scoresFromPreviousSemesterSemester: mostRecentCourseWithRatings[0].semester._id,
scoresFromPreviousSemester: true
}, function (err) {
if (err) {
Expand Down
1 change: 1 addition & 0 deletions models/course.js
Expand Up @@ -64,6 +64,7 @@ var courseSchema = new mongoose.Schema({
}],
scores: {},
scoresFromPreviousSemester: Boolean,
scoresFromPreviousSemesterSemester: Number,
distribution: {
type: String,
uppercase: true,
Expand Down
48 changes: 0 additions & 48 deletions public/scripts/about.js
Expand Up @@ -12,30 +12,6 @@ var init_globals = function() {
document.netid = $("#netid").text()
}

// to initialize feedback mechanism
var init_feedback = function() {
// submission
$('#feedback-form').submit(function() {
if ($('#feedback-text').val().length > 0)
{
var submitURL = ''
submitURL += 'https://docs.google.com/a/princeton.edu/forms/d/e/1FAIpQLSdX3VTSbVfwOOtwMxhWiryQFrlBNuJDUTlp-lUmsV-S0xFM_g/formResponse?'
submitURL += 'entry.1257302391=' + document.netid
submitURL += '&entry.680057223=' + encodeURIComponent($('#feedback-text').val())

$(this)[0].action = submitURL
$('#feedback-submit').text('Thank You!')
$('#feedback-submit').addClass('disabled')
$('#feedback-text').attr('disabled', true)
setTimeout(toggleFeedback, 1000)
}
else {
$('#feedback-text').attr("placeholder", "Please enter feedback.");
}
})
$('#feedback-toggle').click(function() {return toggleNavbar('feedback')})
}

// to intialize logout button
var init_logout = function() {
$('#menu-bar').mouseleave(function() {
Expand All @@ -50,30 +26,6 @@ var init_logout = function() {
})
}

// to initialize updates popup
var init_updates = function() {
var updateMessage = 'You can now search for instructors. Also, take a look at Search Suggestions!'
var updateNo = 0 // BENSU: increment this number for new updates
var updateNoStored = localStorage.getItem('updateNo'); //last update seen by user
$("#updates-bottom-popup").append(updateMessage);
if (updateNo != updateNoStored) // new update
{
localStorage.setItem('updateRead', 'False');
setTimeout(function() {
$('#updates-bottom-popup').show();
}, 1000); // milliseconds
localStorage.setItem('updateNo', updateNo);
}
else {
var updateRead = localStorage.getItem('updateRead');
if (updateRead !== 'True') {
setTimeout(function() {
$('#updates-bottom-popup').show();
}, 1000); // milliseconds
}
}
}

// toggles the feedback form
function toggleNavbar(element) {
toggleFeedback()
Expand Down
111 changes: 67 additions & 44 deletions public/scripts/app.js
@@ -1,9 +1,10 @@
// dependencies: module.js, search.js, display.js, resizable.js, navbar.js, suggest.js
// dependencies: module.js, search.js, display.js, resizable.js, navbar.js, suggest.js, layout.js

// initialization
$(document).ready(function() {

/* init_load(); MEL: now loads after semesters have been loaded in init_search */
init_layout();
init_panes();
init_searchpane();
init_search();
Expand All @@ -19,49 +20,32 @@ $(document).ready(function() {

// loads course from url
var init_load = function () {
// Parse and display search parameters, if any exist
parseSearchParameters()
var courseId = ''

// Parse course from the URL to determine which course (if any) to display on pageload
var pathnameMatch = /^\/course\/(\d+)$/.exec(window.location.pathname)
if (pathnameMatch !== null && pathnameMatch.length === 2) {
// Load the course
courseId = parseInt(pathnameMatch[1])
if (!isNaN(courseId)) displayCourseDetails(courseId)
if (!isNaN(courseId)) {
displayCourseDetails(courseId)
var courseDisplayed = true;
}
}
}

// Handle displaying a course after pushing the back/forward button in the browser
window.onpopstate = function (event) {
if (event.state && event.state.courseID) {
displayCourseDetails(event.state.courseID)
}
parseSearchParameters()
}
// Parse search parameters, if any exist
var parameters = parseSearchParameters(window.location.search)

// perform search
searchForCourses(parameters.search, parameters.semester, parameters.sort)

// initialize history
history_init(courseId, window.location.search)

// handle displaying default page
if (courseId === '' && (parameters.search === undefined || parameters.search === ''))
displayCourseDetails(courseId)

// Parse the URL to check for whether the app should be showing a course and displaying any search terms
var parseSearchParameters = function () {
// Parse search terms
var unparsedParameters = window.location.search.replace('?', '').split('&')
var parameters = {}
for (var parametersIndex in unparsedParameters) {
var keyValue = unparsedParameters[parametersIndex].split('=')
if (keyValue.length === 2) {
parameters[keyValue[0]] = decodeURIComponent(keyValue[1])
}
}
if (parameters.hasOwnProperty('search')) {
$('#searchbox').val(parameters.search)
}
if (parameters.hasOwnProperty('semester')) {
$('#semester').data('query', parameters.semester).val(parameters.semester)
}
if (parameters.hasOwnProperty('sort')) {
$('#sort').val(parameters.sort)
}
if (parameters !== {}) {
searchForCourses()
}
}

// to initialize draggability
Expand Down Expand Up @@ -121,9 +105,22 @@ var init_searchpane = function() {

// to initialize searching function
var init_search = function() {
// Every time a key is pressed inside the #searchbox, call the searchForCourses function
$('#searchbox').on('input', searchForCourses)
$('#semester, #sort').change(searchForCourses)
// restore sort used
var savedSort = localStorage.getItem("sort");
$('#sort').val((savedSort !== undefined && savedSort !== null) ? savedSort : "commonName")

// Every time a key is pressed inside the #searchbox, search
$('#searchbox').on('input', searchFromBox)
$('#semester, #sort').change(searchFromBox)

// Allow clicking the "Search" keyboard button on mobile
if (document.isMobile) {
$('#searchbox').keypress(function (event) {
if (event.keyCode === 13) {
$(this).blur()
}
})
}

// load the semesters for the dropdown
$('#semester').children(":not([disabled])").remove()
Expand Down Expand Up @@ -175,13 +172,13 @@ var init_favorites = function() {
var init_feedback = function() {
// submission
$('#feedback-form').submit(function() {
if ($('#feedback-text').val().length > 0)
if ($('#feedback-text').val().length > 0)
{
var submitURL = ''
submitURL += 'https://docs.google.com/a/princeton.edu/forms/d/e/1FAIpQLSdX3VTSbVfwOOtwMxhWiryQFrlBNuJDUTlp-lUmsV-S0xFM_g/formResponse?'
submitURL += 'entry.1257302391=' + document.netid
submitURL += '&entry.680057223=' + encodeURIComponent($('#feedback-text').val())

$(this)[0].action = submitURL
$('#feedback-submit').text('Thank You!')
$('#feedback-submit').addClass('disabled')
Expand Down Expand Up @@ -219,12 +216,18 @@ var init_evals = function() {
var init_logout = function() {
$('#menu-bar').mouseleave(function() {
var isNetidInvisible = $('#netid').css('display') === 'none'
if (isNetidInvisible) $('#netid, #logout').animate({width: 'toggle'})
if (isNetidInvisible) {
if (document.isMobile) $('#netid, #logout').slideToggle()
else $('#netid, #logout').animate({width: 'toggle'})
}
})

$('#netid').click(function() {
var isLogoutVisible = $('#logout').css('display') !== 'none'
if (!isLogoutVisible) $('#netid, #logout').animate({width: 'toggle'})
if (!isLogoutVisible) {
if (document.isMobile) $('#netid, #logout').slideToggle()
else $('#netid, #logout').animate({width: 'toggle'})
}
return false;
})
}
Expand All @@ -241,8 +244,8 @@ var init_suggest = function() {

// to initialize updates popup
var init_updates = function() {
var updateMessage = 'You can now search for instructors. Also, take a look at Search Suggestions!'
var updateNo = 0 // BENSU: increment this number for new updates
var updateMessage = 'Princeton Courses is now optimized for mobile. Feel free to browse comfortably on any device. Happy course selection!'
var updateNo = 1 // BENSU: increment this number for new updates
var updateNoStored = localStorage.getItem('updateNo'); //last update seen by user
$("#updates-bottom-popup").append(updateMessage);
if (updateNo != updateNoStored) // new update
Expand Down Expand Up @@ -278,3 +281,23 @@ var section_toggle = function(pane, section) {
var saveUpdatePopupState = function() {
localStorage.setItem('updateRead', 'True');
}

// to initialize responsive layout
var init_layout = function() {
// initial layout
var width = $(window).width()
document.isMobile = (width < WIDTH_THRESHOLD)
if (document.isMobile) layout_mobile()
else layout_desktop()

layout_initial_show()

// bind to resizing
$(window).resize(layout_refresh)

$('#menu-back').click(function() {
window.history.back();
})

document.isReady = true;
}

0 comments on commit e123ba6

Please sign in to comment.