Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| db87ecb76e | |||
| afa1552ebf | |||
| 174f69f84d | |||
| 9f5d8bfb93 | |||
| f9b4444763 | |||
| bdb0671171 | |||
| 14c39d292f |
@@ -1,9 +1,10 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { inject as controller } from '@ember/controller';
|
||||
import { observer } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { computed, observer } from '@ember/object';
|
||||
import { alias } from '@ember/object/computed';
|
||||
import { isPresent } from '@ember/utils';
|
||||
import { isPresent, isEmpty } from '@ember/utils';
|
||||
import { all } from 'rsvp';
|
||||
|
||||
export default Controller.extend({
|
||||
|
||||
@@ -16,7 +17,7 @@ export default Controller.extend({
|
||||
|
||||
queryParams: ['path'],
|
||||
|
||||
currentListing: function() {
|
||||
currentListing: function () {
|
||||
if (isPresent(this.get('model.currentListing'))) {
|
||||
return this.get('model.currentListing').sortBy('name');
|
||||
} else {
|
||||
@@ -24,7 +25,34 @@ export default Controller.extend({
|
||||
}
|
||||
}.property('rootListing.[]', 'model.[]'),
|
||||
|
||||
connectedChange: observer('connected', function() {
|
||||
documents: computed('currentListing.[]', function () {
|
||||
if (isEmpty(this.get('currentListing'))) { return []; }
|
||||
|
||||
return this.get('currentListing')
|
||||
.reject(item => item.path.substr(-1) === '/');
|
||||
}),
|
||||
|
||||
currentListingContainsDocuments: computed('documents.[]', function () {
|
||||
return isPresent(this.get('documents'));
|
||||
}),
|
||||
|
||||
documentCount: computed('documents.[]', function () {
|
||||
if (isPresent(this.get('documents'))) {
|
||||
return this.get('documents').length;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}),
|
||||
|
||||
parentDir: computed('currentDirPath', function () {
|
||||
const dirs = this.get('currentDirPath')
|
||||
.split('/')
|
||||
.reject(p => isEmpty(p));
|
||||
|
||||
return dirs.splice(0, dirs.length - 1).join('/') + '/';
|
||||
}),
|
||||
|
||||
connectedChange: observer('connected', function () {
|
||||
if (this.get('connected')) {
|
||||
// console.debug('connectedChange connected');
|
||||
} else {
|
||||
@@ -33,4 +61,27 @@ export default Controller.extend({
|
||||
}
|
||||
}),
|
||||
|
||||
actions: {
|
||||
|
||||
deleteDocuments () {
|
||||
const documentCount = this.get('documentCount');
|
||||
const msg = `This will delete all ${documentCount} documents/files in the current directory. Are you sure?`;
|
||||
if (! window.confirm(msg)) { return false; }
|
||||
|
||||
const client = this.get('storage.client');
|
||||
|
||||
let promises = this.get('documents').map(item => {
|
||||
console.debug('removing ' + item.path);
|
||||
return client.remove(item.path);
|
||||
});
|
||||
|
||||
all(promises).then(() => {
|
||||
this.transitionToRoute('index', {
|
||||
queryParams: { path: this.get('parentDir') }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -11,6 +11,8 @@ export default Route.extend(BodyClassMixin, {
|
||||
console.debug('rs.on error', error);
|
||||
if (error.name === 'Unauthorized') {
|
||||
this.handleUnauthorized();
|
||||
} else if (error.name === 'DiscoveryError') {
|
||||
// Do nothing, because the widget will handle it
|
||||
} else {
|
||||
alert('An unknown error occured. Please check the browser console for details.');
|
||||
}
|
||||
|
||||
@@ -44,6 +44,12 @@ export default Route.extend({
|
||||
|
||||
if (isPresent(model)) {
|
||||
controller.set('currentDirPath', model.currentDirPath);
|
||||
|
||||
if (isEmpty(model.currentListing)) {
|
||||
this.transitionTo('index', {
|
||||
queryParams: { path: controller.get('parentDir') }
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<header>
|
||||
{{breadcrumb-nav currentDirPath=currentDirPath}}
|
||||
<nav class="actions">
|
||||
{{#if currentListingContainsDocuments}}
|
||||
<button class="delete-all" {{action "deleteDocuments"}}>delete all</button>
|
||||
{{/if}}
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
{{#if currentListing}}
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "inspektor",
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -10308,9 +10308,9 @@
|
||||
}
|
||||
},
|
||||
"remotestorage-widget": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/remotestorage-widget/-/remotestorage-widget-1.0.0.tgz",
|
||||
"integrity": "sha512-m1zbsjvDHveJIqETzF3oaQwr4m5I7jg4vLETa7eKrXpgV7HBC5nyYv8GBclBoKrhONY4ZWzUX+3GRLyUNDdIcA==",
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/remotestorage-widget/-/remotestorage-widget-1.2.0.tgz",
|
||||
"integrity": "sha512-6SEJ87UiEew43iO53O9ZuJAjg9mPgpSNbehtflm3I7LO5FpQ6RnJZiiHpQzGOgozUFyK8g3UnnOBAzFwJ6jRcA==",
|
||||
"dev": true
|
||||
},
|
||||
"remotestoragejs": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "inspektor",
|
||||
"version": "0.6.0",
|
||||
"version": "0.7.1",
|
||||
"private": true,
|
||||
"description": "Inspect the contents of your remote storage",
|
||||
"license": "MIT",
|
||||
@@ -43,7 +43,7 @@
|
||||
"ember-resolver": "^4.0.0",
|
||||
"ember-source": "~2.16.0",
|
||||
"loader.js": "^4.2.3",
|
||||
"remotestorage-widget": "^1.0.0",
|
||||
"remotestorage-widget": "^1.2.0",
|
||||
"remotestoragejs": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -4,8 +4,89 @@ moduleFor('controller:index', 'Unit | Controller | index', {
|
||||
needs: ['controller:application', 'service:storage']
|
||||
});
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it exists', function(assert) {
|
||||
test('#parentDir', function(assert) {
|
||||
let controller = this.subject();
|
||||
assert.ok(controller);
|
||||
controller.set('currentDirPath', 'islands/spain/canaries/tenerife/');
|
||||
|
||||
assert.equal(controller.get('parentDir'), 'islands/spain/canaries/');
|
||||
});
|
||||
|
||||
test('#currentListingContainsDocuments', function(assert) {
|
||||
let controller = this.subject();
|
||||
|
||||
controller.set('currentListing', [
|
||||
{
|
||||
"name": "spain/",
|
||||
"type": "folder",
|
||||
"isBinary": false,
|
||||
"isFolder": true,
|
||||
"size": null,
|
||||
"path": "/islands/spain/",
|
||||
"etag": "885098000"
|
||||
}
|
||||
]);
|
||||
|
||||
assert.notOk(controller.get('currentListingContainsDocuments'),
|
||||
'returns false when no documents are present');
|
||||
|
||||
controller.set('currentListing', [
|
||||
{
|
||||
"name": "spain/",
|
||||
"type": "folder",
|
||||
"isBinary": false,
|
||||
"isFolder": true,
|
||||
"size": null,
|
||||
"path": "/islands/spain/",
|
||||
"etag": "885098000"
|
||||
},
|
||||
{
|
||||
"name": "lamu",
|
||||
"type": "application/json",
|
||||
"isBinary": false,
|
||||
"isFolder": false,
|
||||
"size": 202,
|
||||
"path": "/islands/lamu",
|
||||
"etag": "478058546"
|
||||
}
|
||||
]);
|
||||
|
||||
assert.ok(controller.get('currentListingContainsDocuments'),
|
||||
'returns true when no documents are present');
|
||||
});
|
||||
|
||||
test('#documentCount', function(assert) {
|
||||
let controller = this.subject();
|
||||
|
||||
controller.set('currentListing', [
|
||||
{
|
||||
"name": "spain/",
|
||||
"type": "folder",
|
||||
"isBinary": false,
|
||||
"isFolder": true,
|
||||
"size": null,
|
||||
"path": "/islands/spain/",
|
||||
"etag": "885098000"
|
||||
},
|
||||
{
|
||||
"name": "lamu",
|
||||
"type": "application/json",
|
||||
"isBinary": false,
|
||||
"isFolder": false,
|
||||
"size": 202,
|
||||
"path": "/islands/lamu",
|
||||
"etag": "478058546"
|
||||
},
|
||||
{
|
||||
"name": "dominica",
|
||||
"type": "application/json",
|
||||
"isBinary": false,
|
||||
"isFolder": false,
|
||||
"size": 202,
|
||||
"path": "/islands/dominica",
|
||||
"etag": "929838541"
|
||||
}
|
||||
]);
|
||||
|
||||
assert.equal(controller.get('documentCount'), 2,
|
||||
'returns the number of documents in the current listing');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user