Start to show remote shares in shared with you section

This commit is contained in:
Roeland Jago Douma 2015-10-01 12:26:59 +02:00
parent 4fb2ef3bac
commit eeafccb3a6

View file

@ -122,7 +122,9 @@
if (this._reloadCall) { if (this._reloadCall) {
this._reloadCall.abort(); this._reloadCall.abort();
} }
this._reloadCall = $.ajax({
var promises = [];
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */ /* jshint camelcase: false */
data: { data: {
@ -132,25 +134,76 @@
type: 'GET', type: 'GET',
beforeSend: function(xhr) { beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true'); 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); var callBack = this.reloadCallback.bind(this);
return this._reloadCall.then(callBack, callBack); return this._reloadCall.then(callBack, callBack);
}, },
reloadCallback: function(result) { reloadCallback: function(shares, remoteShares) {
delete this._reloadCall; delete this._reloadCall;
this.hideMask(); this.hideMask();
this.$el.find('#headerSharedWith').text( this.$el.find('#headerSharedWith').text(
t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with') t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with')
); );
if (result.ocs && result.ocs.data) {
this.setFiles(this._makeFilesFromShares(result.ocs.data)); var files = [];
}
else { if (shares[0].ocs && shares[0].ocs.data) {
files = files.concat(this._makeFilesFromShares(shares[0].ocs.data));
} else {
// TODO: error handling // 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;
}, },
/** /**