Skip to content

Commit

Permalink
Added previous/next phyloref buttons, closes #50.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed Apr 17, 2018
1 parent fce2db9 commit 01537c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,21 @@ <h4 class="modal-title">Editing {{tunit_editor_target_label}}</h4>

<div class="panel-footer" v-if="selected_phyloref !== undefined && testcase.phylorefs.indexOf(selected_phyloref) != -1">
<div class="btn-group btn-group-justified" role="group" aria-label="Actions for the entire phyloreference">
<a
href="#selected-phyloref"
class="btn btn-default"
@click="change_selected_phyloref(-1)"
>Previous phyloreference</a>
<a
href="#selected-phyloref"
class="btn btn-danger"
onclick="if(window.confirm('Are you sure you want to delete this phyloreference?')) { vm.testcase.phylorefs.splice(vm.testcase.phylorefs.indexOf(vm.selected_phyloref), 1); vm.selected_phyloref = undefined; }"
>Delete phyloreference</a>
<a
href="#selected-phyloref"
class="btn btn-default"
@click="change_selected_phyloref(+1)"
>Next phyloreference</a>
</div>
</div>

Expand Down
35 changes: 35 additions & 0 deletions js/curation-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,41 @@ var vm = new Vue({
return undefined;
},

// Methods for manipulating phyloreferences.
change_selected_phyloref: function(change_to) {
// Change the selected phyloreference in different ways.

if(Number.isInteger(change_to)) {
// Increase or decrease the selected phyloreference by the
// given number of steps.

// Do we have a selected phyloref? If not, select the first one.
if(this.selected_phyloref === undefined) {
if(this.testcase.phylorefs.length > 0) {
// Select the first phyloreference.
this.selected_phyloref = this.testcase.phylorefs[0];
} else {
// We have no phyloreferences to select! Do nothing.
}

return;
}

// We have a selected phyloreference. Switch to the previous or
// next one, wrapping at the length.
let current_phyloref_index = this.testcase.phylorefs.indexOf(this.selected_phyloref);
let new_phyloref_index = (current_phyloref_index + change_to) % this.testcase.phylorefs.length;

// If we decrement past zero, wrap around to the length.
if(new_phyloref_index < 0) new_phyloref_index = (this.testcase.phylorefs.length + new_phyloref_index);

// Switch to the new selected phyloref.
console.log("New phyloref_index: ", new_phyloref_index);
this.selected_phyloref = this.testcase.phylorefs[new_phyloref_index];
return;
}
},

// Methods for manipulating nodes in phylogenies.
get_node_labels_in_phylogeny: function(phylogeny) {
// Return an iterator to all the node labels in a phylogeny. These
Expand Down

0 comments on commit 01537c4

Please sign in to comment.