diff --git a/frontend/app/components/panel/sequence-search.js b/frontend/app/components/panel/sequence-search.js index 7699e7f93..ece67a9bd 100644 --- a/frontend/app/components/panel/sequence-search.js +++ b/frontend/app/components/panel/sequence-search.js @@ -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; @@ -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; } } @@ -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; }), /*--------------------------------------------------------------------------*/ @@ -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 @@ -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; @@ -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); } + /*--------------------------------------------------------------------------*/ + }); diff --git a/frontend/app/templates/components/panel/sequence-search.hbs b/frontend/app/templates/components/panel/sequence-search.hbs index a8ebc3f41..9bc8e5223 100644 --- a/frontend/app/templates/components/panel/sequence-search.hbs +++ b/frontend/app/templates/components/panel/sequence-search.hbs @@ -35,6 +35,18 @@ placeholder="e.g. >BobWhite_c10015_641 AGCTGGGTGTCGTTGATCTTCAGGTCCTTCTGGATGTACAGCGACGCTCC" }} +