From 96fa0953e39b0523ad47bb3f7b76d6de7f29e441 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sun, 29 Jun 2014 20:58:34 -0700 Subject: [PATCH] Fixed issues with popup notifications. --- gui/slick/js/ajaxNotifications.js | 8 +++--- sickbeard/__init__.py | 3 +-- sickbeard/ui.py | 44 +++++++++++-------------------- sickbeard/webapi.py | 2 +- sickbeard/webserve.py | 6 +---- 5 files changed, 23 insertions(+), 40 deletions(-) diff --git a/gui/slick/js/ajaxNotifications.js b/gui/slick/js/ajaxNotifications.js index b87f4af7..d6b7c7d4 100644 --- a/gui/slick/js/ajaxNotifications.js +++ b/gui/slick/js/ajaxNotifications.js @@ -14,10 +14,10 @@ function check_notifications() { poll_interval = 5000; $.each(data, function (name, data) { $.pnotify({ - type: data.type, - hide: data.type == 'notice', - title: data.title, - text: data.message + pnotify_type: data.type, + pnotify_hide: data.type == 'notice', + pnotify_title: data.title, + pnotify_text: data.message }); }); }, diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index d551e829..05fbc778 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -123,7 +123,6 @@ HANDLE_REVERSE_PROXY = None PROXY_SETTING = None LOCALHOST_IP = None -REMOTE_IP = None CPU_PRESET = None @@ -476,7 +475,7 @@ def initialize(consoleLogging=True): GUI_NAME, HOME_LAYOUT, HISTORY_LAYOUT, DISPLAY_SHOW_SPECIALS, COMING_EPS_LAYOUT, COMING_EPS_SORT, COMING_EPS_DISPLAY_PAUSED, COMING_EPS_MISSED_RANGE, FUZZY_DATING, TRIM_ZERO, DATE_PRESET, TIME_PRESET, TIME_PRESET_W_SECONDS, \ METADATA_WDTV, METADATA_TIVO, METADATA_MEDE8ER, IGNORE_WORDS, CALENDAR_UNPROTECTED, CREATE_MISSING_SHOW_DIRS, \ ADD_SHOWS_WO_DIR, USE_SUBTITLES, SUBTITLES_LANGUAGES, SUBTITLES_DIR, SUBTITLES_SERVICES_LIST, SUBTITLES_SERVICES_ENABLED, SUBTITLES_HISTORY, SUBTITLES_FINDER_FREQUENCY, subtitlesFinderScheduler, \ - USE_FAILED_DOWNLOADS, DELETE_FAILED, ANON_REDIRECT, LOCALHOST_IP, REMOTE_IP, TMDB_API_KEY, DEBUG, PROXY_SETTING, \ + USE_FAILED_DOWNLOADS, DELETE_FAILED, ANON_REDIRECT, LOCALHOST_IP, TMDB_API_KEY, DEBUG, PROXY_SETTING, \ AUTOPOSTPROCESSER_FREQUENCY, DEFAULT_AUTOPOSTPROCESSER_FREQUENCY, MIN_AUTOPOSTPROCESSER_FREQUENCY, \ ANIME_DEFAULT, NAMING_ANIME, ANIMESUPPORT, USE_ANIDB, ANIDB_USERNAME, ANIDB_PASSWORD, ANIDB_USE_MYLIST, \ ANIME_SPLIT_HOME, maintenanceScheduler, SCENE_DEFAULT, RES diff --git a/sickbeard/ui.py b/sickbeard/ui.py index c1c689d5..43044c6c 100644 --- a/sickbeard/ui.py +++ b/sickbeard/ui.py @@ -19,17 +19,13 @@ import datetime import sickbeard -from tornado.web import RequestHandler - MESSAGE = 'notice' ERROR = 'error' - class Notifications(object): """ A queue of Notification objects. """ - def __init__(self): self._messages = [] self._errors = [] @@ -37,9 +33,9 @@ class Notifications(object): def message(self, title, message=''): """ Add a regular notification to the queue - + title: The title of the notification - message: The message portion of the notification + message: The message portion of the notification """ self._messages.append(Notification(title, message, MESSAGE)) @@ -48,24 +44,24 @@ class Notifications(object): Add an error notification to the queue title: The title of the notification - message: The message portion of the notification + message: The message portion of the notification """ self._errors.append(Notification(title, message, ERROR)) - def get_notifications(self): + def get_notifications(self, remote_ip='127.0.0.1'): """ Return all the available notifications in a list. Marks them all as seen as it returns them. Also removes timed out Notifications from the queue. - + Returns: A list of Notification objects """ - # filter out expired notifications + # filter out expired notifications self._errors = [x for x in self._errors if not x.is_expired()] self._messages = [x for x in self._messages if not x.is_expired()] # return any notifications that haven't been shown to the client already - return [x.see() for x in self._errors + self._messages if x.is_new()] + return [x.see(remote_ip) for x in self._errors + self._messages if x.is_new(remote_ip)] # static notification queue object notifications = Notifications() @@ -76,7 +72,6 @@ class Notification(object): Represents a single notification. Tracks its own timeout and a list of which clients have seen it before. """ - def __init__(self, title, message='', type=None, timeout=None): self.title = title self.message = message @@ -94,11 +89,11 @@ class Notification(object): else: self._timeout = datetime.timedelta(minutes=1) - def is_new(self): + def is_new(self, remote_ip='127.0.0.1'): """ Returns True if the notification hasn't been displayed to the current client (aka IP address). """ - return sickbeard.REMOTE_IP not in self._seen + return remote_ip not in self._seen def is_expired(self): """ @@ -107,25 +102,24 @@ class Notification(object): return datetime.datetime.now() - self._when > self._timeout - def see(self): + def see(self, remote_ip='127.0.0.1'): """ Returns this notification object and marks it as seen by the client ip """ - self._seen.append(sickbeard.REMOTE_IP) + self._seen.append(remote_ip) return self - class ProgressIndicator(): + def __init__(self, percentComplete=0, currentStatus={'title': ''}): self.percentComplete = percentComplete self.currentStatus = currentStatus - class ProgressIndicators(): _pi = {'massUpdate': [], 'massAdd': [], 'dailyUpdate': [] - } + } @staticmethod def getIndicator(name): @@ -144,12 +138,10 @@ class ProgressIndicators(): def setIndicator(name, indicator): ProgressIndicators._pi[name].append(indicator) - class QueueProgressIndicator(): """ A class used by the UI to show the progress of the queue or a part of it. """ - def __init__(self, name, queueItemList): self.queueItemList = queueItemList self.name = name @@ -164,8 +156,7 @@ class QueueProgressIndicator(): return len([x for x in self.queueItemList if x.isInQueue()]) def nextName(self): - for curItem in [ - sickbeard.showQueueScheduler.action.currentItem] + sickbeard.showQueueScheduler.action.queue: #@UndefinedVariable + for curItem in [sickbeard.showQueueScheduler.action.currentItem]+sickbeard.showQueueScheduler.action.queue: #@UndefinedVariable if curItem in self.queueItemList: return curItem.name @@ -178,12 +169,9 @@ class QueueProgressIndicator(): if numTotal == 0: return 0 else: - return int(float(numFinished) / float(numTotal) * 100) - + return int(float(numFinished)/float(numTotal)*100) class LoadingTVShow(): def __init__(self, dir): self.dir = dir - self.show = None - - + self.show = None \ No newline at end of file diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index 87f310f8..9be9839a 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -1450,7 +1450,7 @@ class CMD_SickBeardGetMessages(ApiCall): def run(self): messages = [] - for cur_notification in ui.notifications.get_notifications(): + for cur_notification in ui.notifications.get_notifications(self.handler.request.remote_ip): messages.append({"title": cur_notification.title, "message": cur_notification.message, "type": cur_notification.type}) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 0600469e..997fc859 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -144,10 +144,6 @@ def redirect(url, permanent=False, status=None): @authenticated class MainHandler(RequestHandler): - def __init__(self, application, request, **kwargs): - super(MainHandler, self).__init__(application, request, **kwargs) - sickbeard.REMOTE_IP = self.request.headers.get('X-Forwarded-For', self.request.headers.get('X-Real-Ip', self.request.remote_ip)) - def http_error_401_handler(self): """ Custom handler for 401 error """ return r''' @@ -4305,7 +4301,7 @@ class UI(MainHandler): def get_messages(self): messages = {} cur_notification_num = 1 - for cur_notification in ui.notifications.get_notifications(): + for cur_notification in ui.notifications.get_notifications(self.request.remote_ip): messages['notification-' + str(cur_notification_num)] = {'title': cur_notification.title, 'message': cur_notification.message, 'type': cur_notification.type}