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

include non-user editable columns in details view #812

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions announcements/resources/schemas/comm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<tables xsi:schemaLocation="http://labkey.org/data/xml ../../../api/schemas/tableInfo.xsd"
xmlns="http://labkey.org/data/xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<table tableName="Announcements" tableDbType="TABLE">
<tableUrl>org.labkey.announcements.AnnouncementsController$ThreadAction.class?rowId=${RowId}</tableUrl>
<columns>
<column columnName="RowId">
<columnTitle>Row Id</columnTitle>
Expand Down
26 changes: 21 additions & 5 deletions api/src/org/labkey/api/data/BaseColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
public class BaseColumnInfo extends ColumnRenderPropertiesImpl implements ColumnInfo
{
private static final Logger LOG = Logger.getLogger(ColumnInfo.class);
private static final Set<String> NON_EDITABLE_COL_NAMES = new CaseInsensitiveHashSet("created", "createdBy", "modified", "modifiedBy", "_ts", "entityId", "container");

private FieldKey _fieldKey;
private String _name;
Expand Down Expand Up @@ -350,7 +349,8 @@ public void setExtraAttributesFrom(ColumnInfo col)
setDefaultValueType(col.getDefaultValueType());
setDefaultValue(col.getDefaultValue());
setImportAliasesSet(col.getImportAliasSet());
setShownInDetailsView(col.isShownInDetailsView());
if (((BaseColumnInfo) col)._shownInDetailsView != null)
setShownInDetailsView(col.isShownInDetailsView());
setShownInInsertView(col.isShownInInsertView());
setShownInUpdateView(col.isShownInUpdateView());
setConditionalFormats(col.getConditionalFormats());
Expand Down Expand Up @@ -1603,9 +1603,6 @@ public static Collection<BaseColumnInfo> createFromDatabaseMetaData(String schem
col._label = reader.getLabel();
col._description = reader.getDescription();

if (NON_EDITABLE_COL_NAMES.contains(col.getPropertyName()))
col.setUserEditable(false);

colMap.put(col.getName(), col);
}
}
Expand Down Expand Up @@ -1711,6 +1708,25 @@ private static void inferMetadata(BaseColumnInfo col)
col.setReadOnly(true);
}

if (NON_EDITABLE_COL_NAMES.contains(colName))
{
col.setUserEditable(false);
col.setShownInDetailsView(false);
col.setShownInInsertView(false);
col.setShownInUpdateView(false);
}

if (colName.equalsIgnoreCase("entityid") || colName.equalsIgnoreCase("lsid") ||
colName.equalsIgnoreCase("lastindexed") ||
SqlDialect.isGUIDType(col.getSqlTypeName()))
{
col.setHidden(true);
col.setUserEditable(false);
col.setShownInDetailsView(false);
col.setShownInInsertView(false);
col.setShownInUpdateView(false);
}

if (JdbcType.INTEGER == col.getJdbcType() &&
(colName.equalsIgnoreCase("createdby") || colName.equalsIgnoreCase("modifiedby")) &&
(schema.getScope().isLabKeyScope()))
Expand Down
25 changes: 23 additions & 2 deletions api/src/org/labkey/api/data/ColumnRenderPropertiesImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.collections.CaseInsensitiveHashSet;
import org.labkey.api.data.Sort.SortDirection;
import org.labkey.api.exp.PropertyType;
import org.labkey.api.gwt.client.DefaultScaleType;
Expand All @@ -25,6 +26,7 @@
import org.labkey.api.query.FieldKey;
import org.labkey.api.util.StringExpression;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.regex.Matcher;
Expand All @@ -40,6 +42,10 @@
*/
public abstract class ColumnRenderPropertiesImpl implements ColumnRenderProperties
{
protected static final Set<String> NON_EDITABLE_COL_NAMES = Collections.unmodifiableSet(new CaseInsensitiveHashSet(
"created", "createdBy", "modified", "modifiedBy",
"_ts", "entityId", "container", "lsid", "lastIndexed"));

protected SortDirection _sortDirection = SortDirection.ASC;
protected String _inputType;
protected int _inputLength = -1;
Expand Down Expand Up @@ -70,7 +76,7 @@ public abstract class ColumnRenderPropertiesImpl implements ColumnRenderProperti
protected DefaultScaleType _defaultScale = DefaultScaleType.LINEAR;
protected boolean _shownInInsertView = true;
protected boolean _shownInUpdateView = true;
protected boolean _shownInDetailsView = true;
protected Boolean _shownInDetailsView;
protected StringExpression _url;
protected String _urlTargetWindow;
protected String _urlCls;
Expand Down Expand Up @@ -299,7 +305,22 @@ public void setHidden(boolean hidden)
@Override
public boolean isShownInDetailsView()
{
return _shownInDetailsView;
if (_shownInDetailsView != null)
return _shownInDetailsView;

return inferShownInDetailsView();
}

// CONSIDER: Refactor BaseColumnInfo.inferMetadata() to use infer metadata methods?
protected boolean inferShownInDetailsView()
{
if (isAutoIncrement())
return false;

if (NON_EDITABLE_COL_NAMES.contains(getName()))
return false;

return true;
}

public void setShownInDetailsView(boolean shownInDetailsView)
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/query/QueryForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected Container getContainer()
}

@Override
public @NotNull BindException bindParameters(PropertyValues params)
public final @NotNull BindException bindParameters(PropertyValues params)
{
return doBindParameters(params);
}
Expand Down
10 changes: 10 additions & 0 deletions api/src/org/labkey/api/query/QueryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3039,6 +3039,11 @@ public void setShowRStudioButton(boolean showRStudioButton)
_showRStudioButton = showRStudioButton;
}

public final boolean isShowDetailsColumn()
{
return _showDetailsColumn;
}

public void setShowDetailsColumn(boolean showDetailsColumn)
{
_showDetailsColumn = showDetailsColumn;
Expand All @@ -3059,6 +3064,11 @@ public void setUpdateURL(DetailsURL updateURL)
_updateURL = updateURL;
}

public final DetailsURL getDetailsURL()
{
return _detailsURL;
}

public void setDetailsURL(String detailsURL)
{
_detailsURL = null==detailsURL ? null : DetailsURL.fromString(detailsURL);
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/view/DataView.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public DataRegion getDataRegion()
{
DataRegion dr = new DataRegion();
dr.setTable(form.getTable());
List<ColumnInfo> allCols = form.getTable().getUserEditableColumns();
List<ColumnInfo> allCols = form.getTable().getColumns();
List<ColumnInfo> includedCols = new ArrayList<>();
for (ColumnInfo col : allCols)
{
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/view/InsertView.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public InsertView(List<ColumnInfo> cols, BindException errors)
@Override
protected boolean isColumnIncluded(ColumnInfo col)
{
return col.isShownInInsertView();
return col.isUserEditable() && col.isShownInInsertView();
}

public void setInitialValues(Map<String, Object> initialValues)
Expand Down
11 changes: 11 additions & 0 deletions assay/src/org/labkey/assay/query/AssayProviderTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.labkey.api.assay.AssayProvider;
import org.labkey.api.assay.AssaySchema;
import org.labkey.api.assay.AssayService;
import org.labkey.api.security.UserPrincipal;
import org.labkey.api.security.permissions.Permission;
import org.labkey.api.security.permissions.ReadPermission;

/**
* User: kevink
Expand All @@ -49,9 +52,17 @@ public AssayProviderTable(@NotNull AssaySchema schema)

ExprColumn runLSIDPrefixCol = new ExprColumn(this, "RunLSIDPrefix", new SQLFragment(ExprColumn.STR_TABLE_ALIAS + ".RunLSIDPrefix"), JdbcType.INTEGER);
runLSIDPrefixCol.setHidden(true);
runLSIDPrefixCol.setShownInDetailsView(false);
addColumn(runLSIDPrefixCol);
}

@Override
public boolean hasPermission(@NotNull UserPrincipal user, @NotNull Class<? extends Permission> perm)
{
return ReadPermission.class.isAssignableFrom(perm) &&
getUserSchema().getContainer().hasPermission(user, perm);
}

@Override @NotNull
public SQLFragment getFromSQL()
{
Expand Down
3 changes: 3 additions & 0 deletions experiment/resources/schemas/exp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@
<column columnName="MaterialLSIDPrefix">
<isReadOnly>true</isReadOnly>
<description>Contains the LSID prefix for all materials that are part of this sample set</description>
<shownInDetailsView>false</shownInDetailsView>
<shownInInsertView>false</shownInInsertView>
<shownInUpdateView>false</shownInUpdateView>
</column>
<column columnName="Description">
<description>Contains an optional description about the contents or purpose of this sample set</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.labkey.experiment.api;

import org.jetbrains.annotations.NotNull;
import org.labkey.api.data.AbstractTableInfo;
import org.labkey.api.data.BaseColumnInfo;
import org.labkey.api.data.ContainerFilter;
Expand All @@ -26,7 +27,10 @@
import org.labkey.api.query.DetailsURL;
import org.labkey.api.query.ExprColumn;
import org.labkey.api.query.UserSchema;
import org.labkey.api.security.UserPrincipal;
import org.labkey.api.security.permissions.InsertPermission;
import org.labkey.api.security.permissions.Permission;
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.security.permissions.UpdatePermission;
import org.labkey.api.view.ActionURL;
import org.labkey.experiment.controllers.exp.ExperimentController;
Expand All @@ -46,6 +50,16 @@ public ExpSampleSetTableImpl(String name, UserSchema schema, ContainerFilter cf)
addAllowablePermission(UpdatePermission.class);
}

@Override
public boolean hasPermission(@NotNull UserPrincipal user, @NotNull Class<? extends Permission> perm)
{
// Allow DetailsView to render
if (ReadPermission.class.isAssignableFrom(perm) && getUserSchema().getContainer().hasPermission(user, perm))
return true;

return super.hasPermission(user, perm);
}

public BaseColumnInfo createColumn(String alias, Column column)
{
switch (column)
Expand Down Expand Up @@ -76,6 +90,9 @@ public BaseColumnInfo createColumn(String alias, Column column)
" m WHERE m.CpasType = " + ExprColumn.STR_TABLE_ALIAS + ".LSID)");
ExprColumn sampleCountColumnInfo = new ExprColumn(this, "SampleCount", sql, JdbcType.INTEGER);
sampleCountColumnInfo.setDescription("Contains the number of samples currently stored in this sample set");
sampleCountColumnInfo.setShownInDetailsView(false);
sampleCountColumnInfo.setShownInInsertView(false);
sampleCountColumnInfo.setShownInUpdateView(false);
return sampleCountColumnInfo;
}
case Properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import org.labkey.api.data.TSVWriter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.data.TableSelector;
import org.labkey.api.data.TableViewForm;
import org.labkey.api.exp.AbstractParameter;
import org.labkey.api.exp.DuplicateMaterialException;
import org.labkey.api.exp.ExperimentDataHandler;
Expand Down Expand Up @@ -626,10 +627,12 @@ public ModelAndView getView(ExpObjectForm form, BindException errors)
QuerySettings settings = schema.getSettings(getViewContext(), "Material", _source.getName());
QueryView queryView = new SampleSetContentsView(_source, schema, settings, errors);

DetailsView detailsView = new DetailsView(getMaterialSourceRegion(getViewContext()), _source.getRowId());
detailsView.getDataRegion().getDisplayColumn("Name").setURL(null);
detailsView.getDataRegion().getDisplayColumn("LSID").setVisible(false);
detailsView.getDataRegion().getDisplayColumn("MaterialLSIDPrefix").setVisible(false);
ExpSchema expSchema = (ExpSchema)QueryService.get().getUserSchema(getUser(), getContainer(), ExpSchema.SCHEMA_NAME);
TableInfo sampleSetsTable = expSchema.getTable(ExpSchema.TableType.SampleSets);

TableViewForm detailsViewForm = new TableViewForm(sampleSetsTable);
detailsViewForm.setPkVal(_source.getRowId());
DetailsView detailsView = new DetailsView(detailsViewForm);
detailsView.setTitle("Sample Set Properties");
detailsView.getDataRegion().getButtonBar(DataRegion.MODE_DETAILS).setStyle(ButtonBar.Style.separateButtons);

Expand Down Expand Up @@ -722,7 +725,6 @@ public ModelAndView getView(ExpObjectForm form, BindException errors)
ActionButton uploadButton = new ActionButton(importURL, "Import More Samples", ActionButton.Action.LINK);
uploadButton.setDisplayPermission(UpdatePermission.class);
detailsView.getDataRegion().getButtonBar(DataRegion.MODE_DETAILS).add(uploadButton);

}
}
}
Expand Down Expand Up @@ -3442,33 +3444,6 @@ private List<? extends ExpRun> getRuns(List<ExpSampleSet> sampleSets)
}
}

private DataRegion getMaterialSourceRegion(ViewContext model)
{
TableInfo tableInfo = ExperimentServiceImpl.get().getTinfoMaterialSource();

QuerySettings settings = new QuerySettings(model, "MaterialsSource");
settings.setSelectionKey(DataRegionSelection.getSelectionKey(tableInfo.getSchema().getName(), tableInfo.getName(), "SampleSets", settings.getDataRegionName()));

DataRegion dr = new DataRegion();
dr.setSettings(settings);
dr.addColumns(tableInfo.getUserEditableColumns());
dr.removeColumns("lastindexed");
dr.getDisplayColumn(0).setVisible(false);

dr.getDisplayColumn("idcol1").setVisible(false);
dr.getDisplayColumn("idcol2").setVisible(false);
dr.getDisplayColumn("idcol3").setVisible(false);
dr.getDisplayColumn("lsid").setVisible(false);
dr.getDisplayColumn("materiallsidprefix").setVisible(false);
dr.getDisplayColumn("parentcol").setVisible(false);

ActionURL url = new ActionURL(ExperimentController.ShowMaterialSourceAction.class, model.getContainer());
dr.getDisplayColumn(1).setURL(url.toString() + "rowId=${RowId}");
dr.setShowRecordSelectors(getContainer().hasOneOf(getUser(), DeletePermission.class, UpdatePermission.class));

return dr;
}

@RequiresPermission(DesignSampleSetPermission.class)
public class UpdateMaterialSourceAction extends BaseSampleSetAction
{
Expand Down
5 changes: 3 additions & 2 deletions query/src/org/labkey/query/controllers/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5991,8 +5991,9 @@ public ApiResponse execute(QueryForm form, BindException errors)
}

SchemaKey schemaKey = SchemaKey.fromString(form.getSchemaName());
QueryManager.get().validateQueryMetadata(schemaKey, form.getQueryName(), getUser(), getContainer(), parseErrors, parseWarnings);
QueryManager.get().validateQueryViews(schemaKey, form.getQueryName(), getUser(), getContainer(), parseErrors, parseWarnings);
QueryManager.get().validateQueryMetadata(schema, table, getUser(), getContainer(), parseErrors, parseWarnings);
QueryManager.get().validateQueryView(form, errors, schema, table, getUser(), getContainer(), parseErrors, parseWarnings);
QueryManager.get().validateQueryCustomViews(schema, table, schemaKey, form.getQueryName(), getUser(), getContainer(), parseErrors, parseWarnings);

for (QueryParseException e : parseErrors)
{
Expand Down
Loading