diff --git a/kudos-services/src/main/java/org/exoplatform/kudos/model/KudosEntityType.java b/kudos-services/src/main/java/org/exoplatform/kudos/model/KudosEntityType.java index ef9688a5a..a6167296a 100644 --- a/kudos-services/src/main/java/org/exoplatform/kudos/model/KudosEntityType.java +++ b/kudos-services/src/main/java/org/exoplatform/kudos/model/KudosEntityType.java @@ -1,5 +1,5 @@ package org.exoplatform.kudos.model; public enum KudosEntityType { - ACTIVITY, COMMENT, USER_PROFILE, USER_TIPTIP, SPACE_PROFILE, SPACE_TIPTIP + ACTIVITY, COMMENT, USER_PROFILE, USER_TIPTIP, SPACE_PROFILE, SPACE_TIPTIP, NONE } diff --git a/kudos-webapps/src/main/webapp/WEB-INF/gatein-resources.xml b/kudos-webapps/src/main/webapp/WEB-INF/gatein-resources.xml index b2da04134..9103fe686 100644 --- a/kudos-webapps/src/main/webapp/WEB-INF/gatein-resources.xml +++ b/kudos-webapps/src/main/webapp/WEB-INF/gatein-resources.xml @@ -165,6 +165,9 @@ extensionRegistry + + commonVueComponents + diff --git a/kudos-webapps/src/main/webapp/vue-app/js/KudosIdentity.js b/kudos-webapps/src/main/webapp/vue-app/js/KudosIdentity.js index 8e1af90d6..78a0f591c 100644 --- a/kudos-webapps/src/main/webapp/vue-app/js/KudosIdentity.js +++ b/kudos-webapps/src/main/webapp/vue-app/js/KudosIdentity.js @@ -38,7 +38,7 @@ export function getReceiver(entityType, entityId) { console.error('Error retrieving activity details with id', entityId, e); }); } else { - console.error('Unkown entity type', entityType, entityId); + return Promise.resolve(); } } diff --git a/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosAPI.vue b/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosAPI.vue index d7baf257b..57c770d6f 100644 --- a/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosAPI.vue +++ b/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosAPI.vue @@ -132,9 +132,9 @@ export default { document.dispatchEvent(new CustomEvent('displayTopBarLoading')); return this.$kudosService.deleteKudos(event.detail).catch(e => { if (e.message === 'KudosAlreadyLinked') { - document.dispatchEvent(new CustomEvent('notification-alert', {detail: { - message: this.$t('kudos.cancel.error.alreadyLinked'), - type: 'error', + document.dispatchEvent(new CustomEvent('alert-message', {detail: { + alertMessage: this.$t('kudos.cancel.error.alreadyLinked'), + alertType: 'error', }})); }}) .finally(() => document.dispatchEvent(new CustomEvent('hideTopBarLoading'))); diff --git a/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosApp.vue b/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosApp.vue index a38d72f35..fa52487e9 100644 --- a/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosApp.vue +++ b/kudos-webapps/src/main/webapp/vue-app/kudos/components/KudosApp.vue @@ -8,7 +8,7 @@ + @click="$refs.drawer.close()"> {{ $t('Confirmation.label.Cancel') }} 0) { - return getReceiver(this.entityType, this.entityId) - .then(receiverDetails => { - this.noReceiverIdentityId = false; - if (receiverDetails && receiverDetails.id && receiverDetails.type) { - receiverDetails.isUserType = receiverDetails.type === 'organization' || receiverDetails.type === 'user'; - if (!receiverDetails.isUserType || receiverDetails.id !== this.username) { - if (this.isLinkedKudos) { - this.selectedReceiver = { - receiverId: receiverDetails.id, - id: `organization:${receiverDetails.id}`, - identityId: receiverDetails.identityId, - profile: { - fullName: receiverDetails.fullname, - avatarUrl: receiverDetails.avatar, - external: receiverDetails.external === 'true', - }, - providerId: 'organization', - remoteId: receiverDetails.id - }; - } else { - this.identity = receiverDetails; - } - this.receiverId = receiverDetails.id; - this.receiverType = receiverDetails.type; - const receiverId = receiverDetails.id; - kudosToSend = { - receiverId: receiverId, - receiverType: receiverDetails.type, - avatar: receiverDetails.avatar, - profileUrl: `${eXo.env.portal.context}/${eXo.env.portal.portalName}/profile/${receiverId}`, - receiverIdentityId: receiverDetails.identityId, - receiverURL: receiverDetails.isUserType ? `/portal/intranet/profile/${receiverDetails.id}` : `/portal/g/:spaces:${receiverDetails.id}`, - receiverFullName: receiverDetails.fullname, - isCurrent: true + this.allKudos = this.allKudosSent.slice(0); + if (this.remainingKudos > 0) { + return (this.entityId && this.entityType && getReceiver(this.entityType, this.entityId) || Promise.resolve(null)) + .then(receiverDetails => { + this.noReceiverIdentityId = !receiverDetails; + if (receiverDetails?.id && receiverDetails?.type) { + receiverDetails.isUserType = receiverDetails.type === 'organization' || receiverDetails.type === 'user'; + if (!receiverDetails.isUserType || receiverDetails.id !== this.username) { + if (this.isLinkedKudos) { + this.selectedReceiver = { + receiverId: receiverDetails.id, + id: `organization:${receiverDetails.id}`, + identityId: receiverDetails.identityId, + profile: { + fullName: receiverDetails.fullname, + avatarUrl: receiverDetails.avatar, + external: receiverDetails.external === 'true', + }, + providerId: 'organization', + remoteId: receiverDetails.id }; - if (receiverDetails.entityId) { - this.entityId = receiverDetails.entityId; - } else { - this.noReceiverIdentityId = true; - if (!receiverDetails.identityId) { - this.selectedReceiver = null; - } - } - if (receiverDetails.notAuthorized) { - this.error = this.$t('exoplatform.kudos.warning.userNotAuthorizedToReceiveKudos'); - } else { - this.kudosToSend = kudosToSend; - } - this.allKudos.push(kudosToSend); - if (this.remainingKudos > 1) { - this.allKudos.push({}); + } else { + this.identity = receiverDetails; + } + this.receiverId = receiverDetails.id; + this.receiverType = receiverDetails.type; + const receiverId = receiverDetails.id; + kudosToSend = { + receiverId: receiverId, + receiverType: receiverDetails.type, + avatar: receiverDetails.avatar, + profileUrl: `${eXo.env.portal.context}/${eXo.env.portal.portalName}/profile/${receiverId}`, + receiverIdentityId: receiverDetails.identityId, + receiverURL: receiverDetails.isUserType ? `/portal/intranet/profile/${receiverDetails.id}` : `/portal/g/:spaces:${receiverDetails.id}`, + receiverFullName: receiverDetails.fullname, + isCurrent: true + }; + if (receiverDetails.entityId) { + this.entityId = receiverDetails.entityId; + } else { + this.noReceiverIdentityId = true; + if (!receiverDetails.identityId) { + this.selectedReceiver = null; } - this.$nextTick(() => { - if ($('.kudosIconContainerTop.kudosIconContainerCurrent').length) { - $('.kudosIconContainerTop.kudosIconContainerCurrent')[0].scrollIntoView(); - } - }); + } + if (receiverDetails.notAuthorized) { + this.error = this.$t('exoplatform.kudos.warning.userNotAuthorizedToReceiveKudos'); } else { - this.entityOwner = null; + this.kudosToSend = kudosToSend; + } + this.allKudos.push(kudosToSend); + if (this.remainingKudos > 1) { + this.allKudos.push({}); } - } else { - this.entityOwner = null; - console.error('Receiver not found for entity type/id', this.entityType, this.entityId, receiverDetails); - throw new Error(this.$t('exoplatform.kudos.error.errorGettingReceiverInformation')); + return this.$nextTick().then(() => { + if ($('.kudosIconContainerTop.kudosIconContainerCurrent').length) { + $('.kudosIconContainerTop.kudosIconContainerCurrent')[0].scrollIntoView(); + } + }); } - }) - .catch(e => { - this.error = String(e); - console.error('Error retrieving entity details with type and id', this.entityType, this.entityId, e); - }); - } + } + this.entityOwner = null; + }) + .catch(e => { + this.error = String(e); + console.error('Error retrieving entity details with type and id', this.entityType, this.entityId, e); + }); } }, refreshLink(element, entityType, entityId) { if (this.ignoreRefresh) { return Promise.resolve(null); } - this.$refs.activityKudosDrawer.startLoading(); + this.$refs.drawer.startLoading(); return getEntityKudos(entityType, entityId) .then(kudosList => { const $sendKudosLink = $(window.parentToWatch).find(`#SendKudosButton${entityType}${entityId}`); $sendKudosLink.data('kudosList', kudosList); this.kudosList = kudosList; }) - .finally(() => this.$refs.activityKudosDrawer.endLoading() + .finally(() => this.$refs.drawer.endLoading() ); }, openDrawer(event) { @@ -556,25 +557,24 @@ export default { this.loading = true; this.$nextTick(() => { this.readOnlySpace = event?.detail?.readOnlySpace; - this.entityType = event && event.detail && event.detail.type; - this.entityId = event && event.detail && event.detail.id; - this.metadataObjectId = null; - this.entityOwner = event && event.detail && event.detail.owner; - this.parentEntityId = event && event.detail && event.detail.parentId; + this.entityType = event?.detail?.type || 'NONE'; + this.entityId = event?.detail?.id || 0; + this.entityOwner = event?.detail?.owner || eXo.env.portal.userName; + this.parentEntityId = event?.detail?.parentId || ''; this.ignoreRefresh = event && event.detail && event.detail.ignoreRefresh; this.spaceURL = event && event.detail && event.detail.spaceURL || null; - this.$refs.activityKudosDrawer.open(); - this.$refs.activityKudosDrawer.startLoading(); - this.initDrawer() - .then(() => this.$nextTick()) + this.metadataObjectId = null; + this.$refs.drawer.open(); + this.$refs.drawer.startLoading(); + Promise.resolve(this.initDrawer()) + .finally(() => this.$nextTick()) .then(() => this.ckEditorInstance.initCKEditor()) .finally( () => { this.loading = false; - this.$refs.activityKudosDrawer.endLoading(); + this.$refs.drawer.endLoading(); }); }); - } - else { + } else { this.displayAlert(this.$t('exoplatform.kudos.info.noKudosLeft', { 0: this.remainingDaysToReset, 1: this.remainingPeriodLabel @@ -586,7 +586,7 @@ export default { this.error = null; const kudosMessage = this.ckEditorInstance.getMessage(); - this.$refs.activityKudosDrawer.startLoading(); + this.$refs.drawer.startLoading(); const kudos = { entityType: this.entityType, entityId: this.entityId, @@ -594,7 +594,7 @@ export default { receiverType: this.receiverType || 'user', receiverId: this.receiverId, message: kudosMessage, - spacePrettyName: this.audience?.remoteId || this.spaceId + spacePrettyName: this.audience?.remoteId || this.spacePrettyName, }; sendKudos(kudos) .then(kudosSent => { @@ -622,7 +622,7 @@ export default { this.selectedReceiver = null; this.resetAudienceChoice(); this.noReceiverIdentityId = false; - this.$refs.activityKudosDrawer.close(); + this.$refs.drawer.close(); this.displayAlert(this.$t('exoplatform.kudos.success.kudosSent')); }) .catch(e => { @@ -630,7 +630,7 @@ export default { this.error = String(e); }) .finally(() => { - this.$refs.activityKudosDrawer.endLoading(); + this.$refs.drawer.endLoading(); }); }, getRemainingDays() { @@ -650,10 +650,13 @@ export default { this.openSentKudos(); } }, + closeAlert() { + document.dispatchEvent(new CustomEvent('close-alert-message')); + }, displayAlert(message, type) { - document.dispatchEvent(new CustomEvent('notification-alert', {detail: { - message, - type: type || 'success', + document.dispatchEvent(new CustomEvent('alert-message', {detail: { + alertMessage: message, + alertType: type || 'success', }})); }, resetAudienceChoice() { diff --git a/kudos-webapps/src/main/webapp/vue-app/kudos/components/SendKudosToolbarAction.vue b/kudos-webapps/src/main/webapp/vue-app/kudos/components/SendKudosToolbarAction.vue index a0ca8ec4e..9159cc2b3 100644 --- a/kudos-webapps/src/main/webapp/vue-app/kudos/components/SendKudosToolbarAction.vue +++ b/kudos-webapps/src/main/webapp/vue-app/kudos/components/SendKudosToolbarAction.vue @@ -62,10 +62,6 @@ export default { methods: { openSendKudosDrawer() { document.dispatchEvent(new CustomEvent('exo-kudos-open-send-modal', {detail: { - id: eXo.env.portal.userIdentityId, - type: 'USER_PROFILE', - parentId: '', - owner: eXo.env.portal.userName, spaceURL: eXo.env.portal.spaceUrl, readOnlySpace: eXo.env.portal.spaceUrl ? true : false }}));