Skip to content
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
Trigger "changeDirectory" even on URL change
When using the browser back button or clicking on sections on the left
sidebar (like favorites), the "changeDirectory" jQuery event did not get
called, so apps like recommendations would not notice the directory
change.

This fixes the issue by also setting changeUrl to true when the file
list's directory got changed as a result from a URL change.

Added optional changedThroughUrl argument to make sure the event
recipient knows if the change was done through a URL change and make it
possible prevent a loop in the onDirectoryChange handler that actually
changes the URL when the origin was already from a URL change.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 authored and backportbot[bot] committed Jan 12, 2022
commit 672669ca98b1299821fc52d5fd393016b8a3b87f
10 changes: 6 additions & 4 deletions apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
* Event handler for when an app notified that its directory changed
*/
_onDirectoryChanged: function(e) {
if (e.dir) {
if (e.dir && !e.changedThroughUrl) {
this._changeUrl(this.navigation.getActiveItem(), e.dir, e.fileId);
}
},
Expand Down Expand Up @@ -376,9 +376,11 @@
params.fileid = fileId;
}
var currentParams = OC.Util.History.parseUrlQuery();
if (currentParams.dir === params.dir && currentParams.view === params.view && currentParams.fileid !== params.fileid) {
// if only fileid changed or was added, replace instead of push
OC.Util.History.replaceState(this._makeUrlParams(params));
if (currentParams.dir === params.dir && currentParams.view === params.view) {
if (currentParams.fileid !== params.fileid) {
// if only fileid changed or was added, replace instead of push
OC.Util.History.replaceState(this._makeUrlParams(params));
}
} else {
OC.Util.History.pushState(this._makeUrlParams(params));
}
Expand Down
13 changes: 8 additions & 5 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
if( (this._currentDirectory || this.$el.find('#dir').val()) && currentDir === e.dir) {
return;
}
this.changeDirectory(e.dir, false, true);
this.changeDirectory(e.dir, true, true, undefined, true);
}
},

Expand Down Expand Up @@ -1912,15 +1912,16 @@
* @param {boolean} [changeUrl=true] if the URL must not be changed (defaults to true)
* @param {boolean} [force=false] set to true to force changing directory
* @param {string} [fileId] optional file id, if known, to be appended in the URL
* @param {bool} [changedThroughUrl=false] true if the dir was set through a URL change
*/
changeDirectory: function(targetDir, changeUrl, force, fileId) {
changeDirectory: function(targetDir, changeUrl, force, fileId, changedThroughUrl) {
var self = this;
var currentDir = this.getCurrentDirectory();
targetDir = targetDir || '/';
if (!force && currentDir === targetDir) {
return;
}
this._setCurrentDir(targetDir, changeUrl, fileId);
this._setCurrentDir(targetDir, changeUrl, fileId, changedThroughUrl);

// discard finished uploads list, we'll get it through a regular reload
this._uploads = {};
Expand Down Expand Up @@ -1955,8 +1956,9 @@
* @param targetDir directory to display
* @param changeUrl true to also update the URL, false otherwise (default)
* @param {string} [fileId] file id
* @param {bool} changedThroughUrl true if the dir was set through a URL change
*/
_setCurrentDir: function(targetDir, changeUrl, fileId) {
_setCurrentDir: function(targetDir, changeUrl, fileId, changedThroughUrl) {
targetDir = targetDir.replace(/\\/g, '/');
if (!this._isValidPath(targetDir)) {
targetDir = '/';
Expand Down Expand Up @@ -1988,6 +1990,7 @@
if (fileId) {
params.fileId = fileId;
}
params.changedThroughUrl = changedThroughUrl
this.$el.trigger(jQuery.Event('changeDirectory', params));
}
this.breadcrumb.setDirectory(this.getCurrentDirectory());
Expand Down Expand Up @@ -2089,7 +2092,7 @@
if (status === 401) {
// We are not authentificated, so reload the page so that we get
// redirected to the login page while saving the current url.
location.reload();
location.reload();
}

// Firewall Blocked request?
Expand Down