mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 18:32:40 +00:00
renderer filter query
This commit is contained in:
@@ -12,6 +12,7 @@ const Account = require('../../navbar/account.navitem.jsx');
|
|||||||
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
|
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
|
||||||
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
||||||
const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx');
|
const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx');
|
||||||
|
//const StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx');
|
||||||
|
|
||||||
const request = require('../../utils/request-middleware.js');
|
const request = require('../../utils/request-middleware.js');
|
||||||
|
|
||||||
@@ -22,12 +23,20 @@ const ArchivePage = createClass({
|
|||||||
},
|
},
|
||||||
getInitialState : function () {
|
getInitialState : function () {
|
||||||
return {
|
return {
|
||||||
|
//request
|
||||||
title : this.props.query.title || '',
|
title : this.props.query.title || '',
|
||||||
brewCollection : null,
|
//tags : {},
|
||||||
page : 1,
|
legacy : true,
|
||||||
|
v3 : true,
|
||||||
pageSize : 10,
|
pageSize : 10,
|
||||||
totalPages : 1,
|
page : 1,
|
||||||
totalBrews : 0,
|
|
||||||
|
//response
|
||||||
|
brewCollection : null,
|
||||||
|
totalPages : null,
|
||||||
|
totalBrews : null,
|
||||||
|
|
||||||
|
|
||||||
searching : false,
|
searching : false,
|
||||||
error : null,
|
error : null,
|
||||||
};
|
};
|
||||||
@@ -36,7 +45,6 @@ const ArchivePage = createClass({
|
|||||||
|
|
||||||
},
|
},
|
||||||
handleChange(inputName, e) {
|
handleChange(inputName, e) {
|
||||||
|
|
||||||
this.setState({ [inputName]: e.target.value });
|
this.setState({ [inputName]: e.target.value });
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -54,9 +62,11 @@ const ArchivePage = createClass({
|
|||||||
this.updateUrl();
|
this.updateUrl();
|
||||||
try {
|
try {
|
||||||
this.setState({ searching: true, error: null });
|
this.setState({ searching: true, error: null });
|
||||||
|
|
||||||
const title = encodeURIComponent(this.state.title);
|
const title = encodeURIComponent(this.state.title);
|
||||||
const size = parseInt(this.state.pageSize);
|
const size = parseInt(this.state.pageSize);
|
||||||
await request.get(`/api/archive?title=${title}&page=${page}&size=${size}`)
|
const {legacy, v3} = this.state;
|
||||||
|
await request.get(`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`)
|
||||||
.then((response)=>{
|
.then((response)=>{
|
||||||
if(response.ok) {
|
if(response.ok) {
|
||||||
this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews);
|
this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews);
|
||||||
@@ -75,16 +85,22 @@ const ArchivePage = createClass({
|
|||||||
|
|
||||||
urlParams.set('title', this.state.title);
|
urlParams.set('title', this.state.title);
|
||||||
urlParams.set('page', this.state.page);
|
urlParams.set('page', this.state.page);
|
||||||
|
urlParams.set('pageSize', this.state.pageSize);
|
||||||
|
urlParams.set('v3', this.state.v3);
|
||||||
|
urlParams.set('legacy', this.state.legacy);
|
||||||
|
|
||||||
|
|
||||||
url.search = urlParams.toString(); // Convert URLSearchParams to string
|
url.search = urlParams.toString(); // Convert URLSearchParams to string
|
||||||
window.history.replaceState(null, null, url);
|
window.history.replaceState(null, null, url);
|
||||||
},
|
},
|
||||||
|
|
||||||
renderPaginationControls() {
|
renderPaginationControls() {
|
||||||
const { title, brewCollection, page, totalPages, error } = this.state;
|
const { page, totalPages,} = this.state;
|
||||||
const pages = new Array(totalPages).fill().map((_, index) => (
|
const pages = new Array(totalPages).fill().map((_, index) => (
|
||||||
<li key={index} className={`pageNumber ${page === index + 1 ? 'currentPage' : ''}`} onClick={() => this.loadPage(index+1)}>{index + 1}</li>
|
<li key={index} className={`pageNumber ${page === index + 1 ? 'currentPage' : ''}`} onClick={() => this.loadPage(index+1)}>{index + 1}</li>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
if(totalPages === null) {return;}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="paginationControls">
|
<div className="paginationControls">
|
||||||
@@ -171,9 +187,33 @@ const ArchivePage = createClass({
|
|||||||
onChange={(e) => this.handleChange('pageSize', e)}
|
onChange={(e) => this.handleChange('pageSize', e)}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
onChange={()=>{this.setState({v3: !this.state.v3})}}
|
||||||
|
checked={this.state.v3}
|
||||||
|
/>
|
||||||
|
Search for v3 brews
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
onChange={()=>{this.setState({legacy: !this.state.legacy})}}
|
||||||
|
checked={this.state.legacy}
|
||||||
|
/>
|
||||||
|
Search for legacy brews
|
||||||
|
</label>
|
||||||
|
|
||||||
|
|
||||||
{/* In the future, we should be able to filter the results by adding tags.
|
{/* In the future, we should be able to filter the results by adding tags.
|
||||||
<label>Tags</label><input type='text' value={this.state.query} placeholder='add a tag to filter'/>
|
<<StringArrayEditor label='tags' valuePatterns={[/^(?:(?:group|meta|system|type):)?[A-Za-z0-9][A-Za-z0-9 \/.\-]{0,40}$/]}
|
||||||
<input type="checkbox" id="v3" /><label>v3 only</label>
|
placeholder='add tag' unique={true}
|
||||||
|
values={this.state.tags}
|
||||||
|
onChange={(e)=>this.handleChange('tags', e)}/>
|
||||||
|
|
||||||
|
check metadataEditor.jsx L65
|
||||||
*/}
|
*/}
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -7,17 +7,28 @@ const archive = {
|
|||||||
/* Searches for matching title, also attempts to partial match */
|
/* Searches for matching title, also attempts to partial match */
|
||||||
findBrews : async (req, res, next)=>{
|
findBrews : async (req, res, next)=>{
|
||||||
try {
|
try {
|
||||||
|
console.table(req.query);
|
||||||
|
|
||||||
const title = req.query.title || '';
|
const title = req.query.title || '';
|
||||||
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
const page = Math.max(parseInt(req.query.page) || 1, 1);
|
||||||
console.log('trying page ', page);
|
|
||||||
const minPageSize = 6;
|
const minPageSize = 6;
|
||||||
const pageSize = Math.max(parseInt(req.query.size) || 10, minPageSize);
|
const pageSize = Math.max(parseInt(req.query.size) || 10, minPageSize);
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
|
|
||||||
const titleQuery = {
|
const titleQuery = {
|
||||||
title : { $regex: decodeURIComponent(title), $options: 'i' },
|
title : { $regex: decodeURIComponent(title), $options: 'i' },
|
||||||
|
$or: [],
|
||||||
published : true
|
published : true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (req.query.legacy === 'true') {
|
||||||
|
titleQuery.$or.push({ renderer: 'legacy' });
|
||||||
|
};
|
||||||
|
|
||||||
|
if (req.query.v3 === 'true') {
|
||||||
|
titleQuery.$or.push({ renderer: 'V3' });
|
||||||
|
};
|
||||||
|
|
||||||
const projection = {
|
const projection = {
|
||||||
editId : 0,
|
editId : 0,
|
||||||
googleId : 0,
|
googleId : 0,
|
||||||
@@ -29,7 +40,7 @@ const archive = {
|
|||||||
.limit(pageSize)
|
.limit(pageSize)
|
||||||
.maxTimeMS(5000)
|
.maxTimeMS(5000)
|
||||||
.exec();
|
.exec();
|
||||||
console.log(brews.length);
|
//console.log(brews.length);
|
||||||
|
|
||||||
if(!brews || brews.length === 0) {
|
if(!brews || brews.length === 0) {
|
||||||
// No published documents found with the given title
|
// No published documents found with the given title
|
||||||
@@ -38,8 +49,8 @@ const archive = {
|
|||||||
const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection);
|
const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection);
|
||||||
|
|
||||||
const totalPages = Math.ceil(totalBrews / pageSize);
|
const totalPages = Math.ceil(totalBrews / pageSize);
|
||||||
console.log('Total brews: ', totalBrews);
|
//console.log('Total brews: ', totalBrews);
|
||||||
console.log('Total pages: ', totalPages);
|
//console.log('Total pages: ', totalPages);
|
||||||
return res.json({ brews, page, totalPages, totalBrews});
|
return res.json({ brews, page, totalPages, totalBrews});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user