The widget has been extended to support the Recent Files view feature so that we can remove the previous portlet. Additionally the VRE Folders folder has been removed from the root and added separately (When in the root VO)
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/workspace-widget-portlet@167383 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e439e1855a
commit
31e9589301
|
@ -13,7 +13,14 @@ import org.gcube.common.portal.PortalContext;
|
|||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
||||
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
||||
import org.gcube.common.storagehub.model.Paths;
|
||||
import org.gcube.common.storagehub.model.expressions.GenericSearchableItem;
|
||||
import org.gcube.common.storagehub.model.expressions.SearchableItem;
|
||||
import org.gcube.common.storagehub.model.expressions.logical.ISDescendant;
|
||||
import org.gcube.common.storagehub.model.items.AbstractFileItem;
|
||||
import org.gcube.common.storagehub.model.items.Item;
|
||||
import org.gcube.common.storagehub.model.query.Queries;
|
||||
import org.gcube.common.storagehub.model.query.Query;
|
||||
import org.gcube.portlets.user.wswidget.shared.AuthorizedUser;
|
||||
import org.gcube.portlets.user.wswidget.shared.WSItem;
|
||||
|
||||
|
@ -90,7 +97,46 @@ public class StorageHubServiceUtil {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param authUser
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
public static List<WSItem> getRecentItems(AuthorizedUser authUser, int limit, Item vreFolder) {
|
||||
WSItem toReturn = new WSItem("recents", "Recent Documents", true);
|
||||
_log.debug("getRecentItems ");
|
||||
ArrayList<WSItem> children = new ArrayList<>();
|
||||
SecurityTokenProvider.instance.set(authUser.getSecurityToken());
|
||||
Query<SearchableItem<?>> query = Queries.queryFor(AbstractFileItem.class);
|
||||
|
||||
//query.setExpression(new ISDescendant(Paths.getPath(vreFolder.getPath())));
|
||||
query.setExpression(new ISDescendant(Paths.getPath("/Home/"+authUser.getUser().getUsername()+"/Workspace/MySpecialFolders/"+vreFolder.getTitle())));
|
||||
|
||||
query.setLimit(limit);
|
||||
query.setOrder(GenericSearchableItem.get().lastModification);
|
||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
List<? extends Item> theChildren = wsclient.search(query, "hl:accounting", "jcr:content");
|
||||
|
||||
if (theChildren == null || theChildren.isEmpty()) {
|
||||
toReturn.setChildren(children);
|
||||
_log.debug("*** Returning empty ");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
for (Item workspaceItem : theChildren) {
|
||||
WSItem toAdd = ItemBuilder.getItem(toReturn, workspaceItem, workspaceItem.getPath(), authUser.getUser().getUsername());
|
||||
children.add(toAdd);
|
||||
}
|
||||
toReturn.setChildren(children);
|
||||
Collections.sort(toReturn.getChildren(), new ItemComparator());
|
||||
_log.debug("*** Returning recents items size: "+toReturn.getChildren().size());
|
||||
return children;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @return the id of the VRE Folder associated to the given context
|
||||
*/
|
||||
public static String getWorkspaceFolderURL(HttpServletRequest request) {
|
||||
String userName = Utils.getCurrentUser(request).getUsername();
|
||||
String scope = Utils.getCurrentContext(request);
|
||||
|
@ -111,6 +157,33 @@ public class StorageHubServiceUtil {
|
|||
}
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param request
|
||||
* @return the VRE Folders Id
|
||||
*/
|
||||
public static String getVREFoldersId(HttpServletRequest request) {
|
||||
String userName = Utils.getCurrentUser(request).getUsername();
|
||||
String scope = Utils.getCurrentContext(request);
|
||||
String authorizationToken = Utils.getCurrentUserToken(scope, userName);
|
||||
SecurityTokenProvider.instance.set(authorizationToken);
|
||||
String toReturn = "";
|
||||
try {
|
||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
try {
|
||||
List<? extends Item> list = wsclient.getVreFolders("hl:accounting");
|
||||
toReturn =list.iterator().next().getParentId();
|
||||
} catch (Exception e) {
|
||||
_log.info("This user has no VRE Folders", e);
|
||||
return null;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ import com.liferay.util.bridges.mvc.MVCPortlet;
|
|||
public class WorkspaceWidget extends MVCPortlet {
|
||||
private static com.liferay.portal.kernel.log.Log _log = LogFactoryUtil.getLog(WorkspaceWidget.class);
|
||||
public static String BREADCRUMB_ATTR = "BREADCRUMB_ATTR_name";
|
||||
public final static int LIMIT = 5;
|
||||
|
||||
/**
|
||||
* all the AJAX calls are served by this method, to discriminate the operation we use the parameters:
|
||||
|
@ -59,10 +60,9 @@ public class WorkspaceWidget extends MVCPortlet {
|
|||
ServletResponseUtil.sendFile(httpReq,httpRes, streamDescr.getFileName(), streamDescr.getStream(), "application/download");
|
||||
streamDescr.getStream().close();
|
||||
}
|
||||
//the user is browsing the workspace
|
||||
//the user is browsing the workspace or asking for recents
|
||||
else {
|
||||
String cmd = ParamUtil.getString(resourceRequest, "cmd", "");
|
||||
System.out.println("******** CMD="+cmd);
|
||||
String selectedItemId = "root";
|
||||
String selectedItemName = "";
|
||||
if (cmd != null && cmd.split("_selectedName").length > 1) {
|
||||
|
@ -101,6 +101,16 @@ public class WorkspaceWidget extends MVCPortlet {
|
|||
toSet = new Breadcrumb(itemId, groupName+"\'s VRE home");
|
||||
request.getPortletSession().setAttribute(BREADCRUMB_ATTR, toSet, PortletSession.APPLICATION_SCOPE);
|
||||
}
|
||||
count = StorageHubServiceUtil.getItemChildrenCount(request, itemId);
|
||||
}
|
||||
else if (itemId.compareTo("recents") == 0) { //is in a VRE and asking for recents files
|
||||
WorkspaceManagerClient wsclient = AbstractPlugin.workspace().build();
|
||||
Item vreFolder = wsclient.getVreFolder("hl:accounting");
|
||||
itemsList = StorageHubServiceUtil.getRecentItems(authUser, offset, vreFolder);
|
||||
count = offset;
|
||||
toSet = (Breadcrumb) request.getPortletSession().getAttribute(BREADCRUMB_ATTR, PortletSession.APPLICATION_SCOPE);
|
||||
toSet.setChild(new Breadcrumb(vreFolder.getId(), "Recent"));
|
||||
request.getPortletSession().setAttribute(BREADCRUMB_ATTR, toSet, PortletSession.APPLICATION_SCOPE);
|
||||
}
|
||||
else {
|
||||
_log.debug("non root");
|
||||
|
@ -108,8 +118,9 @@ public class WorkspaceWidget extends MVCPortlet {
|
|||
toSet = (Breadcrumb) request.getPortletSession().getAttribute(BREADCRUMB_ATTR, PortletSession.APPLICATION_SCOPE);
|
||||
clicked = new WSItem(itemId, itemName, true);
|
||||
computeBreadcrumb(clicked, toSet);
|
||||
count = StorageHubServiceUtil.getItemChildrenCount(request, itemId);
|
||||
}
|
||||
count = StorageHubServiceUtil.getItemChildrenCount(request, itemId);
|
||||
|
||||
JSONObject tableData = buildJSONResponse(itemsList, start, offset, draw, count, request);
|
||||
ServletResponseUtil.write(PortalUtil.getHttpServletResponse(resourceResponse),tableData.toString());
|
||||
} catch (Exception e) {
|
||||
|
@ -143,24 +154,28 @@ public class WorkspaceWidget extends MVCPortlet {
|
|||
private static String constructBreadcrumbHTML(Breadcrumb toSet, ResourceRequest request) {
|
||||
StringBuilder sb =
|
||||
new StringBuilder("<ul class='breadcrumb'>");
|
||||
sb.append("<li>").append(getHREFJavascriptCall(toSet)).append("</li>");
|
||||
sb.append("<li>").append(getHREFJavascriptCall(toSet, false)).append("</li>"); //this is the root of the breadcrumb
|
||||
while (toSet.hasChild()) {
|
||||
toSet = toSet.getChild();
|
||||
if (!toSet.hasChild()) {
|
||||
sb.append("<li><span class='active'> / </span>").append(toSet.getName()).append("</li>");
|
||||
}
|
||||
else {
|
||||
sb.append("<li><span class='divider'>/</span>").append(getHREFJavascriptCall(toSet)).append("</li>");
|
||||
sb.append("<li><span class='divider'>/</span>").append(getHREFJavascriptCall(toSet, true)).append("</li>");
|
||||
}
|
||||
}
|
||||
sb.append("</ul>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String getHREFJavascriptCall(Breadcrumb toSet) {
|
||||
/**
|
||||
* this method construct the breadcrumb server side, the resaulting code is added in the client DOM (once returned)
|
||||
* @param toSet
|
||||
* @return
|
||||
*/
|
||||
private static String getHREFJavascriptCall(Breadcrumb toSet, boolean hideVreFoldersDiv) {
|
||||
String escapedItemName = toSet.getName().replaceAll("\"", "\\\"").replaceAll("'", "\\\\'");
|
||||
StringBuilder sb = new StringBuilder
|
||||
("<a href=\"javascript:loadItemsListIntoTable('").append(toSet.getId()).append("', '").append(escapedItemName).append("');\">")
|
||||
("<a href=\"javascript:loadItemsListIntoTable('").append(toSet.getId()).append("', '").append(escapedItemName).append("', "+hideVreFoldersDiv+");\">")
|
||||
.append(toSet.getName()).append("</a>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -58,6 +58,10 @@
|
|||
|
||||
.workspace-widget-portlet table.dataTable thead th, table.dataTable tfoot th {
|
||||
font-weight: 400;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.workspace-widget-portlet table.dataTable thead th:first-child {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,21 +14,30 @@
|
|||
<portlet:param name="fileToDownloadId" value="itemId=" />
|
||||
</portlet:resourceURL>
|
||||
|
||||
|
||||
<table width="100%" style="border: none; border-collapse: inherit;">
|
||||
<tr>
|
||||
<td><div class="ws-breadcrumb-container"></div></td>
|
||||
<c:choose>
|
||||
<c:when test="${currentGroup.getParentGroupId() > 0}">
|
||||
<td><div class="ws-recents">
|
||||
<a><i style="font-size: 1.2em;" class="material-icons">access_time</i>
|
||||
<a href="javascript:loadRecentItemsListIntoTable('recents', 'Recent documents');"><i
|
||||
style="font-size: 1.2em; color: #8F8F8F;" class="material-icons">access_time</i>
|
||||
<span>Recent</span></a>
|
||||
</div></td>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<td><div class="ws-recents">
|
||||
<a><i class="material-icons">folder_special</i>
|
||||
<span>VRE Folders</span></a>
|
||||
</div></td>
|
||||
<td>
|
||||
<%pageContext.setAttribute("vreFoldersId", StorageHubServiceUtil.getVREFoldersId(request));%>
|
||||
<c:if test="${not empty vreFoldersId}">
|
||||
<div id="vreFoldersDiv" class="ws-recents">
|
||||
<a
|
||||
href="javascript:loadItemsListIntoTable('${vreFoldersId}', 'VRE Folders', true);"><i
|
||||
style="font-size: 1.5em; color: #8F8F8F;" class="material-icons">folder_special</i>
|
||||
<span>VREs</span></a>
|
||||
</div>
|
||||
</c:if>
|
||||
</td>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
</tr>
|
||||
|
@ -52,7 +61,17 @@
|
|||
</div>
|
||||
</c:if>
|
||||
<script>
|
||||
function loadItemsListIntoTable(itemId, itemName) {
|
||||
function loadItemsListIntoTable(itemId, itemName, hideVreFolders) {
|
||||
var table = $('#userTable').DataTable();
|
||||
table.ajax.url('<%=usersCustomDataSourceURL%>'+itemId+'_selectedName='+itemName).load();
|
||||
if (hideVreFolders) {
|
||||
$('#vreFoldersDiv').hide();
|
||||
} else {
|
||||
$('#vreFoldersDiv').show();
|
||||
}
|
||||
}
|
||||
|
||||
function loadRecentItemsListIntoTable(itemId, itemName) {
|
||||
var table = $('#userTable').DataTable();
|
||||
table.ajax.url('<%=usersCustomDataSourceURL%>'+itemId+'_selectedName='+itemName).load();
|
||||
}
|
||||
|
@ -61,7 +80,7 @@ function downloadItem(itemId) {
|
|||
var uri = '<%=downloadFileURL%>'+itemId;
|
||||
window.open(uri, "_blank");
|
||||
}
|
||||
|
||||
//instance of DataTables framework, see https://datatables.net/manual/
|
||||
function mainTable() {
|
||||
var table = $('#userTable').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.
|
||||
|
@ -93,7 +112,7 @@ function mainTable() {
|
|||
var truncatedName = truncateText(obj.Name);
|
||||
var anchorURL = '<a title="'+obj.Name+'" target="_blank" href="<%=downloadFileURL%>'+obj.Id+'">'+truncatedName+'<a/>';
|
||||
if(obj.isFolder) {
|
||||
anchorURL = '<a title="'+obj.Name+'" href="javascript:loadItemsListIntoTable(\''+obj.Id+'\',\''+obj.Name+'\');">'+truncatedName+'<a/>';
|
||||
anchorURL = '<a title="'+obj.Name+'" href="javascript:loadItemsListIntoTable(\''+obj.Id+'\',\''+obj.Name+'\', true);">'+truncatedName+'<a/>';
|
||||
}
|
||||
return '<div class="noselect" style="display: table;">'+
|
||||
'<span style="padding: 5px; background-color: white; border-radius: 20px; color: '+ obj.IconColor+ '; font-size: 1.5em; vertical-align: middle; display: table-cell;">'+
|
||||
|
@ -131,7 +150,7 @@ function mainTable() {
|
|||
var obj = JSON.parse(selectedNameData);
|
||||
var selectedName = obj.Name;
|
||||
if(obj.isFolder)
|
||||
loadItemsListIntoTable(selectedId, selectedName);
|
||||
loadItemsListIntoTable(selectedId, selectedName, true);
|
||||
else
|
||||
downloadItem(selectedId);
|
||||
} )
|
||||
|
|
|
@ -41,7 +41,7 @@ function nameToColor(name) {
|
|||
return colors[index];
|
||||
}
|
||||
|
||||
//very simple hash
|
||||
//very simple hash for assigning always the same color to the owner of the file
|
||||
function hashStr(str) {
|
||||
var hash = 0;
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
|
|
Loading…
Reference in New Issue