Skip to content

Commit

Permalink
feat: Enhance news load resoures using load-group - EXO-63805
Browse files Browse the repository at this point in the history
Prior to this change, all news extensions were loaded inside all-bottom-container including the non needed once in all pages.
This PR add the use of load-group mechanism to enhance the resources load and load only what is needed in the current page.
  • Loading branch information
hakermi committed Aug 11, 2023
1 parent 9e443bf commit d1de7f2
Show file tree
Hide file tree
Showing 27 changed files with 485 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ public Response getNewsByActivityId(@Parameter(description = "Activity id", requ
return Response.status(Response.Status.NOT_FOUND).build();
}
news.setIllustration(null);
Identity userIdentity = identityManager.getOrCreateUserIdentity(currentIdentity.getUserId());
if (userIdentity != null) {
news.setFavorite(favoriteService.isFavorite(new Favorite("news",
news.getId(),
"",
Long.parseLong(userIdentity.getId()))));
}
return Response.ok(news).build();
} catch (IllegalAccessException e) {
LOG.warn("User {} attempt to access unauthorized news with id {}", currentIdentity.getUserId(), activityId);
Expand Down
2 changes: 1 addition & 1 deletion webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"watch": "webpack --config webpack.dev.js --progress --color --watch",
"lint": "eslint --fix ./src/main/webapp/*/*.js ./src/main/webapp/**/*.vue",
"lint": "eslint --fix ./src/main/webapp/*/*.js ./src/main/webapp/*/*/*.js ./src/main/webapp/**/*.vue",
"build": "webpack --config webpack.prod.js --mode production"
},
"author": "eXo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
</value-param>
<object-param>
<name>news-extensions-portlet</name>
<description></description>
<description>News extensions </description>
<object type="org.exoplatform.commons.addons.PortletModel">
<field name="contentId">
<string>news/NewsExtensions</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
activityId: '${activityId}',
hiddenSpace: ${news.hiddenSpace},
isSpaceMember: ${news.isSpaceMember},
favorite: ${news.isFavorite}
},
} """
def notAuthorizedUserLabel = "";
Expand Down
95 changes: 91 additions & 4 deletions webapp/src/main/webapp/WEB-INF/gatein-resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@
<css-path>/skin/css/newsComposer.css</css-path>
</portlet-skin>

<portlet-skin>
<application-name>news</application-name>
<portlet-name>NewsExtensions</portlet-name>
<portal-skin>
<skin-name>Enterprise</skin-name>
<skin-module>NewsComposerActivityStreamExtensions</skin-module>
<css-path>/skin/css/newsExtensions.css</css-path>
</portlet-skin>
<css-priority>11</css-priority>
</portal-skin>

<portlet-skin>
<application-name>news</application-name>
Expand Down Expand Up @@ -150,6 +150,7 @@
</module>
</portlet>

<!--FIXME: We should use the load-group for all declared news extensions-->
<portlet>
<name>NewsExtensions</name>
<module>
Expand Down Expand Up @@ -445,4 +446,90 @@
</depends>
</module>

<module>
<name>NewsActivityStreamExtensions</name>
<load-group>ActivityStreamGRP</load-group>
<script>
<minify>false</minify>
<path>/js/newsActivityExtensions.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>jquery</module>
<as>$</as>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
</module>

<module>
<name>NewsComposerActivityStreamExtensions</name>
<load-group>ActivityStreamGRP</load-group>
<script>
<minify>false</minify>
<path>/js/newsComposerActionExtensions.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>jquery</module>
<as>$</as>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
</module>

<module>
<name>NewsFavoriteDrawerExtensions</name>
<load-group>FavoriteDrawerGRP</load-group>
<script>
<minify>false</minify>
<path>/js/newsFavoriteDrawerExtensions.bundle.js</path>
</script>
<depends>
<module>vue</module>
</depends>
<depends>
<module>vuetify</module>
</depends>
<depends>
<module>eXoVueI18n</module>
</depends>
<depends>
<module>jquery</module>
<as>$</as>
</depends>
<depends>
<module>extensionRegistry</module>
</depends>
<depends>
<module>commonVueComponents</module>
</depends>
<depends>
<module>newsSnackbarComponent</module>
</depends>
</module>
</gatein-resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright (C) 2023 eXo Platform SAS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const newsActivityTypeExtensionOptions = {
name: 'News',
getExtendedComponent: (activity, isActivityDetail) => {
if (activity && isActivityDetail) {
return {
component: Vue.options.components['exo-news-details-activity'],
overrideHeader: true,
overrideFooter: false,
};
}
},
extendSharedActivity: (activity, isActivityDetail) => isActivityDetail,
showSharedInformationFooter: (activity, isActivityDetail) => isActivityDetail,
init: (activity, isActivityDetail) => {
let activityId = activity.id;
if (activity.parentActivity) {
activityId = activity.parentActivity.id;
}
if (!activity.news || isActivityDetail) {
return Vue.prototype.$newsServices.getNewsByActivityId(activityId)
.then(news => activity.news = news);
}
},
canEdit: () => false,
canShare: () => true,
hideOnDelete: true,
supportsThumbnail: true,
windowTitlePrefixKey: 'news.window.title',
getThumbnail: (activity) => `${activity?.news?.illustrationURL}&size=305x285` || '/news/images/news.png',
getThumbnailProperties: (activity) => !(activity?.news?.illustrationURL) && {
height: '90px',
width: '90px',
noBorder: true,
} || null,
isUseSameViewForMobile: (activity) => !activity?.news?.illustrationURL,
getTitle: (activity) => {
const news = activity?.news;
if (news?.title) {
return news.title;
}
return '';
},
getSourceLink: (activity) => `${eXo.env.portal.context}/${eXo.env.portal.portalName}/activity?id=${!activity.parentActivity ? activity.id : activity.parentActivity.id}`,
getSummary: (activity) => {
const news = activity?.news;
if (news?.summary) {
return news.summary;
} else if (news?.body) {
return Vue.prototype.$utils.htmlToText(news.body);
}
return '';
},
getTooltip: (activity, isActivityDetail) => !isActivityDetail && activity && 'news.activity.clickToShowDetail',
};

export function initExtensions() {
extensionRegistry.registerExtension('activity', 'type', {
type: 'news',
options: newsActivityTypeExtensionOptions,
});
}
20 changes: 20 additions & 0 deletions webapp/src/main/webapp/news-extensions/activity-extensions/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright (C) 2023 eXo Platform SAS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {initExtensions} from './extensions.js';

export function init() {
initExtensions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export default {
}),
computed: {
contentTitle() {
return this.content && this.content.title;
return this.content?.title;
},
contentUrl() {
return this.content && this.content.url;
return this.content?.url;
},
},
created() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ export default {
}),
computed: {
contentTitle() {
return this.content && this.content.title;
return this.content?.title;
},
contentUrl() {
return this.content && this.content.url;
return this.content?.url;
},
},
created() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright (C) 2023 eXo Platform SAS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
export function initExtensions() {
extensionRegistry.registerExtension('AnalyticsTable', 'CellValue', {
type: 'news',
options: {
// Rank of executing 'match' method
rank: 60,
// Used Vue component to display cell value
vueComponent: Vue.options.components['analytics-table-cell-content-value'],
// Method complete signature : match: (fieldName, aggregationType, fieldDataType, item) => { ... }
match: (fieldName, aggregationType) => fieldName === 'contentId.keyword' && aggregationType === 'TERMS',
},
});

extensionRegistry.registerExtension('AnalyticsSamples', 'SampleItem', {
type: 'news',
options: {
// Rank of executing 'match' method
rank: 30,
// Used Vue component to display cell value
vueComponent: Vue.options.components['analytics-sample-item-content'],
match: fieldName => fieldName === 'contentId',
},
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright (C) 2023 eXo Platform SAS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import AnalyticsTableCellContentValue from './components/analytics/AnalyticsTableCellContentValue.vue';
import AnalyticsSampleItemContent from './components/analytics/AnalyticsSampleItemContent.vue';

const components = {
'analytics-table-cell-content-value': AnalyticsTableCellContentValue,
'analytics-sample-item-content': AnalyticsSampleItemContent,
};

for (const key in components) {
Vue.component(key, components[key]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright (C) 2023 eXo Platform SAS.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import './initComponents.js';
import {initExtensions} from './extensions.js';
import * as newsServices from '../../services/newsServices';

if (!Vue.prototype.$newsServices) {
window.Object.defineProperty(Vue.prototype, '$newsServices', {
value: newsServices,
});
}

export function init() {
initExtensions();
}
Loading

0 comments on commit d1de7f2

Please sign in to comment.