Add options to sort the member list
This commit is contained in:
parent
393bf04180
commit
403b0be895
|
@ -60,6 +60,7 @@ class SearchViewSet(Base, Retrieve):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
queryset = models.Member.objects.all()
|
queryset = models.Member.objects.all()
|
||||||
search = self.request.data.get('q', '').lower()
|
search = self.request.data.get('q', '').lower()
|
||||||
|
sort = self.request.data.get('sort', '').lower()
|
||||||
|
|
||||||
if not cache.touch('search_strings'):
|
if not cache.touch('search_strings'):
|
||||||
utils.gen_search_strings() # init cache
|
utils.gen_search_strings() # init cache
|
||||||
|
@ -87,9 +88,23 @@ class SearchViewSet(Base, Retrieve):
|
||||||
|
|
||||||
queryset = result_objects
|
queryset = result_objects
|
||||||
logging.info('Search for: {}, results: {}'.format(search, len(queryset)))
|
logging.info('Search for: {}, results: {}'.format(search, len(queryset)))
|
||||||
elif self.action == 'create':
|
elif self.action == 'create' and sort == 'recently_vetted':
|
||||||
utils.gen_search_strings() # update cache
|
utils.gen_search_strings() # update cache
|
||||||
queryset = queryset.order_by('-vetted_date')
|
queryset = queryset.order_by('-vetted_date')
|
||||||
|
elif self.action == 'create' and sort == 'newest_active':
|
||||||
|
queryset = queryset.filter(paused_date__isnull=True)
|
||||||
|
queryset = queryset.order_by('-application_date')
|
||||||
|
elif self.action == 'create' and sort == 'newest_overall':
|
||||||
|
queryset = queryset.filter(paused_date__isnull=True)
|
||||||
|
queryset = queryset.order_by('-application_date')
|
||||||
|
elif self.action == 'create' and sort == 'oldest_active':
|
||||||
|
queryset = queryset.filter(paused_date__isnull=True)
|
||||||
|
queryset = queryset.order_by('application_date')
|
||||||
|
elif self.action == 'create' and sort == 'oldest_overall':
|
||||||
|
queryset = queryset.filter(application_date__isnull=False)
|
||||||
|
queryset = queryset.order_by('application_date')
|
||||||
|
elif self.action == 'create' and sort == 'best_looking':
|
||||||
|
queryset = []
|
||||||
|
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
@ -101,7 +116,13 @@ class SearchViewSet(Base, Retrieve):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
seq = 0
|
seq = 0
|
||||||
|
|
||||||
queryset = self.get_queryset()[:NUM_SEARCH_RESULTS]
|
search = self.request.data.get('q', '').lower()
|
||||||
|
if search:
|
||||||
|
num_results = NUM_SEARCH_RESULTS
|
||||||
|
else:
|
||||||
|
num_results = 100
|
||||||
|
|
||||||
|
queryset = self.get_queryset()[:num_results]
|
||||||
serializer = serializers.SearchSerializer(queryset, many=True)
|
serializer = serializers.SearchSerializer(queryset, many=True)
|
||||||
return Response({'seq': seq, 'results': serializer.data})
|
return Response({'seq': seq, 'results': serializer.data})
|
||||||
|
|
||||||
|
|
BIN
webclient/public/mr-bean.jpg
Normal file
BIN
webclient/public/mr-bean.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useEffect, useReducer } from 'react';
|
import React, { useState, useEffect, useReducer } from 'react';
|
||||||
import { BrowserRouter as Router, Switch, Route, Link, useParams } from 'react-router-dom';
|
import { BrowserRouter as Router, Switch, Route, Link, useParams, useLocation } from 'react-router-dom';
|
||||||
import './light.css';
|
import './light.css';
|
||||||
import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Input, Item, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Input, Item, Menu, Message, Segment, Table } from 'semantic-ui-react';
|
||||||
import { statusColor, isAdmin, isInstructor, BasicTable, staticUrl, requester } from './utils.js';
|
import { statusColor, isAdmin, isInstructor, BasicTable, staticUrl, requester } from './utils.js';
|
||||||
|
@ -7,6 +7,15 @@ import { NotFound, PleaseLogin } from './Misc.js';
|
||||||
import { AdminMemberInfo, AdminMemberPause, AdminMemberForm, AdminMemberCards, AdminMemberTraining, AdminMemberCertifications } from './AdminMembers.js';
|
import { AdminMemberInfo, AdminMemberPause, AdminMemberForm, AdminMemberCards, AdminMemberTraining, AdminMemberCertifications } from './AdminMembers.js';
|
||||||
import { AdminMemberTransactions } from './AdminTransactions.js';
|
import { AdminMemberTransactions } from './AdminTransactions.js';
|
||||||
|
|
||||||
|
const memberSorts = {
|
||||||
|
recently_vetted: 'Recently Vetted',
|
||||||
|
newest_active: 'Newest Active',
|
||||||
|
newest_overall: 'Newest Overall',
|
||||||
|
best_looking: 'Best Looking',
|
||||||
|
oldest_active: 'Oldest Active',
|
||||||
|
oldest_overall: 'Oldest Overall',
|
||||||
|
};
|
||||||
|
|
||||||
export function MembersDropdown(props) {
|
export function MembersDropdown(props) {
|
||||||
const { token, name, onChange, value, initial } = props;
|
const { token, name, onChange, value, initial } = props;
|
||||||
const [response, setResponse] = useState({ results: [] });
|
const [response, setResponse] = useState({ results: [] });
|
||||||
|
@ -52,13 +61,22 @@ export function MembersDropdown(props) {
|
||||||
let searchCache = '';
|
let searchCache = '';
|
||||||
|
|
||||||
export function Members(props) {
|
export function Members(props) {
|
||||||
|
const qs = useLocation().search;
|
||||||
|
const params = new URLSearchParams(qs);
|
||||||
|
const sort = params.get('sort') || 'recently_vetted';
|
||||||
|
|
||||||
const [response, setResponse] = useState(false);
|
const [response, setResponse] = useState(false);
|
||||||
|
const [numShow, setNumShow] = useState(20);
|
||||||
const searchDefault = {seq: 0, q: searchCache};
|
const searchDefault = {seq: 0, q: searchCache};
|
||||||
const [search, setSearch] = useState(searchDefault);
|
const [search, setSearch] = useState(searchDefault);
|
||||||
const { token } = props;
|
const { token } = props;
|
||||||
|
|
||||||
|
console.log(sort);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setResponse(false);
|
||||||
searchCache = search.q;
|
searchCache = search.q;
|
||||||
|
search.sort = sort;
|
||||||
requester('/search/', 'POST', token, search)
|
requester('/search/', 'POST', token, search)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (!search.seq || res.seq > response.seq) {
|
if (!search.seq || res.seq > response.seq) {
|
||||||
|
@ -68,7 +86,7 @@ export function Members(props) {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}, [search]);
|
}, [search, sort]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
@ -91,15 +109,34 @@ export function Members(props) {
|
||||||
/> : ''
|
/> : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<p></p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Sort by{' '}
|
||||||
|
{Object.entries(memberSorts).map((x, i) =>
|
||||||
|
<>
|
||||||
|
<Link to={'/members?sort='+x[0]} replace>{x[1]}</Link>
|
||||||
|
{i < Object.keys(memberSorts).length - 1 && ', '}
|
||||||
|
</>
|
||||||
|
)}.
|
||||||
|
</p>
|
||||||
|
|
||||||
<Header size='medium'>
|
<Header size='medium'>
|
||||||
{search.q.length ? 'Search Results' : 'Newest Vetted Members'}
|
{search.q.length ? 'Search Results' : memberSorts[sort] + ' Members'}
|
||||||
</Header>
|
</Header>
|
||||||
|
|
||||||
{response ?
|
{sort === 'best_looking' ?
|
||||||
|
<center>
|
||||||
|
<img className='bean' src='/mr-bean.jpg' />
|
||||||
|
</center>
|
||||||
|
:
|
||||||
|
response ?
|
||||||
|
<>
|
||||||
<Item.Group unstackable divided>
|
<Item.Group unstackable divided>
|
||||||
{response.results.length ?
|
{response.results.length ?
|
||||||
response.results.map(x =>
|
response.results.slice(0, numShow).map((x, i) =>
|
||||||
<Item key={x.member.id} as={Link} to={'/members/'+x.member.id}>
|
<Item key={x.member.id} as={Link} to={'/members/'+x.member.id}>
|
||||||
|
<div className='list-num'>{i+1}</div>
|
||||||
<Item.Image size='tiny' src={x.member.photo_small ? staticUrl + '/' + x.member.photo_small : '/nophoto.png'} />
|
<Item.Image size='tiny' src={x.member.photo_small ? staticUrl + '/' + x.member.photo_small : '/nophoto.png'} />
|
||||||
<Item.Content verticalAlign='top'>
|
<Item.Content verticalAlign='top'>
|
||||||
<Item.Header>
|
<Item.Header>
|
||||||
|
@ -108,6 +145,7 @@ export function Members(props) {
|
||||||
</Item.Header>
|
</Item.Header>
|
||||||
<Item.Description>Status: {x.member.status || 'Unknown'}</Item.Description>
|
<Item.Description>Status: {x.member.status || 'Unknown'}</Item.Description>
|
||||||
<Item.Description>Joined: {x.member.application_date || 'Unknown'}</Item.Description>
|
<Item.Description>Joined: {x.member.application_date || 'Unknown'}</Item.Description>
|
||||||
|
<Item.Description>ID: {x.member.id}</Item.Description>
|
||||||
</Item.Content>
|
</Item.Content>
|
||||||
</Item>
|
</Item>
|
||||||
)
|
)
|
||||||
|
@ -115,6 +153,14 @@ export function Members(props) {
|
||||||
<p>No Results</p>
|
<p>No Results</p>
|
||||||
}
|
}
|
||||||
</Item.Group>
|
</Item.Group>
|
||||||
|
|
||||||
|
{numShow !== 100 ?
|
||||||
|
<Button
|
||||||
|
content='Load More'
|
||||||
|
onClick={() => setNumShow(100)}
|
||||||
|
/> : ''
|
||||||
|
}
|
||||||
|
</>
|
||||||
:
|
:
|
||||||
<p>Loading...</p>
|
<p>Loading...</p>
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,6 +117,13 @@ body {
|
||||||
margin-left: 1rem;
|
margin-left: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.list-num {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
margin-right: 1rem;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
margin-top: -20rem;
|
margin-top: -20rem;
|
||||||
background: black;
|
background: black;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user