Automatically fill out card number

This commit is contained in:
Tanner Collin 2022-02-06 23:46:58 +00:00
parent 0d19cd8662
commit d535113ca5
3 changed files with 82 additions and 43 deletions

View File

@ -28,6 +28,7 @@ DEFAULTS = {
'track': {}, 'track': {},
'alarm': {}, 'alarm': {},
'sign': '', 'sign': '',
'autoscan': '',
} }
if secrets.MUMBLE: if secrets.MUMBLE:

View File

@ -538,6 +538,7 @@ class StatsViewSet(viewsets.ViewSet, List):
user = self.request.user user = self.request.user
if not user.is_authenticated: if not user.is_authenticated:
stats.pop('alarm', None) stats.pop('alarm', None)
stats.pop('autoscan', None)
stats['at_protospace'] = utils.is_request_from_protospace(request) stats['at_protospace'] = utils.is_request_from_protospace(request)
@ -682,6 +683,14 @@ class StatsViewSet(viewsets.ViewSet, List):
return Response(200) return Response(200)
@action(detail=False, methods=['post'])
def autoscan(self, request):
if 'autoscan' not in request.data:
raise exceptions.ValidationError(dict(autoscan='This field is required.'))
cache.set('autoscan', request.data['autoscan'])
return Response(200)
class MemberCountViewSet(Base, List): class MemberCountViewSet(Base, List):
pagination_class = None pagination_class = None

View File

@ -122,6 +122,8 @@ function AdminCardDetail(props) {
); );
}; };
let prevAutoscan = '';
export function AdminMemberCards(props) { export function AdminMemberCards(props) {
const { token, result, refreshResult } = props; const { token, result, refreshResult } = props;
const cards = result.cards; const cards = result.cards;
@ -163,6 +165,35 @@ export function AdminMemberCards(props) {
}); });
}; };
const getAutoscan = () => {
return requester('/stats/', 'GET', token)
.then(res => {
return res?.autoscan;
})
.catch(err => {
console.log(err);
});
};
const checkAutoscan = () => {
getAutoscan().then(newScan => {
if (newScan != prevAutoscan) {
prevAutoscan = newScan;
setInput({ ...input, card_number: newScan });
}
});
};
useEffect(() => {
if (cardPhoto) {
getAutoscan().then(scan => {
prevAutoscan = scan;
});
const interval = setInterval(checkAutoscan, 1000);
return () => clearInterval(interval);
}
}, [cardPhoto]);
const getCardPhoto = (e) => { const getCardPhoto = (e) => {
e.preventDefault(); e.preventDefault();
requester('/members/' + id + '/card_photo/', 'GET', token) requester('/members/' + id + '/card_photo/', 'GET', token)
@ -193,18 +224,16 @@ export function AdminMemberCards(props) {
<div> <div>
<Header size='medium'>Edit Member Cards</Header> <Header size='medium'>Edit Member Cards</Header>
<Form onSubmit={handleSubmit}> {result.member.photo_large ?
<Header size='small'>Add a Card</Header> <p>
<Button onClick={(e) => getCardPhoto(e)}>Add a Card</Button>
</p>
:
<p>No card image, member photo missing!</p>
}
{result.member.photo_large ? {cardPhoto &&
<p> <Form onSubmit={handleSubmit}>
<Button onClick={(e) => getCardPhoto(e)}>View card image</Button>
</p>
:
<p>No card image, member photo missing!</p>
}
{cardPhoto && <>
<p> <p>
<Image rounded size='medium' src={cardPhoto} /> <Image rounded size='medium' src={cardPhoto} />
</p> </p>
@ -219,41 +248,41 @@ export function AdminMemberCards(props) {
<li>Scan card, add the number</li> <li>Scan card, add the number</li>
<li><b>Have them test their card</b></li> <li><b>Have them test their card</b></li>
</ol> </ol>
</>}
<Form.Group widths='equal'> <Form.Group widths='equal'>
<Form.Input <Form.Input
label='Card Number' label='Card Number (Listening...)'
fluid fluid
{...makeProps('card_number')} {...makeProps('card_number')}
/> />
<Form.Select <Form.Select
label='Card Status' label='Card Status'
options={statusOptions} options={statusOptions}
fluid fluid
{...makeProps('active_status')} {...makeProps('active_status')}
onChange={handleValues} onChange={handleValues}
/> />
<Form.Input <Form.Input
label='Optional Note' label='Optional Note'
fluid fluid
{...makeProps('notes')} {...makeProps('notes')}
/> />
</Form.Group> </Form.Group>
<Form.Checkbox <Form.Checkbox
label='Confirmed that the member has been given a tour and knows the alarm code' label='Confirmed that the member has been given a tour and knows the alarm code'
required required
{...makeProps('given_tour')} {...makeProps('given_tour')}
onChange={handleCheck} onChange={handleCheck}
checked={input.given_tour} checked={input.given_tour}
/> />
<Form.Button disabled={!input.given_tour} loading={loading} error={error.non_field_errors}> <Form.Button disabled={!input.given_tour} loading={loading} error={error.non_field_errors}>
Submit Submit
</Form.Button> </Form.Button>
{success && <div>Success!</div>} {success && <div>Success!</div>}
</Form> </Form>
}
<Header size='small'>Current Cards</Header> <Header size='small'>Current Cards</Header>