Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion api/src/org/labkey/api/data/AbstractFileDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public void renderGridCellContents(RenderContext ctx, HtmlWriter out)
/** @return the short name of the file (not including full path) */
protected abstract String getFileName(RenderContext ctx, Object value);

protected String getFileName(RenderContext ctx, Object value, boolean isDisplay)
{
return getFileName(ctx, value);
}

protected abstract InputStream getFileContents(RenderContext ctx, Object value) throws FileNotFoundException;

protected void renderIconAndFilename(RenderContext ctx, HtmlWriter out, String fileValue, boolean link, boolean thumbnail)
Expand All @@ -99,7 +104,7 @@ protected void renderIconAndFilename(RenderContext ctx, HtmlWriter out, String f
// equivalent of DisplayColumn.renderURL.
// Don't want to call renderUrl (DataColumn.renderUrl) to skip unnecessary displayValue check
StringExpression s = compileExpression(ctx.getViewContext());
String displayName = getFileName(ctx, fileValue);
String displayName = getFileName(ctx, fileValue, true);
boolean unavailable = displayName.endsWith(UNAVAILABLE_FILE_SUFFIX);
String url = null == s || unavailable ? null : s.eval(ctx);
boolean isImage = isImage(fileValue);
Expand Down
14 changes: 12 additions & 2 deletions api/src/org/labkey/api/study/assay/FileLinkDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ public static boolean filePathExist(String path, Container container, User user)

@Override
protected String getFileName(RenderContext ctx, Object value)
{
return getFileName(ctx, value, false);
}

@Override
protected String getFileName(RenderContext ctx, Object value, boolean isDisplay)
{
String result = value == null ? null : StringUtils.trimToNull(value.toString());
if (result != null)
Expand Down Expand Up @@ -335,6 +341,10 @@ protected String getFileName(RenderContext ctx, Object value)
result = relativize(f, FileContentService.get().getFileRoot(container, fileRootType));
if (result != null)
{
// Issue 54062: Strip folder name from displayed name
if (isDisplay)
result = f.getName();

valid = true;
break;
}
Expand Down Expand Up @@ -438,13 +448,13 @@ else if (f.isDirectory())
@Override
public Object getDisplayValue(RenderContext ctx)
{
return getFileName(ctx, super.getDisplayValue(ctx));
return getFileName(ctx, super.getDisplayValue(ctx), true);
}

@Override
public Object getJsonValue(RenderContext ctx)
{
return getDisplayValue(ctx);
return getFileName(ctx, super.getDisplayValue(ctx));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ public void testFileField() throws IOException, CommandException
.selectDatasetByName(datasetName)
.clickViewData();

String expectedText;

if (SystemUtils.IS_OS_WINDOWS)
expectedText = "datasetdata\\sample.txt";
else
expectedText = "datasetdata/sample.txt";
String expectedText = "sample.txt";

assertElementPresent("Did not find the expected sample.txt from the imported dataset.", Locator.tagContainingText("a", expectedText), 1);
downloadedFile = doAndWaitForDownload(() -> waitAndClick(WAIT_FOR_JAVASCRIPT, Locator.tagWithAttribute("a", "title", "Download attached file"), 0));
Expand Down