Skip to content

Commit

Permalink
feat: Add Page Layout Statistics - MEED-6885 - Meeds-io/MIPs#133 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored May 20, 2024
1 parent 6bf0d9b commit 6daf328
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 29 deletions.
18 changes: 18 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,22 @@ files: [
"escape_special_characters": 0,
"escape_quotes" : 0,
},
{
"source" : "/layout-webapp/src/main/resources/locale/portlet/Analytics_en.properties",

"translation" : "%original_path%/%file_name%!_%locale_with_underscore%.%file_extension%",
"translation_replace" : {
"_en!": "","ar_SA": "ar","ar_OM": "aro","az_AZ": "az","ca_ES": "ca","ceb_PH": "ceb",
"co_FR": "co","cs_CZ": "cs","de_DE": "de","el_GR": "el","en_US": "en","es_ES": "es_ES","eu_ES": "eu","fa_IR": "fa",
"fi_FI": "fi","fil_PH": "fil","fr_FR": "fr","hi_IN": "hi","hu_HU": "hu","id_ID": "id","it_IT": "it","ja_JP": "ja",
"kab_KAB": "kab","ko_KR": "ko","lt_LT": "lt","ms_MY": "ms","nl_NL": "nl","no_NO": "no","pcm_NG": "pcm","pl_PL": "pl",
"pt_BR": "pt_BR","pt_PT": "pt_PT","ro_RO": "ro","ru_RU": "ru","sk_SK": "sk","sl_SI": "sl","sq_AL": "sq",
"sv_SE": "sv_SE","th_TH": "th","tl_PH": "tl","tr_TR": "tr","uk_UA": "uk","ur_IN": "ur_IN","vi_VN": "vi",
"zh_CN": "zh_CN","zh_TW": "zh_TW",
},
"dest" : "add__ons/layout/portlet/Analytics.properties",
"update_option" : "update_as_unapproved",
"escape_special_characters": 0,
"escape_quotes" : 0,
},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
analytics.field.label.applicationName=Application Name

analytics.field.label.pageTemplateId=Page Template Id
analytics.field.label.pageTemplateName=Page Template Name
analytics.field.label.pageTemplateCategory=Page Template Category
analytics.field.label.pageTemplateDisabled=Is Page Template Disabled
analytics.field.label.pageTemplateSystem=Is Page Template System
analytics.field.label.pageTemplateIllustrationId=Page Template illustration id
analytics.field.label.pageTemplatePage=Page Template originating page
analytics.field.label.pageReference=Page reference
analytics.field.label.siteName=Site name
analytics.field.label.siteType=Site type
analytics.field.label.pageType=Page type
analytics.field.label.pageName=Page name

analytics.pageLayout=Page Layout
analytics.createPageLayout=Create Page Layout
analytics.createPageTemplate=Create Page Template
analytics.updatePageTemplate=Update Page Template
analytics.deletePageTemplate=Delete Page Template
analytics.enablePageTemplate=Enable Page Template
analytics.disablePageTemplate=Disable Page Template
analytics.siteNavigation=Site topbar navigation
analytics.siteManagement=Sites Management
analytics.pageTemplateManagement=Page Templates Management
analytics.pageLayoutEditor=Layout Editor

analytics.customized=Customized
analytics.blank=Blank
analytics.analytics=Analytics
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ export default {
this.navigationNode.siteKey.name,
this.navigationNode.siteKey.type,
this.elementType, this.elementType === 'LINK' && this.link || null,
this.elementType === 'PAGE' && this.pageTemplate?.id || null)
this.elementType === 'PAGE' && this.pageTemplate?.id || null
)
.then((createdPage) => {
const pageRef = createdPage?.key?.ref || `${createdPage?.key.site.typeName}::${createdPage?.key.site.name}::${createdPage?.pageContext?.key.name}`;
this.$root.$emit('save-node-with-page', {
Expand All @@ -257,6 +258,9 @@ export default {
'createdPage': createdPage,
'openEditLayout': this.elementType === 'PAGE',
});
return createdPage;
}).then(page => {
this.$root.$emit('page-layout-created', page, this.pageTemplate);
}).catch(() => {
this.$root.$emit('alert-message', this.$t('siteNavigation.label.pageCreation.error'), 'error');
}).finally(() => this.loading = false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<script>
export default {
props: {
applicationName: {
type: String,
default: null,
},
},
created() {
this.$root.$on('page-templates-created', this.handlePageTemplateCreation);
this.$root.$on('page-templates-updated', this.handlePageTemplateUpdate);
this.$root.$on('page-templates-deleted', this.handlePageTemplateDeletion);
this.$root.$on('page-templates-enabled', this.handlePageTemplateEnabled);
this.$root.$on('page-templates-disabled', this.handlePageTemplateDisabled);
this.$root.$on('page-layout-created', this.handlePageCreated);
},
beforeDestroy() {
this.$root.$off('page-templates-created', this.handlePageTemplateCreation);
this.$root.$off('page-templates-updated', this.handlePageTemplateUpdate);
this.$root.$off('page-templates-deleted', this.handlePageTemplateDeletion);
this.$root.$off('page-templates-enabled', this.handlePageTemplateEnabled);
this.$root.$off('page-templates-disabled', this.handlePageTemplateDisabled);
this.$root.$off('page-layout-created', this.handlePageCreated);
},
methods: {
handlePageCreated(page, pageTemplate) {
this.sendAnalytics('pageLayout', 'createPageLayout', {
pageTemplateId: pageTemplate?.id || null,
pageTemplateName: pageTemplate?.name || null,
pageTemplateCategory: pageTemplate?.id && (pageTemplate?.category || 'customized') || null,
pageTemplateDisabled: pageTemplate?.id && `${pageTemplate.disabled}` || null,
pageTemplateSystem: pageTemplate?.id && `${pageTemplate.system}` || null,
pageTemplateIllustrationId: pageTemplate?.id && pageTemplate.illustrationId || null,
pageName: page?.state?.displayName,
pageReference: page?.key?.ref,
pageType: page?.state?.type,
siteName: page?.key?.site?.name,
siteType: page?.key?.site?.type,
});
},
handlePageTemplateCreation(pageTemplate, pageRef) {
this.sendAnalytics('pageTemplate', 'createPageTemplate', {
pageTemplateId: pageTemplate.id,
pageTemplateName: pageTemplate.name,
pageTemplateCategory: pageTemplate.category || 'customized',
pageTemplateDisabled: `${pageTemplate.disabled}`,
pageTemplateSystem: `${pageTemplate.system}`,
pageTemplateIllustrationId: pageTemplate.illustrationId,
pageTemplatePage: pageRef,
});
},
handlePageTemplateUpdate(pageTemplate) {
this.sendAnalytics('pageTemplate', 'updatePageTemplate', {
pageTemplateId: pageTemplate.id,
pageTemplateName: pageTemplate.name,
pageTemplateCategory: pageTemplate.category,
pageTemplateDisabled: `${pageTemplate.disabled}`,
pageTemplateSystem: `${pageTemplate.system}`,
pageTemplateIllustrationId: pageTemplate.illustrationId,
});
},
handlePageTemplateDeletion(pageTemplate) {
this.sendAnalytics('pageTemplate', 'deletePageTemplate', {
pageTemplateId: pageTemplate.id,
pageTemplateName: pageTemplate.name,
pageTemplateCategory: pageTemplate.category,
pageTemplateDisabled: `${pageTemplate.disabled}`,
pageTemplateSystem: `${pageTemplate.system}`,
pageTemplateIllustrationId: pageTemplate.illustrationId,
});
},
handlePageTemplateEnabled(pageTemplate) {
this.sendAnalytics('pageTemplate', 'enablePageTemplate', {
pageTemplateId: pageTemplate.id,
pageTemplateName: pageTemplate.name,
pageTemplateCategory: pageTemplate.category,
pageTemplateDisabled: `${pageTemplate.disabled}`,
pageTemplateSystem: `${pageTemplate.system}`,
pageTemplateIllustrationId: pageTemplate.illustrationId,
});
},
handlePageTemplateDisabled(pageTemplate) {
this.sendAnalytics('pageTemplate', 'disablePageTemplate', {
pageTemplateId: pageTemplate.id,
pageTemplateName: pageTemplate.name,
pageTemplateCategory: pageTemplate.category,
pageTemplateDisabled: `${pageTemplate.disabled}`,
pageTemplateSystem: `${pageTemplate.system}`,
pageTemplateIllustrationId: pageTemplate.illustrationId,
});
},
sendAnalytics(subModule, operation, parameters) {
parameters.applicationName = this.applicationName;
document.dispatchEvent(new CustomEvent('exo-statistic-message', {
detail: {
module: 'layout',
subModule,
userId: eXo.env.portal.userIdentityId,
userName: eXo.env.portal.userName,
spaceId: eXo.env.portal.spaceId || 0,
operation,
timestamp: Date.now(),
parameters,
}
}));
},
},
};
</script>
28 changes: 28 additions & 0 deletions layout-webapp/src/main/webapp/vue-app/common/initComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

import LayoutAnalytics from './components/LayoutAnalytics.vue';

const components = {
'layout-analytics': LayoutAnalytics,
};

for (const key in components) {
Vue.component(key, components[key]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
@modified="modified = true" />
<layout-editor-cells-selection-box />
</div>
<layout-analytics
:application-name="pageTemplateId ? 'pageTemplateManagement' : 'pageLayoutEditor'" />
</v-app>
</template>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,22 @@ export default {
this.$pageTemplateService.getPageTemplate(this.templateId)
.then(pageTemplate => {
const newTemplate = (this.$root.pageTemplate && !this.$root.pageTemplate.name);
const disabled = newTemplate ? false : pageTemplate.disabled;
return this.$pageTemplateService.updatePageTemplate({
...pageTemplate,
disabled,
content: this.pageLayoutContent,
});
pageTemplate.disabled = newTemplate ? false : pageTemplate.disabled;
pageTemplate.content = this.pageLayoutContent;
return this.$pageTemplateService.updatePageTemplate(pageTemplate)
.then(() => {
if (newTemplate) {
this.$root.$emit('page-templates-created', pageTemplate);
} else {
this.$root.$emit('page-templates-updated', pageTemplate);
}
});
})
: this.$pageTemplateService.createPageTemplate(this.pageLayoutContent);
: this.$pageTemplateService.createPageTemplate(this.pageLayoutContent)
.then(pageTemplate => {
this.$root.$emit('page-templates-created', pageTemplate, this.$root.pageRef);
return pageTemplate;
});
return savePageRequest
.then(pageTemplate => {
if (pageTemplate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ export default {
this.$root.$emit('close-alert-message');
this.loading = true;
this.$pageTemplateService.getPageTemplate(this.$root.pageTemplateId)
.then(pageTemplate => this.$pageTemplateService.updatePageTemplate({
...pageTemplate,
content: JSON.stringify(pageLayout),
}))
.then(pageTemplate => {
pageTemplate.content = JSON.stringify(pageLayout);
return this.$pageTemplateService.updatePageTemplate(pageTemplate)
.then(() => {
this.$root.$emit('page-templates-updated', pageTemplate);
return pageTemplate;
});
})
.then(() => {
this.$root.$emit('alert-message', this.$t('pageTemplate.layout.update.success'), 'success');
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import './initComponents.js';
import '../common/initComponents.js';
import './extensions.js';
import './services.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
</v-card>
<layout-editor-page-template-drawer />
<page-templates-management-illustration-preview />
<layout-analytics application-name="pageTemplateManagement" />
</v-app>
</template>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ export default {
this.$root.$emit('close-alert-message');
this.loading = true;
this.$pageTemplateService.getPageTemplate(this.pageTemplate.id)
.then(pageTemplate => this.$pageTemplateService.updatePageTemplate({
...pageTemplate,
disabled: this.enabled,
}))
.then(pageTemplate => {
pageTemplate.disabled = this.enabled;
return this.$pageTemplateService.updatePageTemplate(pageTemplate)
.then(() => {
this.$root.$emit(`page-templates-${this.enabled && 'disabled' || 'enabled'}`, pageTemplate);
});
})
.then(() => {
this.$root.$emit('page-templates-refresh');
this.$root.$emit('alert-message', this.$t('pageTemplate.status.update.success'), 'success');
})
.catch(() => this.$root.$emit('alert-message', this.$t('pageTemplate.status.update.error'), 'error'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,21 @@ export default {
},
},
created() {
this.$root.$on('page-templates-saved', this.refreshPageTemplates);
this.$root.$on('page-templates-refresh', this.refreshPageTemplates);
this.$root.$on('page-templates-deleted', this.refreshPageTemplates);
this.$root.$on('page-templates-created', this.refreshPageTemplates);
this.$root.$on('page-templates-updated', this.refreshPageTemplates);
this.$root.$on('page-templates-enabled', this.refreshPageTemplates);
this.$root.$on('page-templates-disabled', this.refreshPageTemplates);
this.$root.$on('page-templates-delete', this.deletePageTemplateConfirm);
this.$root.$on('page-templates-create', this.createPageTemplate);
this.refreshPageTemplates();
},
beforeDestroy() {
this.$root.$off('page-templates-saved', this.refreshPageTemplates);
this.$root.$off('page-templates-refresh', this.refreshPageTemplates);
this.$root.$off('page-templates-deleted', this.refreshPageTemplates);
this.$root.$off('page-templates-created', this.refreshPageTemplates);
this.$root.$off('page-templates-updated', this.refreshPageTemplates);
this.$root.$off('page-templates-enabled', this.refreshPageTemplates);
this.$root.$off('page-templates-disabled', this.refreshPageTemplates);
this.$root.$off('page-templates-delete', this.deletePageTemplateConfirm);
this.$root.$off('page-templates-create', this.createPageTemplate);
},
Expand All @@ -153,7 +159,7 @@ export default {
this.loading = true;
this.$pageTemplateService.deletePageTemplate(pageTemplate.id)
.then(() => {
this.$root.$emit('page-templates-refresh');
this.$root.$emit('page-templates-deleted', pageTemplate);
this.$root.$emit('alert-message', this.$t('pageTemplate.delete.success'), 'success');
})
.catch(() => this.$root.$emit('alert-message', this.$t('pageTemplate.delete.error'), 'error'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import './initComponents.js';
import '../common/initComponents.js';

// get overridden components if exists
if (extensionRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<site-navigation-node-drawer />
<site-navigation-element-drawer />
<manage-permissions-drawer />
<layout-analytics application-name="siteManagement" />
</v-app>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import './initComponents.js';
import '../common/initComponents.js';

// get overridden components if exists
if (extensionRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
icon-class="text-color"
embedded />
<site-navigation-drawers-actions />
<layout-analytics application-name="siteNavigation" />
</v-app>
</template>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import './initComponents.js';
import '../common/initComponents.js';

// get overridden components if exists
if (extensionRegistry) {
Expand Down
Loading

0 comments on commit 6daf328

Please sign in to comment.