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>
</div>
<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>

View File

@ -42,6 +42,12 @@
$('#minScore,#hintSteps,#walkingDist,#maxResults').change(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) {
$.getJSON('/access', {id: id, profile: getProfile()}, function(results) {

View File

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