This repository has been archived by the owner on Jan 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from cbmi/issue-30
Add column headers and enable sorting on results table
- Loading branch information
Showing
10 changed files
with
247 additions
and
4 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
varify/static/cilantro/js/templates/varify/tables/header.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<tr> | ||
<th title='Gene' data-concept-id=5> | ||
<span>Gene<i class='icon-sort'></i></span> | ||
</th> | ||
<th title='HGVS P' data-concept-id=21> | ||
<span>HGVS P<i class='icon-sort'></i></span> | ||
</th> | ||
<th title='Variant Effect' data-concept-id=10> | ||
<span>Effect<i class='icon-sort'></i></span> | ||
</th> | ||
<th title='HGVS C' data-concept-id=19> | ||
<span>HGVS C<i class='icon-sort'></i></span> | ||
</th> | ||
<th title='Genotype' data-concept-id=16> | ||
<span>Genotype<i class='icon-sort'></i></span> | ||
</th> | ||
<th title='Genomic Position' data-concept-id=1> | ||
<span>Position<i class='icon-sort'></i></span> | ||
</th> | ||
<th title='Condensed Flags' class='unsortable-column'></th> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
define [ | ||
'underscore' | ||
'./tables/body' | ||
'./tables/header' | ||
'./tables/row' | ||
'./tables/table' | ||
], (_, mods...) -> | ||
|
83 changes: 83 additions & 0 deletions
83
varify/static/scripts/coffeescript/ui/tables/header.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
define [ | ||
'underscore' | ||
'marionette' | ||
'tpl!templates/varify/tables/header.html' | ||
], (_, Marionette, templates...) -> | ||
|
||
templates = _.object ['header'], templates | ||
|
||
class Header extends Marionette.ItemView | ||
tagName: 'thead' | ||
|
||
template: templates.header | ||
|
||
events: | ||
'click th': 'onClick' | ||
|
||
initialize: -> | ||
@data = {} | ||
if not (@data.view = @options.view) | ||
throw new Error 'view model required' | ||
|
||
_getConcept: (element) -> | ||
concept = parseInt(element.getAttribute('data-concept-id')) | ||
|
||
if concept? and not isNaN(concept) | ||
return concept | ||
|
||
# It is possible we registered a click event on a child of the | ||
# th element. If that is the case, try to read the concept from | ||
# parent of the event target. | ||
return parseInt(element.parentElement.getAttribute('data-concept-id')) | ||
|
||
onClick: (event) => | ||
concept = @_getConcept(event.target) | ||
|
||
if not concept? or isNaN(concept) | ||
throw new Error 'Unrecognized concept ID on column' | ||
|
||
model = _.find @data.view.facets.models, (f) -> | ||
return f.get('concept') == concept | ||
|
||
# If this column is not in the view already, add it in before | ||
# updating the view sort properties. | ||
if not model? | ||
@data.view.facets.add({concept: concept}) | ||
|
||
_.each @data.view.facets.models, (f) -> | ||
if f.get('concept') == concept | ||
direction = f.get('sort') | ||
|
||
if direction? | ||
if direction.toLowerCase() == "asc" | ||
f.set('sort', "desc") | ||
f.set('sort_index', 0) | ||
else | ||
f.unset('sort') | ||
f.unset('sort_index') | ||
else | ||
f.set('sort', "asc") | ||
f.set('sort_index', 0) | ||
else | ||
f.unset('sort') | ||
f.unset('sort_index') | ||
|
||
@data.view.save() | ||
|
||
onRender: => | ||
_.each @data.view.facets.models, (f) -> | ||
$sortIcon = $("th[data-concept-id=#{ f.get('concept') }] i") | ||
|
||
if $sortIcon? | ||
$sortIcon.removeClass('icon-sort icon-sort-up icon-sort-down') | ||
|
||
direction = (f.get('sort') or '').toLowerCase() | ||
|
||
sortClass = switch direction | ||
when 'asc' then 'icon-sort-up' | ||
when 'desc' then 'icon-sort-down' | ||
else 'icon-sort' | ||
|
||
$sortIcon.addClass(sortClass) | ||
|
||
{ Header } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
varify/static/scripts/javascript/src/ui/tables/header.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters