##// END OF EJS Templates
components: small order of elements change and a cleanup
ergo -
r983:c5d592d8 default
parent child Browse files
Show More
@@ -1,18 +1,18 b''
1 1 <link rel="import" href="../../../../../../bower_components/polymer/polymer.html">
2 2 <link rel="import" href="../channelstream-connection/channelstream-connection.html">
3 3 <link rel="import" href="../rhodecode-toast/rhodecode-toast.html">
4 4 <link rel="import" href="../rhodecode-favicon/rhodecode-favicon.html">
5 5
6 6 <dom-module id="rhodecode-app">
7 7 <template>
8 <rhodecode-favicon></rhodecode-favicon>
9 <rhodecode-toast id="notifications"></rhodecode-toast>
10 8 <channelstream-connection
11 9 id="channelstream-connection"
12 10 on-channelstream-listen-message="receivedMessage"
13 11 on-channelstream-connected="handleConnected"
14 12 on-channelstream-subscribed="handleSubscribed">
15 13 </channelstream-connection>
14 <rhodecode-favicon></rhodecode-favicon>
15 <rhodecode-toast id="notifications"></rhodecode-toast>
16 16 </template>
17 17 <script src="rhodecode-app.js"></script>
18 18 </dom-module>
@@ -1,137 +1,137 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 19 this.kickoffChannelstreamPlugin();
20 20 },
21 21
22 22 /** proxy to channelstream connection */
23 23 getChannelStreamConnection: function () {
24 24 return this.$['channelstream-connection'];
25 25 },
26 26
27 27 handleNotifications: function (data) {
28 28 this.$['notifications'].handleNotification(data);
29 29 },
30 30
31 31 faviconUpdate: function (data) {
32 32 this.$$('rhodecode-favicon').counter = data.count;
33 33 },
34 34
35 35 /** opens connection to ws server */
36 36 kickoffChannelstreamPlugin: function (data) {
37 37 ccLog.debug('kickoffChannelstreamPlugin');
38 38 var channels = ['broadcast'];
39 39 var addChannels = this.checkViewChannels();
40 40 for (var i = 0; i < addChannels.length; i++) {
41 41 channels.push(addChannels[i]);
42 42 }
43 43 if (window.CHANNELSTREAM_SETTINGS && CHANNELSTREAM_SETTINGS.enabled){
44 44 var channelstreamConnection = this.getChannelStreamConnection();
45 45 channelstreamConnection.connectUrl = CHANNELSTREAM_URLS.connect;
46 46 channelstreamConnection.subscribeUrl = CHANNELSTREAM_URLS.subscribe;
47 47 channelstreamConnection.websocketUrl = CHANNELSTREAM_URLS.ws + '/ws';
48 48 channelstreamConnection.longPollUrl = CHANNELSTREAM_URLS.longpoll + '/listen';
49 49 // some channels might already be registered by topic
50 50 for (var i = 0; i < channels.length; i++) {
51 51 channelstreamConnection.push('channels', channels[i]);
52 52 }
53 53 // append any additional channels registered in other plugins
54 54 $.Topic('/connection_controller/subscribe').processPrepared();
55 55 channelstreamConnection.connect();
56 56 }
57 57 },
58 58
59 59 checkViewChannels: function () {
60 60 var channels = []
61 61 // subscribe to PR repo channel for PR's'
62 62 if (templateContext.pull_request_data.pull_request_id) {
63 63 var channelName = '/repo$' + templateContext.repo_name + '$/pr/' +
64 64 String(templateContext.pull_request_data.pull_request_id);
65 65 channels.push(channelName);
66 66 }
67 67 return channels;
68 68 },
69 69
70 70 /** subscribes users from channels in channelstream */
71 71 subscribeToChannelTopic: function (channels) {
72 var channelstreamConnection = this.$['channelstream-connection'];
72 var channelstreamConnection = this.getChannelStreamConnection();
73 73 var toSubscribe = channelstreamConnection.calculateSubscribe(channels);
74 74 ccLog.debug('subscribeToChannelTopic', toSubscribe);
75 75 if (toSubscribe.length > 0) {
76 76 // if we are connected then subscribe
77 77 if (channelstreamConnection.connected) {
78 78 channelstreamConnection.subscribe(toSubscribe);
79 79 }
80 80 // not connected? just push channels onto the stack
81 81 else {
82 82 for (var i = 0; i < toSubscribe.length; i++) {
83 83 channelstreamConnection.push('channels', toSubscribe[i]);
84 84 }
85 85 }
86 86 }
87 87 },
88 88
89 89 /** publish received messages into correct topic */
90 90 receivedMessage: function (event) {
91 91 for (var i = 0; i < event.detail.length; i++) {
92 92 var message = event.detail[i];
93 93 if (message.message.topic) {
94 94 ccLog.debug('publishing', message.message.topic);
95 95 $.Topic(message.message.topic).publish(message);
96 96 }
97 97 else if (message.type === 'presence'){
98 98 $.Topic('/connection_controller/presence').publish(message);
99 99 }
100 100 else {
101 101 ccLog.warn('unhandled message', message);
102 102 }
103 103 }
104 104 },
105 105
106 106 handleConnected: function (event) {
107 var channelstreamConnection = this.$['channelstream-connection'];
107 var channelstreamConnection = this.getChannelStreamConnection();
108 108 channelstreamConnection.set('channelsState',
109 109 event.detail.channels_info);
110 110 channelstreamConnection.set('userState', event.detail.state);
111 111 channelstreamConnection.set('channels', event.detail.channels);
112 112 this.propagageChannelsState();
113 113 },
114 114 handleSubscribed: function (event) {
115 var channelstreamConnection = this.$['channelstream-connection'];
115 var channelstreamConnection = this.getChannelStreamConnection();
116 116 var channelInfo = event.detail.channels_info;
117 117 var channelKeys = Object.keys(event.detail.channels_info);
118 118 for (var i = 0; i < channelKeys.length; i++) {
119 119 var key = channelKeys[i];
120 120 channelstreamConnection.set(['channelsState', key], channelInfo[key]);
121 121 }
122 122 channelstreamConnection.set('channels', event.detail.channels);
123 123 this.propagageChannelsState();
124 124 },
125 125 /** propagates channel states on topics */
126 126 propagageChannelsState: function (event) {
127 var channelstreamConnection = this.$['channelstream-connection'];
127 var channelstreamConnection = this.getChannelStreamConnection();
128 128 var channel_data = channelstreamConnection.channelsState;
129 129 var channels = channelstreamConnection.channels;
130 130 for (var i = 0; i < channels.length; i++) {
131 131 var key = channels[i];
132 132 $.Topic('/connection_controller/channel_update').publish(
133 133 {channel: key, state: channel_data[key]}
134 134 );
135 135 }
136 136 }
137 137 });
General Comments 0
You need to be logged in to leave comments. Login now