Changeset 1678 for trunk


Ignore:
Timestamp:
Mar 29, 2011, 2:30:12 PM (12 years ago)
Author:
robert@…
Message:

Added entity names above table editor in simple wizard and added template description to template select boxes (#378)

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/query/AdvancedQueryController.groovy

    r1618 r1678  
    396396                                        criterion.operator = Criterion.parseOperator( formCriterion.operator );
    397397                                } catch( Exception e) {
    398                                         println "Operator " + formCriterion.operator + " could not be parsed: " + e.getMessage();
     398                                        log.debug "Operator " + formCriterion.operator + " could not be parsed: " + e.getMessage();
    399399                                        flash.error += "Criterion could not be used: operator " + formCriterion.operator + " is not valid.<br />\n";
    400400                                        continue;
  • trunk/grails-app/controllers/dbnp/studycapturing/SimpleWizardController.groovy

    r1621 r1678  
    2222import dbnp.importer.ImportRecord
    2323import dbnp.importer.MappingColumn
     24import org.hibernate.SessionFactory;
    2425
    2526@Secured(['IS_AUTHENTICATED_REMEMBERED'])
     
    2930        def importerService
    3031        def gdtService = new GdtService()
     32        def sessionFactory
    3133
    3234        /**
     
    133135                                def filename = params.get( 'importfile' );
    134136               
     137                                handleSampleForm( flow.study, params, flow )
     138
    135139                                // Handle 'existing*' in front of the filename. This is put in front to make a distinction between
    136140                                // an already uploaded file test.txt (maybe moved to some other directory) and a newly uploaded file test.txt
     
    142146                                        filename = filename[9..-1]
    143147                               
    144                                 // Refresh the templates, since the template editor has been opened
     148                                flow.sampleForm.importFile = filename
     149                                       
     150                                // Refresh the templates, since the template editor has been opened. To make this happen
     151                                // the hibernate session has to be cleared first
     152                                sessionFactory.getCurrentSession().clear();
     153                               
    145154                                flow.templates = [
    146155                                                'Sample': Template.findAllByEntity( Sample.class ),
     
    149158                                                'SamplingEvent': Template.findAllByEntity( SamplingEvent.class )
    150159                                ];
    151                                                                                
    152                                 flow.sampleForm = [ importFile: filename ]
     160                       
    153161                        }.to "samples"
    154162                        on("previous").to "returnFromSamples"
     
    256264                         }.to "overview"
    257265                        on( "previous" ).to "returnFromAssays"
    258                         on("refresh") { handleAssays( flow.assay, params, flow ); success() }.to "assays"
     266                        on("refresh") {
     267                                // Refresh the templates, since the template editor has been opened. To make this happen
     268                                // the hibernate session has to be cleared first
     269                                sessionFactory.getCurrentSession().clear();
     270
     271                                handleAssays( flow.assay, params, flow );
     272                               
     273                                flow.assay?.template?.refresh()
     274                                success()
     275                        }.to "assays"
    259276                }
    260277
     
    469486                        filename = filename[9..-1]
    470487
    471                 def sampleTemplateId  = params.long( 'sample_template_id' )
    472                 def subjectTemplateId  = params.long( 'subject_template_id' )
    473                 def eventTemplateId  = params.long( 'event_template_id' )
    474                 def samplingEventTemplateId  = params.long( 'samplingEvent_template_id' )
    475 
     488                handleSampleForm( study, params, flow );
     489
     490                // Check whether the template exists
     491                if (!flow.sampleForm.template.Sample ){
     492                        log.error ".simple study wizard not all fields are filled in (sample template) "
     493                        flash.error = "No template was chosen. Please choose a template for the samples you provided."
     494                        return false
     495                }
     496               
    476497                // These fields have been removed from the form, so will always contain
    477498                // their default value. The code however remains like this for future use.
     
    479500                int dataMatrixStart = (params.int( 'datamatrix_start' ) ?: 2 )
    480501                int headerRow = (params.int( 'headerrow' ) ?: 1 )
     502               
     503                flow.sampleForm.sheetIndex = sheetIndex;
     504                flow.sampleForm.dataMatrixStart = dataMatrixStart
     505                flow.sampleForm.headerRow = headerRow
     506               
     507                def importedfile = fileService.get( filename )
     508                def workbook
     509                if (importedfile.exists()) {
     510                        try {
     511                                workbook = importerService.getWorkbook(new FileInputStream(importedfile))
     512                        } catch (Exception e) {
     513                                log.error ".simple study wizard could not load file: " + e
     514                                flash.error = "The given file doesn't seem to be an excel file. Please provide an excel file for entering samples.";
     515                                return false
     516                        }
     517                } else {
     518                        log.error ".simple study wizard no file given";
     519                        flash.error = "No file was given. Please provide an excel file for entering samples.";
     520                        return false;
     521                }
     522
     523                if( !workbook ) {
     524                        log.error ".simple study wizard could not load file into a workbook"
     525                        flash.error = "The given file doesn't seem to be an excel file. Please provide an excel file for entering samples.";
     526                        return false
     527                }
     528
     529                def selectedentities = []
     530
     531                if( !excelChecks( workbook, sheetIndex, headerRow, dataMatrixStart ) )
     532                        return false;
     533
     534                // Get the header from the Excel file using the arguments given in the first step of the wizard
     535                def importerHeader;
     536                def importerDataMatrix;
     537
     538                try {           
     539                        importerHeader = importerService.getHeader(workbook,
     540                                        sheetIndex - 1,                 // 0 == first sheet
     541                                        headerRow,                              // 1 == first row :s
     542                                        dataMatrixStart - 1,    // 0 == first row
     543                                        Sample.class)
     544               
     545                        importerDataMatrix = importerService.getDatamatrix(
     546                                        workbook,
     547                                        importerHeader,
     548                                        sheetIndex - 1,                 // 0 == first sheet
     549                                        dataMatrixStart - 1,    // 0 == first row
     550                                        5)
     551                } catch( Exception e ) {
     552                        // An error occurred while reading the excel file.
     553                        log.error ".simple study wizard error while reading the excel file";
     554                        e.printStackTrace();
     555
     556                        // Show a message to the user
     557                        flash.error = "An error occurred while reading the excel file. Have you provided the right sheet number and row numbers. Contact your system administrator if this problem persists.";
     558                        return false;
     559                }
     560
     561                // Match excel columns with template fields
     562                def fieldNames = [];
     563                flow.sampleForm.template.each { template ->
     564                        if( template.value ) {
     565                                def fields = template.value.entity.giveDomainFields() + template.value.getFields();
     566                                fields.each { field ->
     567                                        if( !field.entity )
     568                                                field.entity = template.value.entity
     569                                               
     570                                        fieldNames << field
     571                                }
     572                        }
     573                }
     574                importerHeader.each { mc ->
     575                        def bestfit = importerService.mostSimilar( mc.name, fieldNames, 0.8);
     576                        if( bestfit ) {
     577                                // Remove this fit from the list
     578                                fieldNames.remove( bestfit );
     579                               
     580                                mc.entityclass = bestfit.entity
     581                                mc.property = bestfit.name
     582                        }
     583                }
     584               
     585                // Save read excel data into session
     586                def dataMatrix = [];
     587                def df = new DataFormatter();
     588                importerDataMatrix.each {
     589                        dataMatrix << it.collect{ it ? df.formatCellValue(it) : "" }
     590                }
     591               
     592                flow.excel = [
     593                                        filename: filename,
     594                                        sheetIndex: sheetIndex,
     595                                        dataMatrixStart: dataMatrixStart,
     596                                        headerRow: headerRow,
     597                                        data: [
     598                                                header: importerHeader,
     599                                                dataMatrix: dataMatrix
     600                                        ]
     601                                ]
     602
     603                return true
     604        }
     605       
     606        /**
     607         * Copies data from the submitted sample form to the flow
     608         * @param study
     609         * @param params
     610         * @param flow
     611         * @return
     612         */
     613        protected def handleSampleForm( study, params, flow ) {
     614                def sampleTemplateId  = params.long( 'sample_template_id' )
     615                def subjectTemplateId  = params.long( 'subject_template_id' )
     616                def eventTemplateId  = params.long( 'event_template_id' )
     617                def samplingEventTemplateId  = params.long( 'samplingEvent_template_id' )
    481618
    482619                // Save form data in session
    483620                flow.sampleForm = [
    484                                         importFile: filename,
    485621                                        templateId: [
    486622                                                'Sample': sampleTemplateId,
     
    495631                                                'SamplingEvent': samplingEventTemplateId ? Template.get( samplingEventTemplateId ) : null
    496632                                        ],
    497                                         sheetIndex: sheetIndex,
    498                                         dataMatrixStart: dataMatrixStart,
    499                                         headerRow: headerRow
    500633                                ];
    501 
    502                 // Check whether the template exists
    503                 if (!sampleTemplateId || !Template.get( sampleTemplateId ) ){
    504                         log.error ".simple study wizard not all fields are filled in: " + sampleTemplateId
    505                         flash.error = "No template was chosen. Please choose a template for the samples you provided."
    506                         return false
    507                 }
    508                
    509                 def importedfile = fileService.get( filename )
    510                 def workbook
    511                 if (importedfile.exists()) {
    512                         try {
    513                                 workbook = importerService.getWorkbook(new FileInputStream(importedfile))
    514                         } catch (Exception e) {
    515                                 log.error ".simple study wizard could not load file: " + e
    516                                 flash.error = "The given file doesn't seem to be an excel file. Please provide an excel file for entering samples.";
    517                                 return false
    518                         }
    519                 } else {
    520                         log.error ".simple study wizard no file given";
    521                         flash.error = "No file was given. Please provide an excel file for entering samples.";
    522                         return false;
    523                 }
    524 
    525                 if( !workbook ) {
    526                         log.error ".simple study wizard could not load file into a workbook"
    527                         flash.error = "The given file doesn't seem to be an excel file. Please provide an excel file for entering samples.";
    528                         return false
    529                 }
    530 
    531                 def selectedentities = []
    532 
    533                 if( !excelChecks( workbook, sheetIndex, headerRow, dataMatrixStart ) )
    534                         return false;
    535 
    536                 // Get the header from the Excel file using the arguments given in the first step of the wizard
    537                 def importerHeader;
    538                 def importerDataMatrix;
    539 
    540                 try {           
    541                         importerHeader = importerService.getHeader(workbook,
    542                                         sheetIndex - 1,                 // 0 == first sheet
    543                                         headerRow,                              // 1 == first row :s
    544                                         dataMatrixStart - 1,    // 0 == first row
    545                                         Sample.class)
    546                
    547                         importerDataMatrix = importerService.getDatamatrix(
    548                                         workbook,
    549                                         importerHeader,
    550                                         sheetIndex - 1,                 // 0 == first sheet
    551                                         dataMatrixStart - 1,    // 0 == first row
    552                                         5)
    553                 } catch( Exception e ) {
    554                         // An error occurred while reading the excel file.
    555                         log.error ".simple study wizard error while reading the excel file";
    556                         e.printStackTrace();
    557 
    558                         // Show a message to the user
    559                         flash.error = "An error occurred while reading the excel file. Have you provided the right sheet number and row numbers. Contact your system administrator if this problem persists.";
    560                         return false;
    561                 }
    562 
    563                 // Match excel columns with template fields
    564                 def fieldNames = [];
    565                 flow.sampleForm.template.each { template ->
    566                         if( template.value ) {
    567                                 def fields = template.value.entity.giveDomainFields() + template.value.getFields();
    568                                 fields.each { field ->
    569                                         if( !field.entity )
    570                                                 field.entity = template.value.entity
    571                                                
    572                                         fieldNames << field
    573                                 }
    574                         }
    575                 }
    576                 importerHeader.each { mc ->
    577                         def bestfit = importerService.mostSimilar( mc.name, fieldNames, 0.8);
    578                         if( bestfit ) {
    579                                 // Remove this fit from the list
    580                                 fieldNames.remove( bestfit );
    581                                
    582                                 mc.entityclass = bestfit.entity
    583                                 mc.property = bestfit.name
    584                         }
    585                 }
    586                
    587                 // Save read excel data into session
    588                 def dataMatrix = [];
    589                 def df = new DataFormatter();
    590                 importerDataMatrix.each {
    591                         dataMatrix << it.collect{ it ? df.formatCellValue(it) : "" }
    592                 }
    593                
    594                 flow.excel = [
    595                                         filename: filename,
    596                                         sheetIndex: sheetIndex,
    597                                         dataMatrixStart: dataMatrixStart,
    598                                         headerRow: headerRow,
    599                                         data: [
    600                                                 header: importerHeader,
    601                                                 dataMatrix: dataMatrix
    602                                         ]
    603                                 ]
    604 
    605                 return true
    606634        }
    607 
    608635       
    609636        /**
  • trunk/grails-app/views/simpleWizard/simpleWizard/assays.gsp

    r1608 r1678  
    88</head>
    99<body>
    10         <div class="simpleWizard">
     10        <div class="simpleWizard assayspage">
    1111                <h1>Assay</h1>
    1212               
     
    4646               
    4747                        <g:if test="${assay}">
     48                                <g:if test="${assay.template?.description}">
     49                                        <div class="element">
     50                                                <div class="templatedescription">
     51                                                        ${assay.template?.description?.encodeAsHTML()}
     52                                                </div>
     53                                        </div>
     54                                </g:if>                 
    4855                                <af:templateElements ignore="externalassayid" entity="${assay}" />
    4956                        </g:if>
  • trunk/grails-app/views/simpleWizard/simpleWizard/existingSamples.gsp

    r1608 r1678  
    5757                                                                                <g:if test="${entity.value}">
    5858                                                                                        <div class="column">${entity.key} template</div>
    59                                                                                         <af:templateColumnHeaders entity="${entity.value}" class="column" columnWidths="[Name:100]"/>
     59                                                                                        <af:templateColumnHeaders includeEntities="${true}" entity="${entity.value}" class="column" columnWidths="[Name:100]"/>
    6060                                                                                </g:if>
    6161                                                                        </g:each>
  • trunk/grails-app/views/simpleWizard/simpleWizard/missingFields.gsp

    r1610 r1678  
    6464                                                                <g:each var="entity" in="${record}">
    6565                                                                        <g:if test="${entity}">
    66                                                                                 <af:templateColumnHeaders entity="${entity}" class="column" columnWidths="[Name:100]"/>
     66                                                                                <af:templateColumnHeaders includeEntities="${true}" entity="${entity}" class="column" columnWidths="[Name:100]"/>
    6767                                                                        </g:if>
    6868                                                                </g:each>
  • trunk/grails-app/views/simpleWizard/simpleWizard/samples.gsp

    r1668 r1678  
    1010</head>
    1111<body>
    12         <div class="simpleWizard">
    13                 <h1>Samples</h1>
     12        <div class="simpleWizard samplespage">
     13                <h1>Study data</h1>
    1414
    1515                <g:if test="${flash.error}">
     
    2929                        <div id="samplesDialog">
    3030                        <span class="info">
    31                                         <span class="title">Import sample data</span>
     31                                        <span class="title">Import study data</span>
    3232                                        You can import your Excel data to the server by choosing a file from your local harddisk in the form below. The excel sheet should contain
    3333                                        data on the first sheet, and the sheet should contain one row with headers.
     
    3636                                <table border="0">
    3737                                <tr>
    38                                     <td width="100px">
    39                                                 Choose your Excel file to import:
    40                                     </td>
    41                                     <td width="100px">
    42                                                 <af:fileField name="importfile" value="${sampleForm?.importFile}"/>
    43                                     </td>
     38                                            <td width="30%">
     39                                                        Choose your Excel file to import:
     40                                            </td>
     41                                            <td width="25%">
     42                                                        <af:fileField name="importfile" value="${sampleForm?.importFile}"/>
     43                                            </td>
     44                                            <td width="40%"></td>
    4445                                        </tr>
    4546                                        <tr>
     
    4849                                            </td>
    4950                                            <td>
    50                                                         <g:select rel="template" entity="${encodedEntity.Sample}" name="sample_template_id" optionKey="id" optionValue="name" from="${templates.Sample}" value="${sampleForm?.templateId?.Sample}"/>
     51                                                <% /* The select is written manually, since the grails select tag can't handle option titles */ %>
     52                                                        <select rel="template" entity="${encodedEntity.Sample}" onChange="showTemplateDescription( 'templateDescription_sample', $( 'option:selected', $(this) ).attr( 'title' ) ); " name="sample_template_id">
     53                                                                <g:each in="${templates.Sample}" var="templ">
     54                                                                        <option
     55                                                                                value="${templ.id}"
     56                                                                                <g:if test="${templ.id == sampleForm?.templateId?.Sample}">selected="selected"</g:if>
     57                                                                                title="${templ.description?.encodeAsHTML()}"
     58                                                                        >${templ.name?.encodeAsHTML()}</option>
     59                                                                </g:each>
     60                                                        </select>
     61                                            </td>
     62                                            <td>
     63                                                    <%
     64                                                                def sampleTemplate = sampleForm?.template?.Sample ?: templates.Sample?.getAt(0)
     65                                                                def sampleTemplateDescription = sampleTemplate?.description
     66                                                        %>
     67                                                        <div class="templatedescription" id="templateDescription_sample" <g:if test="${!sampleTemplateDescription}">style="display: none;"</g:if>>
     68                                                                ${sampleTemplateDescription?.encodeAsHTML()}
     69                                                        </div>
    5170                                            </td>
    5271                                        </tr>
     
    5675                                            </td>
    5776                                            <td>
    58                                                         <g:select rel="template" entity="${encodedEntity.Subject}" name="subject_template_id" noSelection="${[null: '- no subject template -']}" optionKey="id" optionValue="name" from="${templates.Subject}"  value="${sampleForm?.templateId?.Subject}" />
     77                                                <% /* The select is written manually, since the grails select tag can't handle option titles */ %>
     78                                                        <select rel="template" entity="${encodedEntity.Subject}" onChange="showTemplateDescription( 'templateDescription_subject', $( 'option:selected', $(this) ).attr( 'title' ) ); " name="subject_template_id">
     79                                                                <option value="">- no subject template -</option>
     80                                                                <g:each in="${templates.Subject}" var="templ">
     81                                                                        <option
     82                                                                                value="${templ.id}"
     83                                                                                <g:if test="${templ.id == sampleForm?.templateId?.Subject}">selected="selected"</g:if>
     84                                                                                title="${templ.description?.encodeAsHTML()}"
     85                                                                        >${templ.name?.encodeAsHTML()}</option>
     86                                                                </g:each>
     87                                                        </select>
    5988                                            </td>
     89                                            <td>
     90                                                    <%
     91                                                                def subjectTemplateDescription = sampleForm?.template?.Subject?.description
     92                                                        %>
     93                                                        <div class="templatedescription" id="templateDescription_subject" <g:if test="${!subjectTemplateDescription}">style="display: none;"</g:if>>
     94                                                                ${subjectTemplateDescription?.encodeAsHTML()}
     95                                                        </div>
     96                                            </td>                                           
    6097                                        </tr>
    6198                                        <tr>
     
    64101                                            </td>
    65102                                            <td>
    66                                                         <g:select rel="template" entity="${encodedEntity.Event}" name="event_template_id" noSelection="${[null: '- no event template -']}" optionKey="id" optionValue="name" from="${templates.Event}"  value="${sampleForm?.templateId?.Event}" />
     103                                                <% /* The select is written manually, since the grails select tag can't handle option titles */ %>
     104                                                        <select rel="template" entity="${encodedEntity.Event}" onChange="showTemplateDescription( 'templateDescription_event', $( 'option:selected', $(this) ).attr( 'title' ) ); " name="event_template_id">
     105                                                                <option value="">- no event template -</option>
     106                                                                <g:each in="${templates.Event}" var="templ">
     107                                                                        <option
     108                                                                                value="${templ.id}"
     109                                                                                <g:if test="${templ.id == sampleForm?.templateId?.Event}">selected="selected"</g:if>
     110                                                                                title="${templ.description?.encodeAsHTML()}"
     111                                                                        >${templ.name?.encodeAsHTML()}</option>
     112                                                                </g:each>
     113                                                        </select>
    67114                                            </td>
     115                                            <td>
     116                                                    <%
     117                                                                def eventTemplateDescription = sampleForm?.template?.Event?.description
     118                                                        %>
     119                                                        <div class="templatedescription" id="templateDescription_event" <g:if test="${!eventTemplateDescription}">style="display: none;"</g:if>>
     120                                                                ${eventTemplateDescription?.encodeAsHTML()}
     121                                                        </div>
     122                                            </td>                                                   
    68123                                        </tr>
    69124                                        <tr>
     
    72127                                            </td>
    73128                                            <td>
    74                                                         <g:select rel="template" entity="${encodedEntity.SamplingEvent}" name="samplingEvent_template_id" noSelection="${[null: '- no sampling event template -']}" optionKey="id" optionValue="name" from="${templates.SamplingEvent}"  value="${sampleForm?.templateId?.SamplingEvent}" />
     129                                                <% /* The select is written manually, since the grails select tag can't handle option titles */ %>
     130                                                        <select rel="template" entity="${encodedEntity.SamplingEvent}" onChange="showTemplateDescription( 'templateDescription_samplingEvent', $( 'option:selected', $(this) ).attr( 'title' ) ); " name="samplingEvent_template_id">
     131                                                                <option value="">- no sampling event template -</option>
     132                                                                <g:each in="${templates.SamplingEvent}" var="templ">
     133                                                                        <option
     134                                                                                value="${templ.id}"
     135                                                                                <g:if test="${templ.id == sampleForm?.templateId?.SamplingEvent}">selected="selected"</g:if>
     136                                                                                title="${templ.description?.encodeAsHTML()}"
     137                                                                        >${templ.name?.encodeAsHTML()}</option>
     138                                                                </g:each>
     139                                                        </select>
    75140                                            </td>
     141                                            <td>
     142                                                    <%
     143                                                                def samplingEventTemplateDescription = sampleForm?.template?.SamplingEvent?.description
     144                                                        %>
     145                                                        <div class="templatedescription" id="templateDescription_samplingEvent" <g:if test="${!samplingEventTemplateDescription}">style="display: none;"</g:if>>
     146                                                                ${samplingEventTemplateDescription?.encodeAsHTML()}
     147                                                        </div>
     148                                            </td>                                                   
    76149                                        </tr>           
    77150                                </table>       
  • trunk/grails-app/views/simpleWizard/simpleWizard/study.gsp

    r1608 r1678  
    88</head>
    99<body>
    10         <div class="simpleWizard">
     10        <div class="simpleWizard studypage">
    1111                <h1>Study</h1>
    1212               
     
    8282               
    8383                        <g:if test="${study}">
     84                                <g:if test="${study.template?.description}">
     85                                        <div class="element">
     86                                                <div class="templatedescription">
     87                                                        ${study.template?.description?.encodeAsHTML()}
     88                                                </div>
     89                                        </div>
     90                                </g:if>
    8491                                <af:templateElements ignore="published" entity="${study}" />
    8592                        </g:if>
  • trunk/web-app/css/simplewizard.css

    r1565 r1678  
    2525.simpleWizard div ul.user_list { margin: -22px 0 0 100px; }
    2626
     27/* template descriptions */
     28.templatedescription {  display: block; padding: 3px; border: 1px solid #4CAAED; /* #006DBA; */ }
     29.studypage .templatedescription, .assayspage .templatedescription{ width: 222px; margin: 5px 0 5px 174px; }
     30.samplespage .templatedescription { width: 300px; }
     31
    2732/* .simpleWizard .publication_list li .authors { overflow: hidden; max-height: 8px; text-overflow:ellipsis; } */
    2833
     
    3843.simpleWizard .importcolumns { position: relative; width: 100%; overflow: auto; border: 1px solid #ccc; }
    3944.simpleWizard .importcolumns table { border-width: 0; }
     45
     46/** MISSING FIELDS PAGE / TABLE EDITOR **/
     47.simpleWizard .tableEditor .header { height: auto; line-height: 15px; }
     48.simpleWizard .tableEditor .fieldname { display: inline-block; *display: inline; zoom: 1; }
  • trunk/web-app/js/simpleWizard.js

    r1601 r1678  
    5858        element = $("input[name=" + cellname + "]");
    5959        element.addClass('error')
     60}
     61
     62/**
     63 * Shows the description of a selected template in a div. The div is hidden if no description is given
     64 */
     65function showTemplateDescription( id, description ) {
     66        var el = $( '#' + id );
    6067       
    61        
     68        if( !description || description == "" ) {
     69                el.hide();
     70        } else {
     71                el.text( description );
     72                el.show();
     73        }
    6274}
Note: See TracChangeset for help on using the changeset viewer.