Show More
@@ -566,6 +566,10 b' def make_map(config):' | |||||
566 | '/my_account/toggle_visibility', |
|
566 | '/my_account/toggle_visibility', | |
567 | action='my_notifications_toggle_visibility', |
|
567 | action='my_notifications_toggle_visibility', | |
568 | conditions={'method': ['POST']}) |
|
568 | conditions={'method': ['POST']}) | |
|
569 | m.connect('my_account_notifications_test_channelstream', | |||
|
570 | '/my_account/test_channelstream', | |||
|
571 | action='my_account_notifications_test_channelstream', | |||
|
572 | conditions={'method': ['POST']}) | |||
569 |
|
573 | |||
570 | # NOTIFICATION REST ROUTES |
|
574 | # NOTIFICATION REST ROUTES | |
571 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
575 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
@@ -24,13 +24,16 b' my account controller for RhodeCode admi' | |||||
24 | """ |
|
24 | """ | |
25 |
|
25 | |||
26 | import logging |
|
26 | import logging | |
|
27 | import datetime | |||
27 |
|
28 | |||
28 | import formencode |
|
29 | import formencode | |
29 | from formencode import htmlfill |
|
30 | from formencode import htmlfill | |
|
31 | from pyramid.threadlocal import get_current_registry | |||
30 | from pylons import request, tmpl_context as c, url, session |
|
32 | from pylons import request, tmpl_context as c, url, session | |
31 | from pylons.controllers.util import redirect |
|
33 | from pylons.controllers.util import redirect | |
32 | from pylons.i18n.translation import _ |
|
34 | from pylons.i18n.translation import _ | |
33 | from sqlalchemy.orm import joinedload |
|
35 | from sqlalchemy.orm import joinedload | |
|
36 | from webob.exc import HTTPBadGateway | |||
34 |
|
37 | |||
35 | from rhodecode import forms |
|
38 | from rhodecode import forms | |
36 | from rhodecode.lib import helpers as h |
|
39 | from rhodecode.lib import helpers as h | |
@@ -41,6 +44,8 b' from rhodecode.lib.base import BaseContr' | |||||
41 | from rhodecode.lib.utils import jsonify |
|
44 | from rhodecode.lib.utils import jsonify | |
42 | from rhodecode.lib.utils2 import safe_int, md5, str2bool |
|
45 | from rhodecode.lib.utils2 import safe_int, md5, str2bool | |
43 | from rhodecode.lib.ext_json import json |
|
46 | from rhodecode.lib.ext_json import json | |
|
47 | from rhodecode.lib.channelstream import channelstream_request, \ | |||
|
48 | ChannelstreamException | |||
44 |
|
49 | |||
45 | from rhodecode.model.validation_schema.schemas import user_schema |
|
50 | from rhodecode.model.validation_schema.schemas import user_schema | |
46 | from rhodecode.model.db import ( |
|
51 | from rhodecode.model.db import ( | |
@@ -430,3 +435,33 b' class MyAccountController(BaseController' | |||||
430 | user.update_userdata(notification_status=new_status) |
|
435 | user.update_userdata(notification_status=new_status) | |
431 | Session().commit() |
|
436 | Session().commit() | |
432 | return user.user_data['notification_status'] |
|
437 | return user.user_data['notification_status'] | |
|
438 | ||||
|
439 | @auth.CSRFRequired() | |||
|
440 | @jsonify | |||
|
441 | def my_account_notifications_test_channelstream(self): | |||
|
442 | message = 'Test message sent via Channelstream by user: {}, on {}'.format( | |||
|
443 | c.rhodecode_user.username, datetime.datetime.now()) | |||
|
444 | payload = { | |||
|
445 | 'type': 'message', | |||
|
446 | 'timestamp': datetime.datetime.utcnow(), | |||
|
447 | 'user': 'system', | |||
|
448 | #'channel': 'broadcast', | |||
|
449 | 'pm_users': [c.rhodecode_user.username], | |||
|
450 | 'message': { | |||
|
451 | 'message': message, | |||
|
452 | 'level': 'info', | |||
|
453 | 'topic': '/notifications' | |||
|
454 | } | |||
|
455 | } | |||
|
456 | ||||
|
457 | registry = get_current_registry() | |||
|
458 | rhodecode_plugins = getattr(registry, 'rhodecode_plugins', {}) | |||
|
459 | channelstream_config = rhodecode_plugins.get('channelstream', {}) | |||
|
460 | ||||
|
461 | try: | |||
|
462 | channelstream_request(channelstream_config, [payload], '/message') | |||
|
463 | except ChannelstreamException as e: | |||
|
464 | log.exception('Failed to send channelstream data') | |||
|
465 | return {"response": 'ERROR: {}'.format(e.__class__.__name__)} | |||
|
466 | return {"response": 'Channelstream data sent. ' | |||
|
467 | 'You should see a new live message now.'} |
@@ -5,13 +5,22 b'' | |||||
5 | content-type="application/json" |
|
5 | content-type="application/json" | |
6 | loading="{{changeNotificationsLoading}}" |
|
6 | loading="{{changeNotificationsLoading}}" | |
7 | on-response="handleNotifications" |
|
7 | on-response="handleNotifications" | |
8 |
handle-as="json"> |
|
8 | handle-as="json"> | |
|
9 | </iron-ajax> | |||
|
10 | ||||
|
11 | <iron-ajax id="sendTestNotification" | |||
|
12 | method="post" | |||
|
13 | url="${url('my_account_notifications_test_channelstream')}" | |||
|
14 | content-type="application/json" | |||
|
15 | on-response="handleTestNotification" | |||
|
16 | handle-as="json"> | |||
|
17 | </iron-ajax> | |||
9 |
|
18 | |||
10 | <div class="panel panel-default"> |
|
19 | <div class="panel panel-default"> | |
11 | <div class="panel-heading"> |
|
20 | <div class="panel-heading"> | |
12 | <h3 class="panel-title">${_('Your Live Notification Settings')}</h3> |
|
21 | <h3 class="panel-title">${_('Your Live Notification Settings')}</h3> | |
13 | </div> |
|
22 | </div> | |
14 |
|
|
23 | <div class="panel-body"> | |
15 |
|
24 | |||
16 | <p><strong>IMPORTANT:</strong> This feature requires enabled channelstream websocket server to function correctly.</p> |
|
25 | <p><strong>IMPORTANT:</strong> This feature requires enabled channelstream websocket server to function correctly.</p> | |
17 |
|
26 | |||
@@ -27,13 +36,29 b'' | |||||
27 | <rhodecode-toggle id="live-notifications" active="[[changeNotificationsLoading]]" on-change="toggleNotifications" ${'checked' if c.rhodecode_user.get_instance().user_data.get('notification_status') else ''}></rhodecode-toggle> |
|
36 | <rhodecode-toggle id="live-notifications" active="[[changeNotificationsLoading]]" on-change="toggleNotifications" ${'checked' if c.rhodecode_user.get_instance().user_data.get('notification_status') else ''}></rhodecode-toggle> | |
28 | </div> |
|
37 | </div> | |
29 | </div> |
|
38 | </div> | |
30 | <div class="buttons"> |
|
|||
31 | <a class="btn btn-default" id="test-notification" on-tap="testNotifications">Test notification</a> |
|
|||
32 | </div> |
|
|||
33 | </div> |
|
39 | </div> | |
34 | </div> |
|
40 | </div> | |
|
41 | </div> | |||
|
42 | </div> | |||
35 |
|
43 | |||
36 | </div> |
|
44 | <div class="panel panel-default"> | |
|
45 | <div class="panel-heading"> | |||
|
46 | <h3 class="panel-title">${_('Test Notifications')}</h3> | |||
|
47 | </div> | |||
|
48 | <div class="panel-body"> | |||
|
49 | ||||
|
50 | ||||
|
51 | <div style="padding: 0px 0px 20px 0px"> | |||
|
52 | <button class="btn" id="test-notification" on-tap="testNotifications">Test flash message</button> | |||
|
53 | <button class="btn" id="test-notification-live" on-tap="testNotificationsLive">Test live notification</button> | |||
|
54 | </div> | |||
|
55 | <h4 id="test-response"></h4> | |||
|
56 | </div> | |||
|
57 | ||||
|
58 | </div> | |||
|
59 | ||||
|
60 | ||||
|
61 | ||||
37 | </div> |
|
62 | </div> | |
38 |
|
63 | |||
39 | <script type="text/javascript"> |
|
64 | <script type="text/javascript"> | |
@@ -45,7 +70,7 b'' | |||||
45 | var ctrlr = $('#notificationsPage')[0]; |
|
70 | var ctrlr = $('#notificationsPage')[0]; | |
46 | ctrlr.toggleNotifications = function(event){ |
|
71 | ctrlr.toggleNotifications = function(event){ | |
47 | var ajax = $('#toggleNotifications')[0]; |
|
72 | var ajax = $('#toggleNotifications')[0]; | |
48 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN} |
|
73 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; | |
49 | ajax.body = {notification_status:event.target.active}; |
|
74 | ajax.body = {notification_status:event.target.active}; | |
50 | ajax.generateRequest(); |
|
75 | ajax.generateRequest(); | |
51 | }; |
|
76 | }; | |
@@ -58,13 +83,25 b'' | |||||
58 | var level = levels[Math.floor(Math.random()*levels.length)]; |
|
83 | var level = levels[Math.floor(Math.random()*levels.length)]; | |
59 | var payload = { |
|
84 | var payload = { | |
60 | message: { |
|
85 | message: { | |
61 | message: 'This is a test notification.', |
|
86 | message: 'This is a test notification. ' + new Date(), | |
62 | level: level, |
|
87 | level: level, | |
63 | force: true |
|
88 | force: true | |
64 | } |
|
89 | } | |
65 | }; |
|
90 | }; | |
66 | $.Topic('/notifications').publish(payload); |
|
91 | $.Topic('/notifications').publish(payload); | |
67 | } |
|
92 | }; | |
|
93 | ctrlr.testNotificationsLive = function(event){ | |||
|
94 | var ajax = $('#sendTestNotification')[0]; | |||
|
95 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; | |||
|
96 | ajax.body = {test_msg: 'Hello !'}; | |||
|
97 | ajax.generateRequest(); | |||
|
98 | }; | |||
|
99 | ctrlr.handleTestNotification = function(event){ | |||
|
100 | var reply = event.detail.response.response; | |||
|
101 | reply = reply || 'no reply form server'; | |||
|
102 | $('#test-response').html(reply); | |||
|
103 | }; | |||
68 |
|
104 | |||
69 | </script> |
|
105 | </script> | |
|
106 | ||||
70 | </template> |
|
107 | </template> |
General Comments 0
You need to be logged in to leave comments.
Login now