Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable24] Fallback to root if the picker folder doesn't exists #36563

Merged
merged 1 commit into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
229 changes: 123 additions & 106 deletions core/src/OC/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ const Dialogs = {
/**
* fills the filepicker with files
*/
_fillFilePicker: function(dir) {
_fillFilePicker: async function(dir) {
var self = this
this.$filelist.empty()
this.$filePicker.find('.emptycontent').hide()
Expand All @@ -1139,131 +1139,148 @@ const Dialogs = {
} else {
self.$fileListHeader.find('[data-sort=' + self.filepicker.sortField + '] .sort-indicator').addClass('icon-triangle-s')
}
self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) {
self.filelist = files
if (filter && filter.length > 0 && filter.indexOf('*') === -1) {
files = files.filter(function(file) {
return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1

// Wrap within a method because a promise cannot return multiple values
// But the client impleemntation still does it...
var getFolderContents = async function(dir) {
return self.filepicker.filesClient.getFolderContents(dir)
.then((status, files) => {
return files
})
}
}

if (advancedFilter) {
files = files.filter(advancedFilter)
}
try {
var files = await getFolderContents(dir)
} catch (error) {
// fallback to root if requested dir is non-existent
console.error('Requested path does not exists, falling back to root')
var files = await getFolderContents('/')
this.$filePicker.data('path', '/')
}

// Check if the showHidden input field exist and if it exist follow it
// Otherwise just show the hidden files
const showHiddenInput = document.getElementById('showHiddenFiles')
const showHidden = showHiddenInput === null || showHiddenInput.value === "1"
if (!showHidden) {
files = files.filter(function(file) {
return !file.name.startsWith('.')
})
}
self.filelist = files
if (filter && filter.length > 0 && filter.indexOf('*') === -1) {
files = files.filter(function(file) {
return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1
})
}

var Comparators = {
name: function(fileInfo1, fileInfo2) {
if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') {
return -1
}
if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') {
return 1
}
return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name)
},
size: function(fileInfo1, fileInfo2) {
return fileInfo1.size - fileInfo2.size
},
mtime: function(fileInfo1, fileInfo2) {
return fileInfo1.mtime - fileInfo2.mtime
}
}
var comparator = Comparators[self.filepicker.sortField] || Comparators.name
files = files.sort(function(file1, file2) {
var isFavorite = function(fileInfo) {
return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0
}
if (advancedFilter) {
files = files.filter(advancedFilter)
}

// Check if the showHidden input field exist and if it exist follow it
// Otherwise just show the hidden files
const showHiddenInput = document.getElementById('showHiddenFiles')
const showHidden = showHiddenInput === null || showHiddenInput.value === "1"
if (!showHidden) {
files = files.filter(function(file) {
return !file.name.startsWith('.')
})
}

if (isFavorite(file1) && !isFavorite(file2)) {
var Comparators = {
name: function(fileInfo1, fileInfo2) {
if (fileInfo1.type === 'dir' && fileInfo2.type !== 'dir') {
return -1
} else if (!isFavorite(file1) && isFavorite(file2)) {
}
if (fileInfo1.type !== 'dir' && fileInfo2.type === 'dir') {
return 1
}
return OC.Util.naturalSortCompare(fileInfo1.name, fileInfo2.name)
},
size: function(fileInfo1, fileInfo2) {
return fileInfo1.size - fileInfo2.size
},
mtime: function(fileInfo1, fileInfo2) {
return fileInfo1.mtime - fileInfo2.mtime
}
}
var comparator = Comparators[self.filepicker.sortField] || Comparators.name
files = files.sort(function(file1, file2) {
var isFavorite = function(fileInfo) {
return fileInfo.tags && fileInfo.tags.indexOf(OC.TAG_FAVORITE) >= 0
}

return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2)
})
if (isFavorite(file1) && !isFavorite(file2)) {
return -1
} else if (!isFavorite(file1) && isFavorite(file2)) {
return 1
}

self._fillSlug()
return self.filepicker.sortOrder === 'asc' ? comparator(file1, file2) : -comparator(file1, file2)
})

self._fillSlug()

if (files.length === 0) {
self.$filePicker.find('.emptycontent').show()
self.$fileListHeader.hide()
if (files.length === 0) {
self.$filePicker.find('.emptycontent').show()
self.$fileListHeader.hide()
} else {
self.$filePicker.find('.emptycontent').hide()
self.$fileListHeader.show()
}

self.$filelist.empty();

$.each(files, function(idx, entry) {
if (entry.isEncrypted && entry.mimetype === 'httpd/unix-directory') {
entry.icon = OC.MimeType.getIconUrl('dir-encrypted')
} else {
self.$filePicker.find('.emptycontent').hide()
self.$fileListHeader.show()
entry.icon = OC.MimeType.getIconUrl(entry.mimetype)
}

self.$filelist.empty();

$.each(files, function(idx, entry) {
if (entry.isEncrypted && entry.mimetype === 'httpd/unix-directory') {
entry.icon = OC.MimeType.getIconUrl('dir-encrypted')
} else {
entry.icon = OC.MimeType.getIconUrl(entry.mimetype)
}
var simpleSize, sizeColor
if (typeof (entry.size) !== 'undefined' && entry.size >= 0) {
simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true)
sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2))
} else {
simpleSize = t('files', 'Pending')
sizeColor = 80
}

var simpleSize, sizeColor
if (typeof (entry.size) !== 'undefined' && entry.size >= 0) {
simpleSize = OC.Util.humanFileSize(parseInt(entry.size, 10), true)
sizeColor = Math.round(160 - Math.pow((entry.size / (1024 * 1024)), 2))
} else {
simpleSize = t('files', 'Pending')
sizeColor = 80
}
// split the filename in half if the size is bigger than 20 char
// for ellipsis
if (entry.name.length >= 10) {
// leave maximum 10 letters
var split = Math.min(Math.floor(entry.name.length / 2), 10)
var filename1 = entry.name.substr(0, entry.name.length - split)
var filename2 = entry.name.substr(entry.name.length - split)
} else {
var filename1 = entry.name
var filename2 = ''
}

// split the filename in half if the size is bigger than 20 char
// for ellipsis
if (entry.name.length >= 10) {
// leave maximum 10 letters
var split = Math.min(Math.floor(entry.name.length / 2), 10)
var filename1 = entry.name.substr(0, entry.name.length - split)
var filename2 = entry.name.substr(entry.name.length - split)
} else {
var filename1 = entry.name
var filename2 = ''
var $row = self.$listTmpl.octemplate({
type: entry.type,
dir: dir,
filename: entry.name,
filename1: filename1,
filename2: filename2,
date: OC.Util.relativeModifiedDate(entry.mtime),
size: simpleSize,
sizeColor: sizeColor,
icon: entry.icon
})
if (entry.type === 'file') {
var urlSpec = {
file: dir + '/' + entry.name,
x: 100,
y: 100
}

var $row = self.$listTmpl.octemplate({
type: entry.type,
dir: dir,
filename: entry.name,
filename1: filename1,
filename2: filename2,
date: OC.Util.relativeModifiedDate(entry.mtime),
size: simpleSize,
sizeColor: sizeColor,
icon: entry.icon
})
if (entry.type === 'file') {
var urlSpec = {
file: dir + '/' + entry.name,
x: 100,
y: 100
var img = new Image()
var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec)
img.onload = function() {
if (img.width > 5) {
$row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')')
}
var img = new Image()
var previewUrl = OC.generateUrl('/core/preview.png?') + $.param(urlSpec)
img.onload = function() {
if (img.width > 5) {
$row.find('td.filename').attr('style', 'background-image:url(' + previewUrl + ')')
}
}
img.src = previewUrl
}
self.$filelist.append($row)
})

self.$filelistContainer.removeClass('icon-loading')
img.src = previewUrl
}
self.$filelist.append($row)
})

self.$filelistContainer.removeClass('icon-loading')
},
/**
* fills the tree list with directories
Expand Down
4 changes: 2 additions & 2 deletions dist/core-login.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-login.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/core-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-main.js.map

Large diffs are not rendered by default.