diff --git a/src/components/collection/Search.js b/src/components/collection/Search.js index 7fb3869..9c89346 100644 --- a/src/components/collection/Search.js +++ b/src/components/collection/Search.js @@ -1,167 +1,137 @@ import React from 'react'; -import API from '../SpreadsheetData'; import {observable} from "mobx"; import {observer, inject} from 'mobx-react'; import loki from 'lokijs'; import Collapsible from 'react-collapsible'; +import API from '../SpreadsheetData'; @inject((stores, props, context) => props) @observer -export default class SearchForm extends React.Component { - @observable swamp = "or"; +export default class SearchCollection extends React.Component { + @observable loaded = false; + @observable input = {}; - constructor() { - super(); - this.reset(); + constructor(props) { + super(props); this.filter = new loki("filter.db"); + + // Binding for keeping scope + this.search = this.search.bind(this); + this.handleChange = this.handleChange.bind(this); + this.reset = this.reset.bind(this); + + this.parseQuery(); } componentDidMount() { - this.search(); + // this.search(); } - reset = () => { - this.type = {}; - this.stones = {}; - this.tribes = {}; - this.elements = {}; - this.rarity = {}; - this.sets = {}; - this.gender = {}; - this.mc = {}; - this.energy = {}; - this.bp = {}; - this.base = {}; - }; + parseQuery() { + this.props.handleContent([{'text': 'Loading...'}]); + const queryString = this.props.location.search.toLowerCase(); + + let query = {}; + let pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&'); + for (let i = 0; i < pairs.length; i++) { + let pair = pairs[i].split('='); + query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); + } + + console.log(query); + + if (query.sets) { + query.sets.split(',').map(item => { + this.input[item.toUpperCase()] = true; + }); + } + + } + + updateQuery() { + let query = {sets:[]}; + + Object.keys(this.input).forEach((key) => { + if (key in API.sets) query.sets.push(key); + }); + + let queryString = ""; + + // Sets + if (query.sets.length > 0) { + queryString += "sets="; + query.sets.forEach(item => { + queryString += item.toLowerCase(); + }); + queryString += "&"; + } + + // encodeURIComponent + + // Strip trailing & + queryString = queryString.replace(/\&$/, ''); + + this.props.history.push('/collection/?'+(queryString)); + } + + reset(event) { + event.preventDefault(); + event.stopPropagation(); + this.props.history.push('/collection/'); + Object.keys(this.input).forEach((key) => { + (typeof(this.input[key]) === 'boolean' ? this.input[key] = false : this.input[key] = ''); + }); + } + + handleChange(event) { + const target = event.target; + const value = target.type === 'checkbox' ? target.checked : target.value; + const name = target.name; + this.input[name] = value; + + console.log(this.input); + } render() { + if (API.urls === null || + API.portal === null || + API.cards === null) { + return (Loading...); + } + + if (this.loaded == false) { + API.buildCollection([{'cards': 'attacks'}, {'cards': 'battlegear'}, {'cards': 'creatures'}, {'cards': 'locations'}, {'cards': 'mugic'}]) + .then(() => { + this.loaded = true; + this.search(); + }); + return (Loading...); + } let setsInput = []; for (const key in API.sets) { - setsInput.push(); + setsInput.push(); } - const card_types = ( -
-
-
-
-
- -
- ); - - const card_rarity = ( -
-
-
-
-
-
- -
- ); - - const card_tribes = ( -
-
Tribes
- this.tribes.danian = input}/>  - this.tribes.mipedian = input}/>  - this.tribes.overworld = input}/>  - this.tribes.underworld = input}/>  - this.tribes["m'arrillian"] = input}/>  - this.tribes.generic = input}/> -
- ); - - const card_elements = ( -
-
Elements
- this.elements.fire = input} />  - this.elements.air = input}/>  - this.elements.earth = input}/>  - this.elements.water = input}/>   - this.swamp="or"}/> - this.swamp="and"} /> -
- this.stones.noElements = input}/>No Elements -
- ); - - const card_disciplines = ( -
-
Disciplines
- this.stones.courage = input} />  - this.stones.power = input} />  - this.stones.wisdom = input} />  - this.stones.speed = input} /> -
- ); - return (
-
- -
- -
-
-
-   - -
-
- {card_tribes} -
- {card_elements} -
- {card_disciplines} -
-
- Energy
-   - -
-
-
- Mugic Counters/Cost -
Build Points

-   - -
-
-
-   -   - -
- -
-
- {card_types} - {card_rarity} {setsInput} - -   -   - -
   - +
); } - // TODO advanced filters search = (e) => { if (e) { e.preventDefault(); e.stopPropagation(); + + this.updateQuery(); } + // Sort data descending alphabetically let filter = this.filter.addCollection('filter'); var pview = filter.addDynamicView('filter'); @@ -174,291 +144,34 @@ export default class SearchForm extends React.Component { let locationResults = API.cards.locations.chain(); let mugicResults = API.cards.mugic.chain(); - // Search by name - if (this.stones.name.value) { - attackResults = attackResults.find({'$or': [ - {'gsx$name': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - {'gsx$tags': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - ]}); - battlegearResults = battlegearResults.find({'$or': [ - {'gsx$name': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - {'gsx$tags': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - ]}); - creatureResults = creatureResults.find({'$or': [ - {'gsx$name': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - {'gsx$tags': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - ]}); - locationResults = locationResults.find({'$or': [ - {'gsx$name': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - {'gsx$tags': {'$regex': new RegExp(this.stones.name.value, 'i')}} - ]}); - mugicResults = mugicResults.find({'$or': [ - {'gsx$name': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - {'gsx$tags': {'$regex': new RegExp(this.stones.name.value, 'i')}}, - ]}); - } - - if (this.stones.text.value) { - let textList = this.stones.text.value.split(",").filter(Boolean).map((item) => { - return ({'$regex': new RegExp(item.trim(), 'i')}); - }); - attackResults = attackResults.find({'$or': [ - {'gsx$tags': {"$or": textList}}, - {'gsx$ability': {"$or": textList}}, - {'gsx$flavortext': {"$or": textList}} - ]}); - battlegearResults = battlegearResults.find({'$or': [ - {'gsx$tags': {"$or": textList}}, - {'gsx$ability': {"$or": textList}}, - {'gsx$flavortext': {"$or": textList}} - ]}); - creatureResults = creatureResults.find({'$or': [ - {'gsx$tags': {"$or": textList}}, - {'gsx$ability': {"$or": textList}}, - {'gsx$flavortext': {"$or": textList}}, - {'gsx$brainwashedability': {"$or": textList}} - ]}); - locationResults = locationResults.find({'$or': [ - {'gsx$tags': {"$or": textList}}, - {'gsx$ability': {"$or": textList}}, - {'gsx$flavortext': {"$or": textList}} - ]}); - mugicResults = mugicResults.find({'$or': [ - {'gsx$tags': {"$or": textList}}, - {'gsx$ability': {"$or": textList}}, - {'gsx$flavortext': {"$or": textList}} - ]}); - } - - // Search by tribe - let tribesList = []; - for (const tribe in this.tribes) { - if (this.tribes[tribe].checked) { - 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); - } - - // no elements - if (this.stones.noElements.checked) { - creatureResults = creatureResults.where((obj) => {return (obj.gsx$elements == '');}); - 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); - locationResults = locationResults.limit(0); - mugicResults = mugicResults.limit(0); - } - // Search by elements - else { - let elementsList = []; - let elementsList2 = []; - for (const element in this.elements) { - if (this.elements[element].checked) { - elementsList.push({'$regex': new RegExp(element, 'i')}); - elementsList2.push({['gsx$'+element]: {'$gte': 0}}) - } - } - if (elementsList.length > 0) { - if (this.swamp == "or") { - creatureResults = creatureResults.find({'gsx$elements': {'$or': elementsList} }); - attackResults = attackResults.find({'$or': elementsList2}); - } - if (this.swamp == "and") { - creatureResults = creatureResults.find({'gsx$elements': {'$and': elementsList} }); - attackResults = attackResults.find({'$and': elementsList2}); - } - battlegearResults = battlegearResults.limit(0); - locationResults = locationResults.limit(0); - mugicResults = mugicResults.limit(0); - } - } - - let rarityList = []; - for (const key in this.rarity) { - if (this.rarity[key].checked) { - rarityList.push({'$eq': key}); - } - } - if (rarityList.length > 0) { - attackResults = attackResults.find({'gsx$rarity': {'$or': rarityList} }); - battlegearResults = battlegearResults.find({'gsx$rarity': {'$or': rarityList} }); - creatureResults = creatureResults.find({'gsx$rarity': {'$or': rarityList} }); - locationResults = locationResults.find({'gsx$rarity': {'$or': rarityList} }); - mugicResults = mugicResults.find({'gsx$rarity': {'$or': rarityList} }); - } - - let setsList = []; - for (const key in this.sets) { - if (this.sets[key].checked) { - setsList.push({'$eq': key}); - } - } - if (setsList.length > 0) { - attackResults = attackResults.find({'gsx$set': {'$or': setsList} }); - battlegearResults = battlegearResults.find({'gsx$set': {'$or': setsList} }); - creatureResults = creatureResults.find({'gsx$set': {'$or': setsList} }); - locationResults = locationResults.find({'gsx$set': {'$or': setsList} }); - mugicResults = mugicResults.find({'gsx$set': {'$or': setsList} }); - } - - if (this.stones.subtypes.value) { - let subtypesList = this.stones.subtypes.value.split(",").filter(Boolean).map((item) => { - return ({'$regex': new RegExp(item.trim(), 'i')}); - }); - - creatureResults = creatureResults.find({'gsx$types': {'$or': subtypesList} }); - locationResults = locationResults.find({'gsx$initiative': {'$or': subtypesList}}); - attackResults = attackResults.limit(0); - battlegearResults = battlegearResults.limit(0); - mugicResults = mugicResults.limit(0); - } - - if (this.mc.min.value !== "" && this.mc.min.value >= 0) { - attackResults = attackResults.find({'gsx$bp': {'$gte': this.mc.min.value}}); - creatureResults = creatureResults.find({'gsx$mugicability': {'$gte': this.mc.min.value}}); - mugicResults = mugicResults.find({'gsx$cost': {'$gte': this.mc.min.value}}); - } - if (this.mc.max.value !== "" && this.mc.max.value >= 0 && this.mc.max.value >= this.mc.min.value) { - attackResults = attackResults.find({'gsx$bp': {'$lte': this.mc.max.value}}); - creatureResults = creatureResults.find({'gsx$mugicability': {'$lte': this.mc.max.value}}); - mugicResults = mugicResults.find({'gsx$cost': {'$lte': this.mc.max.value}}); - } - - if (this.mc.max.value !== "" || this.mc.min.value !== "") { - battlegearResults = battlegearResults.limit(0); - locationResults = locationResults.limit(0); - } - - if (this.energy.min.value > 0) { - creatureResults = creatureResults.find({'gsx$energy': {'$gte': this.energy.min.value}}); - } - if (this.energy.max.value > 0 && this.energy.max.value >= this.energy.min.value) { - creatureResults = creatureResults.find({'gsx$energy': {'$lte': this.energy.max.value}}); - } - - if (this.stones.courage.value > 0) { - creatureResults = creatureResults.find({'gsx$courage': {'$gte': this.stones.courage.value}}); - } - if (this.stones.power.value > 0) { - creatureResults = creatureResults.find({'gsx$power': {'$gte': this.stones.power.value}}); - } - if (this.stones.wisdom.value > 0) { - creatureResults = creatureResults.find({'gsx$wisdom': {'$gte': this.stones.wisdom.value}}); - } - if (this.stones.speed.value > 0) { - creatureResults = creatureResults.find({'gsx$speed': {'$gte': this.stones.speed.value}}); - } - - if (this.energy.min.value > 0 || this.energy.max.value > 0 || this.stones.courage.value !== "" || this.stones.power.value !== "" || this.stones.wisdom.value !== "" || this.stones.speed.value !== "") { - attackResults = attackResults.limit(0); - battlegearResults = battlegearResults.limit(0); - locationResults = locationResults.limit(0); - mugicResults = mugicResults.limit(0); - } - - if (this.stones.unique.checked) { - attackResults = attackResults.find({'gsx$unique': {'$gt': 0}}); - battlegearResults = battlegearResults.find({'gsx$unique': {'$gt': 0}}); - creatureResults = creatureResults.find({'gsx$unique': {'$gt': 0}}); - locationResults = locationResults.find({'gsx$unique': {'$gt': 0}}); - mugicResults = mugicResults.find({'gsx$unique': {'$gt': 0}}); - } - - if (this.stones.loyal.checked) { - attackResults = attackResults.limit(0); - battlegearResults = battlegearResults.find({'gsx$loyal': {'$gt': 0}}); - creatureResults = creatureResults.find({'gsx$loyal': {'$gt': 0}}); - mugicResults = mugicResults.limit(0); - locationResults = locationResults.limit(0); - } - - if (this.stones.mixed.checked) { - 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); - } - - if (this.stones.legendary.checked) { - attackResults = attackResults.find({'gsx$legendary': {'$gt': 0}}); - battlegearResults = battlegearResults.find({'gsx$legendary': {'$gt': 0}}); - creatureResults = creatureResults.find({'gsx$legendary': {'$gt': 0}}); - locationResults = locationResults.find({'gsx$legendary': {'$gt': 0}}); - mugicResults = mugicResults.find({'gsx$legendary': {'$gt': 0}}); - } - - if (this.stones.past.checked) { - attackResults = attackResults.find({'gsx$past': {'$gt': 0}}); - battlegearResults = battlegearResults.find({'gsx$past': {'$gt': 0}}); - creatureResults = creatureResults.find({'gsx$types': {'$regex': new RegExp("past", 'i')}}); - locationResults = locationResults.find({'gsx$past': {'$gt': 0}}); - mugicResults = mugicResults.find({'gsx$past': {'$gt': 0}}); - } - - if (this.stones.mirage.checked) { - locationResults = locationResults.find({'gsx$mirage': {'$gt': 0}}); - attackResults = attackResults.limit(0); - battlegearResults = battlegearResults.limit(0); - creatureResults = creatureResults.limit(0); - mugicResults = mugicResults.limit(0); - } - - let genderList = []; - for (const key in this.gender) { - if (this.gender[key].checked) { - genderList.push({'$regex': new RegExp(key, 'i')}) - } - } - if (genderList.length > 0) { - creatureResults = creatureResults.find({'gsx$gender': {'$or': genderList} }); - attackResults = attackResults.limit(0); - battlegearResults = battlegearResults.limit(0); - locationResults = locationResults.limit(0); - mugicResults = mugicResults.limit(0); - } - // Merge data - let types = !(this.type.Attack.checked | this.type.Battlegear.checked | this.type.Creature.checked | this.type.Location.checked | this.type.Mugic.checked); + // let types = !(this.type.Attack.checked | this.type.Battlegear.checked | this.type.Creature.checked | this.type.Location.checked | this.type.Mugic.checked); - if (types || this.type.Attack.checked) { - let temp = attackResults.data(); - temp.forEach(function(v){ delete v.$loki }); - filter.insert(temp); - } - if (types || this.type.Battlegear.checked) { - let temp = battlegearResults.data(); - temp.forEach(function(v){ delete v.$loki }); - filter.insert(temp); - } - if (types || this.type.Creature.checked) { - let temp = creatureResults.data() - temp.forEach(function(v){ delete v.$loki }); - filter.insert(temp); - } - if (types || this.type.Location.checked) { - let temp = locationResults.data() - temp.forEach(function(v){ delete v.$loki }); - filter.insert(temp); - } - if (types || this.type.Mugic.checked) { - let temp = mugicResults.data() - temp.forEach(function(v){ delete v.$loki }); - filter.insert(temp); - } + // if (types || this.type.Attack.checked) { + // let temp = attackResults.data(); + // temp.forEach(function(v){ delete v.$loki }); + // filter.insert(temp); + // } + // if (types || this.type.Battlegear.checked) { + // let temp = battlegearResults.data(); + // temp.forEach(function(v){ delete v.$loki }); + // filter.insert(temp); + // } + // if (types || this.type.Creature.checked) { + // let temp = creatureResults.data() + // temp.forEach(function(v){ delete v.$loki }); + // filter.insert(temp); + // } + // if (types || this.type.Location.checked) { + // let temp = locationResults.data() + // temp.forEach(function(v){ delete v.$loki }); + // filter.insert(temp); + // } + // if (types || this.type.Mugic.checked) { + // let temp = mugicResults.data() + // temp.forEach(function(v){ delete v.$loki }); + // filter.insert(temp); + // } let results = pview.data(); this.filter.removeCollection('filter'); @@ -466,4 +179,5 @@ export default class SearchForm extends React.Component { if (results.length > 0) this.props.handleContent(results); else this.props.handleContent([{'text': 'No Results Found'}]); } + } diff --git a/src/components/collection/index.js b/src/components/collection/index.js index ff60550..8ab11d2 100644 --- a/src/components/collection/index.js +++ b/src/components/collection/index.js @@ -25,31 +25,18 @@ export default class Home extends React.Component { } render() { - - if (API.urls === null || - API.portal === null || - API.cards === null) { - return (Loading...); - } - - if (this.loaded == false) { - API.buildCollection([{'cards': 'attacks'}, , {'cards': 'battlegear'}, {'cards': 'creatures'}, {'cards': 'locations'}, {'cards': 'mugic'}]) - .then(() => { - this.loaded = true; - }); - return (Loading...); - } - return (
{if (n) this.changeImage = n.getInstance().changeImage}} /> - +
- {this.navigation()}
+ {this.navigation()} +
+
{this.navigation()}
diff --git a/src/components/entercode/PackSimulator.js b/src/components/entercode/PackSimulator.js index 06fda1c..bbe0afe 100644 --- a/src/components/entercode/PackSimulator.js +++ b/src/components/entercode/PackSimulator.js @@ -76,7 +76,6 @@ export default class PackSimulator extends React.Component { const target = event.target; const value = target.type === 'checkbox' ? target.checked : target.value; const name = target.name; - this[name] = value; } diff --git a/src/components/portal/Search.js b/src/components/portal/Search.js index 8840d70..dd9fab3 100644 --- a/src/components/portal/Search.js +++ b/src/components/portal/Search.js @@ -57,7 +57,7 @@ class DBSearch extends React.Component { } if (this.loaded == false) { - API.buildCollection([{'portal': 'attacks'}, , {'portal': 'battlegear'}, {'portal': 'creatures'}, {'portal': 'locations'}, {'portal': 'mugic'}]) + API.buildCollection([{'portal': 'attacks'}, {'portal': 'battlegear'}, {'portal': 'creatures'}, {'portal': 'locations'}, {'portal': 'mugic'}]) .then(() => { this.loaded = true; });