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(ui) : select your group in Project page by grid #1575

Merged
merged 1 commit into from
Aug 17, 2022
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 @@ -358,7 +358,10 @@ public AddDocumentRequestSummary addProject(Project project, User user) throws S
// Save creating user
project.createdBy = user.getEmail();
project.createdOn = getCreatedOn();
project.businessUnit = getBUFromOrganisation(user.getDepartment());
if (CommonUtils.isNullEmptyOrWhitespace(project.businessUnit)) {
project.businessUnit = getBUFromOrganisation(user.getDepartment());
}

setRequestedDateAndTrimComment(project, null, user);
project.unsetVendor();
// Add project to database and return ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ public class PortalConstants {
//component actions
public static final String ADD_VENDOR = "add_vendor";
public static final String VIEW_VENDOR = "view_vendor";
public static final String VIEW_DEPARTMENT = "view_department";
public static final String CHECK_COMPONENT_NAME = "check_component_name";
public static final String DELETE_COMPONENT = "delete_component";
public static final String DELETE_RELEASE = "delete_release";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.portlet.PortletRequest;
import javax.portlet.ResourceRequest;
import javax.portlet.RenderRequest;
import javax.portlet.ResourceResponse;

import java.util.*;
import java.util.function.Function;
Expand Down Expand Up @@ -573,4 +574,18 @@ public static String convertObjectToJsonStr(Object obj) {
throw new RuntimeException(e);
}
}

public static void setDepartmentSearchAttribute(ResourceRequest request, ResourceResponse response) {
final User user = UserCacheHolder.getUserFromRequest(request);

List<String> secondaryDepartmentList = new ArrayList<String>();
Map<String, Set<UserGroup>> secondaryRoleMap = user.getSecondaryDepartmentsAndRoles();
if (!CommonUtils.isNullOrEmptyMap(secondaryRoleMap)) {
secondaryDepartmentList.addAll(secondaryRoleMap.keySet());
}

request.setAttribute("primaryDepartment", user.getDepartment());
request.setAttribute("secondaryDepartmentList", nullToEmptyList(secondaryDepartmentList));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException;
import static org.eclipse.sw360.portal.common.PortalConstants.*;
import static org.eclipse.sw360.portal.common.PortletUtils.getVerificationState;
import static org.eclipse.sw360.portal.common.PortletUtils.setDepartmentSearchAttribute;

import org.apache.thrift.transport.TTransportException;

Expand Down Expand Up @@ -189,6 +190,8 @@ public void serveResource(ResourceRequest request, ResourceResponse response) th
serveViewVendor(request, response);
} else if (ADD_VENDOR.equals(action)) {
serveAddVendor(request, response);
} else if (VIEW_DEPARTMENT.equals(action)) {
serveViewDepartment(request, response);
} else if (CHECK_COMPONENT_NAME.equals(action)) {
serveCheckComponentName(request, response);
} else if (DELETE_COMPONENT.equals(action)) {
Expand Down Expand Up @@ -401,6 +404,11 @@ private void serveAddVendor(ResourceRequest request, ResourceResponse response)
log.error("Error adding vendor", e);
}
}

private void serveViewDepartment(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
PortletUtils.setDepartmentSearchAttribute(request, response);
include("/html/components/ajax/departmentSearch.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}

private void serveCheckComponentName(ResourceRequest request, ResourceResponse response) throws IOException {
List<Component> resultComponents = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import static org.eclipse.sw360.datahandler.common.WrappedException.wrapTException;
import static org.eclipse.sw360.portal.common.PortalConstants.*;
import static org.eclipse.sw360.portal.portlets.projects.ProjectPortletUtils.isUsageEquivalent;
import static org.eclipse.sw360.portal.common.PortletUtils.setDepartmentSearchAttribute;

@org.osgi.service.component.annotations.Component(
immediate = true,
Expand Down Expand Up @@ -291,6 +292,8 @@ else if ((PortalConstants.LOAD_OBLIGATIONS_EDIT.equals(action)
serveViewVendor(request, response);
} else if (ADD_VENDOR.equals(action)) {
serveAddVendor(request, response);
} else if (VIEW_DEPARTMENT.equals(action)) {
serveViewDepartment(request, response);
}
}

Expand Down Expand Up @@ -357,6 +360,11 @@ private void renderVendorSearch(ResourceRequest request, ResourceResponse respon
request.setAttribute("vendorsSearch", nullToEmptyList(vendors));
include("/html/components/ajax/vendorSearch.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}

private void serveViewDepartment(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
PortletUtils.setDepartmentSearchAttribute(request, response);
include("/html/components/ajax/departmentSearch.jsp", request, response, PortletRequest.RESOURCE_PHASE);
}

private void prepareVulnerabilitiesView(ResourceRequest request, ResourceResponse response) {
User user = UserCacheHolder.getUserFromRequest(request);
Expand Down Expand Up @@ -2401,7 +2409,6 @@ else if (RequestStatus.NAMINGERROR.equals(requestStatus))
prepareRequestForEditAfterDuplicateError(request, project, user);
return;
}

AddDocumentRequestSummary summary = client.addProject(project, user);
String newProjectId = summary.getId();
String sourceProjectId = request.getParameter(SOURCE_PROJECT_ID);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Copyright TOSHIBA CORPORATION, 2022. Part of the SW360 Portal Project.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.sw360.portal.tags;

import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.apache.commons.lang.StringUtils;

import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.util.ResourceBundleUtil;

/**
* This displays a department field that can be used as extension point for a department
* search dialog via onclick listeners (see also
* src/main/webapp/js/components/includes/departments/searchDepartment.js)
*/
public class DisplayDepartmentEdit extends NameSpaceAwareTag {

private String namespace;
private String id;
private String departmentId = "";
private String label = "";


public int doStartTag() throws JspException {
JspWriter jspWriter = pageContext.getOut();

namespace = getNamespace();
StringBuilder display = new StringBuilder();
try {
if (StringUtils.isNotEmpty(departmentId)) {
printFullDepartment(display);
}else {
printEmptyDepartment(display);
}
jspWriter.print(display.toString());
} catch (Exception e) {
throw new JspException(e);
}
return SKIP_BODY;
}

private void printEmptyDepartment(StringBuilder display) {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", request.getLocale(), getClass());

display.append("<div class=\"form-group\">");
printLabel(display);
display.append(String.format("<input type=\"hidden\" value=\"\" id=\"%s\" name=\"%s%s\"/>", id, namespace, id))
.append("<div class=\"form-group has-feedback\">")
.append(String.format(
"<input type=\"text\" class=\"form-control edit-department clickable\" placeholder=\"" + LanguageUtil.get(resourceBundle, "click.to.set.department") + "\" id=\"%sDisplay\" required=\"\"/>",
id))
.append("<span class=\"glyphicon glyphicon-remove-circle form-control-feedback clearSelection\" id=\"clearDepartment\"/>")
.append("</div>");
display.append("</div>");
}

private void printFullDepartment(StringBuilder display) {
display.append("<div class=\"form-group\">");
printLabel(display);
display.append(String.format("<input type=\"hidden\" value=\"%s\" id=\"%s\" name=\"%s%s\"/>", departmentId, id, namespace, id))
.append("<div class=\"form-group has-feedback\">")
.append(String.format(
"<input type=\"text\" class=\"form-control edit-department clickable\" value=\"%s\" id=\"%sDisplay\" required=\"\"/>",
departmentId, id))
.append("<span class=\"glyphicon glyphicon-remove-circle form-control-feedback clearSelection\" id=\"clearDepartment\"/>")
.append("</div>");
display.append("</div>");
}

private void printLabel(StringBuilder display) {
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
ResourceBundle resourceBundle = ResourceBundleUtil.getBundle("content.Language", request.getLocale(), getClass());

if (StringUtils.isNotEmpty(label)) {
display.append(
String.format("<label class=\"mandatory\" for=\"group\" >%s</label>", LanguageUtil.get(resourceBundle,label)));
}
}

public void setId(String id) {
this.id = id;
}

public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}

public void setLabel(String label) {
this.label = label;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>DisplayDepartmentEdit</name>
<tag-class>org.eclipse.sw360.portal.tags.DisplayDepartmentEdit</tag-class>
<body-content>empty</body-content>
<attribute>
<name>id</name>
<required>true</required>
<type>java.lang.String</type>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>departmentId</name>
<required>false</required>
<type>java.lang.String</type>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>label</name>
<required>false</required>
<type>java.lang.String</type>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<name>DisplayLicensesEdit</name>
<tag-class>org.eclipse.sw360.portal.tags.DisplayLicensesEdit</tag-class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,11 @@ form {
}
}
}


input#departmentsearchinputform{
margin-left:auto;
width:60%
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%--
~ Copyright TOSHIBA CORPORATION, 2022. Part of the SW360 Portal Project.
~
~ This program and the accompanying materials are made
~ available under the terms of the Eclipse Public License 2.0
~ which is available at https://www.eclipse.org/legal/epl-2.0/
~
~ SPDX-License-Identifier: EPL-2.0
--%>

<%@include file="/html/init.jsp"%>

<portlet:defineObjects />
<liferay-theme:defineObjects />

<jsp:useBean id="primaryDepartment" type="java.lang.String" scope="request" />
<jsp:useBean id="secondaryDepartmentList" type="java.util.List<java.lang.String>" scope="request" />

<tr>
<td>
<input type="radio" data-name="department" name="<portlet:namespace/>departmentId" value="<sw360:out value="${primaryDepartment},${primaryDepartment}"/>">
</td>
<td><sw360:out value="${primaryDepartment}"/></td>
<td>PRIMARY</td>
</tr>

<core_rt:if test="${secondaryDepartmentList.size()>0}" >
<core_rt:forEach items="${secondaryDepartmentList}" var="secondaryDepartment">
<tr>
<td>
<input type="radio" data-name="department" name="<portlet:namespace/>departmentId" value="<sw360:out value="${secondaryDepartment},${secondaryDepartment}"/>">
</td>
<td><sw360:out value="${secondaryDepartment}"/></td>
<td>SECONDARY</td>
</tr>
</core_rt:forEach>
</core_rt:if>
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@
<jsp:include page="/html/utils/includes/searchAndSelectUsers.jsp" />
<jsp:include page="/html/utils/includes/searchUsers.jsp" />
<%@include file="/html/components/includes/vendors/searchVendor.jspf" %>
<%@include file="/html/components/includes/departments/searchDepartment.jspf" %>


<script>
require(['jquery', 'components/includes/vendors/searchVendor', 'modules/autocomplete', 'modules/dialog', 'modules/listgroup', 'modules/validation' ], function($, vendorsearch, autocomplete, dialog, listgroup, validation) {
require(['jquery', 'components/includes/vendors/searchVendor','components/includes/departments/searchDepartment', 'modules/autocomplete', 'modules/dialog', 'modules/listgroup', 'modules/validation' ], function($, vendorsearch, departmentsearch, autocomplete, dialog, listgroup, validation) {
document.title = $("<span></span>").html("<sw360:out value='${component.name}'/> - " + document.title).text();

listgroup.initialize('detailTab', $('#detailTab').data('initial-tab') || 'tab-Summary');
Expand Down Expand Up @@ -243,6 +244,11 @@
'<portlet:namespace/>FULLNAME', '<portlet:namespace/>SHORTNAME', '<portlet:namespace/>URL', fillVendorInfo);
});

$('#RolesData input.edit-department').on('click', function() {
departmentsearch.openSearchDialog('<portlet:namespace/>what', '<portlet:namespace/>where',
'<portlet:namespace/>DEPARTMENTID', '<portlet:namespace/>PRIORITY',fillDepartmentInfo);
});

function cancel() {
$.ajax({
type: 'POST',
Expand Down Expand Up @@ -329,6 +335,17 @@
$('#<%=Component._Fields.DEFAULT_VENDOR_ID.toString()%>').val("");
$('#<%=Component._Fields.DEFAULT_VENDOR_ID.toString()%>Display').val("").attr("placeholder", "Click to set vendor");
});

function fillDepartmentInfo(departmentInfo) {

$('#<%=Component._Fields.BUSINESS_UNIT.toString()%>').val(departmentInfo.trim());
$('#<%=Component._Fields.BUSINESS_UNIT.toString()%>Display').val(departmentInfo.trim());
}

$("#clearDepartment").click(function() {
$('#<%=Component._Fields.BUSINESS_UNIT.toString()%>').val("");
$('#<%=Component._Fields.BUSINESS_UNIT.toString()%>Display').val("").attr("placeholder", "Click to set Department");
});
});
</script>
</core_rt:if>
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<!-- if Component visibility restriction is disabled. -->
</core_rt:otherwise>
</core_rt:choose>

<tr>
<td >
<div class="form-group">
Expand Down Expand Up @@ -157,7 +157,7 @@
<core_rt:choose>
<core_rt:when test="${componentVisibilityRestriction}">
<!-- if Component visibility restriction is eabled. -->

<table class="table edit-table three-columns" id="RolesData">
<thead>
<tr>
Expand All @@ -166,16 +166,9 @@
</thead>
<tr>
<td>
<div class="form-group">
<label class="mandatory" for="group"><liferay-ui:message key="group" /></label>
<input id="group" class="form-control" name="<portlet:namespace/><%=Component._Fields.BUSINESS_UNIT%>" type="text"
placeholder="<liferay-ui:message key="enter.group" />" required
value="<sw360:out value="${component.businessUnit}"/>"/>
<div class="invalid-feedback">
<liferay-ui:message key="please.enter.a.group" />
</div>
</div>
<sw360:DisplayDepartmentEdit id="<%=Component._Fields.BUSINESS_UNIT.toString()%>" departmentId="${component.businessUnit}" label="group"/>
</td>

<td>
<sw360:DisplayUserEdit email="${component.componentOwner}"
id="<%=Component._Fields.COMPONENT_OWNER.toString()%>"
Expand Down Expand Up @@ -216,7 +209,7 @@
</core_rt:when>
<core_rt:otherwise>
<!-- if Component visibility restriction is disabled. -->

<table class="table edit-table three-columns" id="RolesData">
<thead>
<tr>
Expand Down Expand Up @@ -261,7 +254,7 @@
<td></td>
</tr>
</table>

</core_rt:otherwise>
</core_rt:choose>

Expand Down
Loading