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
1 changed files with 60 additions and 7 deletions

View File

@ -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;
},
/**