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

Issue 13352 dnd on workflow #13382

Merged
merged 4 commits into from
Jan 16, 2018
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 @@ -29,6 +29,7 @@
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Locale;
import java.util.stream.IntStream;

@SuppressWarnings("serial")
@Beta /* Non Official released */
Expand Down Expand Up @@ -622,7 +623,66 @@ public final Response deleteAction(@Context final HttpServletRequest request,

return response;
} // deleteAction

/**
* Change the order of the steps in a scheme
* @param request HttpServletRequest
* @param workflowReorderActionStepForm WorkflowReorderBean
* @return Response
*/
@PUT
@Path("/reorder/step/{stepId}/order/{order}")
@JSONP
@NoCache
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
public final Response reorderStep(@Context final HttpServletRequest request,
@PathParam("stepId") final String stepId,
@PathParam("order") final int order) {

final InitDataObject initDataObject = this.webResource.init

Choose a reason for hiding this comment

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

MAJOR Remove this useless assignment to local variable "initDataObject". rule
MINOR Remove this unused "initDataObject" local variable. rule

(null, true, request, true, null);
Response response;

try {
WorkflowStep step = workflowAPI.findStep(stepId);
WorkflowScheme scheme = workflowAPI.findScheme(step.getSchemeId());
List<WorkflowStep> steps = workflowAPI.findSteps(scheme);
IntStream.range(0, steps.size())
.filter(i -> steps.get(i).getId().equals(step.getId()))

Choose a reason for hiding this comment

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

MINOR Specify a type for: 'i' rule

.boxed()
.findFirst()
.map(i -> steps.remove((int) i));

Choose a reason for hiding this comment

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

MAJOR The return value of "map" must be used. rule
MINOR Specify a type for: 'i' rule


int newOrder = (order > steps.size()) ? steps.size():order;
steps.add(newOrder, step);

int i=0;
for(WorkflowStep stepp : steps) {
stepp.setMyOrder(i++);
workflowAPI.saveStep(stepp);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we shouldn't have this reorder functionality at a resource leve. I would say at api level.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also let's try to think of resource when possible. Instead of a RPC-style /reorder/ I picture this as a PATCH of the step including only the new order value

Copy link
Contributor

Choose a reason for hiding this comment

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

PATCH /steps/:stepid -d {"order":{newOrderValue}}


response = Response.ok(new ResponseEntityView("Ok")).build(); // 200
} catch (DoesNotExistException e) {

Logger.error(this.getClass(),
"DoesNotExistException on reorderStep, stepId: " + stepId +
", exception message: " + e.getMessage(), e);
response = ExceptionMapperUtil.createResponse(e, Response.Status.NOT_FOUND);
} catch (Exception e) {

Logger.error(this.getClass(),
"Exception on reorderStep, stepId: " + stepId +
", exception message: " + e.getMessage(), e);
response = (e.getCause() instanceof SecurityException)?
ExceptionMapperUtil.createResponse(e, Response.Status.UNAUTHORIZED) :
ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR);
}

return response;
} // reorderAction


/**
* Change the order of an action associated to the step
* @param request HttpServletRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ public class WorkflowActionStepBean extends Validated {

@NotNull
private final String stepId;


@NotNull
private final int order;

public String getActionId() {
return actionId;
}

public String getStepId() {
return stepId;
}

public int getOrder() {
return order;
}
@Override
public String toString() {
return "WorkflowActionStepBean{" +
Expand All @@ -34,11 +39,13 @@ public WorkflowActionStepBean(final Builder builder) {

this.actionId = builder.actionId;
this.stepId = builder.stepId;
this.order = builder.order;
this.checkValid();
}

public static final class Builder {

@JsonProperty(required = true)
private int order=0;
@JsonProperty(required = true)
private String actionId;
@JsonProperty(required = true)
Expand All @@ -54,7 +61,10 @@ public Builder stepId(String stepId) {
this.stepId = stepId;
return this;
}

public Builder order(int order) {
this.order = order;
return this;
}

public WorkflowActionStepBean build() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,23 @@ public WorkflowAction save (final WorkflowActionForm workflowActionForm, final U
} // save.

@WrapInTransaction
public void saveActionToStep(final WorkflowActionStepBean workflowActionStepForm, final User user) {

public void saveActionToStep(final WorkflowActionStepBean workflowActionStepForm, final User user) throws DotDataException, DotSecurityException {

WorkflowAction action = this.workflowAPI.findAction(workflowActionStepForm.getActionId(), workflowActionStepForm.getStepId(), user);
if(action!=null) {
WorkflowReorderBean bean = new WorkflowReorderBean.Builder()
.actionId(workflowActionStepForm.getActionId()).stepId(workflowActionStepForm.getStepId())
.order(workflowActionStepForm.getOrder()).build();

this.reorderAction(bean, user);

}else {



this.workflowAPI.saveAction(workflowActionStepForm.getActionId(),
workflowActionStepForm.getStepId(), user);
workflowActionStepForm.getStepId(), user, workflowActionStepForm.getOrder());
}
} // addActionToStep.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,21 @@ public void addActionToStep(final HttpServletRequest request,

final String stepId = request.getParameter("stepId");
final String actionId = request.getParameter("actionId");

final int order= (request.getParameter("order")!=null) ? Integer.valueOf(request.getParameter("order")): 0;
try {

final User user = this.userWebAPI.getUser(request);

Logger.debug(this, "Adding the action: " + actionId +
", to the step: " + stepId);



this.workflowHelper.saveActionToStep (
new WorkflowActionStepBean.Builder()
.stepId(stepId)
.actionId(actionId)
.order(order)
.build(), user);

writeSuccess(response, stepId );
Expand Down
1 change: 1 addition & 0 deletions dotCMS/src/main/webapp/html/common/top_inc.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ THIS FILE AND ITS INCLUDES

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:bi="urn:bi" xmlns:csp="urn:csp">
<head>
<script src="/html/js/dragula-3.7.2/dragula.min.js"></script>
<meta http-equiv="x-ua-compatible" content="IE=edge" >
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
}

%>


<script type="text/javascript">

dojo.ready(function(){
Expand Down Expand Up @@ -178,7 +180,7 @@
<input type="text" name="actionName" id="actionName" style="width: 80%;"
dojoType="dijit.form.ValidationTextBox" required="true"
value="<%=UtilMethods.webifyString(action.getName())%>"
maxlength="255" onkeypress="actionAdmin.doChange()">
maxlength="255" onkeypress="actionAdmin.doChange()" <%if(action.isNew()){ %>onchange="actionAdmin.saveAction('<%=schemeId %>');"<%} %>>
</dd>
</dl>
<dl class="vertical">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<%} %>
<button dojoType="dijit.form.Button"
onClick='dijit.byId("actionClassParamsDia").destroyRecursive()'
iconClass="cancelIcon">
>
<%=LanguageUtil.get(pageContext, "Cancel")%>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@
<%@page import="com.dotmarketing.util.UtilMethods"%>
<%



WorkflowAPI wapi = APILocator.getWorkflowAPI();
WorkflowScheme defaultScheme = wapi.findDefaultScheme();
boolean showArchived = (request.getParameter("showArchived") != null);

List<WorkflowScheme> schemes = wapi.findSchemes(showArchived);




%>


Expand All @@ -28,7 +23,7 @@
<form id="fm" method="post">
<div class="portlet-toolbar">
<div class="portlet-toolbar__actions-primary">
<b><%=LanguageUtil.get(pageContext, "Workflow-Schemes")%></b>
<h2><%=LanguageUtil.get(pageContext, "Workflow-Schemes")%></h2>
</div>
<div class="portlet-toolbar__info">
<div class="inline-form">
Expand All @@ -54,59 +49,47 @@

<!-- START Listing Results -->


<%if (schemes != null && schemes.size() > 0) {%>


<%for (WorkflowScheme scheme : schemes) {%>
<div class="editRow showPointer">
<table class="listingTable" id="td<%=scheme.getId()%>" style="margin:0 0 25px 0;" onclick="stepAdmin.showViewSteps('<%=scheme.getId()%>');">
<%List<WorkflowStep> steps = wapi.findSteps(scheme);%>
<tr>
<th>
<%if(!scheme.isArchived()){ %>
<span class="workflowIcon"></span> <%=scheme.getName()%>
<%}else{ %>
<strike><%=scheme.getName()%></strike>
<%} %>
<%if(scheme.isMandatory()){ %>(<%=LanguageUtil.get(pageContext, "Mandatory")%>)<%} %>
<div style="font-weight:normal;margin-left:25px;font-size:85%;"><%=UtilMethods.webifyString(scheme.getDescription())%></div>
</th>
</tr>
<tr>
<td>
<div class="board-wrapper">
<div class="flex-container flex-wrap">
<%if (schemes != null && schemes.size() > 0) {%>
<%for (WorkflowScheme scheme : schemes) {%>
<div class="flex-item editRow showPointer">
<div id="td<%=scheme.getId()%>" onclick="stepAdmin.showViewSteps('<%=scheme.getId()%>');">
<div class="wfSchemeTitle">
<a class="pull-right showPointer btn-flat btn-primary " href="#" onclick="schemeAdmin.showAddEdit('<%=scheme.getId()%>');"><i class="fa fa-pencil" aria-hidden="true"></i></a>
<%List<WorkflowStep> steps = wapi.findSteps(scheme);%>
<%if(!scheme.isArchived()){ %>
<span class="workflowIcon"></span> <%=scheme.getName()%>
<%}else{ %>
<strike><%=scheme.getName()%></strike>
<%} %>
<%if(scheme.isMandatory()){ %>(<%=LanguageUtil.get(pageContext, "Mandatory")%>)<%} %>
<div style="font-weight:normal;font-size:12px;"><%=UtilMethods.webifyString(scheme.getDescription())%></div>
</div>
<ol class="wfStepsList">
<%if(steps!= null && steps.size() > 0){ %>

<%for(WorkflowStep step : steps){ %>
<li><%=step.getName() %></li>
<%} %>

<%}else{ %>
<li><%=LanguageUtil.get(pageContext, "No-steps-have-been-created")%></li>
<%} %>
</ol>
</td>
</ol>
</div>
<div style="border-top: 1px solid #e0e0e0; padding: 4px 8px 4px 16px;z-index:10;position: absolute; bottom: 0; width:100%;" onclick="stepAdmin.showViewSteps('<%=scheme.getId()%>');">
<div class="btn-flat btn-primary showPointer" href="#" style="z-index: 10000;" ><%=LanguageUtil.get(pageContext, "View-Steps")%></div>
</div>
</div>
<%}%>
<%} else {%>
<table class="listingTable">
<tr>
<td><%=LanguageUtil.get(pageContext, "No-Workflow-Schemes")%><br /></td>
</tr>
</table>
</div>

<div dojoType="dijit.Menu" class="dotContextMenu" style="display: none;" targetNodeIds="td<%=scheme.getId()%>">
<div dojoType="dijit.MenuItem" iconClass="previewIcon" onClick="stepAdmin.showViewSteps('<%=scheme.getId()%>');"><%=LanguageUtil.get(pageContext, "View-Steps")%></div>
<div dojoType="dijit.MenuItem" iconClass="editIcon" onClick="schemeAdmin.showAddEdit('<%=scheme.getId()%>');"><%=LanguageUtil.get(pageContext, "Edit-Workflow")%></div>
</div>



<%}%>

<%} else {%>
<table class="listingTable">
<tr>
<td><%=LanguageUtil.get(pageContext, "No-Workflow-Schemes")%><br /></td>
</tr>
</table>
<%}%>
</div>
</div>


<script>
Expand Down
Loading