Skip to content

Commit

Permalink
Gamification connectors - Meeds-io/MIPs#64
Browse files Browse the repository at this point in the history
  • Loading branch information
AzmiTouil committed Jun 6, 2023
1 parent c5773df commit b9b2689
Show file tree
Hide file tree
Showing 12 changed files with 506 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ gamification.actions.filter.upcomingActions=Upcoming actions
gamification.actions.filter.endedActions=Ended actions
gamification.actions.filter.disabledActions=Disabled actions
gamification.apply=Apply
gamification.actions.filter.disabledActions=Disabled actions
gamification.achivementRecurrence.once=Once
gamification.achivementRecurrence.onceTooltip=Action is gamified only once
gamification.achivementRecurrence.daily=Daily
Expand All @@ -392,3 +391,14 @@ gamification.achivementRecurrence.weekly=Weekly
gamification.achivementRecurrence.weeklyTooltip=Action is gamified at most once per week
gamification.achivementRecurrence.monthly=Monthly
gamification.achivementRecurrence.monthlyTooltip=Action is gamified at most once per month

gamification.connectors.label.connectors=Gamification connectors
gamification.connectors.label.add=Add
gamification.connectors.label.remove=Remove
gamification.connectors.label.connected=Connected
gamification.connectors.label.noActiveConnectors=No gamification connector available
gamification.connectors.label.connectionFailure=Error while connecting




Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,55 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</init-params>
</component-plugin>
</external-component-plugins>
<external-component-plugins>
<target-component>org.exoplatform.commons.addons.AddOnService</target-component>
<component-plugin>
<name>addPlugin</name>
<set-method>addPlugin</set-method>
<type>org.exoplatform.commons.addons.AddOnPluginImpl</type>
<description></description>
<init-params>
<value-param>
<name>priority</name>
<value>3</value>
</value-param>
<value-param>
<name>containerName</name>
<value>settings-bottom-container</value>
</value-param>
<object-param>
<name>gamification-connectors-settings</name>
<description></description>
<object type="org.exoplatform.commons.addons.PortletModel">
<field name="contentId">
<string>gamification-portlets/ConnectorsSettings</string>
</field>
<field name="permissions">
<collection type="java.util.ArrayList">
<value>
<string>*:/platform/users</string>
</value>
<value>
<string>*:/platform/externals</string>
</value>
</collection>
</field>
<field name="title">
<string>Gamification Connectors Settings</string>
</field>
<field name="showInfoBar">
<boolean>false</boolean>
</field>
<field name="showApplicationState">
<boolean>false</boolean>
</field>
<field name="showApplicationMode">
<boolean>false</boolean>
</field>
</object>
</object-param>
</init-params>
</component-plugin>
</external-component-plugins>

</configuration>
29 changes: 29 additions & 0 deletions portlets/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,35 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</module>
</portlet>

<portlet>
<name>ConnectorsSettings</name>
<module>
<load-group>gamification-connectors</load-group>
<script>
<minify>false</minify>
<path>/js/connectorsSettings.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>gamificationCommon</module>
</depends>
</module>
</portlet>

<module>
<name>EngagementCenterActivityStreamExtension</name>
<load-group>ActivityStreamGRP</load-group>
Expand Down
20 changes: 20 additions & 0 deletions portlets/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,24 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
</portlet-info>
</portlet>

<portlet>
<portlet-name>ConnectorsSettings</portlet-name>
<display-name xml:lang="EN">Gamification Connectors Settings</display-name>
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/html/connectorsSettings.html</value>
</init-param>
<expiration-cache>-1</expiration-cache>
<cache-scope>PUBLIC</cache-scope>
<supports>
<mime-type>text/html</mime-type>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Gamification Connectors Settings</title>
<keywords>Gamification Connectors Settings</keywords>
</portlet-info>
</portlet>

</portlet-app>
7 changes: 7 additions & 0 deletions portlets/src/main/webapp/html/connectorsSettings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="VuetifyApp">
<div id="connectorsSettingsApp">
<script type="text/javascript">
require(['PORTLET/gamification-portlets/ConnectorsSettings'], app => app.init());
</script>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<v-app>
<v-card class="my-3 border-radius" flat>
<v-list two-line>
<v-list-item>
<v-list-item-content>
<v-list-item-title class="title text-color">
{{ $t('gamification.connectors.label.connectors') }}
</v-list-item-title>
<v-list-item-subtitle class="my-3 text-sub-title font-italic">
<gamification-connector-status :connectors="connectors" />
</v-list-item-subtitle>
</v-list-item-content>
<v-list-item-action>
<v-btn
small
icon
@click="openDrawer">
<i class="uiIconEdit uiIconLightBlue pb-2"></i>
</v-btn>
</v-list-item-action>
<gamification-connectors-drawer :connectors="enabledConnectors" />
<gamification-connector
:settings="settings"
:connectors="connectors"
auto-connect
@connectors-loaded="connectors = $event" />
</v-list-item>
</v-list>
</v-card>
</v-app>
</template>

<script>
export default {
props: {
settings: {
type: Object,
default: () => null,
},
},
data: () => ({
connectors: [],
}),
computed: {
enabledConnectors() {
return this.connectors && this.connectors.filter(connector => connector.enabled) || [];
},
},
methods: {
openDrawer() {
this.$root.$emit('gamification-connectors-drawer-open');
},
},
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<script>
export default {
props: {
settings: {
type: Object,
default: () => null,
},
connectors: {
type: Object,
default: () => null,
},
},
data: () => ({
loading: false,
}),
computed: {
connectedConnectorUser() {
return this.connectedConnector && this.connectedConnector.user;
},
connectedConnector() {
return this.connectors && this.connectors.find(connector => connector.connected);
},
},
created() {
document.addEventListener('gamification-connectors-refresh', this.refreshConnectorsList);
this.$root.$on('gamification-connectors-init', this.initConnectors);
this.$root.$on('gamification-connector-connect', this.addAccount);
this.$root.$on('gamification-connector-disconnect', this.removeAccount);
},
mounted() {
this.refreshConnectorsList();
},
methods: {
refreshConnectorsList() {
// Get list of connectors from extensionRegistry
const connectors = extensionRegistry.loadExtensions('gamification', 'connectors') || [];
connectors
.forEach(connector => {
connector.enabled = true;
});
this.$emit('connectors-loaded', connectors);
},
initConnectors() {
this.connectors
.forEach(connector => {
if (connector.init && !connector.initialized && connector.enabled && connector.apiKey) {
connector.init(this.connectionStatusChanged, this.connectionLoading, connector.apiKey, connector.secretKey);
}
});
},
addAccount(connector) {
this.errorMessage = null;
const disconnectPromises = [];
this.connectors.forEach(otherConnector => {
if (connector.name !== otherConnector.name && (otherConnector.user || otherConnector.isSignedIn)) {
disconnectPromises.push(this.disconnect(otherConnector));
}
});
this.$set(connector, 'loading', true);
return Promise.all(disconnectPromises)
.then(() => connector.addAccount(connector))
.then(() => {
this.$set(connector, 'loading', false);
})
.catch(error => {
console.error('Connected - error', connector.name, error);
this.$set(connector, 'loading', false);
if (error.error !== 'popup_closed_by_user') {
console.error('Error while connecting to remote account: ', error);
this.errorMessage = this.$t('gamification.connectors.label.connectionFailure');
}
});
},
removeAccount(connector) {
//disconnect from connected browser
if (connector.isSignedIn) {
return connector.removeAccount().then(() => this.resetConnector(connector));
} else {//disconnect from other browser
return this.resetConnector(connector);
}
},
resetConnector(connector) {
this.$set(connector, 'loading', true);
return this.$settingsService.resetUserConnector()
.then(() => {
this.$set(connector, 'isSignedIn', false);
this.$set(connector, 'connected', false);
this.$set(connector, 'user', null);
})
.finally(() => {
this.$set(connector, 'loading', false);
});
},
connectionLoading(connector, loading) {
this.$set(connector, 'loading', loading);
if (loading) {
this.$set(connector, 'error', '');
this.loading++;
} else if (this.loading) {
this.loading--;
}
},
connectionStatusChanged(connector, connectedUser, error) {
if (connectedUser) {
this.$set(connector, 'error', '');
this.$root.$emit('gamification-connector-connected', connector);
} else if (error) {
const errorMessage = error.details || error.error || error.message || String(error);
this.$set(connector, 'error', errorMessage);
} else {
this.cleanConnectorStatus(connector, connectedUser);
}
},
cleanConnectorStatus(connector, connectedUser) {
this.$set(connector, 'error', '');
if (this.connectedConnectorUser) {
//if user is connected with different account from other browser
if (connectedUser && connectedUser.user !== this.connectedConnectorUser) {
connector.disconnect();
}
} else if (connector && connector.isSignedIn) {
//if user disconnected from other browser
connector.disconnect();
}
this.refreshConnectorsList();
},
},
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div class="connector-status">
<div v-if="connectedConnectorUser" class="connector-connected d-flex">
<v-list-item-avatar class="rounded-0 me-0">
<v-avatar size="32" tile>
<v-icon
size="30">
{{ connectedConnectorIcon }}
</v-icon>
</v-avatar>
</v-list-item-avatar>
<a
class="mx-2 my-auto">
{{ connectedConnectorUser }}
</a>
</div>
</div>
</template>
<script>
export default {
props: {
connectors: {
type: Array,
default: () => null
},
},
computed: {
connectedConnector() {
return this.connectors.find(connector => connector.user);
},
connectedConnectorUser() {
return this.connectedConnector && this.connectedConnector.user || '';
},
connectedConnectorIcon() {
return this.connectedConnector && this.connectedConnector.icon || '';
},
},
};
</script>
Loading

0 comments on commit b9b2689

Please sign in to comment.