Skip to content

Commit

Permalink
support defining link definition within livecomponent
Browse files Browse the repository at this point in the history
cleaned up the aria labels
  • Loading branch information
brooksmtownsend committed Jun 29, 2021
1 parent 12a6a86 commit ef8186c
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 120 deletions.

This file was deleted.

112 changes: 112 additions & 0 deletions wasmcloud_host/lib/wasmcloud_host_web/live/define_link_component.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
defmodule DefineLinkComponent do
use Phoenix.LiveComponent

def mount(socket) do
{:ok, socket}
end

def handle_event("validate", _params, socket) do
# TODO determine feasability of modifying form upon provider select, instead of with custom JS
{:noreply, socket}
end

def handle_event(
"define_link",
%{
"actor_id" => actor_id,
"contract_id" => contract_id,
"link_name" => link_name,
"provider_id" => provider_id,
"values" => values
},
socket
) do
values_map =
values
|> String.split(",")
|> Enum.flat_map(fn s -> String.split(s, "=") end)
|> Enum.chunk_every(2)
|> Enum.map(fn [a, b] -> {a, b} end)
|> Map.new()

HostCore.Linkdefs.Manager.put_link_definition(
actor_id,
contract_id,
link_name,
provider_id,
values_map
)

{:noreply, socket}
end

def render(assigns) do
~L"""
<form class="form-horizontal" phx-submit="define_link" phx-change="validate" phx-target="<%= @myself %>">
<input name="_csrf_token" type="hidden" value="<%= Phoenix.Controller.get_csrf_token() %>">
<div class="form-group row">
<label class="col-md-3 col-form-label" for="text-input">Actor Public Key</label>
<div class="col-md-9">
<select class="form-control select2-single" id="select2-1" name="actor_id">
<option hidden disabled selected value> -- select an actor -- </option>
<%= for {actor, _host_info} <- @actors do %>
<%= for {k, v} <- @claims do %>
<%= if k == actor do %>
<option value="<%= actor %>"><%= v.name %> (<%= String.slice(actor, 0..4) %>...) </option>
<% end %>
<% end %>
<% end %>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="text-input">Provider Public Key</label>
<div class="col-md-9">
<%# On select, populate the linkname and contract_id options with the matching data %>
<select class="form-control select2-single" id="linkdefs-providerid-select" name="provider_id"
onChange="let data = this.options[this.selectedIndex].dataset
document.getElementById('linkdef-linkname-input').value = data['linkname']
document.getElementById('linkdef-contractid-input').value = data['contractid']">
<option hidden disabled selected value> -- select a provider -- </option>
<%= for {provider, instances} <- @providers do %>
<%= for instance <- instances do %>
<option value="<%= provider %>"
data-linkname="<%= Map.get(instance, :link_name)%>"
data-contractid="<%= Map.get(instance, :contract_id)%>">
<%= String.slice(provider, 0..4) %>... (<%= Map.get(instance, :link_name) %>)
</option>
<% end %>
<% end %>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="linkdef-linkname-input">Link Name</label>
<div class="col-md-9">
<input class="form-control" id="linkdef-linkname-input" type="text" name="link_name" placeholder="default" value="default">
<span class="help-block">Select a provider to autopopulate the link name</span>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="linkdef-contractid-input">Contract ID</label>
<div class="col-md-9">
<input class="form-control" id="linkdef-contractid-input" type="text" name="contract_id" placeholder="wasmcloud:contract">
<span class="help-block">Select a provider to autopopulate the contract id</span>
</div>
</div>
<div class="form-group row">
<label class="col-md-3 col-form-label" for="text-input">Values</label>
<div class="col-md-9">
<input class="form-control" id="text-input" type="text" name="values" placeholder="KEY1=VAL1,KEY2=VAL2">
<span class="help-block">Comma separated list of configuration values</span>
</div>
</div>
<div class="modal-footer">
<button id="close_modal-<%= @id %>" class="btn btn-secondary" type="button" data-dismiss="modal">Close</button>
<!-- onClick event closes modal -->
<button class="btn btn-primary" type="submit" onClick="document.getElementById('close_modal-<%= @id %>').click()">Submit</button>
</div>
</form>
"""
end
end
22 changes: 18 additions & 4 deletions wasmcloud_host/lib/wasmcloud_host_web/live/page_live.html.leex
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<!-- /.col-->
</div>
<%# Start actor modal (One for file, one for OCI) %>
<div class="modal fade" id="start_actor_file" tabindex="-1" role="dialog" aria-labelledby="start_actor_file" aria-hidden="true">
<div class="modal fade" id="start_actor_file" tabindex="-1" role="dialog" aria-labelledby="start_actor_file_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -285,7 +285,7 @@
</div>
</div>
</div>
<div class="modal fade" id="start_actor_oci" tabindex="-1" role="dialog" aria-labelledby="start_actor_oci" aria-hidden="true">
<div class="modal fade" id="start_actor_oci" tabindex="-1" role="dialog" aria-labelledby="start_actor_oci_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -299,7 +299,7 @@
</div>
</div>
<%# Start provider modal (One for file, one for OCI) %>
<div class="modal fade" id="start_provider_file" tabindex="-1" role="dialog" aria-labelledby="start_provider_file" aria-hidden="true">
<div class="modal fade" id="start_provider_file" tabindex="-1" role="dialog" aria-labelledby="start_provider_file_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -312,7 +312,7 @@
</div>
</div>
</div>
<div class="modal fade" id="start_provider_oci" tabindex="-1" role="dialog" aria-labelledby="start_provider_oci" aria-hidden="true">
<div class="modal fade" id="start_provider_oci" tabindex="-1" role="dialog" aria-labelledby="start_provider_oci_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -325,3 +325,17 @@
</div>
</div>
</div>
<%# Define link modal %>
<div class="modal fade" id="define_link" tabindex="-1" role="dialog" aria-labelledby="define_link_modal" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Define link</h4>
<button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<%= live_component DefineLinkComponent, id: :define_link_modal, actors: @actors, providers: @providers, claims: @claims %>
</div>
</div>
</div>
</div>
1 change: 0 additions & 1 deletion wasmcloud_host/lib/wasmcloud_host_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ defmodule WasmcloudHostWeb.Router do
pipe_through :browser

live "/", PageLive, :index
post "/define_link", LinkdefsController, :define_link
end

# Other scopes may use custom stacks.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@
<div class="row"></div>
<!-- Displays view -->
<%= @inner_content %>
<!-- Define Link modal-->
<%= render("definelinkmodal.html", actors: @actors, providers: @providers, claims: @claims) %>
<!-- /.row-->
</div>
</div>
Expand Down

0 comments on commit ef8186c

Please sign in to comment.