Skip to content
Permalink
Browse files

- Improved studyEdit datatable output

- Increased the max number out datatables entries showed
- Small improvements to import
  • Loading branch information
ferryjagers committed Jun 18, 2019
1 parent 8f21353 commit 5939fc139de65f4e7d9cd7f1a79fcd667b606d9b
@@ -26,7 +26,6 @@ class StudyEditService {
int ids Total list of filtered ids
*/
def getEntitiesForTemplate( searchParams, study, template ) {

def query = generateHQL( searchParams, study, template )

// Also count the total number of results in the dataset
@@ -57,7 +56,7 @@ class StudyEditService {
*/
def getSamplesForAssaySamplePage( searchParams, study ) {
def query = generateHQLForAssaySamples( searchParams, study )

// Also count the total number of results in the dataset
def output = generateOutput( query, searchParams, Sample )
output.total = Sample.countByParent( study )
@@ -103,21 +102,18 @@ class StudyEditService {
int ids Total list of filtered ids
*/
def generateOutput( query, searchParams, entity ) {

def output = [:]

// First select the number of results
def filteredIds = entity.executeQuery( "SELECT DISTINCT s.id FROM " + query.from + " WHERE " + query.where, query.params )
output.totalFiltered = filteredIds.size()
output.ids = filteredIds

// Now if filteredIds is not empty find the results themselves by that list
if ( filteredIds.size() != 0 ) {
def hql = "SELECT " + query.select + " FROM " + entity.simpleName + " " + query.select + " WHERE id IN :ids" + ( query.order ? " ORDER BY " + query.order : "" )
output.entities = entity.executeQuery( hql, [ ids: filteredIds ], [ max: searchParams.max, offset: searchParams.offset ] )
}
else {
output.entities = []
}
// Now find the results themselves
def hql = "SELECT " + query.select + " FROM " + query.from + " WHERE " + query.where + " " + ( query.order ? " ORDER BY " + query.order : "" )

output.entities = entity.executeQuery( hql, query.params, [ max: searchParams.max, offset: searchParams.offset ] )

if( query.chooseFirst ) {
output.entities = output.entities.collect { it[0] }
@@ -217,26 +213,22 @@ class StudyEditService {
def sortColumnIndex = searchParams.sortColumn ?: 0
def sortOrder = searchParams.sortDirection ?: "ASC"

//In order to have a natural 'order by' for the domainField 'name' we have to use a custom sort
def naturalSort = domainFields[ sortColumnIndex ]?.name.equals('name') ? true : false

// Prepare for differences in selection
def select = "DISTINCT s"

// Custom 'order by' is not allowed when using DISTINCT
if ( naturalSort ) {
select = "s"
}
def select = "DISTINCT (s)"

def chooseFirst = false

if( sortColumnIndex != null || sortColumnIndex >= ( domainFields.size() + template.fields.size() ) ) {
if( sortColumnIndex < domainFields.size() ) {
def sortOn = domainFields[ sortColumnIndex ]?.name
orderBy = "s." + sortOn + " " + sortOrder

if ( naturalSort ) {
if ( sortColumnIndex == 0 ) {
orderBy = "length(s." + sortOn + ") " + sortOrder + ", s." + sortOn + " " + sortOrder
select += ", length(s." + sortOn + ")"
chooseFirst = true
}
else {
orderBy = "s."+sortOn + " " + sortOrder
}
} else {
// Sort on template field: use a join in the sql
@@ -248,11 +240,11 @@ class StudyEditService {
hqlParams[ "sortField" ] = sortField.name
orderBy = "orderJoin " + sortOrder

// When ordering by a templatefield, we have to include it in the query as well
// However, in order to handle the object properly, we will need to tell the
// calling method that only the first object should be chosen.
select += ", orderJoin"
chooseFirst = true
// When ordering by a templatefield, we have to include it in the query as well
// However, in order to handle the object properly, we will need to tell the
// calling method that only the first object should be chosen.
select += ", orderJoin"
chooseFirst = true
}
}

@@ -271,7 +263,7 @@ class StudyEditService {
where: where,
order: orderBy,
params: hqlParams,
chooseFirst: chooseFirst
chooseFirst: chooseFirst
]
}

@@ -285,6 +277,7 @@ class StudyEditService {
* params
*/
def generateHQLForAssaySamples( searchParams, study ) {

def entity = Sample

// Search in
@@ -355,7 +348,7 @@ class StudyEditService {
where += " AND (" + whereClause.join( " OR " ) + ") "

[
select: "s, " + fields.join( ", " ),
select: "DISTINCT (s), " + fields.join( ", " ) + (sortColumnIndex == 0 ? ", length(" + fields[ sortColumnIndex ] + ")" : ""),
from: from,
where: where,
order: orderBy,
@@ -25,7 +25,8 @@

$(document).ready(function() {
$('#compare_templates').dataTable( {
"sPaginationType": "full_numbers"
"sPaginationType": "full_numbers",
"aLengthMenu": [10, 25, 50, 100, 250, 500, 1000]
} );
} );

@@ -60,22 +60,27 @@ class ImporterController {
}
}
}

// Handle form submission
if( request.post && params.importer ) {
// Only do something if a file has been specified
if( params.file && params.file != "existing*" ) {
def sessionKey = generateSessionKey()
storeInSession(sessionKey, parseUploadParams())

def uploadParams = parseUploadParams()

if (params._action == 'exact') {
uploadParams.method = 'exact'
doRedirect action: 'exact', params: defaultParams + [key: sessionKey]
return
}
else {
uploadParams.method = 'match'
doRedirect action: 'match', params: defaultParams + [key: sessionKey]
return
}

storeInSession(sessionKey, uploadParams)
return

} else {
flash.error = "Please upload a valid file"
}
@@ -97,6 +102,7 @@ class ImporterController {
* Screen to match headers
*/
def match() {

// Retrieve information from request and from session
def sessionKey = params.key
def importInfo = getFromSession(sessionKey)
@@ -211,8 +217,6 @@ class ImporterController {
// Determine the headers to match against
def headerOptions = importer.getHeaderOptions(importInfo.parameter)

defaultParams['match'] = 'exact'

render( view: "/importer/exact", model: [
sessionKey: sessionKey
])
@@ -359,7 +363,7 @@ class ImporterController {
def importer = getImporter(importInfo.importer)
def headerOptions = importer.getHeaderOptions(importInfo.parameter)

if ( params?.id.equals('exact') ) {
if ( importInfo.method.equals('exact') ) {

importInfo.mapping = [:]

@@ -415,6 +419,7 @@ class ImporterController {

[
file: filename,
type: params.type,
importer: params.importer,

upload: [
@@ -32,7 +32,7 @@
<g:hiddenField name="_action" />
<g:hiddenField name="key" value="${sessionKey}" />
<div id="match-headers" data-match-url="${g.createLink(action: 'matchHeaders', params: defaultParams, id: 'exact')}">
<div id="match-headers" data-match-url="${g.createLink(action: 'matchHeaders', params: defaultParams )}">
</div>
<div id="match-text">
@@ -32,9 +32,17 @@
description="Choose a file"
id="importFileName"
onUpload="Importer.upload.updateDataPreview"
value="${savedParameters?.file}"
/>

value="${savedParameters?.file}"/>

<div class="element">
<div class="description">Type</div>
<div class="input">
<g:select name="type" value="${savedParameters?.type}"
from="${['new':'Import new data','add':'Import additional data']}"
optionKey="key" optionValue="value"/>
</div>
</div>

<div class="element">
<div class="description">Use data from sheet</div>
<div class="input">

0 comments on commit 5939fc1

Please sign in to comment.
You can’t perform that action at this time.