Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enhance news load resources using load-group - EXO-63805 #910

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,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()))));
}
Comment on lines +583 to +589
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why it should be removed? i have faced an existing old issue and i fixed it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue is that when access news details and that you have set the news as favorite, you will still have the option to set it again and the icon of favorite is empty icon which indicates that news is not marked as favorite while it's the case

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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this variable ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
} """
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 @@ -49,12 +49,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 @@ -157,6 +157,7 @@
</module>
</portlet>

<!--FIXME: We should use the load-group for all declared news extensions-->
<portlet>
<name>NewsExtensions</name>
<module>
Expand Down Expand Up @@ -485,4 +486,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 && `${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