Show More
@@ -566,6 +566,10 b' def make_map(config):' | |||
|
566 | 566 | '/my_account/toggle_visibility', |
|
567 | 567 | action='my_notifications_toggle_visibility', |
|
568 | 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 | 574 | # NOTIFICATION REST ROUTES |
|
571 | 575 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
@@ -24,13 +24,16 b' my account controller for RhodeCode admi' | |||
|
24 | 24 | """ |
|
25 | 25 | |
|
26 | 26 | import logging |
|
27 | import datetime | |
|
27 | 28 | |
|
28 | 29 | import formencode |
|
29 | 30 | from formencode import htmlfill |
|
31 | from pyramid.threadlocal import get_current_registry | |
|
30 | 32 | from pylons import request, tmpl_context as c, url, session |
|
31 | 33 | from pylons.controllers.util import redirect |
|
32 | 34 | from pylons.i18n.translation import _ |
|
33 | 35 | from sqlalchemy.orm import joinedload |
|
36 | from webob.exc import HTTPBadGateway | |
|
34 | 37 | |
|
35 | 38 | from rhodecode import forms |
|
36 | 39 | from rhodecode.lib import helpers as h |
@@ -41,6 +44,8 b' from rhodecode.lib.base import BaseContr' | |||
|
41 | 44 | from rhodecode.lib.utils import jsonify |
|
42 | 45 | from rhodecode.lib.utils2 import safe_int, md5, str2bool |
|
43 | 46 | from rhodecode.lib.ext_json import json |
|
47 | from rhodecode.lib.channelstream import channelstream_request, \ | |
|
48 | ChannelstreamException | |
|
44 | 49 | |
|
45 | 50 | from rhodecode.model.validation_schema.schemas import user_schema |
|
46 | 51 | from rhodecode.model.db import ( |
@@ -430,3 +435,33 b' class MyAccountController(BaseController' | |||
|
430 | 435 | user.update_userdata(notification_status=new_status) |
|
431 | 436 | Session().commit() |
|
432 | 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,7 +5,16 b'' | |||
|
5 | 5 | content-type="application/json" |
|
6 | 6 | loading="{{changeNotificationsLoading}}" |
|
7 | 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 | 19 | <div class="panel panel-default"> |
|
11 | 20 | <div class="panel-heading"> |
@@ -27,13 +36,29 b'' | |||
|
27 | 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 | 37 | </div> |
|
29 | 38 | </div> |
|
30 |
|
|
|
31 | <a class="btn btn-default" id="test-notification" on-tap="testNotifications">Test notification</a> | |
|
39 | </div> | |
|
32 | 40 |
|
|
33 | 41 |
|
|
34 | 42 |
|
|
35 | 43 | |
|
44 | <div class="panel panel-default"> | |
|
45 | <div class="panel-heading"> | |
|
46 | <h3 class="panel-title">${_('Test Notifications')}</h3> | |
|
36 | 47 |
|
|
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 | 62 | </div> |
|
38 | 63 | |
|
39 | 64 | <script type="text/javascript"> |
@@ -45,7 +70,7 b'' | |||
|
45 | 70 | var ctrlr = $('#notificationsPage')[0]; |
|
46 | 71 | ctrlr.toggleNotifications = function(event){ |
|
47 | 72 | var ajax = $('#toggleNotifications')[0]; |
|
48 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN} | |
|
73 | ajax.headers = {"X-CSRF-Token": CSRF_TOKEN}; | |
|
49 | 74 | ajax.body = {notification_status:event.target.active}; |
|
50 | 75 | ajax.generateRequest(); |
|
51 | 76 | }; |
@@ -58,13 +83,25 b'' | |||
|
58 | 83 | var level = levels[Math.floor(Math.random()*levels.length)]; |
|
59 | 84 | var payload = { |
|
60 | 85 | message: { |
|
61 | message: 'This is a test notification.', | |
|
86 | message: 'This is a test notification. ' + new Date(), | |
|
62 | 87 | level: level, |
|
63 | 88 | force: true |
|
64 | 89 | } |
|
65 | 90 | }; |
|
66 | 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 | 105 | </script> |
|
106 | ||
|
70 | 107 | </template> |
General Comments 0
You need to be logged in to leave comments.
Login now