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

View File

@ -45,6 +45,7 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
*
*/
public class SystemServiceDefinition extends MVCPortlet {
private static Logger logger = LoggerFactory.getLogger(SystemServiceDefinition.class);
private void paramsInfo(ActionRequest actionRequest) {
@ -240,10 +241,14 @@ public class SystemServiceDefinition extends MVCPortlet {
}
int limit = 0;
if (start + length > recordsFiltered) {
limit = recordsFiltered;
if (length != -1) {
if (start + length > recordsFiltered) {
limit = recordsFiltered;
} else {
limit = start + length;
}
} else {
limit = start + length;
limit = recordsFiltered;
}
ArrayList<DefinitionItem> windowItemsList = new ArrayList<>();
@ -347,6 +352,16 @@ public class SystemServiceDefinition extends MVCPortlet {
PortalUtil.copyRequestParameters(actionRequest, actionResponse);
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp");
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");
if (description == null || description.isEmpty()) {
@ -358,6 +373,7 @@ public class SystemServiceDefinition extends MVCPortlet {
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/ssd_create.jsp");
break;
}
logger.debug("Requested: [clientId={}, description={}]", clientId, description);
try {
String username = clientId;
@ -369,7 +385,7 @@ public class SystemServiceDefinition extends MVCPortlet {
SessionMessages.add(actionRequest, "success-definition-created");
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
} catch (Exception e) {
logger.error(e.getLocalizedMessage(),e);
logger.error(e.getLocalizedMessage(), e);
SessionErrors.add(actionRequest, "error-create-definition");
SessionMessages.add(actionRequest,
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 {
@SuppressWarnings("unused")
UserCredentials userCredentials;
@ -455,8 +469,7 @@ public class SystemServiceDefinition extends MVCPortlet {
}
paramsInfo(actionRequest);
logger.debug("Delete Request");
String clientId = ParamUtil.getString(actionRequest, "clientId");
if (clientId == null || clientId.isEmpty()) {
@ -468,9 +481,9 @@ public class SystemServiceDefinition extends MVCPortlet {
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
return;
}
try {
DefinitionItem definitionItem=new DefinitionItem(clientId);
DefinitionItem definitionItem = new DefinitionItem(clientId);
InformationSystemUtils.deleteSSD(definitionItem, Constants.SYSTEM_SERVICE_CATEGORY,
userCredentials.getCurrentScope());
publishDeleteSSDEvent(definitionItem);
@ -478,41 +491,39 @@ public class SystemServiceDefinition extends MVCPortlet {
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
} catch (Exception e) {
logger.error(e.getLocalizedMessage(),e);
logger.error(e.getLocalizedMessage(), e);
SessionErrors.add(actionRequest, "error-delete-definition");
SessionMessages.add(actionRequest,
PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
actionResponse.setRenderParameter("jspPage", "/html/systemservicedefinition/view.jsp");
}
}
private void publishCreateSSDEvent(DefinitionItem definitionItem) {
logger.debug("Trying to send the event to create System Service");
CreateSSDEvent toCreate = new CreateSSDEvent(definitionItem);
toCreate.publisher.publish(toCreate);
logger.info("Done send create event " + toCreate.getName() + " for " + toCreate.getUser());
try {
Thread.sleep(2000);
Thread.sleep(Constants.SLEEP_TIME);
} catch (InterruptedException e) {
}
}
private void publishDeleteSSDEvent(DefinitionItem definitionItem) {
logger.debug("Trying to send the event to delete System Service");
DeleteSSDEvent toDelete = new DeleteSSDEvent(definitionItem);
toDelete.publisher.publish(toDelete);
logger.info("Done send delete event " + toDelete.getName() + " for " + toDelete.getUser());
try {
Thread.sleep(2000);
Thread.sleep(Constants.SLEEP_TIME);
} catch (InterruptedException e) {
}
}
/*
* private void createDefinition(ResourceRequest resourceRequest,
* 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_TOKEN = "";
public static final String DEFAULT_ROLE = "OrganizationMember";
// Session
@ -22,6 +21,7 @@ public class Constants {
public static final String SOCIAL_NETWORKING_NAME = "SocialNetworking";
public static final String SOCIAL_NETWORKING_CATEGORY = "Portal";
// SSD Services Endpoint
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_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
select option:checked {
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"%>
<portlet:actionURL name="createDefinition" var="createDefinitionURL" />
<liferay-ui:error key="error-invalid-clientId" message="Invalid client id!" />
<liferay-ui:error key="error-invalid-description" message="Invalid description!" />
<liferay-ui:error key="error-invalid-clientId"
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"
action="<%=createDefinitionURL.toString()%>" method="POST"
name="createDefinitionForm">
<div>
<label for="clientId">Client Id:</label>
<input type="text" id="clientId" name="clientId" size="45"
<label for="clientId">Client Id:</label> <input type="text"
id="clientId" name="clientId" size="45"
value="<%=ParamUtil.getString(renderRequest, "clientId")%>">
</div>
<div>
<label for="description">Description:</label>
<input type="text" id="description" name="description" size="45"
<label for="description">Description:</label> <input type="text"
id="description" name="description" size="45"
value="<%=ParamUtil.getString(renderRequest, "description")%>">
</div>
<input type="hidden" id="act" name="act" value="">
<div>
<button class="btn btn-primary" type="submit" name="act"
value="submit">Save</button>
<button class="btn btn-primary"
onclick="sendRequest('createDefinitionForm', this)">Save</button>
<button class="btn btn-default"
onClick="location.href = '<%=createDefinitionURL.toString()%>'"
name="act" value="cancel">Cancel</button>
onclick="cancel()">Cancel</button>
</div>
</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.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-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:error key="error-delete-definition" message="Error deleting the definition!" />
<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%">
<thead>
@ -200,7 +177,7 @@ attr: {
function mainTable() {
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.
"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>>'>",
select: {
style: 'single'