3.0 KiB · text History 9c0fc16
<div class="overflow-x-auto">
  <div class="my-2 flex flex-wrap items-center gap-2">
    <.link patch={~p"/cfg/devices"} class="btn btn-ghost normal-case">
      <i class="fa-solid fa-chevron-left"></i> All devices
    </.link>
    <span class="text-sm opacity-60">
      A place can name a machine to start new devices on. A device discovered in that
      place, or moved into it, is linked to that machine straight away — unless something
      is already driving it, in which case it is left alone.
    </span>
  </div>

  <table class="table table-zebra w-full">
    <thead>
      <tr>
        <th>Place</th>
        <th>Devices</th>
        <th>Starts on</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <%= if places(@devices, @defaults) == [] do %>
        <tr>
          <th colspan="4">
            No places yet. Give a device a Place on the Devices page and it shows up here.
          </th>
        </tr>
      <% end %>
      <%= for place <- places(@devices, @defaults) do %>
        <tr>
          <th><i class="fa-solid fa-fw fa-location-dot"></i> <%= place %></th>
          <td>
            <%= length(in_place(@devices, place)) %>
            <%= if waiting(@devices, @links, place) > 0 do %>
              <span class="badge badge-sm">
                <%= waiting(@devices, @links, place) %> unlinked
              </span>
            <% end %>
          </td>
          <td>
            <form phx-change="default" id={"place-default-#{place}"}>
              <input type="hidden" name="place" value={place} />
              <select name="machine" class="select select-bordered select-sm">
                <option value="" selected={@defaults[place] == nil}>Nothing</option>
                <%= for machine <- machine_options(@machines) do %>
                  <option value={machine} selected={@defaults[place] == machine}>
                    <%= machine %>
                  </option>
                <% end %>
                <%= if @defaults[place] && @defaults[place] not in machine_options(@machines) do %>
                  <option value={@defaults[place]} selected>
                    <%= @defaults[place] %> (not running)
                  </option>
                <% end %>
              </select>
            </form>
          </td>
          <td>
            <div class="flex items-center gap-3">
              <%= if @defaults[place] && waiting(@devices, @links, place) > 0 do %>
                <button class="btn btn-sm btn-primary" phx-click="adopt" phx-value-place={place}>
                  <i class="fa-solid fa-link"></i>
                  Link <%= waiting(@devices, @links, place) %> now
                </button>
              <% end %>
              <%= if @defaults[place] do %>
                <span class="text-sm opacity-60">
                  <i class="fa-solid fa-thumbtack fa-fw"></i> pinned so it comes back
                </span>
              <% end %>
            </div>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
</div>