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,48 +191,52 @@ 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(
rows,
function(row, callback) {
pool.query(
'SELECT * FROM historyGroups WHERE historyId = (?)',
[row.id],
function(err, historyGroupRows) {
var reviewFeatures = {};
_.each(historyGroupRows, function(historyGroupRow) {
reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue;
});
async.map( console.log(context.profile);
rows, console.log(reviewFeatures);
function(row, callback) { console.log('***\n');
pool.query( var groupScore = innerProduct(context.profile, reviewFeatures);
'SELECT * FROM historyGroups WHERE historyId = (?)', callback(err, groupScore);
[row.id],
function(err, historyGroupRows) {
if (err) {
throw err;
} }
);
var reviewFeatures = {}; },
_.each(historyGroupRows, function(historyGroupRow) { function(err, groupScores) {
reviewFeatures[historyGroupRow.categoryId] = historyGroupRow.categoryValue; record.groupScores = groupScores;
}); callback(err);
var groupScore = innerProduct(context.profile, reviewFeatures);
callback(err, groupScore);
}
);
},
function(err, results) {
if (err) {
throw err;
} }
);
callback(results); }
} );
);
});
}, },
function(err, results) { function(err) {
// console.log(results); if (err) {
throw err;
}
_.each(records, function(record) {
if (record.groupScores.length > 0) {
console.log(record);
}
});
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) {