9
9
< link rel ="import " href ="../../../paper-tooltip/paper-tooltip.html ">
10
10
< link rel ="import " href ="../../mqtt-elements.html ">
11
11
12
+ < link rel ="import " href ="mqtt-subscription-view.html ">
13
+
14
+
12
15
< dom-module id ="demo-element ">
13
16
14
17
< link rel ="import " type ="css " href ="demo.css ">
28
31
<!--create a mqtt subscription for every item in topics-->
29
32
< template is ="dom-repeat " items ="{{topics}} " as ="t ">
30
33
< mqtt-subscription topic ="[[t.topic]] "
34
+ messages ="{{t.messages}} "
31
35
number-of-messages ="10 "
32
36
qos ="[[t.qos]] "> </ mqtt-subscription >
33
37
</ template >
@@ -113,40 +117,8 @@ <h3>Publish on <span>[[topic]]</span></h3>
113
117
</ div >
114
118
115
119
<!--output every subscription-->
116
- < template id ="subscriptionList " is ="dom-repeat " items ="[[subscriptions]] " as ="sub " observe ="messages.* ">
117
- < div class ="vertical-section ">
118
- < div >
119
- < div class ="sub-header ">
120
- < h2 class ="title "> Subscribed to - < span > [[sub.topic]]</ span > </ h2 >
121
- < h3 class ="qos "> QoS: < span > [[sub.qos]]</ span > </ h3 >
122
- < paper-icon-button on-tap ="_removeSubscription "
123
- icon ="icons:delete "
124
- alt ="remove "
125
- title ="remove subscription "> </ paper-icon-button >
126
- </ div >
127
- < table >
128
- < thead >
129
- < tr >
130
- < th colspan ="3 "> Messages</ th >
131
- </ tr >
132
- < tr >
133
- < th > Topic</ th >
134
- < th > QoS</ th >
135
- < th class ="full "> Payload</ th >
136
- </ tr >
137
- </ thead >
138
- < tbody >
139
- < template is ="dom-repeat " items ="{{sub.messages}} " as ="message ">
140
- < tr >
141
- < td > {{message.topic}}</ td >
142
- < td > {{message.message.qos}}</ td >
143
- < td class ="full "> {{message.parsedPayload}}</ td >
144
- </ tr >
145
- </ template >
146
- </ tbody >
147
- </ table >
148
- </ div >
149
- </ div >
120
+ < template id ="subscriptionList " is ="dom-repeat " items ="[[topics]] " as ="sub ">
121
+ < mqtt-subscription-view model ="[[sub]] "> </ mqtt-subscription-view >
150
122
</ template >
151
123
</ div >
152
124
</ template >
@@ -166,12 +138,9 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
166
138
type : Object ,
167
139
} ,
168
140
169
- subscriptions : {
170
- type : Array ,
171
- } ,
172
-
173
141
newSubTopic : {
174
142
type : String ,
143
+ value : ""
175
144
} ,
176
145
177
146
subQos : {
@@ -194,7 +163,7 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
194
163
195
164
topic : {
196
165
type : String ,
197
- value : "foo/bar " ,
166
+ value : "" ,
198
167
} ,
199
168
200
169
messages : {
@@ -224,7 +193,17 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
224
193
225
194
clientId : {
226
195
type : String ,
196
+ } ,
197
+
198
+ value : {
199
+ type : String ,
200
+ value : "foo/bar"
227
201
}
202
+
203
+ } ,
204
+
205
+ listeners : {
206
+ "mqtt-subscription-remove-view" : "_removeSubscription"
228
207
} ,
229
208
230
209
observers : [ ] ,
@@ -261,7 +240,7 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
261
240
262
241
_addSub : function ( ) {
263
242
if ( this . newSubTopic . length > 0 ) {
264
- this . push ( "topics" , { topic : this . newSubTopic , qos : this . subQos } ) ;
243
+ this . push ( "topics" , { topic : this . newSubTopic , qos : this . subQos , messages : [ ] } ) ;
265
244
}
266
245
} ,
267
246
@@ -291,11 +270,8 @@ <h3 class="qos">QoS: <span>[[sub.qos]]</span></h3>
291
270
} ,
292
271
293
272
_removeSubscription : function ( event ) {
294
- // using the index of the subscriptions array only works because we have not changed the order of the
295
- // subscriptions. Otherwise it would be nessesary to have some sort of ID for each subscription to easily map
296
- // the subscription to the model.
297
- var index = this . subscriptions . indexOf ( event . model . sub )
298
- this . splice ( "topics" , index , 1 ) ;
273
+ var key = Polymer . Collection . get ( this . topics ) . getKey ( event . detail ) ;
274
+ this . splice ( "topics" , key , 1 ) ;
299
275
} ,
300
276
301
277
} ) ;
0 commit comments