diff --git a/src/components/collection/Search.js b/src/components/collection/Search.js index 0b9b89b..ea6f311 100644 --- a/src/components/collection/Search.js +++ b/src/components/collection/Search.js @@ -32,8 +32,8 @@ export default class SearchCollection extends React.Component { sets: {}, types: {attack: false, battlegear: false, creature: false, location: false, mugic: false}, rarity: {common: false, uncommon: false, rare: false, 'super rare': false, 'ultra rare': false, promo: false}, - tribes: {danian: false, generic: false, 'm\'arrillian': false, 'mipedian': false, overworld: false, underworld: false, frozen: false}, - elements: {fire: false, air: false, earth: false, water: false}, + tribes: {danian: false, 'm\'arrillian': false, 'mipedian': false, overworld: false, underworld: false, generic: false}, + elements: {fire: false, air: false, earth: false, water: false, none: false, and: false}, disciplines: {courage: false, power: false, wisdom: false, speed: false}, energy: {min: 0, max: 0}, mcbp: {min: 0, max: 0}, @@ -63,11 +63,8 @@ export default class SearchCollection extends React.Component { } } - update("sets"); - update("types"); - update("rarity"); - update("gender"); - update("mull"); + ["sets", "types", "rarity", "gender", "mull", "elements" + ].forEach(item => update(item)); } async updateQuery() { @@ -85,11 +82,8 @@ export default class SearchCollection extends React.Component { else return ""; } - queryString += update("sets"); - queryString += update("types"); - queryString += update("rarity"); - queryString += update("gender"); - queryString += update("mull"); + ["sets", "types", "rarity", "gender", "mull", "elements" + ].forEach(item => queryString += update(item)); // Strip trailing & queryString = queryString.replace(/\&$/, ''); @@ -112,34 +106,38 @@ export default class SearchCollection extends React.Component { return (Loading...); } - let gen = (d, display) => { + let gen = (d, display, text) => { let tmp = []; Object.keys(this.input[d]).forEach((item, i) => { - tmp.push( + tmp.push( ); }); return tmp; } - let sets = gen("sets", (item) => { + let sets = gen("sets", "block", (item) => { return API.sets[item.toUpperCase()]; }); - let types = gen("types", (item) => { + let types = gen("types", "block", (item) => { return item.charAt(0).toUpperCase()+item.slice(1); }); - let rarity = gen("rarity", (item) => { + let rarity = gen("rarity", "block", (item) => { return item.split(" ").map(st => {return st.charAt(0).toUpperCase()+st.slice(1)}).join(" "); }); - let gender = gen("gender", (item) => { + let gender = gen("gender", "block", (item) => { return item.charAt(0).toUpperCase()+item.slice(1); }); - let tribes = []; + let tribes = gen("tribes", "inline", (item) => { + return ( ); + }); - let elements = []; + let elements = gen("elements", "inline", (item) => { + return ( ); + }).slice(0, -2); let disciplines = []; @@ -168,12 +166,22 @@ export default class SearchCollection extends React.Component { */}
- {tribes} + Tribes
- {elements} + {tribes} +

+ Elements +
+ {elements}  + {this.input.elements.and=false;}} /> + {this.input.elements.and=true;}} /> +
+ +

+ Disciplines
{disciplines} -
+

{/*
Energy
  @@ -192,7 +200,7 @@ export default class SearchCollection extends React.Component { {sets} {gender}
-    +     
@@ -232,6 +240,63 @@ export default class SearchCollection extends React.Component { let locationResults = API.cards.locations.chain(); let mugicResults = API.cards.mugic.chain(); + // Search by tribe + let tribesList = []; + for (const tribe in this.input.tribes) { + if (this.input.tribes[tribe]) + tribesList.push({'$regex': new RegExp(tribe, 'i')}); + } + if (tribesList.length > 0) { + creatureResults = creatureResults.find({'gsx$tribe': {'$or': tribesList} }); + mugicResults = mugicResults.find({'gsx$tribe': {'$or': tribesList} }); + attackResults = attackResults.limit(0); + battlegearResults = battlegearResults.limit(0); + locationResults = locationResults.limit(0); + } + + // Search by elements + if (this.input.elements.none) { + attackResults = attackResults.where( + (obj) => {return (obj.gsx$fire == ('') );} + ).where( + (obj) => {return (obj.gsx$air == ('') );} + ).where( + (obj) => {return (obj.gsx$earth == ('') );} + ).where( + (obj) => {return (obj.gsx$water == ('') );} + ); + battlegearResults = battlegearResults.limit(0); + creatureResults = creatureResults.where(obj => (obj.gsx$elements == '')); + locationResults = locationResults.limit(0); + mugicResults = mugicResults.limit(0); + } + else { + let elementsList = []; + let elementsList2 = []; + for (const element in this.input.elements) { + if (element === "none" || element === "and") continue; + if (this.input.elements[element]) { + elementsList.push({'$regex': new RegExp(element, 'i')}); + elementsList2.push({['gsx$'+element]: {'$gte': 0}}) + } + } + if (elementsList.length > 0) { + console.log(elementsList, elementsList2); + if (this.input.elements.and) { + creatureResults = creatureResults.find({'gsx$elements': {'$and': elementsList} }); + attackResults = attackResults.find({'$and': elementsList2}); + } + else { + creatureResults = creatureResults.find({'gsx$elements': {'$or': elementsList} }); + attackResults = attackResults.find({'$or': elementsList2}); + } + battlegearResults = battlegearResults.limit(0); + locationResults = locationResults.limit(0); + mugicResults = mugicResults.limit(0); + } + } + + // Unique if (this.input.mull.unique) { attackResults = attackResults.find({'gsx$unique': {'$gt': 0}}); battlegearResults = battlegearResults.find({'gsx$unique': {'$gt': 0}}); @@ -240,6 +305,7 @@ export default class SearchCollection extends React.Component { mugicResults = mugicResults.find({'gsx$unique': {'$gt': 0}}); } + // Loyal if (this.input.mull.loyal) { attackResults = attackResults.limit(0); battlegearResults = battlegearResults.find({'gsx$loyal': {'$gt': 0}}); @@ -248,14 +314,7 @@ export default class SearchCollection extends React.Component { locationResults = locationResults.limit(0); } - if (this.input.mull.mixed) { - attackResults = attackResults.limit(0); - creatureResults = creatureResults.find({'gsx$loyal': {'$lte': 0}}); - battlegearResults = battlegearResults.find({'gsx$loyal': {'$lte': 0}}); - mugicResults = mugicResults.limit(0); - locationResults = locationResults.limit(0); - } - + // Legendary if (this.input.mull.legendary) { attackResults = attackResults.find({'gsx$legendary': {'$gt': 0}}); battlegearResults = battlegearResults.find({'gsx$legendary': {'$gt': 0}}); @@ -264,6 +323,16 @@ export default class SearchCollection extends React.Component { mugicResults = mugicResults.find({'gsx$legendary': {'$gt': 0}}); } + // Non Loyal + if (this.input.mull.mixed) { + attackResults = attackResults.limit(0); + creatureResults = creatureResults.find({'gsx$loyal': {'$lte': 0}}); + battlegearResults = battlegearResults.find({'gsx$loyal': {'$lte': 0}}); + mugicResults = mugicResults.limit(0); + locationResults = locationResults.limit(0); + } + + // Sets let setsList = []; for (const key in this.input.sets) { if (this.input.sets[key]) @@ -277,6 +346,7 @@ export default class SearchCollection extends React.Component { mugicResults = mugicResults.find({'gsx$set': {'$or': setsList} }); } + // Rarity let rarityList = []; for (const key in this.input.rarity) { if (this.input.rarity[key]) @@ -290,11 +360,11 @@ export default class SearchCollection extends React.Component { mugicResults = mugicResults.find({'gsx$rarity': {'$or': rarityList} }); } + // Gender let genderList = []; for (const key in this.input.gender) { - if (this.input.gender[key]) { + if (this.input.gender[key]) genderList.push({'$regex': new RegExp(key, 'i')}) - } } if (genderList.length > 0) { attackResults = attackResults.limit(0);