Changeset 1445


Ignore:
Timestamp:
Jan 27, 2011, 1:43:36 PM (6 years ago)
Author:
s.h.sikkema@…
Message:

Rudimentary assay export functionality

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy

    r1440 r1445  
    141141        Assay assay = Assay.get(params.assayId)
    142142
     143        // check if assay exists
    143144        if (!assay) {
    144145            flash.errorMessage = "No assay found with id: $params.assayId."
     
    159160        } catch (Exception e) {
    160161
    161             flash.errorMessage = e.toString()
     162            flash.errorMessage = e.cause?.message ?: e.message
    162163            redirect action: 'selectAssay'
    163164
  • trunk/grails-app/views/assay/selectAssay.gsp

    r1430 r1445  
    1414      function updateAssay(jsonData, selectID) {
    1515        var a = eval(jsonData);
    16         var sel = $('#'+selectID).empty()
     16        var sel = $('#'+selectID).empty();
    1717       
    1818        $(a).each(function(i, el){
    19           sel.append($("<option></option>").attr("value",el.id).text(el.name));
    20         });
     19          sel.append($("<option></option>").attr("value",el.id).text(el.name))
     20        })
    2121      }
     22
     23      $(document).ready(function(){
     24        // trigger change event to load assay based on currently selected study.
     25        // After pressing 'Back', the browser may use last selected study.
     26        $('#study').change()
     27
     28      })
    2229    </script>
    2330  </head>
     
    2734  </div>
    2835  <g:form name="assaySelect" action="exportAssayAsExcel">
    29     <g:select optionKey="id" optionValue="title" name="studyId" from="${userStudies}"
    30             onChange="${remoteFunction(controller:'study',action:'ajaxGetAssays',params:'\'id=\'+escape(this.value)',onComplete: 'updateAssay(XMLHttpRequest.responseText, \'assay\')')}"/>
    31     <g:select optionKey="id" name="assayId" id="assay" from="${assays}"/>
     36    <g:select optionKey="id" optionValue="title" name="studyId" from="${userStudies}" id="study"
     37      onChange="${remoteFunction(controller:'study',action:'ajaxGetAssays',params:'\'id=\'+escape(this.value)',onComplete: 'updateAssay(XMLHttpRequest.responseText, \'assay\')')}"/>
     38    <g:select optionKey="id" name="assayId" id="assay" from=""/>
     39    %{--<g:select optionKey="id" name="assayId" id="assay" from="${assays}"/>--}%
    3240    <g:submitButton name="submit" value="Submit"/>
    3341  </g:form>
  • trunk/test/unit/dbnp/studycapturing/AssayControllerTests.groovy

    r1430 r1445  
    1818    protected void setUp() {
    1919        super.setUp()
     20        mockDomain(Assay, [new Assay(id:1)])
    2021    }
    2122
     
    2526
    2627    void testWrongAssayID() {
    27         mockParams.assayId = 1
     28        mockParams.assayId = 3
    2829
    2930        controller.exportAssayAsExcel()
     
    3435
    3536    void testExceptionHandling() {
     37        mockParams.assayId = 1
     38
     39        controller.metaClass.'grailsApplication' = [
     40                config: [modules: [metabolomics: [url: 'www.ab.com']]]
     41        ]
     42
    3643        controller.assayService = [
    37                 collectAssayData:{a, b -> throw new Exception('msg1')},
    38                 exportColumnWiseDataToExcelFile:{a, b -> throw new Exception('msg2')}
     44
     45                collectAssayData:                   {a, b -> def e = new Exception('msga'); e.metaClass.cause = new Exception('msg1'); throw e },
     46                exportColumnWiseDataToExcelFile:    {a, b -> def e = new Exception('msgb'); e.metaClass.cause = new Exception('msg2'); throw e }
     47
    3948        ]
     49
    4050        controller.exportAssayAsExcel()
    4151
    4252        assertEquals 'Redirected action should match', [action: 'selectAssay'], redirectArgs
    43         assertEquals 'Error message', 'java.lang.Exception: msg1', mockFlash.errorMessage
     53        assertEquals 'Error message', 'msg1', mockFlash.errorMessage
    4454
    4555        controller.assayService.collectAssayData = {a, b -> true}
     
    4757
    4858        assertEquals 'Redirected action should match', [action: 'selectAssay'], redirectArgs
    49         assertEquals 'Error message', 'java.lang.Exception: msg2', mockFlash.errorMessage
     59        assertEquals 'Error message', 'msg2', mockFlash.errorMessage
    5060
    5161    }
Note: See TracChangeset for help on using the changeset viewer.