Skip to content

Commit

Permalink
feat: Allow to Hide Actions Widget when empty using UI - MEED-7649 - M…
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker committed Nov 4, 2024
1 parent 3ecbef3 commit b4458f1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,9 @@ gamification.overview.monthlyAchievements=Contributions of the Month
gamification.overview.quarterlyAchievements=Contributions of the Quarter
gamification.overview.noWeeklyAchievements=No contributions yet this week
gamification.overview.actions=Actions
gamification.overview.space.actions=Community Actions
gamification.overview.actionsList=Actions
gamification.overview.space.actionsList=Community Actions
gamification.overview.programsList=Programs
gamification.overview.space.programsList=Community Programs
gamification.overview.leaderboard.drawer.title=Leaderboard
Expand Down Expand Up @@ -614,6 +616,7 @@ gamification.rules.overviewSettings.actionsEndingSoon=Actions ending soon
gamification.rules.overviewSettings.actionsToDoFirst=Actions to do first
gamification.rules.overviewSettings.actionsAvailable=Actions Available
gamification.rules.overviewSettings.actionsSoonAvailable=Actions Soon Available
gamification.rules.overviewSettings.hideWhenEmpty=Hide widget when no actions to list

gamification.myContributions.title=My Contributions
gamification.myContributions.settings.title=Edit Contributions Widget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</value>
</collection>
</field>
<field name="portletPrefs">
<map type="java.util.HashMap">
<entry>
<key>
<string>hideWidgetWhenEmpty</string>
</key>
<value>
<string>true</string>
</value>
</entry>
</map>
</field>
<field name="title">
<string>Rules Overview</string>
</field>
Expand Down
2 changes: 2 additions & 0 deletions portlets/src/main/webapp/WEB-INF/jsp/rulesOverview.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
if (Utils.canAccessAnonymousResources()) {
String portletStorageId = ((String) request.getAttribute("portletStorageId"));
String sortBy = request.getAttribute("rulesSortBy") == null ? "score" : ((String[]) request.getAttribute("rulesSortBy"))[0];
String hideWidgetWhenEmpty = request.getAttribute("hideWidgetWhenEmpty") == null ? "false" : ((String[]) request.getAttribute("hideWidgetWhenEmpty"))[0];
String lockedRulesLimit = request.getAttribute("lockedRulesLimit") == null ? "2" : ((String[]) request.getAttribute("lockedRulesLimit"))[0];
String endingRulesLimit = request.getAttribute("endingRulesLimit") == null ? "2" : ((String[]) request.getAttribute("endingRulesLimit"))[0];
String availableRulesLimit = request.getAttribute("availableRulesLimit") == null ? "4" : ((String[]) request.getAttribute("availableRulesLimit"))[0];
Expand All @@ -46,6 +47,7 @@
<%=availableRulesLimit%>,
<%=upcomingRulesLimit%>,
'<%=sortBy%>',
<%=hideWidgetWhenEmpty%>,
<%=canEdit%>,
'<%=pageRef%>'
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
<v-hover v-model="hover">
<gamification-rules-overview-widget
:hover-edit="hoverEdit"
:hide-empty-placeholder="$root.hideWidgetWhenEmpty"
@open-list="$refs.listDrawer.open()"
@hide="hidden = true" />
</v-hover>
<gamification-rules-overview-list-drawer
ref="listDrawer" />
<gamification-rules-overview-settings-drawer
v-if="$root.canEdit" />
v-if="$root.canEdit && !hidden" />
<engagement-center-rule-extensions />
</v-app>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
v-model="drawer"
:right="!$vuetify.rtl"
:loading="loading"
eager
@closed="reset">
eager>
<template slot="title">
{{ $t('gamification.rules.overviewSettings.title') }}
</template>
Expand Down Expand Up @@ -84,6 +83,12 @@
:step="1"
class="ms-auto me-n1 my-0 pa-0" />
</div>
<div class="d-flex align-center px-5 mt-4">
<div>{{ $t('gamification.rules.overviewSettings.hideWhenEmpty') }}</div>
<v-switch
v-model="hideWidgetWhenEmpty"
class="ms-auto my-0 pa-0" />
</div>
</template>
<template #footer>
<div class="d-flex align-center">
Expand Down Expand Up @@ -114,6 +119,7 @@ export default {
endingRulesLimit: 0,
availableRulesLimit: 0,
upcomingRulesLimit: 0,
hideWidgetWhenEmpty: false,
sortBy: 'score',
}),
computed: {
Expand All @@ -135,13 +141,13 @@ export default {
},
created() {
this.$root.$on('rules-overview-settings', this.open);
this.reset();
},
beforeDestroy() {
this.$root.$off('rules-overview-settings', this.open);
},
methods: {
open() {
this.reset();
this.$refs.drawer.open();
},
reset() {
Expand All @@ -150,17 +156,19 @@ export default {
this.endingRulesLimit = this.$root.endingRulesLimit;
this.availableRulesLimit = this.$root.availableRulesLimit;
this.upcomingRulesLimit = this.$root.upcomingRulesLimit;
this.hideWidgetWhenEmpty = this.$root.hideWidgetWhenEmpty;
this.loading = false;
},
close() {
this.$refs.drawer.close();
},
save() {
this.loading = true;
const formData = new FormData();
formData.append('pageRef', this.$root.pageRef);
formData.append('applicationId', this.$root.portletStorageId);
const params = new URLSearchParams(formData).toString();
this.loading = true;
return fetch(`/layout/rest/pages/application/preferences?${params}`, {
method: 'PATCH',
credentials: 'include',
Expand All @@ -180,6 +188,9 @@ export default {
}, {
name: 'upcomingRulesLimit',
value: String(this.upcomingRulesLimit),
}, {
name: 'hideWidgetWhenEmpty',
value: String(this.hideWidgetWhenEmpty),
}, {
name: 'rulesSortBy',
value: this.sortBy || 'modifiedDate',
Expand All @@ -192,8 +203,10 @@ export default {
this.$root.endingRulesLimit = this.endingRulesLimit;
this.$root.availableRulesLimit = this.availableRulesLimit;
this.$root.upcomingRulesLimit = this.upcomingRulesLimit;
window.setTimeout(() => this.$root.hideWidgetWhenEmpty = this.hideWidgetWhenEmpty, 500);
this.close();
})
.then(() => this.$nextTick())
.finally(() => this.loading = false);
},
},
Expand Down
2 changes: 2 additions & 0 deletions portlets/src/main/webapp/vue-app/rulesOverview/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function init(
availableRulesLimit,
upcomingRulesLimit,
rulesSortBy,
hideWidgetWhenEmpty,
canEdit,
pageRef) {
exoi18n.loadLanguageAsync(lang, urls)
Expand All @@ -45,6 +46,7 @@ export function init(
availableRulesLimit,
upcomingRulesLimit,
rulesSortBy,
hideWidgetWhenEmpty,
canEdit: portletStorageId && canEdit || false,
pageRef,
displayNotPublicallyVisible: eXo.env.portal.portalName === 'public' && canEdit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</gamification-overview-widget-row>
<div v-else class="d-flex flex-column align-center justify-center full-width full-height">
<v-icon color="tertiary" size="60">fa-rocket</v-icon>
<span class="text-body mt-5">{{ $t('gamification.overview.actions') }}</span>
<span class="text-body mt-5">{{ spaceId && $t('gamification.overview.space.actions') || $t('gamification.overview.actions') }}</span>
</div>
</template>
<script>
Expand All @@ -56,6 +56,9 @@ export default {
default: false,
},
},
data: () => ({
spaceId: eXo.env.portal.spaceId,
}),
computed: {
completedRulesImageIndex() {
return (Number(eXo.env.portal.spaceId || '0') + Number(eXo.env.portal.userIdentityId)) % 8 + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
:right="!$vuetify.rtl"
:go-back-button="goBackButton">
<template #title>
{{ $t('gamification.overview.actionsList') }}
{{ spaceId && $t('gamification.overview.space.actionsList') || $t('gamification.overview.actionsList') }}
</template>
<template #titleIcons>
<v-btn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,10 @@ export default {
return this.sectionsCount > 0;
},
isHiddenWhenEmpty() {
return (this.hideIfEmpty && !this.hideEmptyPlaceholder)
|| this.$root.isAnonymous
|| (this.spaceId?.length
&& (eXo.env.portal.hiddenGamOverviewEmptyWidgetBySpace?.[this.spaceId]
|| !this.activeRulesSize))
return this.$root.isAnonymous
|| this.hideEmptyPlaceholder
|| this.hideIfEmpty
|| eXo.env.portal.hiddenGamOverviewEmptyWidgetBySpace?.[this.spaceId]
|| false;
},
isHiddenWidget() {
Expand Down

0 comments on commit b4458f1

Please sign in to comment.