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