1

Adding ability to reset local storage.

This commit is contained in:
Alex Yatskov 2015-03-17 15:23:57 +09:00
parent 2afbc7f77a
commit 7ba02e6fdc
3 changed files with 54 additions and 44 deletions

View File

@ -25,7 +25,8 @@
<iframe src="/profile.html" width="100%" height="250" frameborder="0"></iframe> <iframe src="/profile.html" width="100%" height="250" frameborder="0"></iframe>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button class="btn btn-default" data-dismiss="modal">OK</button> <button class="btn btn-danger" id="resetStorage">Reset</button>
<button class="btn btn-default" data-dismiss="modal">Accept</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -42,6 +42,12 @@
$('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch); $('#minScore,#hintSteps,#walkingDist,#maxResults').change(onSearch);
$('#profileDlg').on('hidden.bs.modal', onSearch); $('#profileDlg').on('hidden.bs.modal', onSearch);
$('#resetStorage').click(function() {
if (confirm('Are you sure you want to reset your profile?')) {
localStorage.clear();
$('iframe').attr('src', $('iframe').attr('src'));
}
});
window.accessReview = function(id) { window.accessReview = function(id) {
$.getJSON('/access', {id: id, profile: getProfile()}, function(results) { $.getJSON('/access', {id: id, profile: getProfile()}, function(results) {

View File

@ -191,15 +191,13 @@ function computeRecordGeo(records, context) {
} }
function computeRecordCompat(records, context, callback) { function computeRecordCompat(records, context, callback) {
console.log(context.profile); async.each(
async.map(
records, records,
function(record, callback) { function(record, callback) {
pool.query('SELECT * FROM history WHERE reviewId = (?)', [record.id], function(err, rows) { pool.query(
if (err) { 'SELECT * FROM history WHERE reviewId = (?)',
throw err; [record.id],
} function(err, rows) {
async.map( async.map(
rows, rows,
function(row, callback) { function(row, callback) {
@ -207,32 +205,38 @@ function computeRecordCompat(records, context, callback) {
'SELECT * FROM historyGroups WHERE historyId = (?)', 'SELECT * FROM historyGroups WHERE historyId = (?)',
[row.id], [row.id],
function(err, historyGroupRows) { function(err, historyGroupRows) {
if (err) {
throw err;
}
var reviewFeatures = {}; var reviewFeatures = {};
_.each(historyGroupRows, function(historyGroupRow) { _.each(historyGroupRows, function(historyGroupRow) {
reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue; reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue;
}); });
console.log(context.profile);
console.log(reviewFeatures);
console.log('***\n');
var groupScore = innerProduct(context.profile, reviewFeatures); var groupScore = innerProduct(context.profile, reviewFeatures);
callback(err, groupScore); callback(err, groupScore);
} }
); );
}, },
function(err, results) { function(err, groupScores) {
record.groupScores = groupScores;
callback(err);
}
);
}
);
},
function(err) {
if (err) { if (err) {
throw err; throw err;
} }
callback(results); _.each(records, function(record) {
if (record.groupScores.length > 0) {
console.log(record);
} }
);
}); });
},
function(err, results) {
// console.log(results);
callback(records); callback(records);
} }
); );
@ -245,8 +249,8 @@ function sanitizeQuery(query) {
'affordable', 'affordable',
'atmospheric', 'atmospheric',
'nearby', 'nearby',
'accessible' 'accessible',
// 'compatible' 'compatible'
]; ];
var features = {}; var features = {};
@ -256,11 +260,10 @@ function sanitizeQuery(query) {
query.features = features; query.features = features;
// for (var category in query.profile) { query.profile = _.reject(
// if (parseFloat(query.profile[category]) === 0) { query.profile,
// delete query.profile[category]; function(num) { return num === 0; }
// } );
// }
} }
function getCategories(callback) { function getCategories(callback) {