diff --git a/app-center-services/src/main/java/org/exoplatform/appcenter/service/ApplicationCenterService.java b/app-center-services/src/main/java/org/exoplatform/appcenter/service/ApplicationCenterService.java index 40d03fad1..df0fd3b75 100644 --- a/app-center-services/src/main/java/org/exoplatform/appcenter/service/ApplicationCenterService.java +++ b/app-center-services/src/main/java/org/exoplatform/appcenter/service/ApplicationCenterService.java @@ -569,8 +569,13 @@ public ApplicationList getAuthorizedApplicationsList(int offset, * {@link UserApplication} */ public ApplicationList getMandatoryAndFavoriteApplicationsList(String username) { - List mandatoryAndFavoriteApplications = appCenterStorage.getMandatoryApplications(); - mandatoryAndFavoriteApplications.addAll(appCenterStorage.getFavoriteApplicationsByUser(username)); + List mandatoryAndFavoriteApplications = appCenterStorage.getFavoriteApplicationsByUser(username); + List mandatoryAndFavoriteApplicationsId = mandatoryAndFavoriteApplications.stream().map(userApplication -> userApplication.getId()).collect(Collectors.toList()); + appCenterStorage.getMandatoryApplications().forEach(userApplication -> { + if (!mandatoryAndFavoriteApplicationsId.contains(userApplication.getId())) { + mandatoryAndFavoriteApplications.add(userApplication); + } + }); List applications = mandatoryAndFavoriteApplications.stream() .filter(app -> hasPermission(username, app)) .collect(Collectors.toList()); diff --git a/app-center-services/src/main/java/org/exoplatform/appcenter/storage/ApplicationCenterStorage.java b/app-center-services/src/main/java/org/exoplatform/appcenter/storage/ApplicationCenterStorage.java index 10d0d3f4b..d170ba28c 100644 --- a/app-center-services/src/main/java/org/exoplatform/appcenter/storage/ApplicationCenterStorage.java +++ b/app-center-services/src/main/java/org/exoplatform/appcenter/storage/ApplicationCenterStorage.java @@ -170,13 +170,14 @@ public void addApplicationToUserFavorite(long applicationId, String username) th favoriteApplicationDAO.create(new FavoriteApplicationEntity(application, username)); } - public void updateFavoriteApplicationOrder(long applicationId, String username, Long order) { + public void updateFavoriteApplicationOrder(long applicationId, String username, Long order) throws ApplicationNotFoundException { FavoriteApplicationEntity entity = favoriteApplicationDAO.getFavoriteAppByUserNameAndAppId(applicationId, username); - // check if it is a favorite application and not a system application - if (entity != null && !entity.getApplication().isMandatory()) { - entity.setOrder(order); - favoriteApplicationDAO.update(entity); + if (entity == null) { + addApplicationToUserFavorite(applicationId, username); + entity = favoriteApplicationDAO.getFavoriteAppByUserNameAndAppId(applicationId, username); } + entity.setOrder(order); + favoriteApplicationDAO.update(entity); } public void deleteApplicationFavorite(Long applicationId, String username) { @@ -204,7 +205,7 @@ public List getFavoriteApplicationsByUser(String username) { List applications = favoriteApplicationDAO.getFavoriteAppsByUser(username); return applications.stream() .map(this::toUserApplicationDTO) - .filter(userApplication -> userApplication.isActive() && !userApplication.isMandatory()) + .filter(userApplication -> userApplication.isActive()) .collect(Collectors.toList()); } diff --git a/app-center-webapps/src/main/webapp/vue-apps/appLauncher/components/AppLauncherDrawer.vue b/app-center-webapps/src/main/webapp/vue-apps/appLauncher/components/AppLauncherDrawer.vue index 12216720a..c494513fd 100644 --- a/app-center-webapps/src/main/webapp/vue-apps/appLauncher/components/AppLauncherDrawer.vue +++ b/app-center-webapps/src/main/webapp/vue-apps/appLauncher/components/AppLauncherDrawer.vue @@ -42,49 +42,6 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. v-if="hasApplications" slot="content" class="content"> - - - - - - - - { + console.log('getMandatoryAndFavoriteApplications, data=',data); // manage system apps localized names data.applications.forEach(app => { if (app.system) { @@ -290,47 +247,46 @@ export default { } else { applications.push(...data.applications); } - this.mandatoryApplicationsList = applications.filter(app => app.mandatory && !app.favorite); - // sort mandatory applications alphabetical - this.mandatoryApplicationsList.sort((a, b) => { - if (a.title < b.title) { + this.favoriteApplicationsList = applications.filter(app => app.favorite || app.mandatory); + // sort favorite applications alphabetically by default + if (this.favoriteApplicationsList.some(app => app.order !== null)) { + this.alphabeticalOrder = false; + } + + this.favoriteApplicationsList.sort((a, b) => { + if (typeof a.order === 'undefined' && typeof b.order === 'undefined') { + if (a.title < b.title) { + return -1; + } + if (a.title > b.title) { + return 1; + } + return 0; + } + if (a.order && typeof b.order === 'undefined') { return -1; } - - if (a.title > b.title) { + if (typeof a.order === 'undefined' && b.order) { return 1; } - - return 0; - }); - this.favoriteApplicationsList = applications.filter(app => app.favorite && !app.mandatory); - // sort favorite applications alphabetically by default - if (this.favoriteApplicationsList.some(app => app.order !== null)) { - this.alphabeticalOrder = false; - } else { - this.favoriteApplicationsList.sort((a, b) => { + if (a.order === b.order) { if (a.title < b.title) { return -1; } - if (a.title > b.title) { return 1; } - return 0; - }); - } + } + return a.order - b.order; + + }); + // store favorite applications order this.applicationsOrder = {}; this.favoriteApplicationsList.forEach(app => { this.applicationsOrder[`${app.id}`] = this.favoriteApplicationsList.indexOf(app); }); - - this.mandatoryApplicationsList.forEach(app => { - app.computedUrl = app.url.replace(/^\.\//, `${eXo.env.portal.context}/${eXo.env.portal.portalName}/`); - app.computedUrl = app.computedUrl.replace('@user@', eXo.env.portal.userName); - app.target = app.computedUrl.indexOf('/') === 0 ? '_self' : '_blank'; - }); this.favoriteApplicationsList.forEach(app => { app.computedUrl = app.url.replace(/^\.\//, `${eXo.env.portal.context}/${eXo.env.portal.portalName}/`); app.computedUrl = app.computedUrl.replace('@user@', eXo.env.portal.userName); @@ -339,6 +295,7 @@ export default { }).finally(() => this.loading = false); }, updateApplicationsOrder(applicationsOrder) { + console.log('updateApplicationsOrder=',applicationsOrder); return fetch('/portal/rest/app-center/applications/favorites', { headers: { 'Content-Type': 'application/json' diff --git a/app-center-webapps/src/main/webapp/vue-apps/userSetup/components/UserFavoriteApplications.vue b/app-center-webapps/src/main/webapp/vue-apps/userSetup/components/UserFavoriteApplications.vue index d2498f0a0..c9c118ba6 100644 --- a/app-center-webapps/src/main/webapp/vue-apps/userSetup/components/UserFavoriteApplications.vue +++ b/app-center-webapps/src/main/webapp/vue-apps/userSetup/components/UserFavoriteApplications.vue @@ -177,36 +177,37 @@ export default { allApplications.push(...data.applications); } } - const mandatoryApps = allApplications.filter(app => app.mandatory && !app.favorite); - const favoriteApps = allApplications.filter(app => app.favorite && !app.mandatory); - mandatoryApps.sort((a, b) => { - if (a.title < b.title) { + this.favoriteApplicationsList = allApplications; + + // check if favorite applications are alphabetically ordered + this.favoriteApplicationsList.sort((a, b) => { + if (typeof a.order === 'undefined' && typeof b.order === 'undefined') { + if (a.title < b.title) { + return -1; + } + if (a.title > b.title) { + return 1; + } + return 0; + } + if (a.order && typeof b.order === 'undefined') { return -1; } - - if (a.title > b.title) { + if (typeof a.order === 'undefined' && b.order) { return 1; } - - return 0; - }); - // check if favorite applications are alphabetically ordered - if (!favoriteApps.some(app => app.order !== null)) { - favoriteApps.sort((a, b) => { + if (a.order === b.order) { if (a.title < b.title) { return -1; } - if (a.title > b.title) { return 1; } - return 0; - }); - } - this.favoriteApplicationsList = []; - this.favoriteApplicationsList.push(...mandatoryApps); - this.favoriteApplicationsList.push(...favoriteApps); + } + return a.order - b.order; + }); + this.favoriteApplicationsList.forEach(app => { app.computedUrl = app.url.replace(/^\.\//, `${eXo.env.portal.context}/${eXo.env.portal.portalName}/`); app.computedUrl = app.computedUrl.replace('@user@', eXo.env.portal.userName);