Fixed sharing coding style and display - Added all shares overview

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>

Fixed if condition

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2018-07-13 11:45:50 +02:00
parent e1a2bb9d69
commit 34368cc031
No known key found for this signature in database
GPG key ID: 60C25B8C072916CF

View file

@ -195,120 +195,70 @@
// there is only root
this._setCurrentDir('/', false);
if (!this._isOverview) {
if (this._showDeleted) {
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
} else {
var shares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: !!this._sharedWithUser,
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
}
var promises = [];
promises.push(shares);
var promises = [];
if (!!this._sharedWithUser) {
var remoteShares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
promises.push(remoteShares);
} else {
//Push empty promise so callback gets called the same way
promises.push($.Deferred().resolve());
}
var deletedShares = {
url: OC.linkToOCS('apps/files_sharing/api/v1', 2) + 'deletedshares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
};
this._reloadCall = $.when.apply($, promises);
var callBack = this.reloadCallback.bind(this);
return this._reloadCall.then(callBack, callBack);
var shares = {
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: this._sharedWithUser !== false,
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
};
var remoteShares = {
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
};
// Add the proper ajax requests to the list and run them
// and make sure we have 2 promises
if (this._showDeleted) {
promises.push($.ajax(deletedShares));
} else {
var promises = [];
var sharedWith = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: true,
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
promises.push(sharedWith);
promises.push($.ajax(shares));
var sharedBy = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares',
/* jshint camelcase: false */
data: {
format: 'json',
shared_with_me: false,
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
promises.push(sharedBy);
var remoteShares = $.ajax({
url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
/* jshint camelcase: false */
data: {
format: 'json',
include_tags: true
},
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
},
});
promises.push(remoteShares);
this._reloadCall = $.when.apply($, promises);
var callBack = this.reloadOverviewCallBack().bind(this);
return this._reloadCall.then(callBack, callBack, callBack);
if (this._sharedWithUser !== false || this._isOverview) {
promises.push($.ajax(remoteShares));
}
if (this._isOverview) {
shares.data.shared_with_me = !shares.data.shared_with_me
promises.push($.ajax(shares));
}
}
this._reloadCall = $.when.apply($, promises);
var callBack = this.reloadCallback.bind(this);
return this._reloadCall.then(callBack, callBack);
},
reloadOverviewCallBack: function(sharedWith, sharedBy, remote) {
delete this._reloadCall;
this.hideMask();
alert('foo');
},
reloadCallback: function(shares, remoteShares) {
reloadCallback: function(shares, remoteShares, additionnalShares) {
delete this._reloadCall;
this.hideMask();
@ -318,12 +268,21 @@
var files = [];
if (shares[0].ocs && shares[0].ocs.data) {
files = files.concat(this._makeFilesFromShares(shares[0].ocs.data));
// make sure to use the same format
if(shares[0] && shares[0].ocs) {
shares = shares[0];
}
if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) {
files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data));
if (shares.ocs && shares.ocs.data) {
files = files.concat(this._makeFilesFromShares(shares.ocs.data));
}
if (remoteShares && remoteShares.ocs && remoteShares.ocs.data) {
files = files.concat(this._makeFilesFromRemoteShares(remoteShares.ocs.data));
}
if (additionnalShares && additionnalShares[0] && additionnalShares[0].ocs && additionnalShares[0].ocs.data) {
files = files.concat(this._makeFilesFromShares(additionnalShares[0].ocs.data));
}
this.setFiles(files);