Skip to content

Commit

Permalink
Merge pull request #1 from sz3/dev
Browse files Browse the repository at this point in the history
Zoom settings + multiple concurrent uploads
  • Loading branch information
sz3 committed Feb 22, 2020
2 parents 2fadc47 + 1aef149 commit 34cab3c
Show file tree
Hide file tree
Showing 22 changed files with 236 additions and 29 deletions.
18 changes: 18 additions & 0 deletions js_tests/mock_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ return {
return _thenDoIt(_response['removeKeyfile']);
},

zoom : function()
{
_calls.push('zoom()');
return _thenDoIt(_response['zoom']);
},

zoomChange : function(amount)
{
_calls.push('zoomChange(' + amount + ')');
return _thenDoIt(_response['zoomChange']);
},

zoomReset : function()
{
_calls.push('zoomReset()');
return _thenDoIt(_response['zoomReset']);
},

downloadArchive : function(mfn)
{
_calls.push('downloadArchive(' + mfn + ')');
Expand Down
2 changes: 2 additions & 0 deletions js_tests/test_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ QUnit.config.reorder = false;
QUnit.testStart(function(details) {
FileBrowser.get('open-archive').clear();
FileBrowser.get('open-archive').showFiles([
{'path': ''},
{'path': 's3:bucket/'},
{'path': 's3:bucket/dir/'},
{'path': 's3:bucket/dir/foo'},
{'path': 's3:bucket/file.txt'},
{'path': 'local:local.mfn'},
{'path': 'local:local2.mfn'},
{'path': 'local:mydir/'},
{'path': 'local:mydir/home/'},
{'path': 'local:mydir/home/1.txt'}
Expand Down
21 changes: 18 additions & 3 deletions js_tests/test_filebrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ QUnit.test( "initial load manifest list", function( assert ) {
var files = getFiles('open-archive');

assert.deepEqual( folders, ['s3:bucket/', 'local:mydir/'] );
assert.deepEqual( files, ['local:local.mfn'] );
assert.deepEqual( files, ['local:local.mfn', 'local:local2.mfn'] );
});

QUnit.test( "open dir", function( assert ) {
Expand Down Expand Up @@ -71,7 +71,7 @@ QUnit.test( "breadcrumbs", function( assert ) {
});

QUnit.test( "refresh", function( assert ) {
Api.setResponseForCall('listManifests', [{'path': 's3:mfns/'}, {'path': 'refresh.mfn'}]);
Api.setResponseForCall('listManifests', [{'path': ''}, {'path': 's3:mfns/'}, {'path': 'refresh.mfn'}]);

// dig in
$('#open-archive a.folders')[0].click();
Expand All @@ -88,7 +88,7 @@ QUnit.test( "refresh", function( assert ) {
});

QUnit.test( "open archive and download", function( assert ) {
Api.setResponseForCall('scanManifest', [{'path': 'zdir/'}, {'path': '1.txt'}]);
Api.setResponseForCall('scanManifest', [{'path': ''}, {'path': 'zdir/'}, {'path': '1.txt'}]);

$('#open-archive a.files')[0].click();

Expand All @@ -110,3 +110,18 @@ QUnit.test( "open archive and download", function( assert ) {

assert.deepEqual(Api.calls(), ['downloadArchive(local:local.mfn)']);
});

QUnit.test( "open archive with absolute paths", function( assert ) {
Api.setResponseForCall('scanManifest', [{'path': '/'}, {'path': '/dir/'}, {'path': '/dir/file.txt'}]);

$('#open-archive a.files')[1].click();

assert.equal(window.location.hash, '#local:local2.mfn');
assert.deepEqual(Api.calls(), ['scanManifest(local:local2.mfn)']);

var folders = getFolders('local:local2.mfn');
var files = getFiles('local:local2.mfn');

assert.deepEqual( folders, ['/dir/'] );
assert.deepEqual( files, [] );
});
48 changes: 48 additions & 0 deletions js_tests/test_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,51 @@ QUnit.test( "remove keyfile", function( assert ) {
assert.deepEqual(Api.calls(), ['removeKeyfile(key.one)']);
assert.deepEqual(getKeyfileEntries(), ['/path/to/key']);
});

QUnit.test( "change zoom", function( assert ) {
settingsSetup();
Api.setResponseForCall('zoomChange', 120);
Api.setResponseForCall('zoomReset', 100);

// increase zoom
$('#settings .zoom-setting button')[2].click();

assert.deepEqual(Api.calls(), ['zoomChange(10)']);
assert.equal(document.body.style.zoom, '120%');
Api.clear();

// decrease zoom
$('#settings .zoom-setting button')[0].click();
assert.deepEqual(Api.calls(), ['zoomChange(-10)']);
Api.clear();

// reset zoom
$('#settings .zoom-setting button')[1].click();
assert.deepEqual(Api.calls(), ['zoomReset()']);
assert.equal(document.body.style.zoom, '100%');
});

QUnit.test( "change zoom", function( assert ) {
settingsSetup();
Api.setResponseForCall('zoomChange', 120);
Api.setResponseForCall('zoomReset', 100);

// increase zoom
$('#settings .zoom-setting button')[2].click();

assert.deepEqual(Api.calls(), ['zoomChange(10)']);
assert.equal(document.body.style.zoom, '120%');
assert.equal($('#settings .zoom-setting-current').text(), '120%');
Api.clear();

// decrease zoom
$('#settings .zoom-setting button')[0].click();
assert.deepEqual(Api.calls(), ['zoomChange(-10)']);
Api.clear();

// reset zoom
$('#settings .zoom-setting-current').click();
assert.deepEqual(Api.calls(), ['zoomReset()']);
assert.equal(document.body.style.zoom, '100%');
assert.equal($('#settings .zoom-setting-current').text(), '100%');
});
7 changes: 7 additions & 0 deletions js_tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ <h2 class="content-subhead">Add Remote Storage</h2>
<h2 class="content-subhead">Keyfiles</h2>
<form id="settings-keyfiles" class="pog-checklist"></form>
<button class="pure-button settings-keyfiles-add" href="javascript:;" onclick="Settings.updateKeyfilesDir()">Find</button>

<h2 class="content-subhead">Zoom</h2>
<div class="pure-button-group zoom-setting" role="group" aria-label="...">
<button class="pure-button" href="javascript:;" onclick="Settings.zoomOut()">-</button>
<button class="zoom-setting-current pure-button" href="javascript:;" onclick="Settings.zoomReset()">100%</button>
<button class="pure-button" href="javascript:;" onclick="Settings.zoomIn()">+</button>
</div>
</div>

<div id="create-archive" class="page create-archive">
Expand Down
4 changes: 4 additions & 0 deletions pogui/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __setitem__(self, key, value):
def get(self, key, default=None):
return self.content.get(key) or default

def unset(self, key):
self.content.pop(key, None)
self.save()

def lpush(self, key, elem):
current = set(self.get(key, []))
current.add(elem)
Expand Down
2 changes: 2 additions & 0 deletions pogui/lib/async_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def _list_manifests(self, loc):

def _collect_result(self, res):
self.total = list(itertools.chain(*res))
if self.total:
self.total = [{'path': ''}] + self.total

def wait(self):
self.waiter.wait()
Expand Down
2 changes: 1 addition & 1 deletion pogui/lib/path_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def backfill_parent_dirs(paths):
paths = list(paths)
all_paths = set(paths)
for p in paths:
while p:
while p and p != '/':
p = _dirname(p)
if p in all_paths:
break
Expand Down
32 changes: 28 additions & 4 deletions pogui/pogui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, config):
self.config = config
self.cli.set_keyfiles(*self.config.get('keyfiles', []))
self._refresh_list_manifests()
self._progress_count = 0

def _refresh_list_manifests(self):
locations = self.config.get('fs', []) + ['local']
Expand Down Expand Up @@ -82,6 +83,18 @@ def removeKeyfile(self, path):
def listKeyfiles(self, __=None):
return self.config.get('keyfiles', [])

def zoom(self, __=None):
return self.config.get('zoom', 100)

def zoomChange(self, amount):
new_zoom = self.zoom() + amount;
self.config['zoom'] = new_zoom
return new_zoom

def zoomReset(self, __=None):
self.config.unset('zoom')
return self.zoom()

def listManifests(self, __=None):
self._refresh_list_manifests()
return self.waitForManifests()
Expand All @@ -97,12 +110,12 @@ def scanManifest(self, mfn):
paths = backfill_parent_dirs(blobs.keys())
return [{'path': p, **blob_details(p, blobs.get(p))} for p in paths]

def _backgroundProgress(self, status_iter, mfn, dest_path=None):
def _backgroundProgress(self, status_iter, progress_id, dest_path=None):
for info in status_iter:
# need to snapshot these better
percent = info['current'] * 100 / info['total']
print('giving {} to window'.format(info))
window.evaluate_js("ProgressBar.update('{}', '{:.2f}%');".format(mfn, percent))
window.evaluate_js("ProgressBar.update('{}', '{:.2f}%');".format(progress_id, percent))

if dest_path:
system_open_folder(dest_path)
Expand All @@ -120,10 +133,15 @@ def downloadArchive(self, mfn):

status_iter = self.cli.decrypt(real_mfn_path, cwd=path)
first_chunk = next(status_iter)

self._progress_count += 1
progress_id = f'{mfn}.{self._progress_count}'
Thread(
target=self._backgroundProgress,
kwargs={'status_iter': status_iter, 'mfn': mfn, 'dest_path': path}
kwargs={'status_iter': status_iter, 'progress_id': progress_id, 'dest_path': path}
).start()

first_chunk['progress_id'] = progress_id
return first_chunk

def downloadFile(self, params):
Expand All @@ -135,10 +153,15 @@ def createArchive(self, params):
paths, destinations = params
status_iter = self.cli.encrypt(paths, destinations)
first_chunk = next(status_iter)

self._progress_count += 1
progress_id = f'NewArchive.{self._progress_count}'
Thread(
target=self._backgroundProgress,
kwargs={'status_iter': status_iter, 'mfn': 'create-archive'}
kwargs={'status_iter': status_iter, 'progress_id': progress_id}
).start()

first_chunk['progress_id'] = progress_id
return first_chunk

def getLocalFolders(self, __=None):
Expand All @@ -162,6 +185,7 @@ def load_page_data(window):
'waitForManifests',
'listFS',
'listKeyfiles',
'zoom',
]
for fun in startups:
js = 'Page.pyinit("{}");'.format(fun)
Expand Down
15 changes: 15 additions & 0 deletions pogui/web/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ return {
return window.pywebview.api.removeKeyfile(entry).catch(Page.showMessage);
},

zoom : function()
{
return window.pywebview.api.zoom().catch(Page.showMessage);
},

zoomChange : function(amount)
{
return window.pywebview.api.zoomChange(amount).catch(Page.showMessage);
},

zoomReset : function()
{
return window.pywebview.api.zoomReset().catch(Page.showMessage);
},

downloadArchive : function(mfn)
{
return window.pywebview.api.downloadArchive(mfn).catch(Page.showMessage);
Expand Down
3 changes: 2 additions & 1 deletion pogui/web/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ return {
var targets = {
'waitForManifests': FileBrowser.get('open-archive').showFiles,
'listFS': Settings.refreshRemoteStorageView,
'listKeyfiles': Settings.refreshKeyfilesView
'listKeyfiles': Settings.refreshKeyfilesView,
'zoom': Settings.zoom
};
Api[apifun]().then(targets[apifun]);
},
Expand Down
5 changes: 3 additions & 2 deletions pogui/web/create-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ return {
{
var paths = CheckList.get('create-archive-list').items();
var destinations = CreateArchive.getDestinations();
Api.createArchive(paths, destinations).then(function() {
ProgressBar.add('create-archive');
Api.createArchive(paths, destinations).then(function(res) {
if (res)
ProgressBar.add(res['progress_id']);
});
}
}
Expand Down
14 changes: 11 additions & 3 deletions pogui/web/filebrowser/fb-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ var _response = [],
// public methods
// Splits a file path and turns it into clickable breadcrumbs
function generateBreadcrumbs(nextDir) {
var paths = nextDir.split('/').slice(0);
for(var i=1;i<paths.length;i++){
var paths = nextDir.split('/');
for (var i = 1; i < paths.length; i++)
paths[i] = paths[i-1] + '/' + paths[i];
}
if (!paths[0])
paths = paths.slice(1);
return paths;
}

Expand All @@ -33,6 +34,13 @@ return {
return _response;
},

rootPath : function()
{
if (!_response || !_response[0])
return '';
return _response[0].path;
},

setCurrentPath : function(currentPath)
{
_currentPath = currentPath;
Expand Down
11 changes: 5 additions & 6 deletions pogui/web/filebrowser/fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function updateSearch(query) {
function navigateTo(path) {
// make path legit
if (!path || !path.trim().length) {
path = '';
path = _state.rootPath();
}
_state.setCurrentPath(path);
render(_state.getResponse(), _state.getCurrentPath(), _state.getBreadcrumbs());
Expand Down Expand Up @@ -290,7 +290,7 @@ function showFiles(data) {
// sometimes we get erroneous(?) extra events. Sanity check them.
// the only readon we'd want to navigate is if we click the "root" link
if ($(this).attr('href') == '📁')
navigateTo('');
navigateTo(_state.rootPath());
return;
}

Expand All @@ -309,13 +309,12 @@ function showFiles(data) {
});

// with everything ready, load the initial state
navigateTo('');
navigateTo(_state.rootPath());
loading(false);
}

function loading(is_loading)
{
console.log('setting loading to ' + is_loading + ' for ' + _parent_id);
$('[id="' + _parent_id + '"]').toggleClass('lds-ripple', is_loading);
}

Expand Down Expand Up @@ -394,7 +393,7 @@ return {
download.click(function() {
Api.downloadArchive(id).then(function(res) {
if (res)
ProgressBar.add(id);
ProgressBar.add(res['progress_id']);
});
});
act.append(download);
Expand Down Expand Up @@ -441,6 +440,6 @@ return {
FileBrowser.init();

/*var sample =
[{'path': 's3:bucket/'}, {'path': 's3:bucket/dir/'}, {'path': 's3:bucket/dir/foo'}, {'path': 's3:bucket/file.mfn'}, {'path': 'local:dir/'}, {'path': 'local:dir/nested/'}, {'path': 'local:dir/nested/bar.mfn'}, {'path': 'local:file.mfn'}];
[{'path': ''}, {'path': 's3:bucket/'}, {'path': 's3:bucket/dir/'}, {'path': 's3:bucket/dir/foo'}, {'path': 's3:bucket/file.mfn'}, {'path': 'local:dir/'}, {'path': 'local:dir/nested/'}, {'path': 'local:dir/nested/bar.mfn'}, {'path': 'local:file.mfn'}];
FileBrowser.get('open-archive').showFiles(sample);
//*/
Loading

0 comments on commit 34cab3c

Please sign in to comment.