Skip to content

Commit 0b285bd

Browse files
committed
specify policy when creating a channel
1 parent f1dcfc4 commit 0b285bd

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

packages/pico-engine/krl/io.picolabs.wrangler.krl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ ruleset io.picolabs.wrangler {
220220
returns channel
221221
}
222222

223-
createChannel = defaction(id , name, type) {
223+
createChannel = defaction(id , name, type, policy_id) {
224224
every{
225-
engine:newChannel(id , name, type) setting(channel);
225+
engine:newChannel(id , name, type, policy_id) setting(channel);
226226
}
227227
returns channel
228228
}
@@ -384,7 +384,8 @@ ruleset io.picolabs.wrangler {
384384
if(checkName(channel_name) && not channel_name.isnull() ) then every {
385385
createChannel(meta:picoId,
386386
channel_name,
387-
event:attr("type").defaultsTo("_wrangler")) setting(channel);
387+
event:attr("type").defaultsTo("_wrangler"),
388+
event:attr("policy_id")) setting(channel);
388389
send_directive("channel_Created", channel);
389390
}
390391
fired {

packages/pico-engine/public/index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ <h2>Children</h2>
241241
<script id="channels-template" type="text/x-handlebars-template">
242242
Channels
243243
<table class="channel-table">
244-
<tr><th>id</th><th>&nbsp;</th><th>name</th><th>type</th><th>policy</th></tr>
244+
<tr><th>id</th><th>&nbsp;</th><th>name</th><th>type</th>
245+
<th>policy id</th><th>policy name</th></tr>
245246
{{#each channel}}
246247
<tr>
247248
<td>{{id}}</td>
@@ -251,14 +252,21 @@ <h2>Children</h2>
251252
{{/if}}
252253
</td>
253254
<td>{{name}}</td><td>{{type}}</td>
254-
<td>{{policy_id}}</td>
255+
<td>{{policy_id}}</td><td>{{policy_name}}</td>
255256
</tr>
256257
{{/each}}
257258
</table>
258259
<p></p>
259260
<form class="js-ajax-form" action="/sky/event/{{eci}}/0/wrangler/channel_creation_requested" method="GET">
260261
<input type="text" name="name" placeholder="name...">
261262
<input type="text" name="type" placeholder="type...">
263+
{{#if policy}}
264+
<select name="policy_id">
265+
{{#each policy}}
266+
<option value="{{id}}">{{name}}</option>
267+
{{/each}}
268+
</select>
269+
{{/if}}
262270
<button type="submit">add channel</button>
263271
</form>
264272
</script>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,24 @@ $.getJSON("/api/db-dump?legacy=true", function(db_dump){
172172
callback({"pico_id": thePicoInp.id, "eci":eci, "testing":testing});
173173
} else if (label === "Channels") {
174174
var theChannels = [];
175+
var thePolicies = {};
175176
Object.keys(thePicoInp.channel).forEach(function(id){
176177
var aChannel = get(thePicoInp,["channel",id],undefined);
177178
if (aChannel) {
178179
if (aChannel.type!="secret" || aChannel.name!="admin") {
179180
aChannel.canDel = true;
180181
}
182+
var policy_id = aChannel.policy_id;
183+
var policy_name = thePolicies[policy_id];
184+
if (!policy_name) {
185+
policy_name = get(db_dump,["policy",policy_id,"name"]);
186+
thePolicies[policy_id] = policy_name;
187+
}
188+
aChannel.policy_name = policy_name;
181189
theChannels.push(aChannel);
182190
}
183191
});
184-
callback({ "pico_id": thePicoInp.id, "id": thePicoInp.id, "eci": thePicoInp.admin_eci, "channel": theChannels });
192+
callback({ "pico_id": thePicoInp.id, "id": thePicoInp.id, "eci": thePicoInp.admin_eci, "channel": theChannels, "policy": get(db_dump,["policy"]) });
185193
} else if (label == "Subscriptions") {
186194
var theSubscriptions = {};
187195
theSubscriptions.pico_id = thePicoInp.id;

0 commit comments

Comments
 (0)