Skip to content

Commit

Permalink
sequence-search : add checks on user input, and Search button.
Browse files Browse the repository at this point in the history
sequence-search.js :
add clearMsgs() (based from data-base.js, with added nameWarning : null), selectedParent.  drop reference to selectedDataset (only present in data-csv)
Add checkInputs(), loading (taskGet not added yet), search(), inputsOK(), searchButtonDisabled(),
Call dnaSequenceInput() from search() (and pass in text) instead of paste().

sequence-search.hbs : add search button and replaceDataset checkbox (value not yet passed to API).
  • Loading branch information
Don-Isdale committed May 11, 2021
1 parent acd77ec commit 1e7c0e9
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 20 deletions.
114 changes: 94 additions & 20 deletions frontend/app/components/panel/sequence-search.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Component from '@ember/component';
import { bind, once, later, throttle } from '@ember/runloop';
import { bind, once, later, throttle, debounce } from '@ember/runloop';
import { inject as service } from '@ember/service';
import { observer, computed } from '@ember/object';
import { alias } from '@ember/object/computed';


const dLog = console.debug;
Expand Down Expand Up @@ -29,20 +30,30 @@ export default Component.extend({
errorMessage: msg,
});
},

clearMsgs() {
this.setProperties({
successMessage: null,
errorMessage: null,
warningMessage: null,
nameWarning : null,
});
},

/*--------------------------------------------------------------------------*/
/** copied from data-csv.js; could factor as a mixin. */
newDatasetName: '',
nameWarning: null,
selectedParent: '',
/** Checks if entered dataset name is already taken in dataset list
* Debounced call through observer */
isDupName: function() {
let selectedMap = this.get('selectedDataset');
if (selectedMap === 'new') {
let newMap = this.get('newDatasetName');
{
let datasetName = this.get('newDatasetName');
let datasets = this.get('datasets');
let matched = datasets.findBy('name', newMap);
let matched = datasets.findBy('name', datasetName);
if(matched){
this.set('nameWarning', `Dataset name '${newMap}' is already in use`);
this.set('nameWarning', `Dataset name '${datasetName}' is already in use`);
return true;
}
}
Expand All @@ -52,10 +63,17 @@ export default Component.extend({
onNameChange: observer('newDatasetName', function() {
debounce(this, this.isDupName, 500);
}),
onSelectChange: observer('selectedDataset', 'selectedParent', function() {
this.clearMsgs();
this.isDupName();
this.checkBlocks();
onSelectChange: observer('selectedParent', function() {
this.checkInputs();
}),

/*--------------------------------------------------------------------------*/

loading : alias('taskGet.isRunning'),

refreshClassNames : computed('loading', function () {
let classNames = "btn btn-info pull-right";
return this.get('loading') ? classNames + ' disabled' : classNames;
}),

/*--------------------------------------------------------------------------*/
Expand All @@ -82,34 +100,68 @@ export default Component.extend({
/** this action function is called before jQuery val() is updated. */
later(() => {
this.set('text', text);
this.dnaSequenceInput(/*text*/);
// this.dnaSequenceInput(/*text*/);
}, 500);
},

dnaSequenceInput(text, event) {
dLog("dnaSequenceInput", this, text.length, event.keyCode);
this.set('text', text);
throttle(this.get('dnaSequenceInputBound'), 2000);
// throttle(this.get('dnaSequenceInputBound'), 2000);
},

search() {
if (this.checkInputs()) {
let text = this.get('text');
this.dnaSequenceInput(text);
}
}

},

/*--------------------------------------------------------------------------*/

checkInputs() {
let ok;
this.clearMsgs();

let datasetName = this.get('newDatasetName');
let parentName = this.get('selectedParent');
if (! parentName || ! parentName.length || (parentName === 'None')) {
this.set('nameWarning', 'Please select a reference genome to search');
ok = false;
} else if (this.get('addDataset') && ! (datasetName && datasetName.length)) {
this.set('nameWarning', 'Please enter name for the dataset to add containing the search results.o');
ok = false;
} else if (this.get('addDataset') && this.isDupName()) {
ok = false;
} else {
ok = true;
}
return ok;
},
inputsOK : computed('selectedParent', 'addDataset', 'newDatasetName', 'datasets.[]', function() {
return this.checkInputs();
}),
searchButtonDisabled : computed('inputsOK', 'isProcessing', function() {
return ! this.get('inputsOK') || this.get('isProcessing');
}),

/** throttle depends on constant function */
dnaSequenceInputBound : computed(function() {
return bind(this, this.dnaSequenceInput);
}),

dnaSequenceInput(rawText) {
rawText = this.get('text');
// dLog("dnaSequenceInput");

/*
let
text$ = $('textarea', this.element),
// dLog("dnaSequenceInput", rawText && rawText.length);
/** if the user has use paste or newline then .text is defined,
* otherwise use jQuery to get it from the textarea.
*/
if (! rawText) {
let text$ = $('textarea', this.element);
/** before textarea is created, .val() will be undefined. */
// rawText = text$.val();
rawText = text$.val();
}
if (rawText)
{
let
Expand All @@ -136,7 +188,11 @@ export default Component.extend({
promise.then(
(data) => {
dLog('dnaSequenceInput', data.features.length);
this.set('data', data.features); },
this.set('data', data.features);
if (this.get('addDataset') && this.get('replaceDataset')) {
this.unviewDataset(this.get('newDatasetName'));
}
},
// copied from data-base.js - could be factored.
(err, status) => {
let errobj = err.responseJSON.error;
Expand All @@ -155,6 +211,24 @@ export default Component.extend({

);
}
},

/*--------------------------------------------------------------------------*/
/* copied from file-drop-zone.js, can factor if this is retained. */

/** Unview the blocks of the dataset which has been replaced by successful upload.
*/
unviewDataset(datasetName) {
let
store = this.get('apiServers').get('primaryServer').get('store'),
replacedDataset = store.peekRecord('dataset', datasetName),
viewedBlocks = replacedDataset.get('blocks').toArray().filterBy('isViewed'),
blockService = this.get('blockService'),
blockIds = viewedBlocks.map((b) => b.id);
dLog('unviewDataset', datasetName, blockIds);
blockService.setViewed(blockIds, false);
}

/*--------------------------------------------------------------------------*/

});
18 changes: 18 additions & 0 deletions frontend/app/templates/components/panel/sequence-search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
placeholder="e.g. >BobWhite_c10015_641
AGCTGGGTGTCGTTGATCTTCAGGTCCTTCTGGATGTACAGCGACGCTCC" }}

<div style="margin: 1em; overflow-y: auto;">
{{#elem/button-base
click=(action "search")
classNames=refreshClassNames
disabled=searchButtonDisabled
icon='refresh'
classColour="primary"
}}
<span>&nbsp; Search</span>
{{/elem/button-base}}
</div>


<ul class="config-list">

Expand Down Expand Up @@ -77,6 +89,11 @@ AGCTGGGTGTCGTTGATCTTCAGGTCCTTCTGGATGTACAGCGACGCTCC" }}

{{!-- copied from data-csv.hbs --}}
{{#if this.addDataset}}
<span class="filter-group-col">
{{input type="checkbox" name="replaceDataset" checked=replaceDataset }}
<label>Replace Dataset</label>
</span>

<div id="new_dataset_options">
{{input
id="dataset_new"
Expand All @@ -87,6 +104,7 @@ AGCTGGGTGTCGTTGATCTTCAGGTCCTTCTGGATGTACAGCGACGCTCC" }}
disabled=isProcessing
}}
</div>

{{/if}}
</li>

Expand Down

0 comments on commit 1e7c0e9

Please sign in to comment.