From eeafccb3a65498e83071e71d5954bf4a856a1caa Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 1 Oct 2015 12:26:59 +0200 Subject: [PATCH] Start to show remote shares in shared with you section --- apps/files_sharing/js/sharedfilelist.js | 67 ++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 98dbd4c670..7912944ac1 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -122,7 +122,9 @@ if (this._reloadCall) { this._reloadCall.abort(); } - this._reloadCall = $.ajax({ + + var promises = []; + var shares = $.ajax({ url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', /* jshint camelcase: false */ data: { @@ -132,25 +134,76 @@ type: 'GET', beforeSend: function(xhr) { xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - } + }, }); + promises.push(shares); + + if (!!this._sharedWithUser) { + var remoteShares = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', + /* jshint camelcase: false */ + data: { + format: 'json' + }, + type: 'GET', + beforeSend: function(xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }); + promises.push(remoteShares); + } + + this._reloadCall = $.when.apply($, promises); var callBack = this.reloadCallback.bind(this); return this._reloadCall.then(callBack, callBack); }, - reloadCallback: function(result) { + reloadCallback: function(shares, remoteShares) { delete this._reloadCall; this.hideMask(); this.$el.find('#headerSharedWith').text( t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with') ); - if (result.ocs && result.ocs.data) { - this.setFiles(this._makeFilesFromShares(result.ocs.data)); - } - else { + + var files = []; + + if (shares[0].ocs && shares[0].ocs.data) { + files = files.concat(this._makeFilesFromShares(shares[0].ocs.data)); + } else { // TODO: error handling } + + if (remoteShares[0].ocs && remoteShares[0].ocs.data) { + files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data)); + } else { + // TODO: error handling + } + + this.setFiles(files); + }, + + _makeFilesFromRemoteShares: function(data) { + var self = this; + var files = data; + + files = _.chain(files) + // convert share data to file data + .map(function(share) { + var file = { + shareOwner: share.owner + '@' + share.remote, + name: share.name + }; + + file.shares = [{ + id: share.id, + type: OC.Share.SHARE_TYPE_REMOTE, + target: share.mountpoint + }]; + return file; + }) + .value(); + return files; }, /**