Skip to content
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
77 changes: 77 additions & 0 deletions webapps/src/main/java/io/meeds/task/portlet/TasksPortlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2026 Meeds Association contact@meeds.io
*
* 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.
*/


package io.meeds.task.portlet;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.services.security.ConversationState;

public class TasksPortlet extends GenericDispatchedViewPortlet {

private UserACL userAcl;

@Override
public void processAction(ActionRequest request, ActionResponse response) throws IOException, PortletException {
if (!canModifySettings()) {
throw new PortletException("User is not allowed to save settings");
}
PortletPreferences preferences = request.getPreferences();
String settings = request.getParameter("settings");
preferences.setValue("settings", settings);
preferences.store();
response.setPortletMode(PortletMode.VIEW);
}

@Override
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
request.setAttribute("canEdit", canModifySettings());
super.doView(request, response);
}

private boolean canModifySettings() {
PortalRequestContext requestContext = PortalRequestContext.getCurrentInstance();
if (requestContext == null || requestContext.getPage() == null) {
return false;
}
return getUserAcl().hasEditPermission(requestContext.getPage(),
ConversationState.getCurrent().getIdentity());
}

private UserACL getUserAcl() {
if (userAcl == null) {
userAcl = ExoContainerContext.getService(UserACL.class);
}
return userAcl;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ label.and=and
label.projectManagers=Project Managers
label.projectParticipants=Project Participant(s)
tasks.label.allSet=All set!
label.seeAll=See all
label.editSettings=Edit settings

task.placeholder=Share your thoughts here
label.userOrGroup=User or Group
Expand Down Expand Up @@ -446,3 +448,9 @@ alert.success.label.updated=Label successfully updated
alert.error=An error occured
alert.error.title.mandatory=Task title is mandatory
alert.error.title.length=Task title length should be between 3 and 1024.

tasks.settings.edit.drawer.title=Edit tasks list
tasks.settings.edit.drawer.updateSeeMore.label=Update see more
tasks.settings.edit.drawer.opensInSameTab=Opens in same tab
tasks.settings.save.success.message=Settings saved successfully
tasks.settings.save.error.message=Error while saving settings
13 changes: 12 additions & 1 deletion webapps/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<portlet>
<portlet-name>tasks</portlet-name>
<portlet-class>org.exoplatform.commons.api.portlet.GenericDispatchedViewPortlet</portlet-class>
<portlet-class>io.meeds.task.portlet.TasksPortlet</portlet-class>
<init-param>
<name>portlet-view-dispatched-file-path</name>
<value>/tasks.jsp</value>
Expand All @@ -41,6 +41,17 @@
<portlet-info>
<title>Tasks</title>
</portlet-info>
<portlet-preferences>
<preference>
<name>settings</name>
<value>
{
"seeAllUrl":null,
"sameTab":true
}
</value>
</preference>
</portlet-preferences>
</portlet>

<portlet>
Expand Down
188 changes: 188 additions & 0 deletions webapps/src/main/webapp/WEB-INF/tld/portlet_2_0.tld
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?xml version="1.0" encoding="UTF-8"?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">

<description>Portlet 2.0 Tag Library</description>
<display-name>Portlet 2.0 Tags</display-name>
<tlib-version>2.0</tlib-version>
<short-name>portlet</short-name>
<uri>http://java.sun.com/portlet_2_0</uri>

<tag>

<name>param</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.URLParameter286Tag</tag-class>
<body-content>empty</body-content>

<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
<tag>

<name>property</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.URLProperty286Tag</tag-class>
<body-content>empty</body-content>

<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>value</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
<tag>

<name>renderURL</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.RenderURL286Tag</tag-class>
<tei-class>org.gatein.pc.portlet.impl.jsr286.taglib.GenerateURL286TagTEI</tei-class>
<body-content>JSP</body-content>

<attribute>
<name>portletMode</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>secure</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>var</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>windowState</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>escapeXml</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>copyCurrentRenderParameters</name>
<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
<tag>

<name>defineObjects</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.DefineObjects286Tag</tag-class>
<tei-class>org.gatein.pc.portlet.impl.jsr286.taglib.DefineObjects286TagTEI</tei-class>
<body-content>empty</body-content>

</tag>
<tag>

<name>actionURL</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.ActionURL286Tag</tag-class>
<tei-class>org.gatein.pc.portlet.impl.jsr286.taglib.GenerateURL286TagTEI</tei-class>
<body-content>JSP</body-content>

<attribute>
<name>portletMode</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>secure</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>var</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>windowState</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>escapeXml</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>copyCurrentRenderParameters</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>name</name>
<rtexprvalue>true</rtexprvalue>

</attribute>


</tag>
<tag>

<name>resourceURL</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.ResourceURL286Tag</tag-class>
<tei-class>org.gatein.pc.portlet.impl.jsr286.taglib.ResourceURL286TagTEI</tei-class>
<body-content>JSP</body-content>

<attribute>
<name>secure</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>var</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>escapeXml</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>cacheability</name>
<rtexprvalue>true</rtexprvalue>

</attribute>
<attribute>
<name>id</name>
<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
<tag>

<name>namespace</name>
<tag-class>org.gatein.pc.portlet.impl.jsr286.taglib.Namespace286Tag</tag-class>
<body-content>empty</body-content>

</tag>

</taglib>
6 changes: 6 additions & 0 deletions webapps/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@
<url-pattern>/images/*</url-pattern>
</filter-mapping>

<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
<taglib-location>/WEB-INF/tld/portlet_2_0.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
18 changes: 18 additions & 0 deletions webapps/src/main/webapp/js/tasksService.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,21 @@ export function updateCompleted(task) {
body: JSON.stringify(task)
}).then(resp => resp.json()).finally(() => document.dispatchEvent(new CustomEvent('hideTopBarLoading')));
}

export function saveSettings(saveSettingsURL, settings) {
const formData = new FormData();
formData.append('settings', JSON.stringify(settings));
const urlParams = new URLSearchParams(formData).toString();
return fetch(saveSettingsURL.replaceAll('&amp;', '&'), {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: urlParams,
}).then(resp => {
if (!resp.ok) {
throw new Error('Error while saving tasks settings');
}
});
}
40 changes: 27 additions & 13 deletions webapps/src/main/webapp/tasks.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,35 @@
%>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="org.exoplatform.services.resources.ResourceBundleService" %>
<%@ page import="org.exoplatform.container.PortalContainer" %><%

String itemsLimit = System.getProperty("exo.dw.page.snapshot.itemsLimit", "10");
<%@ page import="org.exoplatform.container.PortalContainer" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:actionURL var="saveSettingsUrl" />
<%
String itemsLimit = System.getProperty("exo.dw.page.snapshot.itemsLimit", "10");

PortalContainer portalContainer = PortalContainer.getCurrentInstance(session.getServletContext());
ResourceBundleService resourceBundleService = portalContainer.getComponentInstanceOfType(ResourceBundleService.class);
ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("locale.portlet.taskManagement", request.getLocale());
PortalContainer portalContainer = PortalContainer.getCurrentInstance(session.getServletContext());
ResourceBundleService resourceBundleService = portalContainer.getComponentInstanceOfType(ResourceBundleService.class);
ResourceBundle resourceBundle = resourceBundleService.getResourceBundle("locale.portlet.taskManagement", request.getLocale());
String portletId = (String) request.getAttribute("portletStorageId");
String domId = "tasksApplication" + portletId;
String valueDomId = "tasksSettingsValue" + portletId;

boolean canEdit = (boolean) request.getAttribute("canEdit");
Object settings = (String[]) request.getAttribute("settings");
if (settings != null) {
settings = ((String[]) settings)[0];
}

%>

<div class="VuetifyApp">
<div id="tasks">
<script>
require(['SHARED/tasksBundle'], function(tasksApp) {
tasksApp.init('<%=itemsLimit%>');
});
</script>
</div>
<div id="<%=domId%>">
<textarea id="<%=valueDomId%>" style="display:none;"><%=settings == null ? "{}" : settings%></textarea>
<script>
require(['SHARED/tasksBundle'], function(tasksApp) {
tasksApp.init('<%=domId%>', '<%=itemsLimit%>', JSON.parse(document.getElementById('<%=valueDomId%>').value), '<%=saveSettingsUrl%>', <%=canEdit%>);
});
</script>
</div>
</div>
Loading