Add comprehensive module documentation to 12 LiveView modules covering member, user, property, and property_type management views.
82 lines
2.2 KiB
Elixir
82 lines
2.2 KiB
Elixir
defmodule MvWeb.PropertyLive.Index do
|
|
@moduledoc """
|
|
LiveView for displaying and managing properties.
|
|
|
|
## Features
|
|
- List all properties with their values and types
|
|
- Show which member each property belongs to
|
|
- Display property type information
|
|
- Navigate to property details and edit forms
|
|
- Delete properties
|
|
|
|
## Relationships
|
|
Each property is linked to:
|
|
- A member (the property owner)
|
|
- A property type (defining value type and behavior)
|
|
|
|
## Events
|
|
- `delete` - Remove a property from the database
|
|
|
|
## Note
|
|
Properties are typically managed through the member edit form.
|
|
This view provides a global overview of all properties.
|
|
"""
|
|
use MvWeb, :live_view
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.app flash={@flash} current_user={@current_user}>
|
|
<.header>
|
|
Listing Properties
|
|
<:actions>
|
|
<.button variant="primary" navigate={~p"/properties/new"}>
|
|
<.icon name="hero-plus" /> New Property
|
|
</.button>
|
|
</:actions>
|
|
</.header>
|
|
|
|
<.table
|
|
id="properties"
|
|
rows={@streams.properties}
|
|
row_click={fn {_id, property} -> JS.navigate(~p"/properties/#{property}") end}
|
|
>
|
|
<:col :let={{_id, property}} label="Id">{property.id}</:col>
|
|
|
|
<:action :let={{_id, property}}>
|
|
<div class="sr-only">
|
|
<.link navigate={~p"/properties/#{property}"}>Show</.link>
|
|
</div>
|
|
|
|
<.link navigate={~p"/properties/#{property}/edit"}>Edit</.link>
|
|
</:action>
|
|
|
|
<:action :let={{id, property}}>
|
|
<.link
|
|
phx-click={JS.push("delete", value: %{id: property.id}) |> hide("##{id}")}
|
|
data-confirm="Are you sure?"
|
|
>
|
|
Delete
|
|
</.link>
|
|
</:action>
|
|
</.table>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "Listing Properties")
|
|
|> stream(:properties, Ash.read!(Mv.Membership.Property))}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("delete", %{"id" => id}, socket) do
|
|
property = Ash.get!(Mv.Membership.Property, id)
|
|
Ash.destroy!(property)
|
|
|
|
{:noreply, stream_delete(socket, :properties, property)}
|
|
end
|
|
end
|