Skip to content

Commit

Permalink
Merge pull request IQSS#4140 from IQSS/4059-dynamic-fields
Browse files Browse the repository at this point in the history
4059 dynamic dataset summary fields
  • Loading branch information
kcondon authored Sep 20, 2017
2 parents 365f7e4 + cb35530 commit 2ad148a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 39 deletions.
11 changes: 10 additions & 1 deletion doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1182,4 +1182,13 @@ This setting is experimental and related to Repository Storage Abstraction Layer

Limit on how many guestbook entries to display on the guestbook-responses page. By default, only the 5000 most recent entries will be shown. Use the standard settings API in order to change the limit. For example, to set it to 10,000, make the following API call:

``curl -X PUT -d 10000 http://localhost:8080/api/admin/settings/:GuestbookResponsesPageDisplayLimit``
``curl -X PUT -d 10000 http://localhost:8080/api/admin/settings/:GuestbookResponsesPageDisplayLimit``

:CustomDatasetSummaryFields
+++++++++++++++++++++++++

You can replace the default dataset metadata fields that are displayed above files table on the dataset page with a custom list separated by commas using the curl command below.

``curl http://localhost:8080/api/admin/settings/:CustomDatasetSummaryFields -X PUT -d 'producer,subtitle,alternativeTitle'``

You have to put the datasetFieldType name attribute in the :CustomDatasetSummaryFields setting for this to work.
17 changes: 16 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.dataaccess.SwiftAccessIO;
import edu.harvard.iq.dataverse.dataset.DatasetThumbnail;
import edu.harvard.iq.dataverse.dataset.DatasetUtil;
import edu.harvard.iq.dataverse.datavariable.VariableServiceBean;
import edu.harvard.iq.dataverse.engine.command.Command;
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
Expand Down Expand Up @@ -210,6 +211,7 @@ public enum DisplayMode {
private String protocol = "";
private String authority = "";
private String separator = "";
private String customFields="";

private boolean noDVsAtAll = false;

Expand Down Expand Up @@ -3889,5 +3891,18 @@ public String getThumbnail() {
return null;
}
}*/


/**
* this method returns the dataset fields to be shown in the dataset summary
* on the dataset page.
* It returns the default summary fields( subject, description, keywords, related publications and notes)
* if the custom summary datafields has not been set, otherwise will set the custom fields set by the sysadmins
*
*/
public List<DatasetField> getDatasetSummaryFields() {
customFields = settingsService.getValueForKey(SettingsServiceBean.Key.CustomDatasetSummaryFields);

return DatasetUtil.getDatasetSummaryFields(workingVersion, customFields);
}

}
31 changes: 31 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/dataset/DatasetUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import edu.harvard.iq.dataverse.DataFile;
import edu.harvard.iq.dataverse.Dataset;
import edu.harvard.iq.dataverse.DatasetField;
import edu.harvard.iq.dataverse.DatasetVersion;
import edu.harvard.iq.dataverse.FileMetadata;
import edu.harvard.iq.dataverse.dataaccess.DataAccess;
import static edu.harvard.iq.dataverse.dataaccess.DataAccess.getStorageIO;
import edu.harvard.iq.dataverse.dataaccess.StorageIO;
import edu.harvard.iq.dataverse.dataaccess.ImageThumbConverter;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.FileUtil;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
Expand All @@ -27,6 +29,9 @@
import java.util.List;
import java.util.logging.Logger;
import java.util.Base64;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.commons.io.IOUtils;

Expand Down Expand Up @@ -385,4 +390,30 @@ public static boolean isDatasetLogoPresent(Dataset dataset) {
return false;
}

public static List<DatasetField> getDatasetSummaryFields(DatasetVersion datasetVersion, String customFields) {

List<DatasetField> datasetFields = new ArrayList<>();

//if customFields are empty, go with default fields.
if(customFields==null || customFields.isEmpty()){
customFields="dsDescription,subject,keyword,publication,notesText";
}

String[] customFieldList= customFields.split(",");
Map<String,DatasetField> DatasetFieldsSet=new HashMap<>();

for (DatasetField dsf : datasetVersion.getFlatDatasetFields()) {
DatasetFieldsSet.put(dsf.getDatasetFieldType().getName(),dsf);
}

for(String cfl : customFieldList)
{
DatasetField df = DatasetFieldsSet.get(cfl);
if(df!=null)
datasetFields.add(df);
}

return datasetFields;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class SettingsServiceBean {
* So there.
*/
public enum Key {
/**
* Ordered, comma-separated list of custom fields to show above the fold
* on dataset page such as "data_type,sample,pdb"
*/
CustomDatasetSummaryFields,
/**
* Defines a public installation -- all datafiles are unrestricted
*/
Expand Down
94 changes: 57 additions & 37 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -326,51 +326,71 @@
<p>#{bundle['dataset.beAccessedAt']} <a href="#{DatasetPage.workingVersion.archiveNote}" target="_blank">#{DatasetPage.workingVersion.archiveNote}</a></p>
</ui:fragment>
</div>
<div id="metadata-panel" class="row panel panel-default"
jsf:rendered="#{!widgetWrapper.widgetView and !DatasetPage.workingVersion.deaccessioned and
(!empty DatasetPage.datasetVersionUI.descriptionDisplay
<!-- BEGIN: DATASET SUMMARY -->
<div id="dataset-summary-metadata" class="row panel panel-default"
jsf:rendered="#{!widgetWrapper.widgetView and !DatasetPage.workingVersion.deaccessioned and
( !empty DatasetPage.datasetVersionUI.descriptionDisplay
or !empty DatasetPage.datasetVersionUI.keywordDisplay
or !empty DatasetPage.datasetVersionUI.subject.value
or !empty DatasetPage.datasetVersionUI.relPublicationCitation
or !empty DatasetPage.datasetVersionUI.notes.value)}">
or !empty DatasetPage.datasetVersionUI.notes.value ) and !empty DatasetPage.datasetSummaryFields }">
<div class="panel-body metadata-panel-body">
<div id="description" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.descriptionDisplay}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.description.datasetFieldType.description}">#{bundle['dataset.descriptionDisplay.title']}</span>
</label>
<div class="col-sm-9"><h:outputText value="#{DatasetPage.datasetVersionUI.descriptionDisplay}" escape="false"/></div>
</div>
<div id="subject" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.subject.value}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.subject.datasetFieldType.description}">#{DatasetPage.datasetVersionUI.subject.datasetFieldType.title}</span>
</label>
<div class="col-sm-9">#{DatasetPage.datasetVersionUI.subject.displayValue}</div>
</div>
<div id="keywords" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.keywordDisplay}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.keyword.datasetFieldType.description}">#{bundle['dataset.keywordDisplay.title']}</span>
</label>
<div class="col-sm-9">#{DatasetPage.datasetVersionUI.keywordDisplay}</div>
</div>
<div id="publication" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.relPublicationCitation}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.datasetRelPublications.get(0).description}">#{DatasetPage.datasetVersionUI.datasetRelPublications.get(0).title}</span>
</label>
<div class="col-sm-9">
<h:outputText value="#{MarkupChecker:sanitizeBasicHTML(DatasetPage.datasetVersionUI.relPublicationCitation)}" escape="false"/>
<a href="#{DatasetPage.datasetVersionUI.relPublicationUrl}" title="#{DatasetPage.datasetVersionUI.relPublicationUrl}" target="_blank">#{DatasetPage.datasetVersionUI.relPublicationId}</a>
<ui:repeat value="#{DatasetPage.datasetSummaryFields}" var="dsf">

<div id="keywords" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.keywordDisplay and dsf.datasetFieldType.id==DatasetPage.datasetVersionUI.keyword.datasetFieldType.id}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.keyword.datasetFieldType.description}">#{bundle['dataset.keywordDisplay.title']}</span>
</label>
<div class="col-sm-9">#{DatasetPage.datasetVersionUI.keywordDisplay}</div>
</div>
</div>
<div id="note" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.notes.value}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.notes.datasetFieldType.description}">#{DatasetPage.datasetVersionUI.notes.datasetFieldType.title}</span>
</label>
<div class="col-sm-9">
<h:outputText value="#{MarkupChecker:sanitizeBasicHTML(DatasetPage.datasetVersionUI.notes.value)}" escape="false"/>
<div id="publication" class="form-group" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.relPublicationCitation and dsf.datasetFieldType.name=='publication'}">
<label class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{DatasetPage.datasetVersionUI.datasetRelPublications.get(0).description}">#{DatasetPage.datasetVersionUI.datasetRelPublications.get(0).title}</span>
</label>
<div class="col-sm-9">
<h:outputText value="#{MarkupChecker:sanitizeBasicHTML(DatasetPage.datasetVersionUI.relPublicationCitation)}" escape="false"/>
<a href="#{DatasetPage.datasetVersionUI.relPublicationUrl}" title="#{DatasetPage.datasetVersionUI.relPublicationUrl}" target="_blank">#{DatasetPage.datasetVersionUI.relPublicationId}</a>
</div>
</div>
</div>

<div class="form-group" jsf:rendered="#{dsf.datasetFieldType.name!='publication' and dsf.datasetFieldType.name!='keyword' }">
<label for="metadata_#{dsf.datasetFieldType.name}" class="col-sm-3 control-label">
<span data-toggle="tooltip" data-placement="auto right" class="tooltiplabel text-info" data-original-title="#{dsf.datasetFieldType.description}">
#{dsf.datasetFieldType.title}
</span>
</label>
<!-- Primitive datasetFields -->
<div class="col-sm-9" jsf:rendered="#{dsf.datasetFieldType.primitive}">
<h:outputText value="#{dsf.displayValue}" rendered="#{!dsf.datasetFieldType.allowMultiples}"
escape="#{dsf.datasetFieldType.isEscapeOutputText()}"/>
<ui:repeat value="#{dsf.values}" var="value" varStatus="loop" rendered="#{dsf.datasetFieldType.allowMultiples}">
<h:outputText value="#{loop.first?'':'; '}#{ value }"
escape="#{dsf.datasetFieldType.isEscapeOutputText()}"/>
</ui:repeat>
</div>
<!-- Compound datasetFields -->
<div class="col-sm-9" jsf:rendered="#{dsf.datasetFieldType.compound}">
<ui:fragment rendered="#{dsf.datasetFieldType.name == 'datasetContact'}">
<p class="help-block">
<span class="glyphicon glyphicon-info-sign"/>
<h:outputText value=" #{bundle['dataset.contact.tip']}"/>
</p>
</ui:fragment>
<ui:repeat value="#{dsf.datasetFieldCompoundValues}" var="compoundValue">
<div>
<ui:repeat value="#{compoundValue.displayValueMap.entrySet().toArray()}" var="cvPart" varStatus="partStatus">
<h:outputText value="#{dsf.datasetFieldType.displayFormat} " rendered="${!partStatus.first}"/>
<h:outputText value="#{cvPart.value}"
escape="#{cvPart.key.datasetFieldType.isEscapeOutputText()}"/>
</ui:repeat>
</div>
</ui:repeat>
</div>
</div>
</ui:repeat>
</div>
</div>
<!-- END: DATASET SUMMARY -->
</div>
</div>
<!-- END View editMode -->
Expand Down

0 comments on commit 2ad148a

Please sign in to comment.