diff --git a/apiserver/apiserver/api/utils_stats.py b/apiserver/apiserver/api/utils_stats.py index 7088ece..570efc5 100644 --- a/apiserver/apiserver/api/utils_stats.py +++ b/apiserver/apiserver/api/utils_stats.py @@ -28,6 +28,7 @@ DEFAULTS = { 'track': {}, 'alarm': {}, 'sign': '', + 'autoscan': '', } if secrets.MUMBLE: diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index e12284f..64d9a9a 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -538,6 +538,7 @@ class StatsViewSet(viewsets.ViewSet, List): user = self.request.user if not user.is_authenticated: stats.pop('alarm', None) + stats.pop('autoscan', None) stats['at_protospace'] = utils.is_request_from_protospace(request) @@ -682,6 +683,14 @@ class StatsViewSet(viewsets.ViewSet, List): 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): pagination_class = None diff --git a/webclient/src/AdminMembers.js b/webclient/src/AdminMembers.js index b8d1ec7..77ff5c2 100644 --- a/webclient/src/AdminMembers.js +++ b/webclient/src/AdminMembers.js @@ -122,6 +122,8 @@ function AdminCardDetail(props) { ); }; +let prevAutoscan = ''; + export function AdminMemberCards(props) { const { token, result, refreshResult } = props; 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) => { e.preventDefault(); requester('/members/' + id + '/card_photo/', 'GET', token) @@ -193,18 +224,16 @@ export function AdminMemberCards(props) {
Edit Member Cards
-
-
Add a Card
+ {result.member.photo_large ? +

+ +

+ : +

No card image, member photo missing!

+ } - {result.member.photo_large ? -

- -

- : -

No card image, member photo missing!

- } - - {cardPhoto && <> + {cardPhoto && +

@@ -219,41 +248,41 @@ export function AdminMemberCards(props) {
  • Scan card, add the number
  • Have them test their card
  • - } - - - - - + + + + + - + - - Submit - - {success &&
    Success!
    } - + + Submit + + {success &&
    Success!
    } + + }
    Current Cards