-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add loading spinner to download icon #17175
Changes from all commits
28a51ef
0cdb46b
16c2902
28a8697
5a52821
e557fe0
3d8297c
3f5aa27
43afa4c
009d1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -583,14 +583,23 @@ a.action>img { | |
#fileList tr:focus a.action, | ||
#fileList a.action.permanent, | ||
#fileList tr:hover a.action.no-permission:hover, | ||
#fileList tr:focus a.action.no-permission:focus | ||
/*#fileList .name:focus .action*/ { | ||
#fileList tr:focus a.action.no-permission:focus, | ||
/*#fileList .name:focus .action,*/ | ||
/* also enforce the low opacity for disabled links that are hovered/focused */ | ||
.ie8 #fileList a.action.disabled:hover img, | ||
#fileList tr:hover a.action.disabled:hover, | ||
#fileList tr:focus a.action.disabled:focus, | ||
#fileList .name:focus a.action.disabled:focus, | ||
#fileList a.action.disabled img { | ||
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; | ||
filter: alpha(opacity=50); | ||
opacity: .5; | ||
display:inline; | ||
} | ||
.ie8 #fileList a.action:hover img, | ||
#fileList tr a.action.disabled.action-download, | ||
#fileList tr:hover a.action.disabled.action-download:hover, | ||
#fileList tr:focus a.action.disabled.action-download:focus, | ||
#fileList tr:hover a.action:hover, | ||
#fileList tr:focus a.action:focus, | ||
#fileList .name:focus a.action:focus { | ||
|
@@ -599,6 +608,18 @@ a.action>img { | |
opacity: 1; | ||
display:inline; | ||
} | ||
#fileList tr a.action.disabled { | ||
background: none; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because usually disabled links have a grey background. |
||
} | ||
|
||
#selectedActionsList a.download.disabled, | ||
#fileList tr a.action.action-download.disabled { | ||
color: #000000; | ||
} | ||
|
||
#fileList tr:hover a.action.disabled:hover * { | ||
cursor: default; | ||
} | ||
|
||
.summary { | ||
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,15 +478,48 @@ | |
}, function (filename, context) { | ||
var dir = context.dir || context.fileList.getCurrentDirectory(); | ||
var url = context.fileList.getDownloadUrl(filename, dir); | ||
|
||
var downloadFileaction = $(context.$file).find('.fileactions .action-download'); | ||
|
||
// don't allow a second click on the download action | ||
if(downloadFileaction.hasClass('disabled')) { | ||
return; | ||
} | ||
|
||
if (url) { | ||
OC.redirect(url); | ||
var disableLoadingState = function(){ | ||
OCA.Files.FileActions.updateFileActionSpinner(downloadFileaction, false); | ||
}; | ||
|
||
OCA.Files.FileActions.updateFileActionSpinner(downloadFileaction, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, here you can use "self.updateFileActionSpinner(...)". But you need to add Feel free to leave it now. Just a hint for next time 😄 |
||
OCA.Files.Files.handleDownload(url, disableLoadingState); | ||
} | ||
}, t('files', 'Download')); | ||
} | ||
}; | ||
|
||
OCA.Files.FileActions = FileActions; | ||
|
||
/** | ||
* Replaces the download icon with a loading spinner and vice versa | ||
* - also adds the class disabled to the passed in element | ||
* | ||
* @param downloadButtonElement download fileaction | ||
* @param {boolean} showIt whether to show the spinner(true) or to hide it(false) | ||
*/ | ||
OCA.Files.FileActions.updateFileActionSpinner = function(downloadButtonElement, showIt) { | ||
var icon = downloadButtonElement.find('img'), | ||
sourceImage = icon.attr('src'); | ||
|
||
if(showIt) { | ||
downloadButtonElement.addClass('disabled'); | ||
icon.attr('src', sourceImage.replace('actions/download.svg', 'loading-small.gif')); | ||
} else { | ||
downloadButtonElement.removeClass('disabled'); | ||
icon.attr('src', sourceImage.replace('loading-small.gif', 'actions/download.svg')); | ||
} | ||
}; | ||
|
||
/** | ||
* File action attributes. | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -417,7 +417,21 @@ | |
else { | ||
files = _.pluck(this.getSelectedFiles(), 'name'); | ||
} | ||
OC.redirect(this.getDownloadUrl(files, dir)); | ||
|
||
var downloadFileaction = $('#selectedActionsList').find('.download'); | ||
|
||
// don't allow a second click on the download action | ||
if(downloadFileaction.hasClass('disabled')) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
|
||
var disableLoadingState = function(){ | ||
OCA.Files.FileActions.updateFileActionSpinner(downloadFileaction, false); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate code with above, but I guess this is only your POC and you intended to refactor later ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is a good place to put this? in the filelist class? |
||
|
||
OCA.Files.FileActions.updateFileActionSpinner(downloadFileaction, true); | ||
OCA.Files.Files.handleDownload(this.getDownloadUrl(files, dir), disableLoadingState); | ||
return false; | ||
}, | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1513,8 +1513,38 @@ OC.Util = { | |
} | ||
} | ||
return aa.length - bb.length; | ||
}, | ||
/** | ||
* Calls the callback in a given interval until it returns true | ||
* @param {function} callback | ||
* @param {integer} interval in milliseconds | ||
*/ | ||
waitFor: function(callback, interval) { | ||
var internalCallback = function() { | ||
if(callback() !== true) { | ||
setTimeout(internalCallback, interval); | ||
} | ||
}; | ||
|
||
internalCallback(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice! |
||
}, | ||
/** | ||
* Checks if a cookie with the given name is present and is set to the provided value. | ||
* @param {string} name name of the cookie | ||
* @param {string} value value of the cookie | ||
* @return {boolean} true if the cookie with the given name has the given value | ||
*/ | ||
isCookieSetToValue: function(name, value) { | ||
var cookies = document.cookie.split(';'); | ||
for (var i=0; i < cookies.length; i++) { | ||
var cookie = cookies[i].split('='); | ||
if (cookie[0].trim() === name && cookie[1].trim() === value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Utility class for the history API, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we won't be able to use WebDAV download in the future, unless the WebDAV endpoint also sets cookies, super ugly. Or we keep a special ajax download endpoint only for this logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or hmmmm a Sabre plugin that detects that the WebDAV upload was done from a web UI and sets the cookie, might be cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of magic is this 🙊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe. This is the only way to detect if a download has started and to remove the download spinner animation. Because the download is handled in a separate request the browsers sandbox doesn't allow to check if the request already finished or not. With this we set the cookie and the browser then sets the cookie for the whole domain. If the cookie is set, the JS part knows, that the download has started and can remove the loading spinner.
@PVince81 Yes ... we need to find a way to do this in WebDAV too :/ But user feedback for such stuff is also quite essential I think ... otherwise users click really often on the download button just because the backend needs some time to fetch a file 🙈