From 7e8713171ee30cb2e80cf80b9cd0cc7cabcef925 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 5 Aug 2014 17:45:40 -0400 Subject: [PATCH] - Change updated_tags into the expected dict, not a list - Update the event code on both sides to expect the dict - Add filter support to the string builder --- endpoints/notificationevent.py | 6 +++--- initdb.py | 2 +- static/js/app.js | 34 +++++++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/endpoints/notificationevent.py b/endpoints/notificationevent.py index ed0e20716..f1cbec42c 100644 --- a/endpoints/notificationevent.py +++ b/endpoints/notificationevent.py @@ -59,7 +59,7 @@ class RepoPushEvent(NotificationEvent): return 'Repository %s updated' % (event_data['repository']) def get_message(self, event_data, notification_data): - if not event_data.get('updated_tags', []): + if not event_data.get('updated_tags', {}).keys(): html = """ Repository %s has been updated via a push. """ % (event_data['homepage'], @@ -71,13 +71,13 @@ class RepoPushEvent(NotificationEvent): Tags Updated: %s """ % (event_data['homepage'], event_data['repository'], - ', '.join(event_data['updated_tags'])) + ', '.join(event_data['updated_tags'].keys())) return html def get_sample_data(self, repository): return build_event_data(repository, { - 'updated_tags': ['latest', 'foo', 'bar'], + 'updated_tags': {'latest': 'someimageid', 'foo': 'anotherimage'}, 'pushed_image_count': 10, 'pruned_image_count': 3 }) diff --git a/initdb.py b/initdb.py index 1a3265a68..7e48ae3af 100644 --- a/initdb.py +++ b/initdb.py @@ -313,7 +313,7 @@ def populate_database(): outside_org.verified = True outside_org.save() - model.create_notification('test_notification', new_user_1, metadata={'some': 'value'}) + model.create_notification('test_notification', new_user_1, metadata={'some': 'value', 'arr': [1,2,3], 'obj': {'a': 1, 'b': 2}}) from_date = datetime.utcnow() to_date = from_date + timedelta(hours=1) diff --git a/static/js/app.js b/static/js/app.js index f46fea5a1..a35d7f1c0 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -548,6 +548,18 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading 'client_id': 'chain' }; + var filters = { + 'obj': function(value) { + if (!value) { return []; } + return Object.getOwnPropertyNames(value); + }, + + 'updated_tags': function(value) { + if (!value) { return []; } + return Object.getOwnPropertyNames(value); + } + }; + var description = value_or_func; if (typeof description != 'string') { description = description(metadata); @@ -555,7 +567,17 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading for (var key in metadata) { if (metadata.hasOwnProperty(key)) { - var value = metadata[key] != null ? metadata[key].toString() : '(Unknown)'; + var value = metadata[key] != null ? metadata[key] : '(Unknown)'; + if (filters[key]) { + value = filters[key](value); + } + + if (Array.isArray(value)) { + value = value.join(', '); + } + + value = value.toString(); + if (key.indexOf('image') >= 0) { value = value.substr(0, 12); } @@ -1083,7 +1105,7 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading var notificationKinds = { 'test_notification': { 'level': 'primary', - 'message': 'This notification is a long message for testing', + 'message': 'This notification is a long message for testing: {obj}', 'page': '/about/', 'dismissable': true }, @@ -1119,7 +1141,13 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading }, 'repo_push': { 'level': 'info', - 'message': 'Repository {repository} has been pushed with the following tags updated: {updated_tags}', + 'message': function(metadata) { + if (metadata.updated_tags && Object.getOwnPropertyNames(metadata.updated_tags).length) { + return 'Repository {repository} has been pushed with the following tags updated: {updated_tags}'; + } else { + return 'Repository {repository} has been pushed'; + } + }, 'page': function(metadata) { return '/repository/' + metadata.repository; },