From 4fcd4830305fa08e3d7632811d4c1aa1b03d12a4 Mon Sep 17 00:00:00 2001 From: Marco Nassabain Date: Sun, 7 Mar 2021 00:27:19 +0100 Subject: =?UTF-8?q?=F0=9F=A7=B9=20Cleanup=20ShareController=20&=20ShareRes?= =?UTF-8?q?ource?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marco Nassabain --- js/controller/ShareController.js | 25 ++++++++++++++++++------- js/service/ShareResource.js | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/js/controller/ShareController.js b/js/controller/ShareController.js index 66d3ce217..694843d79 100644 --- a/js/controller/ShareController.js +++ b/js/controller/ShareController.js @@ -5,6 +5,9 @@ * later. See the COPYING file. * * @author Marco Nassabain + * @author Nicolas Wendling + * @author Jimmy Huynh + * @author Aurélien David */ app.controller('ShareController', function (ShareResource, Loading) { 'use strict'; @@ -15,9 +18,12 @@ app.controller('ShareController', function (ShareResource, Loading) { this.showDropDown = !this.showDropDown; }; + /** Array containing users to share an item with */ this.userList = []; /** + * @param search Username search query + * * Retrieve users matching search query using OC */ this.searchUsers = function(search) { @@ -35,10 +41,17 @@ app.controller('ShareController', function (ShareResource, Loading) { }); }; - // Dict (user_id)>: Local mapping b/w users & articles: - //[Article 1 : , Article 2: <...>] + /** Dictionary mapping articles to users they're shared with */ 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) { Loading.setLoading(userId, true); if (this.usersSharedArticles[itemId] && this.usersSharedArticles[itemId].includes(userId)) { @@ -46,16 +59,14 @@ app.controller('ShareController', function (ShareResource, Loading) { return; } - // quick initialization (instead of if (...) : []) this.usersSharedArticles[itemId] = this.usersSharedArticles[itemId] ? this.usersSharedArticles[itemId] : []; - this.usersSharedArticles[itemId].push(userId); - var response = ShareResource.shareItem(itemId, userId); - response.then((result) => { + ShareResource.shareItem(itemId, userId) + .then((result) => { Loading.setLoading(userId, false); return result; }); }; -}); \ No newline at end of file +}); diff --git a/js/service/ShareResource.js b/js/service/ShareResource.js index f68918ca3..ff390a9e2 100644 --- a/js/service/ShareResource.js +++ b/js/service/ShareResource.js @@ -34,4 +34,4 @@ app.factory('ShareResource', function (Resource, $http, BASE_URL) { return new ShareResource($http, BASE_URL); -}); \ No newline at end of file +}); -- cgit v1.2.3