Changeset 4644


Ignore:
Timestamp:
03/07/14 13:00:36 (10 years ago)
Author:
Twan Goosen
Message:

added details panel for resources on the record page

Location:
vlo/branches/vlo-3.0/vlo-web-app/src
Files:
1 added
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/ResourceInfo.java

    r4639 r4644  
    2424
    2525    private final String href;
     26    private final String fileName;
    2627    private final String mimeType;
    2728    private final ResourceType resourceType;
    2829
    29     public ResourceInfo(String href, String mimeType, ResourceType resourceType) {
     30    public ResourceInfo(String href, String fileName, String mimeType, ResourceType resourceType) {
    3031        this.href = href;
     32        this.fileName = fileName;
    3133        this.mimeType = mimeType;
    3234        this.resourceType = resourceType;
     
    3537    public String getHref() {
    3638        return href;
     39    }
     40
     41    public String getFileName() {
     42        return fileName;
    3743    }
    3844
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/impl/ResourceStringConverterImpl.java

    r4639 r4644  
    2222import eu.clarin.cmdi.vlo.pojo.ResourceType;
    2323import eu.clarin.cmdi.vlo.service.ResourceStringConverter;
     24import java.net.URI;
     25import java.net.URISyntaxException;
    2426import java.util.regex.Pattern;
     27import org.apache.commons.io.FilenameUtils;
    2528
    2629/**
     
    3841        final String mimeType = tokens[0];
    3942        final String href = tokens[1];
     43
     44        final String fileName = getFileName(href);
    4045        // determine resource type based on mime type
    4146        final ResourceType resourceType = determineResourceType(mimeType);
    42         return new ResourceInfo(href, mimeType, resourceType);
     47        return new ResourceInfo(href, fileName, mimeType, resourceType);
     48    }
     49
     50    private String getFileName(final String href) {
     51        try {
     52            //analyse URI
     53            final URI uri = new URI(href);
     54            final String scheme = uri.getScheme();
     55            final String path = uri.getPath();
     56            // in case of path information or handle, return original href
     57            if (path == null || path.isEmpty() || (scheme != null && scheme.equals("hdl"))) {
     58                return href;
     59            } else {
     60                return FilenameUtils.getName(path);
     61            }
     62        } catch (URISyntaxException ex) {
     63            return href;
     64        }
    4365    }
    4466
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/ResourceLinkDetailsPanel.html

    r4640 r4644  
    2424    <body>
    2525        <wicket:panel>
    26             <wicket:container wicket:id="resource">
    27                 <a wicket:id="showResource">
    28                     <wicket:container wicket:id="filename">resource.txt</wicket:container>
    29                 </a>
    30             </wicket:container>
    31 
    32             <!--            <div wicket:id="resourceDetails" class="recordresourcedetails">
    33                             <h2 wicket:id="title">Bachelorscriptie+Rene+Witteveen+3375005.docx</h2>
    34                             <ul>
    35                                 <li wicket:id="fileType">File type: text file</li>
    36                                 <li wicket:id="resourceType">Mime type: application/msword</li>
    37                                 <li>Location:
    38                                     <a wicket:id="link" class="resourcedownloadlink">
    39                                         <wicket:container wicket:id="href"></wicket:container>
    40                                     </a>
    41                                 </li>
    42                             </ul>
    43                         </div>-->
     26            <h2 wicket:id="fileName">Bachelorscriptie+Rene+Witteveen+3375005.docx</h2>
     27            <ul>
     28                <li>File type: <span wicket:id="resourceType">text file</span></li>
     29                <li>Mime type: <span wicket:id="mimeType">application/msword</span></li>
     30                <li>Location:
     31                    <a wicket:id="link" class="resourcedownloadlink">
     32                        <wicket:container wicket:id="href"></wicket:container>
     33                    </a>
     34                </li>
     35            </ul>
    4436        </wicket:panel>
    4537    </body>
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/ResourceLinksPanel.html

    r4640 r4644  
    2525        <wicket:panel>
    2626            <wicket:container wicket:id="resource">
    27                 <a wicket:id="showResource">
     27                <a class="resourceLink" wicket:id="showResource">
    2828                    <wicket:container wicket:id="filename">resource.txt</wicket:container>
    2929                </a>
    3030            </wicket:container>
    3131
    32             <!--            <div wicket:id="resourceDetails" class="recordresourcedetails">
    33                             <h2 wicket:id="title">Bachelorscriptie+Rene+Witteveen+3375005.docx</h2>
    34                             <ul>
    35                                 <li wicket:id="fileType">File type: text file</li>
    36                                 <li wicket:id="resourceType">Mime type: application/msword</li>
    37                                 <li>Location:
    38                                     <a wicket:id="link" class="resourcedownloadlink">
    39                                         <wicket:container wicket:id="href"></wicket:container>
    40                                     </a>
    41                                 </li>
    42                             </ul>
    43                         </div>-->
     32            <div wicket:id="detailsContainer" id="recordresourcedetailsContainer">
     33                <div wicket:id="details" class="recordresourcedetails"></div>
     34            </div>
    4435        </wicket:panel>
    4536    </body>
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/ResourceLinksPanel.java

    r4640 r4644  
    2121import eu.clarin.cmdi.vlo.wicket.model.CollectionListModel;
    2222import java.util.Collection;
     23import java.util.List;
    2324import org.apache.wicket.AttributeModifier;
     25import org.apache.wicket.ajax.AjaxRequestTarget;
     26import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
     27import org.apache.wicket.behavior.AttributeAppender;
     28import org.apache.wicket.markup.html.WebMarkupContainer;
    2429import org.apache.wicket.markup.html.basic.Label;
    2530import org.apache.wicket.markup.html.link.Link;
     
    3439
    3540/**
     41 * Panel that shows all resources represented by a collection of resource
     42 * strings as links that trigger a details panel for the selected resource
    3643 *
    3744 * @author twagoo
     
    4148    @SpringBean
    4249    private ResourceStringConverter resourceStringConverter;
     50    private final WebMarkupContainer detailsContainer;
    4351
    4452    /**
     
    4957    public ResourceLinksPanel(String id, IModel<Collection<String>> model) {
    5058        super(id, model);
    51         final ListView<String> resourcesView = new ListView<String>("resource", new CollectionListModel<String>(model)) {
     59        // list view that shows all resources as links that show a resource details panel when clicked
     60        add(new ResourcesListView("resource", new CollectionListModel<String>(model)));
    5261
    53             @Override
    54             protected void populateItem(ListItem<String> item) {
    55                 final ResourceInfoModel resourceInfoModel = new ResourceInfoModel(item.getModel());
    56                 final Link link = new Link("showResource") {
     62        // container for resource details (to enable AJAX updates)
     63        detailsContainer = new WebMarkupContainer("detailsContainer");
     64        detailsContainer.setOutputMarkupId(true);
     65        add(detailsContainer);
    5766
    58                     @Override
    59                     public void onClick() {
    60                         throw new UnsupportedOperationException("Not supported yet.");
    61                     }
    62                 };
    63                 item.add(link);
    64                 // set the file name as the link's text content
    65                 link.add(new Label("filename", new PropertyModel(resourceInfoModel, "href")));
    66                 // set the class attribute on the link from the value associated
    67                 // with the resource type as defined in the properties file
    68                 link.add(new AttributeModifier("class",
    69                         new StringResourceModel("class.${resourceType}", ResourceLinksPanel.this, resourceInfoModel, "")));
    70             }
    71         };
    72         resourcesView.setReuseItems(true);
    73         add(resourcesView);
    74 
     67        // insert a place holder until one of the resource links is clicked
     68        final WebMarkupContainer detailsPlaceholder = new WebMarkupContainer("details");
     69        detailsPlaceholder.setVisible(false);
     70        detailsContainer.add(detailsPlaceholder);
    7571    }
    7672
     73    private class ResourcesListView extends ListView<String> {
     74
     75        public ResourcesListView(String id, IModel<? extends List<? extends String>> model) {
     76            super(id, model);
     77            setReuseItems(true);
     78        }
     79
     80        @Override
     81        protected void populateItem(ListItem<String> item) {
     82            final ResourceInfoModel resourceInfoModel = new ResourceInfoModel(item.getModel());
     83            // add a link that will show the resource details panel when clicked
     84            item.add(createLink(resourceInfoModel));
     85        }
     86
     87        private Link createLink(final ResourceInfoModel resourceInfoModel) {
     88            final Link link = new AjaxFallbackLink("showResource") {
     89
     90                @Override
     91                public void onClick(AjaxRequestTarget target) {
     92                    // replace any existing details panel or placeholder with
     93                    // a details panel for the current resource
     94                    detailsContainer.addOrReplace(new ResourceLinkDetailsPanel("details", resourceInfoModel));
     95                    if (target != null) {
     96                        target.add(detailsContainer);
     97                        target.prependJavaScript("hideResourceDetails();");
     98                        target.appendJavaScript("showResourceDetails();");
     99                    }
     100                }
     101            };
     102            link.setAnchor(detailsContainer);
     103            // set the file name as the link's text content
     104            link.add(new Label("filename", new PropertyModel(resourceInfoModel, "fileName")));
     105
     106            // set the class attribute on the link from the value associated
     107            // with the resource type as defined in the properties file
     108            final StringResourceModel linkClass = new StringResourceModel("class.${resourceType}", ResourceLinksPanel.this, resourceInfoModel, "");
     109            link.add(new AttributeAppender("class", linkClass).setSeparator(" "));
     110
     111            return link;
     112        }
     113    }
     114
     115    /**
     116     * Model for {@link ResourceInfo} that dynamically instantiates its objects
     117     * from a resource string (as retrieved from the Solr index) using the
     118     * {@link ResourceStringConverter}
     119     */
    77120    private class ResourceInfoModel extends LoadableDetachableModel<ResourceInfo> {
    78121
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/webapp/js/vlo-record.js

    r4466 r4644  
    1616 */
    1717
    18 $(document).ready(function() {   
     18$(document).ready(function() {
    1919    $("#recordtechnicaldetails, #recordcmdi").hide();
    2020    $("#hiderecordtechnicaldetails, #hiderecordcmdi").hide();
    21     $("#recordcmditoggle a").click(function(event){
     21    $("#recordcmditoggle a").click(function(event) {
    2222        event.preventDefault();
    2323        $("#recordcmdi").toggle();
    2424        $("#recordcmditoggle a").toggle();
    2525    });
    26     $("#recordtechnicaldetailstoggle a").click(function(event){
     26    $("#recordtechnicaldetailstoggle a").click(function(event) {
    2727        event.preventDefault();
    2828        $("#recordtechnicaldetails").toggle();
    2929        $("#recordtechnicaldetailstoggle a").toggle();
    3030    });
    31    
     31});
     32
     33function hideResourceDetails() {
     34    $(".recordresourcedetails").slideUp('fast');
     35}
     36
     37function showResourceDetails() {
     38    $(window).scrollTop($('#recordresourcedetailsContainer').position().top);
    3239    $(".recordresourcedetails").hide();
    33     $("#recordresources > a").click(function(event){
    34         event.preventDefault();
    35         $(".recordresourcedetails").slideToggle('fast');
    36     });
    37 });
     40    $(".recordresourcedetails").slideDown('fast');
     41}
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/webapp/style/vlo-record.css

    r4640 r4644  
    128128}
    129129
    130 #recordresources a {
     130#recordresources a.resourceLink {
    131131    display: inline-block;
    132132    float: left;
     
    141141}
    142142
    143 #recordresources a:hover {
     143#recordresources a.resourceLink:hover {
    144144    background-color: #ccc;
    145145}
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/ResourceStringConverterImplTest.java

    r4639 r4644  
    9696        assertEquals(ResourceType.OTHER, result.getResourceType());
    9797    }
     98   
     99    @Test
     100    public void testGetResourceInfoFilename() {
     101        assertFileNameResult("file.txt", "http://myserver.com/file.txt");
     102        assertFileNameResult("file.txt", "file:/somehwere/on/my/fs/this/file.txt");
     103        assertFileNameResult("http://myserver.com", "http://myserver.com");
     104        assertFileNameResult("hdl:12345", "hdl:12345");
     105    }
     106   
     107    private void assertFileNameResult(String expected, String href){
     108        String resourceString = "application/test" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + href;
     109        ResourceInfo result = instance.getResourceInfo(resourceString);
     110        assertEquals(expected, result.getFileName());
     111    }
    98112
    99113}
  • vlo/branches/vlo-3.0/vlo-web-app/src/test/java/eu/clarin/cmdi/vlo/service/impl/ResourceTypeCountingServiceImplTest.java

    r4639 r4644  
    5252                "annotation resource string",
    5353                "other resource string"
    54 //                "video/mpeg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myvideo",
    55 //                "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio",
    56 //                "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio"
     54        //                "video/mpeg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myvideo",
     55        //                "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio",
     56        //                "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio"
    5757        //                "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio",
    5858        //                "audio/ogg" + FacetConstants.FIELD_RESOURCE_SPLIT_CHAR + "myaudio",
     
    6767                exactly(6).of(converter).getResourceInfo(with(any(String.class)));
    6868                will(onConsecutiveCalls(
    69                         returnValue(new ResourceInfo("href1", "video/mpeg", ResourceType.VIDEO)),
    70                         returnValue(new ResourceInfo("href2", "video/mpeg", ResourceType.VIDEO)),
    71                         returnValue(new ResourceInfo("href3", "audio/ogg", ResourceType.AUDIO)),
    72                         returnValue(new ResourceInfo("href4", "audio/ogg", ResourceType.TEXT)),
    73                         returnValue(new ResourceInfo("href5", "audio/ogg", ResourceType.ANNOTATION)),
    74                         returnValue(new ResourceInfo("href6", "audio/ogg", ResourceType.OTHER))
     69                        returnValue(new ResourceInfo("href1", "fileName1", "video/mpeg", ResourceType.VIDEO)),
     70                        returnValue(new ResourceInfo("href2", "fileName2", "video/mpeg", ResourceType.VIDEO)),
     71                        returnValue(new ResourceInfo("href3", "fileName3", "audio/ogg", ResourceType.AUDIO)),
     72                        returnValue(new ResourceInfo("href4", "fileName4", "audio/ogg", ResourceType.TEXT)),
     73                        returnValue(new ResourceInfo("href5", "fileName5", "audio/ogg", ResourceType.ANNOTATION)),
     74                        returnValue(new ResourceInfo("href6", "fileName6", "audio/ogg", ResourceType.OTHER))
    7575                ));
    7676            }
     
    8282        assertThat(result, hasItem(new ResourceTypeCount(ResourceType.TEXT, 1)));
    8383        assertThat(result, hasItem(new ResourceTypeCount(ResourceType.ANNOTATION, 1)));
    84         assertThat(result, hasItem(new ResourceTypeCount(ResourceType.OTHER, 1))); 
     84        assertThat(result, hasItem(new ResourceTypeCount(ResourceType.OTHER, 1)));
    8585    }
    8686
Note: See TracChangeset for help on using the changeset viewer.