Autogen registration UI.

This commit is contained in:
codevictory
2021-03-27 16:50:43 +02:00
parent 299b47ca56
commit da4ed0a6c1
13 changed files with 509 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
defmodule RunosaariWeb.PerformerController do
use RunosaariWeb, :controller
alias Runosaari.Registration
alias Runosaari.Registration.Performer
def index(conn, _params) do
performers = Registration.list_performers()
render(conn, "index.html", performers: performers)
end
def new(conn, _params) do
changeset = Registration.change_performer(%Performer{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"performer" => performer_params}) do
case Registration.create_performer(performer_params) do
{:ok, performer} ->
conn
|> put_flash(:info, "Performer created successfully.")
|> redirect(to: Routes.performer_path(conn, :show, performer))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
performer = Registration.get_performer!(id)
render(conn, "show.html", performer: performer)
end
def edit(conn, %{"id" => id}) do
performer = Registration.get_performer!(id)
changeset = Registration.change_performer(performer)
render(conn, "edit.html", performer: performer, changeset: changeset)
end
def update(conn, %{"id" => id, "performer" => performer_params}) do
performer = Registration.get_performer!(id)
case Registration.update_performer(performer, performer_params) do
{:ok, performer} ->
conn
|> put_flash(:info, "Performer updated successfully.")
|> redirect(to: Routes.performer_path(conn, :show, performer))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", performer: performer, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
performer = Registration.get_performer!(id)
{:ok, _performer} = Registration.delete_performer(performer)
conn
|> put_flash(:info, "Performer deleted successfully.")
|> redirect(to: Routes.performer_path(conn, :index))
end
end

View File

@@ -17,6 +17,7 @@ defmodule RunosaariWeb.Router do
pipe_through :browser
get "/", PageController, :index
resources "/performers", PerformerController
end
# Other scopes may use custom stacks.

View File

@@ -0,0 +1,5 @@
<h1>Edit Performer</h1>
<%= render "form.html", Map.put(assigns, :action, Routes.performer_path(@conn, :update, @performer)) %>
<span><%= link "Back", to: Routes.performer_path(@conn, :index) %></span>

View File

@@ -0,0 +1,39 @@
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
<%= label f, :performerId %>
<%= number_input f, :performerId %>
<%= error_tag f, :performerId %>
<%= label f, :fname %>
<%= text_input f, :fname %>
<%= error_tag f, :fname %>
<%= label f, :lname %>
<%= text_input f, :lname %>
<%= error_tag f, :lname %>
<%= label f, :email %>
<%= text_input f, :email %>
<%= error_tag f, :email %>
<%= label f, :tel %>
<%= text_input f, :tel %>
<%= error_tag f, :tel %>
<%= label f, :confirmed %>
<%= checkbox f, :confirmed %>
<%= error_tag f, :confirmed %>
<%= label f, :notes %>
<%= text_input f, :notes %>
<%= error_tag f, :notes %>
<div>
<%= submit "Save" %>
</div>
<% end %>

View File

@@ -0,0 +1,38 @@
<h1>Listing Performers</h1>
<table>
<thead>
<tr>
<th>Performerid</th>
<th>Fname</th>
<th>Lname</th>
<th>Email</th>
<th>Tel</th>
<th>Confirmed</th>
<th>Notes</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for performer <- @performers do %>
<tr>
<td><%= performer.performerId %></td>
<td><%= performer.fname %></td>
<td><%= performer.lname %></td>
<td><%= performer.email %></td>
<td><%= performer.tel %></td>
<td><%= performer.confirmed %></td>
<td><%= performer.notes %></td>
<td>
<span><%= link "Show", to: Routes.performer_path(@conn, :show, performer) %></span>
<span><%= link "Edit", to: Routes.performer_path(@conn, :edit, performer) %></span>
<span><%= link "Delete", to: Routes.performer_path(@conn, :delete, performer), method: :delete, data: [confirm: "Are you sure?"] %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Performer", to: Routes.performer_path(@conn, :new) %></span>

View File

@@ -0,0 +1,5 @@
<h1>New Performer</h1>
<%= render "form.html", Map.put(assigns, :action, Routes.performer_path(@conn, :create)) %>
<span><%= link "Back", to: Routes.performer_path(@conn, :index) %></span>

View File

@@ -0,0 +1,43 @@
<h1>Show Performer</h1>
<ul>
<li>
<strong>Performerid:</strong>
<%= @performer.performerId %>
</li>
<li>
<strong>Fname:</strong>
<%= @performer.fname %>
</li>
<li>
<strong>Lname:</strong>
<%= @performer.lname %>
</li>
<li>
<strong>Email:</strong>
<%= @performer.email %>
</li>
<li>
<strong>Tel:</strong>
<%= @performer.tel %>
</li>
<li>
<strong>Confirmed:</strong>
<%= @performer.confirmed %>
</li>
<li>
<strong>Notes:</strong>
<%= @performer.notes %>
</li>
</ul>
<span><%= link "Edit", to: Routes.performer_path(@conn, :edit, @performer) %></span>
<span><%= link "Back", to: Routes.performer_path(@conn, :index) %></span>

View File

@@ -0,0 +1,3 @@
defmodule RunosaariWeb.PerformerView do
use RunosaariWeb, :view
end