New entity: Visitors.

This commit is contained in:
codevictory
2021-05-03 20:28:36 +03:00
parent 811454f2e7
commit 1308f691a4
12 changed files with 521 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
defmodule RunosaariWeb.VisitorController do
use RunosaariWeb, :controller
alias Runosaari.Registration
alias Runosaari.Registration.Visitor
def index(conn, _params) do
visitors = Registration.list_visitors()
render(conn, "index.html", visitors: visitors)
end
def new(conn, _params) do
changeset = Registration.change_visitor(%Visitor{})
render(conn, "new.html", changeset: changeset)
end
def create(conn, %{"visitor" => visitor_params}) do
case Registration.create_visitor(visitor_params) do
{:ok, visitor} ->
conn
|> put_flash(:info, "Visitor created successfully.")
|> redirect(to: Routes.visitor_path(conn, :show, visitor))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
def show(conn, %{"id" => id}) do
visitor = Registration.get_visitor!(id)
render(conn, "show.html", visitor: visitor)
end
def edit(conn, %{"id" => id}) do
visitor = Registration.get_visitor!(id)
changeset = Registration.change_visitor(visitor)
render(conn, "edit.html", visitor: visitor, changeset: changeset)
end
def update(conn, %{"id" => id, "visitor" => visitor_params}) do
visitor = Registration.get_visitor!(id)
case Registration.update_visitor(visitor, visitor_params) do
{:ok, visitor} ->
conn
|> put_flash(:info, "Visitor updated successfully.")
|> redirect(to: Routes.visitor_path(conn, :show, visitor))
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "edit.html", visitor: visitor, changeset: changeset)
end
end
def delete(conn, %{"id" => id}) do
visitor = Registration.get_visitor!(id)
{:ok, _visitor} = Registration.delete_visitor(visitor)
conn
|> put_flash(:info, "Visitor deleted successfully.")
|> redirect(to: Routes.visitor_path(conn, :index))
end
end

View File

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

View File

@@ -0,0 +1,47 @@
<%= 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, :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, :date1 %>
<%= checkbox f, :date1 %>
<%= error_tag f, :date1 %>
<%= label f, :date2 %>
<%= checkbox f, :date2 %>
<%= error_tag f, :date2 %>
<%= label f, :date3 %>
<%= checkbox f, :date3 %>
<%= error_tag f, :date3 %>
<%= label f, :bus %>
<%= checkbox f, :bus %>
<%= error_tag f, :bus %>
<%= label f, :accom %>
<%= checkbox f, :accom %>
<%= error_tag f, :accom %>
<div>
<%= submit "Save" %>
</div>
<% end %>

View File

@@ -0,0 +1,42 @@
<h1>Listing Visitors</h1>
<table>
<thead>
<tr>
<th>Fname</th>
<th>Lname</th>
<th>Email</th>
<th>Tel</th>
<th>Date1</th>
<th>Date2</th>
<th>Date3</th>
<th>Bus</th>
<th>Accom</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for visitor <- @visitors do %>
<tr>
<td><%= visitor.fname %></td>
<td><%= visitor.lname %></td>
<td><%= visitor.email %></td>
<td><%= visitor.tel %></td>
<td><%= visitor.date1 %></td>
<td><%= visitor.date2 %></td>
<td><%= visitor.date3 %></td>
<td><%= visitor.bus %></td>
<td><%= visitor.accom %></td>
<td>
<span><%= link "Show", to: Routes.visitor_path(@conn, :show, visitor) %></span>
<span><%= link "Edit", to: Routes.visitor_path(@conn, :edit, visitor) %></span>
<span><%= link "Delete", to: Routes.visitor_path(@conn, :delete, visitor), method: :delete, data: [confirm: "Are you sure?"] %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Visitor", to: Routes.visitor_path(@conn, :new) %></span>

View File

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

View File

@@ -0,0 +1,53 @@
<h1>Show Visitor</h1>
<ul>
<li>
<strong>Fname:</strong>
<%= @visitor.fname %>
</li>
<li>
<strong>Lname:</strong>
<%= @visitor.lname %>
</li>
<li>
<strong>Email:</strong>
<%= @visitor.email %>
</li>
<li>
<strong>Tel:</strong>
<%= @visitor.tel %>
</li>
<li>
<strong>Date1:</strong>
<%= @visitor.date1 %>
</li>
<li>
<strong>Date2:</strong>
<%= @visitor.date2 %>
</li>
<li>
<strong>Date3:</strong>
<%= @visitor.date3 %>
</li>
<li>
<strong>Bus:</strong>
<%= @visitor.bus %>
</li>
<li>
<strong>Accom:</strong>
<%= @visitor.accom %>
</li>
</ul>
<span><%= link "Edit", to: Routes.visitor_path(@conn, :edit, @visitor) %></span>
<span><%= link "Back", to: Routes.visitor_path(@conn, :index) %></span>

View File

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