Show More
@@ -1,150 +1,166 b'' | |||
|
1 | 1 | ccLog = Logger.get('RhodeCodeApp'); |
|
2 | 2 | ccLog.setLevel(Logger.OFF); |
|
3 | 3 | |
|
4 | 4 | var rhodeCodeApp = Polymer({ |
|
5 | 5 | is: 'rhodecode-app', |
|
6 | 6 | attached: function () { |
|
7 | 7 | ccLog.debug('rhodeCodeApp created'); |
|
8 | 8 | $.Topic('/notifications').subscribe(this.handleNotifications.bind(this)); |
|
9 | 9 | $.Topic('/favicon/update').subscribe(this.faviconUpdate.bind(this)); |
|
10 | 10 | $.Topic('/connection_controller/subscribe').subscribe( |
|
11 | 11 | this.subscribeToChannelTopic.bind(this)); |
|
12 | 12 | // this event can be used to coordinate plugins to do their |
|
13 | 13 | // initialization before channelstream is kicked off |
|
14 | 14 | $.Topic('/__MAIN_APP__').publish({}); |
|
15 | 15 | |
|
16 | 16 | for (var i = 0; i < alertMessagePayloads.length; i++) { |
|
17 | 17 | $.Topic('/notifications').publish(alertMessagePayloads[i]); |
|
18 | 18 | } |
|
19 |
this. |
|
|
19 | this.initPlugins(); | |
|
20 | // after rest of application loads and topics get fired, launch connection | |
|
21 | $(document).ready(function () { | |
|
22 | this.kickoffChannelstreamPlugin(); | |
|
23 | }.bind(this)); | |
|
20 | 24 | }, |
|
21 | 25 | |
|
26 | initPlugins: function(){ | |
|
27 | for (var i = 0; i < window.APPLICATION_PLUGINS.length; i++) { | |
|
28 | var pluginDef = window.APPLICATION_PLUGINS[i]; | |
|
29 | if (pluginDef.component){ | |
|
30 | var pluginElem = document.createElement(pluginDef.component); | |
|
31 | this.shadowRoot.appendChild(pluginElem); | |
|
32 | if (typeof pluginElem.init !== 'undefined'){ | |
|
33 | pluginElem.init(); | |
|
34 | } | |
|
35 | } | |
|
36 | } | |
|
37 | }, | |
|
22 | 38 | /** proxy to channelstream connection */ |
|
23 | 39 | getChannelStreamConnection: function () { |
|
24 | 40 | return this.$['channelstream-connection']; |
|
25 | 41 | }, |
|
26 | 42 | |
|
27 | 43 | handleNotifications: function (data) { |
|
28 | 44 | var elem = document.getElementById('notifications'); |
|
29 | 45 | if(elem){ |
|
30 | 46 | elem.handleNotification(data); |
|
31 | 47 | } |
|
32 | 48 | |
|
33 | 49 | }, |
|
34 | 50 | |
|
35 | 51 | faviconUpdate: function (data) { |
|
36 | 52 | this.shadowRoot.querySelector('rhodecode-favicon').counter = data.count; |
|
37 | 53 | }, |
|
38 | 54 | |
|
39 | 55 | /** opens connection to ws server */ |
|
40 | 56 | kickoffChannelstreamPlugin: function (data) { |
|
41 | 57 | ccLog.debug('kickoffChannelstreamPlugin'); |
|
42 | 58 | var channels = ['broadcast']; |
|
43 | 59 | var addChannels = this.checkViewChannels(); |
|
44 | 60 | for (var i = 0; i < addChannels.length; i++) { |
|
45 | 61 | channels.push(addChannels[i]); |
|
46 | 62 | } |
|
47 | 63 | if (window.CHANNELSTREAM_SETTINGS && CHANNELSTREAM_SETTINGS.enabled){ |
|
48 | 64 | var channelstreamConnection = this.getChannelStreamConnection(); |
|
49 | 65 | channelstreamConnection.connectUrl = CHANNELSTREAM_URLS.connect; |
|
50 | 66 | channelstreamConnection.subscribeUrl = CHANNELSTREAM_URLS.subscribe; |
|
51 | 67 | channelstreamConnection.websocketUrl = CHANNELSTREAM_URLS.ws + '/ws'; |
|
52 | 68 | channelstreamConnection.longPollUrl = CHANNELSTREAM_URLS.longpoll + '/listen'; |
|
53 | 69 | // some channels might already be registered by topic |
|
54 | 70 | for (var i = 0; i < channels.length; i++) { |
|
55 | 71 | channelstreamConnection.push('channels', channels[i]); |
|
56 | 72 | } |
|
57 | 73 | // append any additional channels registered in other plugins |
|
58 | 74 | $.Topic('/connection_controller/subscribe').processPrepared(); |
|
59 | 75 | channelstreamConnection.connect(); |
|
60 | 76 | } |
|
61 | 77 | }, |
|
62 | 78 | |
|
63 | 79 | checkViewChannels: function () { |
|
64 | 80 | // subscribe to different channels data is sent. |
|
65 | 81 | |
|
66 | 82 | var channels = []; |
|
67 | 83 | // subscribe to PR repo channel for PR's' |
|
68 | 84 | if (templateContext.pull_request_data.pull_request_id) { |
|
69 | 85 | var channelName = '/repo$' + templateContext.repo_name + '$/pr/' + |
|
70 | 86 | String(templateContext.pull_request_data.pull_request_id); |
|
71 | 87 | channels.push(channelName); |
|
72 | 88 | } |
|
73 | 89 | |
|
74 | 90 | if (templateContext.commit_data.commit_id) { |
|
75 | 91 | var channelName = '/repo$' + templateContext.repo_name + '$/commit/' + |
|
76 | 92 | String(templateContext.commit_data.commit_id); |
|
77 | 93 | channels.push(channelName); |
|
78 | 94 | } |
|
79 | 95 | |
|
80 | 96 | return channels; |
|
81 | 97 | }, |
|
82 | 98 | |
|
83 | 99 | /** subscribes users from channels in channelstream */ |
|
84 | 100 | subscribeToChannelTopic: function (channels) { |
|
85 | 101 | var channelstreamConnection = this.getChannelStreamConnection(); |
|
86 | 102 | var toSubscribe = channelstreamConnection.calculateSubscribe(channels); |
|
87 | 103 | ccLog.debug('subscribeToChannelTopic', toSubscribe); |
|
88 | 104 | if (toSubscribe.length > 0) { |
|
89 | 105 | // if we are connected then subscribe |
|
90 | 106 | if (channelstreamConnection.connected) { |
|
91 | 107 | channelstreamConnection.subscribe(toSubscribe); |
|
92 | 108 | } |
|
93 | 109 | // not connected? just push channels onto the stack |
|
94 | 110 | else { |
|
95 | 111 | for (var i = 0; i < toSubscribe.length; i++) { |
|
96 | 112 | channelstreamConnection.push('channels', toSubscribe[i]); |
|
97 | 113 | } |
|
98 | 114 | } |
|
99 | 115 | } |
|
100 | 116 | }, |
|
101 | 117 | |
|
102 | 118 | /** publish received messages into correct topic */ |
|
103 | 119 | receivedMessage: function (event) { |
|
104 | 120 | for (var i = 0; i < event.detail.length; i++) { |
|
105 | 121 | var message = event.detail[i]; |
|
106 | 122 | if (message.message.topic) { |
|
107 | 123 | ccLog.debug('publishing', message.message.topic); |
|
108 | 124 | $.Topic(message.message.topic).publish(message); |
|
109 | 125 | } |
|
110 | 126 | else if (message.type === 'presence'){ |
|
111 | 127 | $.Topic('/connection_controller/presence').publish(message); |
|
112 | 128 | } |
|
113 | 129 | else { |
|
114 | 130 | ccLog.warn('unhandled message', message); |
|
115 | 131 | } |
|
116 | 132 | } |
|
117 | 133 | }, |
|
118 | 134 | |
|
119 | 135 | handleConnected: function (event) { |
|
120 | 136 | var channelstreamConnection = this.getChannelStreamConnection(); |
|
121 | 137 | channelstreamConnection.set('channelsState', |
|
122 | 138 | event.detail.channels_info); |
|
123 | 139 | channelstreamConnection.set('userState', event.detail.state); |
|
124 | 140 | channelstreamConnection.set('channels', event.detail.channels); |
|
125 | 141 | this.propagageChannelsState(); |
|
126 | 142 | }, |
|
127 | 143 | handleSubscribed: function (event) { |
|
128 | 144 | var channelstreamConnection = this.getChannelStreamConnection(); |
|
129 | 145 | var channelInfo = event.detail.channels_info; |
|
130 | 146 | var channelKeys = Object.keys(event.detail.channels_info); |
|
131 | 147 | for (var i = 0; i < channelKeys.length; i++) { |
|
132 | 148 | var key = channelKeys[i]; |
|
133 | 149 | channelstreamConnection.set(['channelsState', key], channelInfo[key]); |
|
134 | 150 | } |
|
135 | 151 | channelstreamConnection.set('channels', event.detail.channels); |
|
136 | 152 | this.propagageChannelsState(); |
|
137 | 153 | }, |
|
138 | 154 | /** propagates channel states on topics */ |
|
139 | 155 | propagageChannelsState: function (event) { |
|
140 | 156 | var channelstreamConnection = this.getChannelStreamConnection(); |
|
141 | 157 | var channel_data = channelstreamConnection.channelsState; |
|
142 | 158 | var channels = channelstreamConnection.channels; |
|
143 | 159 | for (var i = 0; i < channels.length; i++) { |
|
144 | 160 | var key = channels[i]; |
|
145 | 161 | $.Topic('/connection_controller/channel_update').publish( |
|
146 | 162 | {channel: key, state: channel_data[key]} |
|
147 | 163 | ); |
|
148 | 164 | } |
|
149 | 165 | } |
|
150 | 166 | }); |
@@ -1,161 +1,162 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | <!DOCTYPE html> |
|
3 | 3 | |
|
4 | 4 | <% |
|
5 | 5 | c.template_context['repo_name'] = getattr(c, 'repo_name', '') |
|
6 | 6 | go_import_header = '' |
|
7 | 7 | if hasattr(c, 'rhodecode_db_repo'): |
|
8 | 8 | c.template_context['repo_type'] = c.rhodecode_db_repo.repo_type |
|
9 | 9 | c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_rev[1] |
|
10 | 10 | |
|
11 | 11 | if getattr(c, 'repo_group', None): |
|
12 | 12 | c.template_context['repo_group_id'] = c.repo_group.group_id |
|
13 | 13 | |
|
14 | 14 | if getattr(c, 'rhodecode_user', None) and c.rhodecode_user.user_id: |
|
15 | 15 | c.template_context['rhodecode_user']['username'] = c.rhodecode_user.username |
|
16 | 16 | c.template_context['rhodecode_user']['email'] = c.rhodecode_user.email |
|
17 | 17 | c.template_context['rhodecode_user']['notification_status'] = c.rhodecode_user.get_instance().user_data.get('notification_status', True) |
|
18 | 18 | c.template_context['rhodecode_user']['first_name'] = c.rhodecode_user.first_name |
|
19 | 19 | c.template_context['rhodecode_user']['last_name'] = c.rhodecode_user.last_name |
|
20 | 20 | |
|
21 | 21 | c.template_context['visual']['default_renderer'] = h.get_visual_attr(c, 'default_renderer') |
|
22 | 22 | c.template_context['default_user'] = { |
|
23 | 23 | 'username': h.DEFAULT_USER, |
|
24 | 24 | 'user_id': 1 |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | 27 | %> |
|
28 | 28 | <html xmlns="http://www.w3.org/1999/xhtml"> |
|
29 | 29 | <head> |
|
30 | 30 | <script src="${h.asset('js/vendors/webcomponentsjs/webcomponents-lite.js', ver=c.rhodecode_version_hash)}"></script> |
|
31 | 31 | <link rel="import" href="${h.asset('js/rhodecode-components.html', ver=c.rhodecode_version_hash)}"> |
|
32 | 32 | <title>${self.title()}</title> |
|
33 | 33 | <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> |
|
34 | 34 | |
|
35 | 35 | ${h.go_import_header(request, getattr(c, 'rhodecode_db_repo', None))} |
|
36 | 36 | |
|
37 | 37 | % if 'safari' in (request.user_agent or '').lower(): |
|
38 | 38 | <meta name="referrer" content="origin"> |
|
39 | 39 | % else: |
|
40 | 40 | <meta name="referrer" content="origin-when-cross-origin"> |
|
41 | 41 | % endif |
|
42 | 42 | |
|
43 | 43 | <%def name="robots()"> |
|
44 | 44 | <meta name="robots" content="index, nofollow"/> |
|
45 | 45 | </%def> |
|
46 | 46 | ${self.robots()} |
|
47 | 47 | <link rel="icon" href="${h.asset('images/favicon.ico', ver=c.rhodecode_version_hash)}" sizes="16x16 32x32" type="image/png" /> |
|
48 | 48 | |
|
49 | 49 | ## CSS definitions |
|
50 | 50 | <%def name="css()"> |
|
51 | 51 | <link rel="stylesheet" type="text/css" href="${h.asset('css/style.css', ver=c.rhodecode_version_hash)}" media="screen"/> |
|
52 | 52 | <!--[if lt IE 9]> |
|
53 | 53 | <link rel="stylesheet" type="text/css" href="${h.asset('css/ie.css', ver=c.rhodecode_version_hash)}" media="screen"/> |
|
54 | 54 | <![endif]--> |
|
55 | 55 | ## EXTRA FOR CSS |
|
56 | 56 | ${self.css_extra()} |
|
57 | 57 | </%def> |
|
58 | 58 | ## CSS EXTRA - optionally inject some extra CSS stuff needed for specific websites |
|
59 | 59 | <%def name="css_extra()"> |
|
60 | 60 | </%def> |
|
61 | 61 | |
|
62 | 62 | ${self.css()} |
|
63 | 63 | |
|
64 | 64 | ## JAVASCRIPT |
|
65 | 65 | <%def name="js()"> |
|
66 | 66 | |
|
67 | 67 | <script src="${h.asset('js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script> |
|
68 | 68 | <script type="text/javascript"> |
|
69 | 69 | // register templateContext to pass template variables to JS |
|
70 | 70 | var templateContext = ${h.json.dumps(c.template_context)|n}; |
|
71 | 71 | |
|
72 | 72 | var APPLICATION_URL = "${h.route_path('home').rstrip('/')}"; |
|
73 | var APPLICATION_PLUGINS = []; | |
|
73 | 74 | var ASSET_URL = "${h.asset('')}"; |
|
74 | 75 | var DEFAULT_RENDERER = "${h.get_visual_attr(c, 'default_renderer')}"; |
|
75 | 76 | var CSRF_TOKEN = "${getattr(c, 'csrf_token', '')}"; |
|
76 | 77 | |
|
77 | 78 | var APPENLIGHT = { |
|
78 | 79 | enabled: ${'true' if getattr(c, 'appenlight_enabled', False) else 'false'}, |
|
79 | 80 | key: '${getattr(c, "appenlight_api_public_key", "")}', |
|
80 | 81 | % if getattr(c, 'appenlight_server_url', None): |
|
81 | 82 | serverUrl: '${getattr(c, "appenlight_server_url", "")}', |
|
82 | 83 | % endif |
|
83 | 84 | requestInfo: { |
|
84 | 85 | % if getattr(c, 'rhodecode_user', None): |
|
85 | 86 | ip: '${c.rhodecode_user.ip_addr}', |
|
86 | 87 | username: '${c.rhodecode_user.username}' |
|
87 | 88 | % endif |
|
88 | 89 | }, |
|
89 | 90 | tags: { |
|
90 | 91 | rhodecode_version: '${c.rhodecode_version}', |
|
91 | 92 | rhodecode_edition: '${c.rhodecode_edition}' |
|
92 | 93 | } |
|
93 | 94 | }; |
|
94 | 95 | |
|
95 | 96 | </script> |
|
96 | 97 | <%include file="/base/plugins_base.mako"/> |
|
97 | 98 | <!--[if lt IE 9]> |
|
98 | 99 | <script language="javascript" type="text/javascript" src="${h.asset('js/src/excanvas.min.js')}"></script> |
|
99 | 100 | <![endif]--> |
|
100 | 101 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode/routes.js', ver=c.rhodecode_version_hash)}"></script> |
|
101 | 102 | <script> var alertMessagePayloads = ${h.flash.json_alerts(request=request)|n}; </script> |
|
102 | 103 | ## avoide escaping the %N |
|
103 | 104 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode-components.js', ver=c.rhodecode_version_hash)}"></script> |
|
104 | 105 | <script>CodeMirror.modeURL = "${h.asset('') + 'js/mode/%N/%N.js?ver='+c.rhodecode_version_hash}";</script> |
|
105 | 106 | |
|
106 | 107 | |
|
107 | 108 | ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates |
|
108 | 109 | ${self.js_extra()} |
|
109 | 110 | |
|
110 | 111 | <script type="text/javascript"> |
|
111 | 112 | Rhodecode = (function() { |
|
112 | 113 | function _Rhodecode() { |
|
113 | 114 | this.comments = new CommentsController(); |
|
114 | 115 | } |
|
115 | 116 | return new _Rhodecode(); |
|
116 | 117 | })(); |
|
117 | 118 | |
|
118 | 119 | $(document).ready(function(){ |
|
119 | 120 | show_more_event(); |
|
120 | 121 | timeagoActivate(); |
|
121 | 122 | clipboardActivate(); |
|
122 | 123 | }) |
|
123 | 124 | </script> |
|
124 | 125 | |
|
125 | 126 | </%def> |
|
126 | 127 | |
|
127 | 128 | ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates |
|
128 | 129 | <%def name="js_extra()"></%def> |
|
129 | 130 | ${self.js()} |
|
130 | 131 | |
|
131 | 132 | <%def name="head_extra()"></%def> |
|
132 | 133 | ${self.head_extra()} |
|
133 | 134 | ## extra stuff |
|
134 | 135 | %if c.pre_code: |
|
135 | 136 | ${c.pre_code|n} |
|
136 | 137 | %endif |
|
137 | 138 | </head> |
|
138 | 139 | <body id="body"> |
|
139 | 140 | <noscript> |
|
140 | 141 | <div class="noscript-error"> |
|
141 | 142 | ${_('Please enable JavaScript to use RhodeCode Enterprise')} |
|
142 | 143 | </div> |
|
143 | 144 | </noscript> |
|
144 | 145 | ## IE hacks |
|
145 | 146 | <!--[if IE 7]> |
|
146 | 147 | <script>$(document.body).addClass('ie7')</script> |
|
147 | 148 | <![endif]--> |
|
148 | 149 | <!--[if IE 8]> |
|
149 | 150 | <script>$(document.body).addClass('ie8')</script> |
|
150 | 151 | <![endif]--> |
|
151 | 152 | <!--[if IE 9]> |
|
152 | 153 | <script>$(document.body).addClass('ie9')</script> |
|
153 | 154 | <![endif]--> |
|
154 | 155 | |
|
155 | 156 | ${next.body()} |
|
156 | 157 | %if c.post_code: |
|
157 | 158 | ${c.post_code|n} |
|
158 | 159 | %endif |
|
159 | 160 | <rhodecode-app></rhodecode-app> |
|
160 | 161 | </body> |
|
161 | 162 | </html> |
General Comments 0
You need to be logged in to leave comments.
Login now