mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-05-09 07:34:05 +02:00
🧹 Cleanup ShareController & ShareResource
Signed-off-by: Marco Nassabain <marco.nassabain@hotmail.com>
This commit is contained in:
parent
04cf2672c3
commit
4fcd483030
js
@ -5,6 +5,9 @@
|
|||||||
* later. See the COPYING file.
|
* later. See the COPYING file.
|
||||||
*
|
*
|
||||||
* @author Marco Nassabain <marco.nassabain@hotmail.com>
|
* @author Marco Nassabain <marco.nassabain@hotmail.com>
|
||||||
|
* @author Nicolas Wendling <nicolas.wendling1011@gmail.com>
|
||||||
|
* @author Jimmy Huynh <natorisaki@gmail.com>
|
||||||
|
* @author Aurélien David <dav.aurelien@gmail.com>
|
||||||
*/
|
*/
|
||||||
app.controller('ShareController', function (ShareResource, Loading) {
|
app.controller('ShareController', function (ShareResource, Loading) {
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -15,9 +18,12 @@ app.controller('ShareController', function (ShareResource, Loading) {
|
|||||||
this.showDropDown = !this.showDropDown;
|
this.showDropDown = !this.showDropDown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Array containing users to share an item with */
|
||||||
this.userList = [];
|
this.userList = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param search Username search query
|
||||||
|
*
|
||||||
* Retrieve users matching search query using OC
|
* Retrieve users matching search query using OC
|
||||||
*/
|
*/
|
||||||
this.searchUsers = function(search) {
|
this.searchUsers = function(search) {
|
||||||
@ -35,10 +41,17 @@ app.controller('ShareController', function (ShareResource, Loading) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Dict <itemId, List<Int>(user_id)>: Local mapping b/w users & articles:
|
/** Dictionary mapping articles to users they're shared with */
|
||||||
//[Article 1 : <Jimmy, Aurelien, ...>, Article 2: <...>]
|
|
||||||
this.usersSharedArticles = {};
|
this.usersSharedArticles = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param itemId ID of the item to be shared
|
||||||
|
* @param userId ID of the recipient
|
||||||
|
*
|
||||||
|
* Call the /share route with the appropriate params to share an item.
|
||||||
|
* Fills this.usersSharedArticles to avoid re-sharing the same article
|
||||||
|
* with the same user multiple times.
|
||||||
|
*/
|
||||||
this.shareItem = function(itemId, userId) {
|
this.shareItem = function(itemId, userId) {
|
||||||
Loading.setLoading(userId, true);
|
Loading.setLoading(userId, true);
|
||||||
if (this.usersSharedArticles[itemId] && this.usersSharedArticles[itemId].includes(userId)) {
|
if (this.usersSharedArticles[itemId] && this.usersSharedArticles[itemId].includes(userId)) {
|
||||||
@ -46,16 +59,14 @@ app.controller('ShareController', function (ShareResource, Loading) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick initialization (instead of if (...) : [])
|
|
||||||
this.usersSharedArticles[itemId] = this.usersSharedArticles[itemId] ? this.usersSharedArticles[itemId] : [];
|
this.usersSharedArticles[itemId] = this.usersSharedArticles[itemId] ? this.usersSharedArticles[itemId] : [];
|
||||||
|
|
||||||
this.usersSharedArticles[itemId].push(userId);
|
this.usersSharedArticles[itemId].push(userId);
|
||||||
|
|
||||||
var response = ShareResource.shareItem(itemId, userId);
|
ShareResource.shareItem(itemId, userId)
|
||||||
response.then((result) => {
|
.then((result) => {
|
||||||
Loading.setLoading(userId, false);
|
Loading.setLoading(userId, false);
|
||||||
return result;
|
return result;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -34,4 +34,4 @@ app.factory('ShareResource', function (Resource, $http, BASE_URL) {
|
|||||||
|
|
||||||
|
|
||||||
return new ShareResource($http, BASE_URL);
|
return new ShareResource($http, BASE_URL);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user