Added simple progress bar

This commit is contained in:
Giancarlo Panichi 2021-10-15 16:54:57 +02:00
parent 0b3d051096
commit fbbfe752e0
8 changed files with 182 additions and 58 deletions

View File

@ -41,7 +41,7 @@ public class SessionUtil {
*/ */
UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope,accessToken); UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope,accessToken);
logger.info(serviceCredentials.toString()); logger.debug(serviceCredentials.toString());
return serviceCredentials; return serviceCredentials;
} }
@ -64,7 +64,7 @@ public class SessionUtil {
*/ */
UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope, accessToken); UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope, accessToken);
logger.info(serviceCredentials.toString()); logger.debug(serviceCredentials.toString());
return serviceCredentials; return serviceCredentials;
} }
@ -88,7 +88,7 @@ public class SessionUtil {
*/ */
UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope, accessToken); UserCredentials serviceCredentials = new UserCredentials(userId, username, currentScope, accessToken);
logger.info(serviceCredentials.toString()); logger.debug(serviceCredentials.toString());
return serviceCredentials; return serviceCredentials;
} }

View File

@ -45,6 +45,7 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
* *
*/ */
public class SystemServiceDefinition extends MVCPortlet { public class SystemServiceDefinition extends MVCPortlet {
private static Logger logger = LoggerFactory.getLogger(SystemServiceDefinition.class); private static Logger logger = LoggerFactory.getLogger(SystemServiceDefinition.class);
private void paramsInfo(ActionRequest actionRequest) { private void paramsInfo(ActionRequest actionRequest) {
@ -240,10 +241,14 @@ public class SystemServiceDefinition extends MVCPortlet {
} }
int limit = 0; int limit = 0;
if (start + length > recordsFiltered) { if (length != -1) {
limit = recordsFiltered; if (start + length > recordsFiltered) {
limit = recordsFiltered;
} else {
limit = start + length;
}
} else { } else {
limit = start + length; limit = recordsFiltered;
} }
ArrayList<DefinitionItem> windowItemsList = new ArrayList<>(); ArrayList<DefinitionItem> windowItemsList = new ArrayList<>();
@ -347,6 +352,16 @@ public class SystemServiceDefinition extends MVCPortlet {
PortalUtil.copyRequestParameters(actionRequest, actionResponse); PortalUtil.copyRequestParameters(actionRequest, actionResponse);
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp"); actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp");
break; break;
} else {
if (clientId.contains(" ")) {
logger.error("Invalid client id: " + clientId);
SessionErrors.add(actionRequest, "error-invalid-clientId-space");
SessionMessages.add(actionRequest,
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
PortalUtil.copyRequestParameters(actionRequest, actionResponse);
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp");
break;
}
} }
String description = ParamUtil.getString(actionRequest, "description"); String description = ParamUtil.getString(actionRequest, "description");
if (description == null || description.isEmpty()) { if (description == null || description.isEmpty()) {
@ -358,6 +373,7 @@ public class SystemServiceDefinition extends MVCPortlet {
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp"); actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp");
break; break;
} }
logger.debug("Requested: [clientId={}, description={}]", clientId, description); logger.debug("Requested: [clientId={}, description={}]", clientId, description);
try { try {
String username = clientId; String username = clientId;
@ -369,7 +385,7 @@ public class SystemServiceDefinition extends MVCPortlet {
SessionMessages.add(actionRequest, "success-definition-created"); SessionMessages.add(actionRequest, "success-definition-created");
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp"); actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage(),e); logger.error(e.getLocalizedMessage(), e);
SessionErrors.add(actionRequest, "error-create-definition"); SessionErrors.add(actionRequest, "error-create-definition");
SessionMessages.add(actionRequest, SessionMessages.add(actionRequest,
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
@ -393,8 +409,6 @@ public class SystemServiceDefinition extends MVCPortlet {
} }
public void editDefinition(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { public void editDefinition(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {
@SuppressWarnings("unused") @SuppressWarnings("unused")
UserCredentials userCredentials; UserCredentials userCredentials;
@ -455,8 +469,7 @@ public class SystemServiceDefinition extends MVCPortlet {
} }
paramsInfo(actionRequest); paramsInfo(actionRequest);
logger.debug("Delete Request"); logger.debug("Delete Request");
String clientId = ParamUtil.getString(actionRequest, "clientId"); String clientId = ParamUtil.getString(actionRequest, "clientId");
if (clientId == null || clientId.isEmpty()) { if (clientId == null || clientId.isEmpty()) {
@ -468,9 +481,9 @@ public class SystemServiceDefinition extends MVCPortlet {
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp"); actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
return; return;
} }
try { try {
DefinitionItem definitionItem=new DefinitionItem(clientId); DefinitionItem definitionItem = new DefinitionItem(clientId);
InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY, InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
userCredentials.getCurrentScope()); userCredentials.getCurrentScope());
publishDeleteSSDEvent(definitionItem); publishDeleteSSDEvent(definitionItem);
@ -478,41 +491,39 @@ public class SystemServiceDefinition extends MVCPortlet {
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp"); actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getLocalizedMessage(),e); logger.error(e.getLocalizedMessage(), e);
SessionErrors.add(actionRequest, "error-delete-definition"); SessionErrors.add(actionRequest, "error-delete-definition");
SessionMessages.add(actionRequest, SessionMessages.add(actionRequest,
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE); PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp"); actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
} }
} }
private void publishCreateSSDEvent(DefinitionItem definitionItem) { private void publishCreateSSDEvent(DefinitionItem definitionItem) {
logger.debug("Trying to send the event to create System Service"); logger.debug("Trying to send the event to create System Service");
CreateSSDEvent toCreate = new CreateSSDEvent(definitionItem); CreateSSDEvent toCreate = new CreateSSDEvent(definitionItem);
toCreate.publisher.publish(toCreate); toCreate.publisher.publish(toCreate);
logger.info("Done send create event " + toCreate.getName() + " for " + toCreate.getUser()); logger.info("Done send create event " + toCreate.getName() + " for " + toCreate.getUser());
try { try {
Thread.sleep(2000); Thread.sleep(Constants.SLEEP_TIME);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
private void publishDeleteSSDEvent(DefinitionItem definitionItem) { private void publishDeleteSSDEvent(DefinitionItem definitionItem) {
logger.debug("Trying to send the event to delete System Service"); logger.debug("Trying to send the event to delete System Service");
DeleteSSDEvent toDelete = new DeleteSSDEvent(definitionItem); DeleteSSDEvent toDelete = new DeleteSSDEvent(definitionItem);
toDelete.publisher.publish(toDelete); toDelete.publisher.publish(toDelete);
logger.info("Done send delete event " + toDelete.getName() + " for " + toDelete.getUser()); logger.info("Done send delete event " + toDelete.getName() + " for " + toDelete.getUser());
try { try {
Thread.sleep(2000); Thread.sleep(Constants.SLEEP_TIME);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
/* /*
* private void createDefinition(ResourceRequest resourceRequest, * private void createDefinition(ResourceRequest resourceRequest,
* ResourceResponse resourceResponse, UserCredentials userCredentials) throws * ResourceResponse resourceResponse, UserCredentials userCredentials) throws

View File

@ -12,7 +12,6 @@ public class Constants {
public static final String DEFAULT_SCOPE = "/gcube"; public static final String DEFAULT_SCOPE = "/gcube";
public static final String DEFAULT_TOKEN = ""; public static final String DEFAULT_TOKEN = "";
public static final String DEFAULT_ROLE = "OrganizationMember"; public static final String DEFAULT_ROLE = "OrganizationMember";
// Session // Session
@ -22,6 +21,7 @@ public class Constants {
public static final String SOCIAL_NETWORKING_NAME = "SocialNetworking"; public static final String SOCIAL_NETWORKING_NAME = "SocialNetworking";
public static final String SOCIAL_NETWORKING_CATEGORY = "Portal"; public static final String SOCIAL_NETWORKING_CATEGORY = "Portal";
// SSD Services Endpoint // SSD Services Endpoint
public static final String SYSTEM_SERVICE_CATEGORY = "SystemService"; public static final String SYSTEM_SERVICE_CATEGORY = "SystemService";
@ -29,5 +29,7 @@ public class Constants {
public static final String IAM_SERVICE_NAME = "IAM"; public static final String IAM_SERVICE_NAME = "IAM";
public static final String IAM_SERVICE_CATEGORY = "Auth"; public static final String IAM_SERVICE_CATEGORY = "Auth";
// SLEEP TIME
public static final int SLEEP_TIME = 5000;
} }

View File

@ -149,4 +149,21 @@
.system-service-definition-portlet .dataTables_wrapper .dataTables_length .system-service-definition-portlet .dataTables_wrapper .dataTables_length
select option:checked { select option:checked {
background: #50a2f5; background: #50a2f5;
} }
.system-service-definition-portlet #simpleProgress {
width: 100%;
background-color: #ddd;
visibility: hidden;
}
.system-service-definition-portlet #simpleBar {
width: 30%;
height: 20px;
background-color: #50a2f5;
text-align: center;
line-height: 20px;
color: white;
}

View File

@ -0,0 +1,58 @@
<div id="simpleProgress">
<div id="simpleBar"></div>
</div>
<script type="text/javascript">
var elem = document.getElementById("simpleBar");
var position = 0;
var rm = true;
var id;
function frame() {
if(rm) {
if(position>70){
rm=false;
position--;
} else {
position++;
}
} else {
if(position>0){
position--;
} else {
rm=true;
position++;
}
}
elem.style.marginLeft = position+"%";
}
function end(){
clearInterval(id);
var elemContainer = document.getElementById("simpleProgress");
//elemContainer.style.display = "none";
elemContainer.style.visibility = "hidden";
}
function move() {
var elemContainer = document.getElementById("simpleProgress");
//elemContainer.style.display = "block";
elemContainer.style.visibility = "visible";
id=setInterval(frame, 10);
}
function sendRequest(formName, elem){
console.log("Send Request");
elem.disabled=true;
move();
let frm=document.getElementById(formName);
document.getElementById("act").value="submit";
frm.submit();
}
</script>

View File

@ -1,28 +1,43 @@
<%@include file="init.jsp"%> <%@include file="init.jsp"%>
<portlet:actionURL name="createDefinition" var="createDefinitionURL" /> <portlet:actionURL name="createDefinition" var="createDefinitionURL" />
<liferay-ui:error key="error-invalid-clientId" message="Invalid client id!" /> <liferay-ui:error key="error-invalid-clientId"
<liferay-ui:error key="error-invalid-description" message="Invalid description!" /> message="Invalid client id!" />
<liferay-ui:error key="error-invalid-clientId-space"
message="Invalid client id! Space characters are not allowed." />
<liferay-ui:error key="error-invalid-description"
message="Invalid description!" />
<form id="createDefinitionForm" <form id="createDefinitionForm"
action="<%=createDefinitionURL.toString()%>" method="POST" action="<%=createDefinitionURL.toString()%>" method="POST"
name="createDefinitionForm"> name="createDefinitionForm">
<div> <div>
<label for="clientId">Client Id:</label> <label for="clientId">Client Id:</label> <input type="text"
<input type="text" id="clientId" name="clientId" size="45" id="clientId" name="clientId" size="45"
value="<%=ParamUtil.getString(renderRequest, "clientId")%>"> value="<%=ParamUtil.getString(renderRequest, "clientId")%>">
</div> </div>
<div> <div>
<label for="description">Description:</label> <label for="description">Description:</label> <input type="text"
<input type="text" id="description" name="description" size="45" id="description" name="description" size="45"
value="<%=ParamUtil.getString(renderRequest, "description")%>"> value="<%=ParamUtil.getString(renderRequest, "description")%>">
</div> </div>
<input type="hidden" id="act" name="act" value="">
<div> <div>
<button class="btn btn-primary" type="submit" name="act" <button class="btn btn-primary"
value="submit">Save</button> onclick="sendRequest('createDefinitionForm', this)">Save</button>
<button class="btn btn-default" <button class="btn btn-default"
onClick="location.href = '<%=createDefinitionURL.toString()%>'" onclick="cancel()">Cancel</button>
name="act" value="cancel">Cancel</button>
</div> </div>
</form> </form>
<script type="text/javascript">
function cancel(){
document.getElementById("act").value="cancel";
location.href = '<%=createDefinitionURL.toString()%>';
}
</script>
<%@include file="simpleProgressBar.jsp" %>

View File

@ -0,0 +1,44 @@
<%@include file="init.jsp"%>
<portlet:renderURL var="ssdDialogCreateContent"
windowState="<%=LiferayWindowState.EXCLUSIVE.toString()%>">
<portlet:param name="mvcPath"
value="/html/systemservicedefinition/ssd_dialog_create_content.jsp" />
</portlet:renderURL>
<div>
<aui:button name="ssd_dialog_create" id="ssd_dialog_create"
value="Create">
</aui:button>
</div>
<aui:script>
AUI().use('aui-base',
'aui-io-plugin-deprecated',
'liferay-util-window',
function(A) {
var popUpWindow=Liferay.Util.Window.getWindow(
{
dialog: {
centered: true,
constrain2view: true,
//cssClass: 'yourCSSclassName',
modal: true,
resizable: false,
width: 475
}
}
).plug(
A.Plugin.IO,
{
autoLoad: false
}
).render();
popUpWindow.show();
popUpWindow.titleNode.html("Loading");
popUpWindow.io.set('uri','<%=ssdDialogCreateContent%>');
popUpWindow.io.start();
});
});
</aui:script>

View File

@ -37,7 +37,7 @@ pageContext.setAttribute("currentUsername", currentUsername);
<script src="<%=renderRequest.getContextPath()%>/js/buttons.html5.min.js"></script> <script src="<%=renderRequest.getContextPath()%>/js/buttons.html5.min.js"></script>
<script src="<%=renderRequest.getContextPath()%>/js/buttons.print.min.js"></script> <script src="<%=renderRequest.getContextPath()%>/js/buttons.print.min.js"></script>
<p>Use this portlet to automatically create or delete System Services.</p>
<liferay-ui:error key="error-session" message="Invalid Session please refresh the page!" /> <liferay-ui:error key="error-session" message="Invalid Session please refresh the page!" />
<liferay-ui:error key="error-create-definition" message="Error creating the definition!" /> <liferay-ui:error key="error-create-definition" message="Error creating the definition!" />
@ -46,29 +46,6 @@ pageContext.setAttribute("currentUsername", currentUsername);
<liferay-ui:success key="success-definition-updated" message="Definition updated!" /> <liferay-ui:success key="success-definition-updated" message="Definition updated!" />
<liferay-ui:error key="error-delete-definition" message="Error deleting the definition!" /> <liferay-ui:error key="error-delete-definition" message="Error deleting the definition!" />
<liferay-ui:success key="success-definition-deleted" message="Definition deleted!" /> <liferay-ui:success key="success-definition-deleted" message="Definition deleted!" />
<!-- HTML
<div>
<table style="border: none; border-collapse: inherit; overflow-x: hidden;">
<tr>
<td width="100%"><div class="messages-container"></div></td>
</tr>
</table>
</div> -->
<%--
<div>
<button id="ssdCreate" class="btn btn-primary" onClick="createSSD()">Create</button>
<button id="ssdEdit" class="btn btn-primary" disabled onClick="editSSD()">Edit</button>
<button id="ssdDelete" class="btn btn-primary" disabled onClick="deleteSSD()">Delete</button>
</div>
--%>
<%-- <%@include file="ssd_dialog.jsp" %> --%>
<table id="definitionsTable" style="width:100%"> <table id="definitionsTable" style="width:100%">
<thead> <thead>
@ -200,7 +177,7 @@ attr: {
function mainTable() { function mainTable() {
var table = $('#definitionsTable').DataTable( { var table = $('#definitionsTable').DataTable( {
retrieve: true, // tell DataTables that you are aware that the initialisation options can't be changed after initialisation, and that should that occur, that you just want the DataTable instance to be returned. retrieve: true, // tell DataTables that you are aware that the initialisation options can't be changed after initialisation, and that should that occur, that you just want the DataTable instance to be returned.
"lengthMenu": [ [5, 12, 25, 50, -1], [5, 12, 25, 50, "All"] ], "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ],
"dom": "<'row'<'small-6 columns'Bf>r>t<'row'<'mydt-pagination'p><'#mydtwrap'<'mydt-block'l><i>>'>", "dom": "<'row'<'small-6 columns'Bf>r>t<'row'<'mydt-pagination'p><'#mydtwrap'<'mydt-block'l><i>>'>",
select: { select: {
style: 'single' style: 'single'