Skip to content

Commit f6788b5

Browse files
authored
Merge pull request #586 from Peergos/fix/misc-app-improvements
App improvements
2 parents a1d5be7 + 1b9d251 commit f6788b5

File tree

6 files changed

+139
-139
lines changed

6 files changed

+139
-139
lines changed

src/components/picker/FilePicker.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = {
6060
fileThumbnail : ''
6161
}
6262
},
63-
props: ['baseFolder', 'selectedFile_func', 'pickerFileExtension', 'pickerFilterMedia', 'pickerShowThumbnail'],
63+
props: ['baseFolder', 'selectedFile_func', 'pickerFileExtension', 'pickerFilterMedia', 'pickerShowThumbnail', 'pickerFilters'],
6464
mixins:[folderTreeMixin],
6565
computed: {
6666
...Vuex.mapState([
@@ -74,7 +74,7 @@ module.exports = {
7474
that.showSpinner = false;
7575
that.spinnerMessage = '';
7676
};
77-
this.loadSubFoldersAndFiles(this.baseFolder + "/", this.pickerFileExtension, this.pickerFilterMedia, callback);
77+
this.loadSubFoldersAndFiles(this.baseFolder + "/", this.pickerFileExtension, this.pickerFilterMedia, this.pickerFilters, callback);
7878
},
7979
methods: {
8080
close: function () {
@@ -99,7 +99,7 @@ module.exports = {
9999
this.showSpinner = false;
100100
},
101101
loadFolderLazily: function(path, callback) {
102-
this.loadSubFoldersAndFiles(path, this.pickerFileExtension, this.pickerFilterMedia, callback);
102+
this.loadSubFoldersAndFiles(path, this.pickerFileExtension, this.pickerFilterMedia, this.pickerFilters, callback);
103103
},
104104
fileSelected: function() {
105105
this.selectedFile_func(this.selectedFile);

src/components/sandbox/AppSandbox.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
:baseFolder="filePickerBaseFolder"
3333
:pickerFileExtension="pickerFileExtension"
3434
:pickerFilterMedia="pickerFilterMedia"
35+
:pickerFilters="pickerFilters"
3536
:pickerShowThumbnail="pickerShowThumbnail"
3637
:selectedFile_func="selectedFileFromPicker"
3738
/>
@@ -182,6 +183,7 @@ module.exports = {
182183
selectedFileFromPicker: null,
183184
pickerFileExtension: "",
184185
pickerFilterMedia: false,
186+
pickerFilters: null,
185187
pickerShowThumbnail: false,
186188
commandQueue: [],
187189
executingCommands: false,
@@ -534,7 +536,7 @@ module.exports = {
534536
that.showError('Path not accessible: ' + streamFilePath);
535537
} else {
536538
var prefix = '';
537-
if (!this.browserMode && streamFilePath != this.appPath) {
539+
if (!this.browserMode && !streamFilePath.startsWith(this.appPath)) {
538540
if(streamFilePath.startsWith(that.apiRequest + '/data')) {
539541
streamFilePath = streamFilePath.substring(that.apiRequest.length);
540542
} else {

src/mixins/sandbox/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,13 @@ module.exports = {
416416
&& props.fileExtensions[0].trim().length > 0
417417
&& props.fileExtensions[0] != '*';
418418
let createFile = editPermission && hasFileExtensions;
419+
let openFile = props.launchable && !props.folderAction && !createFile
420+
&& (props.fileExtensions.length > 0 || props.mimeTypes.length > 0 || props.fileTypes.length > 0);
421+
let openFileFilters = {fileExtensions: props.fileExtensions, mimeTypes: props.mimeTypes, fileTypes: props.fileTypes};
419422
let primaryFileExtension = hasFileExtensions ? props.fileExtensions[0] : '';
423+
420424
let item = {name: props.name, displayName: props.displayName,
421-
createFile: createFile, launchable: props.launchable,
425+
createFile: createFile, openFile: openFile, openFileFilters: openFileFilters, launchable: props.launchable,
422426
folderAction: props.folderAction, appIcon: props.appIcon, contextMenuText: contextMenuText,
423427
source: props.source, version: props.version, createFile: createFile, primaryFileExtension: primaryFileExtension};
424428

src/mixins/tree-walker/index.js

Lines changed: 33 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,20 @@
11
module.exports = {
22
methods: {
3-
loadFoldersAndFiles: function(path, fileExtension, filterMedia, callback) {
4-
this.loadAllFolders(path, callback, true, fileExtension, filterMedia);
5-
},
6-
loadSubFoldersAndFiles: function(path, fileExtension, filterMedia, callback) {
7-
this.loadSubFoldersNotRecursive(path, callback, true, fileExtension, filterMedia);
8-
},
9-
loadFolders: function(path, callback) {
10-
this.loadAllFolders(path, callback, false, '', false);
3+
loadSubFoldersAndFiles: function(path, fileExtension, filterMedia, fileFilters, callback) {
4+
this.loadSubFoldersNotRecursive(path, callback, true, fileExtension, filterMedia, fileFilters);
115
},
126
loadSubFolders: function(path, callback) {
13-
this.loadSubFoldersNotRecursive(path, callback, false, '', false);
14-
},
15-
loadAllFolders: function(path, callback, includeFiles, fileExtension, filterMedia) {
16-
var that = this;
17-
let folderTree = {};
18-
this.context.getByPath(path).thenApply(function(dirOpt){
19-
let dir = dirOpt.get();
20-
let folderProperties = dir.getFileProperties();
21-
if (folderProperties.isDirectory && !folderProperties.isHidden) {
22-
that.walk(dir, path, folderTree, includeFiles, fileExtension, filterMedia).thenApply( () => {
23-
callback(folderTree);
24-
});
25-
} else {
26-
callback(folderTree);
27-
}
28-
}).exceptionally(function(throwable) {
29-
this.spinnerMessage = 'Unable to load folders...';
30-
throwable.printStackTrace();
31-
});
7+
this.loadSubFoldersNotRecursive(path, callback, false, '', false, null);
328
},
339

34-
walk: function(file, path, currentTreeData, includeFiles, fileExtension, filterMedia) {
35-
currentTreeData.path = path.substring(0, path.length -1);
36-
currentTreeData.children = [];
37-
currentTreeData.isOpen = false;
38-
let that = this;
39-
let future = peergos.shared.util.Futures.incomplete();
40-
file.getChildren(that.context.crypto.hasher, that.context.network).thenApply(function(children) {
41-
let arr = children.toArray();
42-
let funcArray = [];
43-
arr.forEach(function(child, index){
44-
let childProps = child.getFileProperties();
45-
let newPath = childProps.isDirectory ? path + child.getFileProperties().name + '/' : path;
46-
if (childProps.isDirectory && !childProps.isHidden) {
47-
let node = {};
48-
currentTreeData.children.push(node);
49-
funcArray.push(() => {
50-
return that.walk(child, newPath, node, includeFiles, fileExtension, filterMedia);
51-
});
52-
}
53-
if (includeFiles === true && !childProps.isDirectory && !childProps.isHidden) {
54-
let testAcceptAll = (fileExtension == null || fileExtension.length == 0 ) && !filterMedia;
55-
var matchExtension = false;
56-
if (!testAcceptAll ) {
57-
if (filterMedia) {
58-
let mimeType = childProps.mimeType;
59-
matchExtension = mimeType.startsWith("image") || mimeType.startsWith("video");
60-
}
61-
if (!matchExtension) {
62-
let extensions = fileExtension.split(',').filter(e => e.length > 0).map(i => i.toLowerCase().trim());
63-
let matches = extensions.filter(ext => child.getFileProperties().name.toLowerCase().endsWith(ext));
64-
matchExtension = matches.length > 0;
65-
}
66-
}
67-
if (testAcceptAll || matchExtension) {
68-
let node = {};
69-
currentTreeData.children.push(node);
70-
funcArray.push(() => {
71-
return that.addFile(child, newPath, node);
72-
});
73-
}
74-
}
75-
});
76-
if (funcArray.length > 0) {
77-
let completed = {count: 0};
78-
funcArray.forEach((func, idx) => {
79-
func().thenApply(() => {
80-
completed.count ++;
81-
if (completed.count == funcArray.length) {
82-
future.complete(true);
83-
}
84-
});
85-
});
86-
} else {
87-
future.complete(true);
88-
}
89-
});
90-
return future;
91-
},
92-
addFile(file, path, currentTreeData) {
93-
let future = peergos.shared.util.Futures.incomplete();
94-
currentTreeData.path = path + file.getName();
95-
currentTreeData.children = [];
96-
currentTreeData.isLeaf = true;
97-
currentTreeData.isOpen = false;
98-
future.complete(true);
99-
return future;
100-
},
101-
loadSubFoldersNotRecursive: function(path, callback, includeFiles, fileExtension, filterMedia) {
10+
loadSubFoldersNotRecursive: function(path, callback, includeFiles, fileExtension, filterMedia, fileFilters) {
10211
var that = this;
10312
let folderTree = {};
10413
this.context.getByPath(path).thenApply(function(dirOpt){
10514
let dir = dirOpt.get();
10615
let folderProperties = dir.getFileProperties();
10716
if (folderProperties.isDirectory && !folderProperties.isHidden) {
108-
that.walkNotRecursive(dir, path, folderTree, includeFiles, fileExtension, filterMedia).thenApply( () => {
17+
that.walkNotRecursive(dir, path, folderTree, includeFiles, fileExtension, filterMedia, fileFilters).thenApply( () => {
10918
callback(folderTree);
11019
});
11120
} else {
@@ -117,7 +26,7 @@ module.exports = {
11726
});
11827
},
11928

120-
walkNotRecursive: function(file, path, currentTreeData, includeFiles, fileExtension, filterMedia) {
29+
walkNotRecursive: function(file, path, currentTreeData, includeFiles, fileExtension, filterMedia, fileFilters) {
12130
currentTreeData.path = path.substring(0, path.length -1);
12231
currentTreeData.children = [];
12332
currentTreeData.isOpen = false;
@@ -137,20 +46,35 @@ module.exports = {
13746
currentTreeData.children.push(node);
13847
}
13948
if (includeFiles === true && !childProps.isDirectory && !childProps.isHidden) {
140-
let testAcceptAll = (fileExtension == null || fileExtension.length == 0 ) && !filterMedia;
141-
var matchExtension = false;
142-
if (!testAcceptAll ) {
143-
if (filterMedia) {
144-
let mimeType = childProps.mimeType;
145-
matchExtension = mimeType.startsWith("image") || mimeType.startsWith("video");
146-
}
147-
if (!matchExtension) {
148-
let extensions = fileExtension.split(',').filter(e => e.length > 0).map(i => i.toLowerCase().trim());
149-
let matches = extensions.filter(ext => child.getFileProperties().name.toLowerCase().endsWith(ext));
150-
matchExtension = matches.length > 0;
49+
var fileMatch = false;
50+
if (fileFilters != null) { //{fileExtensions: app.fileExtensions, mimeTypes: app.mimeTypes, fileTypes: app.fileTypes}
51+
let wildcardInclude = fileFilters.fileExtensions.length == 1 && fileFilters.fileExtensions[0] == '*'
52+
|| fileFilters.mimeTypes.length == 1 && fileFilters.mimeTypes[0] == '*'
53+
|| fileFilters.fileTypes.length == 1 && fileFilters.fileTypes[0] == '*'
54+
let props = child.getFileProperties();
55+
let filename = props.name.toLowerCase().trim();
56+
let extensionMatches = fileFilters.fileExtensions.filter(ext => filename.endsWith(ext.toLowerCase().trim())).length > 0;
57+
let mimeTypesMatches = fileFilters.mimeTypes.filter(mimeType => props.mimeType == mimeType).length > 0;
58+
let fileType = props.getType();
59+
let fileTypesMatches = fileFilters.fileTypes.filter(ft => fileType == ft).length > 0;
60+
fileMatch = wildcardInclude || extensionMatches || mimeTypesMatches || fileTypesMatches;
61+
} else {
62+
let testAcceptAll = (fileExtension == null || fileExtension.length == 0 ) && !filterMedia;
63+
var matchExtension = false;
64+
if (!testAcceptAll ) {
65+
if (filterMedia) {
66+
let mimeType = childProps.mimeType;
67+
matchExtension = mimeType.startsWith("image") || mimeType.startsWith("video");
68+
}
69+
if (!matchExtension) {
70+
let extensions = fileExtension.split(',').filter(e => e.length > 0).map(i => i.toLowerCase().trim());
71+
let matches = extensions.filter(ext => child.getFileProperties().name.toLowerCase().endsWith(ext));
72+
matchExtension = matches.length > 0;
73+
}
15174
}
75+
fileMatch = testAcceptAll || matchExtension;
15276
}
153-
if (testAcceptAll || matchExtension) {
77+
if (fileMatch) {
15478
let node = {};
15579
node.path = newPath + child.getName();
15680
node.children = [];

src/views/Drive.vue

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -943,29 +943,44 @@ module.exports = {
943943
this.context.getEntryPath().thenApply(function (linkPath) {
944944
var path = that.initPath == null ? null : decodeURIComponent(that.initPath);
945945
if (path != null && (path.startsWith(linkPath) || linkPath.startsWith(path))) {
946-
that.$store.commit('SET_PATH', path.split('/').filter(n => n.length > 0))
947-
if (that.download || that.open) {
948-
that.context.getByPath(path)
949-
.thenApply(function (file) {
950-
if (! file.get().isDirectory()) {
951-
if (that.download) {
952-
that.downloadFile(file.get());
953-
} else if (that.open) {
954-
var open = () => {
955-
const filename = file.get().getName();
956-
that.selectedFiles = that.files.filter(f => f.getName() == filename);
957-
var app = that.getApp(file.get(), path, false);
958-
that.openInApp({filename:filename}, app);
959-
that.openFileOrDir(app, that.getPath, {filename:filename}, false);
960-
};
961-
that.onUpdateCompletion.push(open);
962-
}
963-
} else {
964-
let app = that.getApp(file.get(), linkPath);
965-
that.openFileOrDir(app, linkPath, {path:path});
966-
}
967-
});
968-
}
946+
that.$store.commit('SET_PATH', path.split('/').filter(n => n.length > 0))
947+
if (that.download || that.open) {
948+
that.context.getByPath(path)
949+
.thenApply(function (file) {
950+
if (! file.get().isDirectory()) {
951+
if (that.download) {
952+
that.downloadFile(file.get());
953+
} else if (that.open) {
954+
var open = () => {
955+
const filename = file.get().getName();
956+
that.selectedFiles = that.files.filter(f => f.getName() == filename);
957+
var app = that.getApp(file.get(), path, false);
958+
that.openInApp({filename:filename}, app);
959+
that.openFileOrDir(app, that.getPath, {filename:filename}, false);
960+
};
961+
that.onUpdateCompletion.push(open);
962+
}
963+
} else {
964+
let app = that.getApp(file.get(), linkPath);
965+
that.openFileOrDir(app, linkPath, {path:path});
966+
}
967+
});
968+
} else if(path.startsWith("/peergos/recommended-apps")) {
969+
let appPath = "/peergos/recommended-apps/";
970+
that.context.getByPath(appPath + "index.html").thenApply(file => {
971+
if (file.ref != null) {
972+
var openRecApps = () => {
973+
const filename = "index.html";
974+
that.selectedFiles = that.files.filter(f => f.getName() == filename);
975+
that.showAppSandbox = true;
976+
that.sandboxAppName = '$$app-gallery$$';
977+
that.currentFile = file.ref;
978+
that.currentPath = appPath;
979+
};
980+
that.onUpdateCompletion.push(openRecApps);
981+
}
982+
});
983+
}
969984
} else {
970985
that.$store.commit('SET_PATH', linkPath.split('/').filter(n => n.length > 0))
971986
if (that.download) {

0 commit comments

Comments
 (0)