Skip to content

Commit c4492a8

Browse files
committed
more subscriptions UI
1 parent 9b9d565 commit c4492a8

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

packages/pico-engine/public/index.html

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,43 @@ <h2>Children</h2>
345345
{{/if}}
346346
</script>
347347
<script id="subscriptions-template" type="text/x-handlebars-template">
348-
{{#unless subscriptions}}
349-
Subscriptions
348+
{{#if disabled}}
349+
Subscriptions are disabled.
350+
To enable, add the ruleset "io.picolabs.subscriptions" to this pico.
350351
{{else}}
351-
Subscriptions established
352+
{{#if established}}
353+
Established subscriptions
352354
<ul class="subscriptions-list" style="list-style: none;padding:0">
353-
{{#each subscriptions}}
355+
{{#each established}}
354356
<li><input type="checkbox"> to pico "{{name}}" (did:npe:{{Tx}})
355357
<a class="js-ajax-link" href="/sky/event/{{../eci}}/delete-subscription/wrangler/subscription_cancellation?Rx={{this.Rx}}">del</a>
356358
<pre>{{this.asString}}</pre>
357359
</li>
358360
{{/each}}
359361
</ul>
360-
{{/unless}}
362+
{{/if}}
363+
{{#if outbound}}
364+
Outbound subscriptions
365+
<ul class="subscriptions-list" style="list-style: none;padding:0">
366+
{{#each outbound}}
367+
<li><input type="checkbox"> to pico "{{name}}" (did:npe:{{Tx}})
368+
<a class="js-ajax-link" href="/sky/event/{{../eci}}/cancel-outbound/wrangler/outbound_cancellation?Rx={{this.Rx}}">del</a>
369+
<pre>{{this.asString}}</pre>
370+
</li>
371+
{{/each}}
372+
</ul>
373+
{{/if}}
374+
{{#if inbound}}
375+
Inbound subscriptions
376+
<ul class="subscriptions-list" style="list-style: none;padding:0">
377+
{{#each inbound}}
378+
<li><input type="checkbox"> from pico "{{name}}" (did:npe:{{Tx}})
379+
<a class="js-ajax-link" href="/sky/event/{{../eci}}/reject-inbound/wrangler/inbound_rejection?Rx={{this.Rx}}">del</a>
380+
<pre>{{this.asString}}</pre>
381+
</li>
382+
{{/each}}
383+
</ul>
384+
{{/if}}
361385
<p>Propose new subscription</p>
362386
<form class="js-ajax-form" action="/sky/event/{{eci}}/subscr/wrangler/subscription" method="GET">
363387
<table>
@@ -378,6 +402,7 @@ <h2>Children</h2>
378402
</table>
379403
<button type="submit">wrangler:subscription</button>
380404
</form>
405+
{{/if}}
381406
</script>
382407
</head>
383408
<body>

packages/pico-engine/public/js/index.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,33 @@ $.getJSON("/api/db-dump?legacy=true", function(db_dump){
184184
callback({ "pico_id": thePicoInp.id, "id": thePicoInp.id, "eci": thePicoInp.admin_eci, "channel": theChannels });
185185
} else if (label == "Subscriptions") {
186186
var theSubscriptions = {};
187-
var subscriptionsCount = 0;
188-
var subscriptions = get(db_dump.pico,[thePicoInp.id,"io.picolabs.subscription","vars","established"]);
189-
if (subscriptions) {
190-
Object.keys(subscriptions).forEach(function(id){
191-
++subscriptionsCount;
192-
theSubscriptions[id] = subscriptions[id];
193-
theSubscriptions[id].asString = JSON.stringify(subscriptions[id],undefined,2);
194-
var subs_eci = subscriptions[id].Tx;
187+
theSubscriptions.pico_id = thePicoInp.id;
188+
theSubscriptions.eci = eci;
189+
var subsRID = "io.picolabs.subscription";
190+
if (get(db_dump,["pico",thePicoInp.id,"ruleset",subsRID,"on"])) {
191+
} else {
192+
theSubscriptions.disabled = true;
193+
}
194+
var theSubsVars = get(db_dump,["pico",thePicoInp.id,subsRID,"vars"]);
195+
var recSubs = function(subsType) {
196+
if (theSubsVars && theSubsVars[subsType]) {} else return;
197+
var someSub = {};
198+
var subCount = 0;
199+
var theSubs = theSubsVars[subsType];
200+
Object.keys(theSubs).forEach(function(id){
201+
++subCount;
202+
someSub[id] = theSubs[id];
203+
someSub[id].asString = JSON.stringify(theSubs[id],undefined,2);
204+
var subs_eci = theSubs[id].Tx;
195205
var pico = { id: get(db_dump.channel,[subs_eci,"pico_id"])};
196-
theSubscriptions[id].name = getV(pico,"dname");
206+
someSub[id].name = getV(pico,"dname");
197207
});
198-
}
199-
callback({"pico_id": thePicoInp.id, eci:eci,"subscriptions":subscriptionsCount ? theSubscriptions : false});
208+
if(subCount) theSubscriptions[subsType] = someSub;
209+
};
210+
recSubs("established");
211+
recSubs("outbound");
212+
recSubs("inbound");
213+
callback(theSubscriptions);
200214
} else {
201215
callback(thePicoInp);
202216
}

0 commit comments

Comments
 (0)