From 8a16f595a305877aa6f5bc452e15b4e23f67bc4d Mon Sep 17 00:00:00 2001 From: "Hurtado, Iker (ikerh)" <iker.hurtado@bsc.es> Date: Tue, 11 Sep 2018 09:14:55 +0200 Subject: [PATCH] convenience commit --- client/bundle.js | 55 +++++++++++++--------- client/src/search-mod/MaterialList.view.js | 10 ++++ client/src/search-mod/NewSearchMod.js | 45 +++++++++--------- 3 files changed, 64 insertions(+), 46 deletions(-) diff --git a/client/bundle.js b/client/bundle.js index 6f882f0a..dab65b1c 100644 --- a/client/bundle.js +++ b/client/bundle.js @@ -7638,6 +7638,7 @@ let MaterialList = __webpack_require__(35); //let PropertiesBox = require('./PropertiesBox.view.js'); let FilterPanel = __webpack_require__(36); + let SwitchComponent = __webpack_require__(13); @@ -7695,8 +7696,7 @@ <button class="name-add-btn" >Name</button> </div> <div class="bool-buttons" style="width: 28%; display: inline-block" > - <button disabled >AND</button> - <button disabled >OR</button> + OR <span id="and-or-switch" ></span> AND <button disabled >NOT</button> <button disabled >(</button> <button disabled >)</button> <!--<input type="checkbox" name="and-or" class="not-symbol-btn" />NOT--> @@ -7734,6 +7734,9 @@ this.addPanel= this.element.querySelector('.add-panel'); + let andOrSwitch = new SwitchComponent(util.IMAGE_DIR+'switch'); + this.element.querySelector('#and-or-switch').appendChild(andOrSwitch.element); + this.elementTable= new ElementTable(); this.elementTable.setClickListener(elementArray => { this.addElementsInSearchQuery(elementArray); @@ -7817,8 +7820,7 @@ //else let esMatchQuery; if (this.formulaBox.getMultiplesOfFormula()){ - esMatchQuery = this._getESSimpleMatch('formula_reduced', item); - this._reduceFormula(item); + esMatchQuery = this._getESSimpleMatch('formula_reduced', this._reduceFormula(item)); }else esMatchQuery = this._getESSimpleMatch('formula', item); queryObj.bool.filter.push(esMatchQuery); @@ -7986,7 +7988,7 @@ let map = new Map(); let key; while ( index < formula.length ){ - console.log('_reduceFormula index', index); + //console.log('_reduceFormula index', index); let el2 = formula.substring(index, index+2); let el1 = formula.substring(index, index+1); @@ -7994,30 +7996,24 @@ map.set(el2, 1); // 1 default value index += 2; key = el2; - console.log('eleemnt 2chars', key); + //console.log('eleemnt 2chars', key); }else if (util.ELEMENTS.indexOf(el1) >= 0){ map.set(el1, 1); // 1 default value index++; key = el1; - console.log('eleemnt 1chars', key); + //console.log('eleemnt 1chars', key); }else{ // It's a number - // ************ parseInt(el2) let num = parseInt(el2); - //console.log('parsed number ', el2, num); - if (num >= 10){ // 2 figures number - index += 2; - }else{ // 1 figure number - index++; - } - console.log('number ', num, key); + if (num >= 10) index += 2; // 2 figures number + else index++;// 1 figure number + //console.log('number ', num, key); map.set(key, num); } - console.log('FINAL LOOP', map, index); + // console.log('FINAL LOOP', map, index); } let counter = 0; - while ( !checkIfReduced(map) ){ - console.log('Reducing', map); + while ( !checkIfReduced(map) ){ // console.log('Reducing', map); let div = 1; if (isDivisibleBy(map, 2)) div = 2; else if (isDivisibleBy(map, 3)) div = 3; @@ -8026,11 +8022,9 @@ else if (isDivisibleBy(map, 11)) div = 11; map.forEach( (value, key) => { - value = value/div; map.set(key, (value/div)); }); - console.log('Reducing DIV', map); - + //console.log('Reducing DIV', map); counter++; if (counter > 5) break; } @@ -8050,8 +8044,13 @@ }); return div; } - //console.log('_reduceFormula', map); - return formula; + + let newFormula = ''; + map.forEach( (value, key) => { + newFormula += key+(value === 1 ? '' : value); + }); + console.log('_reduceFormula RETURN: ', map, newFormula); + return newFormula; } @@ -9120,6 +9119,16 @@ } `; */ + postQuery= ` + { + "bool" : { + "should" : [ + {"match":{"formula":"H4O2"}}, + {"match":{"atom_labels":"Sc"}} + ] + } + } `; + console.log('SENDING: ', postQuery); diff --git a/client/src/search-mod/MaterialList.view.js b/client/src/search-mod/MaterialList.view.js index 633b9862..949aa6dc 100644 --- a/client/src/search-mod/MaterialList.view.js +++ b/client/src/search-mod/MaterialList.view.js @@ -140,6 +140,16 @@ class MaterialList { } `; */ +postQuery= ` + { + "bool" : { + "should" : [ + {"match":{"formula":"H4O2"}}, + {"match":{"atom_labels":"Sc"}} + ] + } + } `; + console.log('SENDING: ', postQuery); diff --git a/client/src/search-mod/NewSearchMod.js b/client/src/search-mod/NewSearchMod.js index 65461004..fdff05ba 100644 --- a/client/src/search-mod/NewSearchMod.js +++ b/client/src/search-mod/NewSearchMod.js @@ -31,6 +31,7 @@ let ElementTable = require('./ElemenTable.view.js'); let MaterialList = require('./MaterialList.view.js'); //let PropertiesBox = require('./PropertiesBox.view.js'); let FilterPanel = require('./FilterPanel.view.js'); +let SwitchComponent = require('../common/SwitchComponent.js'); @@ -88,8 +89,7 @@ class NewSearchMod { <button class="name-add-btn" >Name</button> </div> <div class="bool-buttons" style="width: 28%; display: inline-block" > - <button disabled >AND</button> - <button disabled >OR</button> + OR <span id="and-or-switch" ></span> AND <button disabled >NOT</button> <button disabled >(</button> <button disabled >)</button> <!--<input type="checkbox" name="and-or" class="not-symbol-btn" />NOT--> @@ -127,6 +127,9 @@ class NewSearchMod { this.addPanel= this.element.querySelector('.add-panel'); + let andOrSwitch = new SwitchComponent(util.IMAGE_DIR+'switch'); + this.element.querySelector('#and-or-switch').appendChild(andOrSwitch.element); + this.elementTable= new ElementTable(); this.elementTable.setClickListener(elementArray => { this.addElementsInSearchQuery(elementArray); @@ -210,8 +213,7 @@ class NewSearchMod { //else let esMatchQuery; if (this.formulaBox.getMultiplesOfFormula()){ - esMatchQuery = this._getESSimpleMatch('formula_reduced', item); - this._reduceFormula(item); + esMatchQuery = this._getESSimpleMatch('formula_reduced', this._reduceFormula(item)); }else esMatchQuery = this._getESSimpleMatch('formula', item); queryObj.bool.filter.push(esMatchQuery); @@ -379,7 +381,7 @@ class NewSearchMod { let map = new Map(); let key; while ( index < formula.length ){ - console.log('_reduceFormula index', index); + //console.log('_reduceFormula index', index); let el2 = formula.substring(index, index+2); let el1 = formula.substring(index, index+1); @@ -387,30 +389,24 @@ class NewSearchMod { map.set(el2, 1); // 1 default value index += 2; key = el2; - console.log('eleemnt 2chars', key); + //console.log('eleemnt 2chars', key); }else if (util.ELEMENTS.indexOf(el1) >= 0){ map.set(el1, 1); // 1 default value index++; key = el1; - console.log('eleemnt 1chars', key); + //console.log('eleemnt 1chars', key); }else{ // It's a number - // ************ parseInt(el2) let num = parseInt(el2); - //console.log('parsed number ', el2, num); - if (num >= 10){ // 2 figures number - index += 2; - }else{ // 1 figure number - index++; - } - console.log('number ', num, key); + if (num >= 10) index += 2; // 2 figures number + else index++;// 1 figure number + //console.log('number ', num, key); map.set(key, num); } - console.log('FINAL LOOP', map, index); + // console.log('FINAL LOOP', map, index); } let counter = 0; - while ( !checkIfReduced(map) ){ - console.log('Reducing', map); + while ( !checkIfReduced(map) ){ // console.log('Reducing', map); let div = 1; if (isDivisibleBy(map, 2)) div = 2; else if (isDivisibleBy(map, 3)) div = 3; @@ -419,11 +415,9 @@ class NewSearchMod { else if (isDivisibleBy(map, 11)) div = 11; map.forEach( (value, key) => { - value = value/div; map.set(key, (value/div)); }); - console.log('Reducing DIV', map); - + //console.log('Reducing DIV', map); counter++; if (counter > 5) break; } @@ -443,8 +437,13 @@ class NewSearchMod { }); return div; } - //console.log('_reduceFormula', map); - return formula; + + let newFormula = ''; + map.forEach( (value, key) => { + newFormula += key+(value === 1 ? '' : value); + }); + console.log('_reduceFormula RETURN: ', map, newFormula); + return newFormula; } -- GitLab