Permalink
Browse files

Merge pull request #1109 from mapbox/remember-path

remember user paths in file browser
  • Loading branch information...
samanpwbb committed Dec 20, 2014
2 parents 4d6bb14 + c6edb1a commit 953ecc35ff6eca3fb5f1caf099ec46f85e86c60c
Showing with 39 additions and 4 deletions.
  1. +23 −3 app/lib.js
  2. +16 −1 app/test/app.test.style.js
View
@@ -142,13 +142,17 @@ views.Browser.prototype.initialize = function(options, initCallback) {
this.filter = options.filter || function(f) { return true; };
this.isFile = options.isFile || function() {};
this.isProject = options.isProject || function() {};
this.cwd = this.$('input[name=cwd]').val();
this.cwd = localStorage.getItem(window.location.pathname.split('/').pop() + $(this.el).attr('id')) || this.$('input[name=cwd]').val();
return this.render();
};
views.Browser.prototype.render = function() {
var view = this;
var win = view.cwd.indexOf(':') === 1;
var sep = win ? '\\' : '/';
// Store path for each modal type separately, with separate values saved for Source and Style.
localStorage.setItem(window.location.pathname.split('/').pop() + $(this.el).attr('id'), view.cwd);
$.ajax({
url: '/browse?path=' + view.cwd,
dataType: 'json',
@@ -176,8 +180,24 @@ views.Browser.prototype.render = function() {
// Reset scroll position to top.
view.$('.list').get(0).scrollTop = 0;
},
// @TODO
error: function(resp) {}
error: function(resp) {
// If path is already set to root and errors, give up
if (view.cwd === '/') return Modal.show('error', resp.responseText);
// Assume localstorage path doesn't exist, try default path
var newPath = view.$('input[name=cwd]').val();
// If default path returned error, set path to root
if (view.cwd === newPath) {
newPath = '/';
}
// Try again
localStorage.setItem(window.location.pathname.split('/').pop() + $(this.el).attr('id'), newPath);
view.cwd = newPath;
view.render();
}
});
};
View
@@ -182,10 +182,25 @@ tape('#settings-form', function(t) {
});
tape('.js-history browses projects', function(t) {
localStorage.clear();
var path = cwd;
$('.js-history browses projects')
t.ok(!hasModal('#browseproject'));
$('.js-history .js-browseproject').click();
t.ok(hasModal('#browseproject'));
t.end();
t.ok(localStorage.getItem('stylebrowseproject') === path, ' intial key/value in localstorage equals path.');
onajax(function() {
var destination = $('#browseproject .folder:eq(0)').attr('href').split('#').pop();
// requires double click
$('#browseproject .folder:eq(0)').click().click();
onajax(function() {
t.ok(localStorage.getItem('stylebrowseproject') === destination, ' new path saved to localstorage.');
localStorage.clear();
t.end();
});
});
});
tape('stylesheet error ', function(t) {

0 comments on commit 953ecc3

Please sign in to comment.