Example #1
0
 def announceMessage(self,
                     message,
                     duration=3000,
                     level='default',
                     horizontal='left',
                     vertical='bottom'):
     """
     Please see docu in Dataclasses/Antrag.py in announceMessage method
     :param message:
     :param duration:
     :param level:
     :param horizontal:
     :param vertical:
     :return:
     """
     logger.debug(f"Announce message: {message}")
     msg = json.dumps({
         'text': message,
         'autoHideDuration': duration,
         'variant': level,
         'anchorOrigin': {
             'horizontal': horizontal,
             'vertical': vertical,
         }
     })
     messenger.announce(f"data: {msg}\n\n")
Example #2
0
def notifications():
    user = auth.current_user()
    toast = db.session.query(ToastNotifications).filter_by(
        seen_at=None).filter_by(user_id=user.id).filter_by(
            company_id=user.company_id).first()
    if toast:
        if toast.type == "badge":
            badge = db.session.query(GamificationBadge).filter_by(
                id=toast.message).first()
            if badge:
                messenger.announce_badge(badge=badge, duration=5000)
            else:
                logger.info(f"Badge id {str(toast.message)} not found.")
        else:
            msg = json.dumps({
                'text': toast.message,
                'autoHideDuration': toast.duration,
                'variant': toast.type,
                'anchorOrigin': {
                    'horizontal': toast.horizontal,
                    'vertical': toast.vertical,
                }
            })
            messenger.announce(f'data: {msg}\n\n')
        toast.set_seen()
        return Response(response=f"New Notifications found", status=200)
    return Response(response=f"No Notification", status=200)
Example #3
0
 def announceMessage(message,
                     duration=3000,
                     level='default',
                     horizontal='left',
                     vertical='bottom'):
     """
     Will send a toast to the frontend
     :param message: The message text.
     :param duration: None = user needs to click "close" in order to disappear, any other value in MilliSeconds
                      until the Toast disappears
     :param level: 'info' will provide blue background with white font,
                   'default' will provide black background with white font,
                   'success' will bring green backgroudn
                   'error' --> red background
                   'warning' --> orange background
     :param horizontal: "left", "right", "center"
     :param vertical: "bottom", "top"
     :return:
     """
     logger.debug(f"Announce: {message}")
     msg = json.dumps({
         'text': message,
         'autoHideDuration': duration,
         'variant': level,
         'anchorOrigin': {
             'horizontal': horizontal,
             'vertical': vertical,
         }
     })
     messenger.announce(f"data: {msg}\n\n")
Example #4
0
def ping():
    #msg = messenger.format_sse(data='ping', event='fasifu')
    data = {
        'text': 'Fasifu message!',
        #'variant': 'success',
        #'anchorOrigin': {
        #    'vertical': 'top',
        #    'horizontal': 'left',
        #},
        #'autoHideDuration': 2000,
    }
    msg = f"data: {json.dumps(data)}\n\n"
    messenger.announce(msg=msg)
    return {'success': msg}, 200
Example #5
0
def push_link():
    #msg = messenger.format_sse(data='ping', event='fasifu')
    data = {
        'text':
        'Follow the&nbsp;<a href="https://en.wikipedia.org/wiki/White_Rabbit">White Rabbit!</a>',
        'variant': 'success',
        'anchorOrigin': {
            'vertical': 'top',
            'horizontal': 'center',
        },
        'autoHideDuration': None,
    }
    msg = f"data: {json.dumps(data)}\n\n"
    messenger.announce(msg=msg)
    return {'success': msg}, 200