-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make it possible for users to view their data on Panorama Public #387
Changes from 6 commits
5039b7d
46857e5
fba1640
963f851
f4c685e
506e392
0610ae9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ | |
import org.labkey.api.security.roles.ProjectAdminRole; | ||
import org.labkey.api.security.roles.Role; | ||
import org.labkey.api.security.roles.RoleManager; | ||
import org.labkey.api.settings.AppProps; | ||
import org.labkey.api.util.DOM; | ||
import org.labkey.api.util.HtmlString; | ||
import org.labkey.api.util.PageFlowUtil; | ||
|
@@ -65,8 +66,10 @@ | |
import org.labkey.panoramapublic.PanoramaPublicController; | ||
import org.labkey.panoramapublic.PanoramaPublicManager; | ||
import org.labkey.panoramapublic.PanoramaPublicSchema; | ||
import org.labkey.panoramapublic.model.CatalogEntry; | ||
import org.labkey.panoramapublic.model.DataLicense; | ||
import org.labkey.panoramapublic.model.ExperimentAnnotations; | ||
import org.labkey.panoramapublic.view.publish.CatalogEntryWebPart; | ||
import org.labkey.panoramapublic.view.publish.ShortUrlDisplayColumnFactory; | ||
|
||
import java.io.IOException; | ||
|
@@ -75,8 +78,12 @@ | |
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static org.labkey.api.util.DOM.Attribute.height; | ||
import static org.labkey.api.util.DOM.Attribute.href; | ||
import static org.labkey.api.util.DOM.Attribute.onclick; | ||
import static org.labkey.api.util.DOM.Attribute.src; | ||
import static org.labkey.api.util.DOM.Attribute.title; | ||
import static org.labkey.api.util.DOM.Attribute.width; | ||
import static org.labkey.api.util.DOM.IMG; | ||
import static org.labkey.api.util.DOM.at; | ||
|
||
|
@@ -337,6 +344,10 @@ public Class getDisplayValueClass() | |
getMutableColumn("CreatedBy").setFk(new UserIdQueryForeignKey(schema)); | ||
getMutableColumn("ModifiedBy").setFk(new UserIdQueryForeignKey(schema)); | ||
|
||
ExprColumn catalogEntryCol = getCatalogEntryCol(); | ||
catalogEntryCol.setDisplayColumnFactory(colInfo -> new CatalogEntryIconColumn(colInfo)); | ||
addColumn(catalogEntryCol); | ||
|
||
List<FieldKey> visibleColumns = new ArrayList<>(); | ||
visibleColumns.add(FieldKey.fromParts("Share")); | ||
visibleColumns.add(FieldKey.fromParts("Title")); | ||
|
@@ -407,6 +418,18 @@ private ExprColumn getVersionCountCol() | |
return versionCountCol; | ||
} | ||
|
||
private ExprColumn getCatalogEntryCol() | ||
{ | ||
SQLFragment catalogEntrySql = new SQLFragment(" (SELECT entry.id AS CatalogEntry ") | ||
.append(" FROM ").append(PanoramaPublicManager.getTableInfoCatalogEntry(), "entry") | ||
.append(" WHERE ") | ||
.append(" entry.shortUrl = ").append(ExprColumn.STR_TABLE_ALIAS).append(".shortUrl") | ||
.append(") "); | ||
ExprColumn col = new ExprColumn(this, "CatalogEntry", catalogEntrySql, JdbcType.INTEGER); | ||
col.setDescription("Add or view the catalog entry for the experiment"); | ||
return col; | ||
} | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
|
@@ -724,4 +747,47 @@ String getRenderId() | |
return "input-picker-div-instrument"; | ||
} | ||
} | ||
|
||
public static class CatalogEntryIconColumn extends DataColumn | ||
{ | ||
public CatalogEntryIconColumn(ColumnInfo col) | ||
{ | ||
super(col); | ||
super.setCaption("Catalog Entry"); | ||
} | ||
|
||
@Override | ||
public void renderGridCellContents(RenderContext ctx, Writer out) throws IOException | ||
{ | ||
User user = ctx.getViewContext().getUser(); | ||
if (user == null || user.isGuest()) | ||
{ | ||
HtmlString.NBSP.appendTo(out); | ||
return; | ||
} | ||
Integer catalogEntryId = ctx.get(getColumnInfo().getFieldKey(), Integer.class); | ||
|
||
// Get the experiment connected with this catalog entry. | ||
Integer experimentId = ctx.get(FieldKey.fromParts("id"), Integer.class); | ||
if (experimentId != null) | ||
{ | ||
ExperimentAnnotations expAnnot = ExperimentAnnotationsManager.get(experimentId); | ||
// Display the catalog entry link only if the user has the required permissions (Admin or PanoramaPublicSubmitter) in the the experiment folder. | ||
if (expAnnot != null && CatalogEntryWebPart.canBeDisplayed(expAnnot, user)) | ||
{ | ||
CatalogEntry entry = catalogEntryId == null ? null : CatalogEntryManager.get(catalogEntryId); | ||
String imageUrl = entry != null ? AppProps.getInstance().getContextPath() + "/PanoramaPublic/images/slideshow-icon-green.png" | ||
: AppProps.getInstance().getContextPath() + "/PanoramaPublic/images/slideshow-icon.png"; | ||
String imageTitle = entry != null ? "View catalog entry" : "Add catalog entry"; | ||
ActionURL catalogEntryLink = entry != null ? PanoramaPublicController.getViewCatalogEntryUrl(expAnnot, entry) | ||
: PanoramaPublicController.getAddCatalogEntryUrl(expAnnot).addReturnURL(ctx.getViewContext().getActionURL().clone()); | ||
DOM.A(at(href, catalogEntryLink.getLocalURIString(), title, PageFlowUtil.filter(imageTitle)), | ||
DOM.IMG(at(src, imageUrl, height, 22, width, 22))) | ||
.appendTo(out); | ||
return; | ||
} | ||
} | ||
HtmlString.EMPTY_STRING.appendTo(out); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This codepath uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.labkey.panoramapublic.query; | ||
|
||
import org.labkey.api.data.CompareType; | ||
import org.labkey.api.data.ContainerFilter; | ||
import org.labkey.api.data.SimpleFilter; | ||
import org.labkey.api.query.FieldKey; | ||
import org.labkey.api.security.User; | ||
import org.labkey.panoramapublic.PanoramaPublicSchema; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MyDataTableInfo extends ExperimentAnnotationsTableInfo | ||
{ | ||
public static final String NAME = "MyPanoramaPublicData"; | ||
|
||
public MyDataTableInfo(PanoramaPublicSchema schema, ContainerFilter cf, User user) | ||
{ | ||
super(schema, cf); | ||
|
||
if (user != null) | ||
{ | ||
// Filter to rows where the given user is either the submitter or the lab head. | ||
SimpleFilter.OrClause or = new SimpleFilter.OrClause(); | ||
or.addClause(new CompareType.EqualsCompareClause(FieldKey.fromParts("submitter"), CompareType.EQUAL, user.getUserId())); | ||
or.addClause(new CompareType.EqualsCompareClause(FieldKey.fromParts("labhead"), CompareType.EQUAL, user.getUserId())); | ||
SimpleFilter filter = new SimpleFilter(); | ||
filter.addClause(or); | ||
addCondition(filter); | ||
} | ||
|
||
List<FieldKey> visibleColumns = new ArrayList<>(); | ||
visibleColumns.add(FieldKey.fromParts("Share")); | ||
visibleColumns.add(FieldKey.fromParts("Title")); | ||
visibleColumns.add(FieldKey.fromParts("Organism")); | ||
visibleColumns.add(FieldKey.fromParts("Instrument")); | ||
visibleColumns.add(FieldKey.fromParts("Runs")); | ||
visibleColumns.add(FieldKey.fromParts("Keywords")); | ||
visibleColumns.add(FieldKey.fromParts("Citation")); | ||
visibleColumns.add(FieldKey.fromParts("pxid")); | ||
visibleColumns.add(FieldKey.fromParts("Public")); | ||
visibleColumns.add(FieldKey.fromParts("CatalogEntry")); | ||
setDefaultVisibleColumns(visibleColumns); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this form at all? It seems like we only support viewing data for the current user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we don't need a userId since we are only displaying the data for the currently logged in user! I removed the form.