Editable workshops.
This commit is contained in:
@@ -6,7 +6,9 @@ defmodule RunosaariWeb.PerformanceController do
|
||||
|
||||
def index(conn, _params) do
|
||||
performances = Schedule.list_sorted_performances()
|
||||
render(conn, "index.html", performances: performances)
|
||||
workshops = Schedule.list_sorted_workshops()
|
||||
|
||||
render(conn, "index.html", Map.new(performances: performances, workshops: workshops))
|
||||
end
|
||||
|
||||
def admin(conn, _params) do
|
||||
|
||||
67
lib/runosaari_web/controllers/workshop_controller.ex
Normal file
67
lib/runosaari_web/controllers/workshop_controller.ex
Normal file
@@ -0,0 +1,67 @@
|
||||
defmodule RunosaariWeb.WorkshopController do
|
||||
use RunosaariWeb, :controller
|
||||
|
||||
alias Runosaari.Schedule
|
||||
alias Runosaari.Schedule.Workshop
|
||||
|
||||
def index(conn, _params) do
|
||||
workshops = Schedule.list_workshops()
|
||||
render(conn, "index.html", workshops: workshops)
|
||||
end
|
||||
|
||||
def admin(conn, _params) do
|
||||
workshops = Schedule.list_workshops()
|
||||
render(conn, "admin.html", workshops: workshops)
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = Schedule.change_workshop(%Workshop{})
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{"workshop" => workshop_params}) do
|
||||
case Schedule.create_workshop(workshop_params) do
|
||||
{:ok, workshop} ->
|
||||
conn
|
||||
|> put_flash(:info, "Workshop created successfully.")
|
||||
|> redirect(to: Routes.admin_workshop_path(conn, :show, workshop))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
workshop = Schedule.get_workshop!(id)
|
||||
render(conn, "show.html", workshop: workshop)
|
||||
end
|
||||
|
||||
def edit(conn, %{"id" => id}) do
|
||||
workshop = Schedule.get_workshop!(id)
|
||||
changeset = Schedule.change_workshop(workshop)
|
||||
render(conn, "edit.html", workshop: workshop, changeset: changeset)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "workshop" => workshop_params}) do
|
||||
workshop = Schedule.get_workshop!(id)
|
||||
|
||||
case Schedule.update_workshop(workshop, workshop_params) do
|
||||
{:ok, workshop} ->
|
||||
conn
|
||||
|> put_flash(:info, "Workshop updated successfully.")
|
||||
|> redirect(to: Routes.admin_workshop_path(conn, :show, workshop))
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, "edit.html", workshop: workshop, changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
workshop = Schedule.get_workshop!(id)
|
||||
{:ok, _workshop} = Schedule.delete_workshop(workshop)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Workshop deleted successfully.")
|
||||
|> redirect(to: Routes.admin_workshop_path(conn, :admin))
|
||||
end
|
||||
end
|
||||
@@ -40,6 +40,8 @@ defmodule RunosaariWeb.Router do
|
||||
get "/info", InfoController, :admin
|
||||
resources "/survival", SurvivalController, except: [:index]
|
||||
get "/survival", SurvivalController, :admin
|
||||
resources "/workshops", WorkshopController, except: [:index]
|
||||
get "/workshops", WorkshopController, :admin
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<h2>Työpajat</h2>
|
||||
<p id="workshops">
|
||||
<b>Jaana Kouri:</b> Shamanistinen kirjoitustyöpaja <br class="workshops-br">
|
||||
<b>Hanna Toivonen:</b> Sarjakuvatyöpaja <br class="workshops-br">
|
||||
<br />
|
||||
<i>Näihin avataan ennakkoilmoittautuminen hyvissä ajoin.</i>
|
||||
</p>
|
||||
<%= for workshop <- @workshops do %>
|
||||
<p class="workshop-paragraph">
|
||||
<b><%= workshop.name %></b><%= workshop.text %>
|
||||
</p>
|
||||
<% end %>
|
||||
<i class="foot-note">Näihin avataan ennakkoilmoittautuminen hyvissä ajoin.</i>
|
||||
</section>
|
||||
|
||||
32
lib/runosaari_web/templates/workshop/admin.html.eex
Normal file
32
lib/runosaari_web/templates/workshop/admin.html.eex
Normal file
@@ -0,0 +1,32 @@
|
||||
<section class="main">
|
||||
<h1>HALLINTA - Työpajat</h1>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nimi</th>
|
||||
<th>Teksti</th>
|
||||
<th>Prioriteetti</th>
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= for workshop <- @workshops do %>
|
||||
<tr>
|
||||
<td><%= workshop.name %></td>
|
||||
<td><%= workshop.text %></td>
|
||||
<td><%= workshop.seqnum %></td>
|
||||
|
||||
<td class="actions">
|
||||
<span><%= link "Lisätietoja", to: Routes.admin_workshop_path(@conn, :show, workshop) %></span>
|
||||
<span><%= link "Muokkaa", to: Routes.admin_workshop_path(@conn, :edit, workshop) %></span>
|
||||
<span><%= link "Poista", to: Routes.admin_workshop_path(@conn, :delete, workshop), method: :delete, data: [confirm: "Oletko varma?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span><%= link "Luo uusi työpaja", to: Routes.admin_workshop_path(@conn, :new) %></span>
|
||||
</section>
|
||||
5
lib/runosaari_web/templates/workshop/edit.html.eex
Normal file
5
lib/runosaari_web/templates/workshop/edit.html.eex
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>Muokkaa työpajan tietoja</h1>
|
||||
|
||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_workshop_path(@conn, :update, @workshop)) %>
|
||||
|
||||
<span><%= link "Takaisin", to: Routes.admin_workshop_path(@conn, :admin) %></span>
|
||||
23
lib/runosaari_web/templates/workshop/form.html.eex
Normal file
23
lib/runosaari_web/templates/workshop/form.html.eex
Normal file
@@ -0,0 +1,23 @@
|
||||
<%= form_for @changeset, @action, fn f -> %>
|
||||
<%= if @changeset.action do %>
|
||||
<div class="alert alert-danger">
|
||||
<p>Joku kentistä on tyhjä.</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= label f, :name, "Nimi" %>
|
||||
<%= text_input f, :name %>
|
||||
<%= error_tag f, :name %>
|
||||
|
||||
<%= label f, :text, "Teksti" %>
|
||||
<%= textarea f, :text %>
|
||||
<%= error_tag f, :text %>
|
||||
|
||||
<%= label f, :seqnum, "Prioriteetti (1 on korkein)" %>
|
||||
<%= number_input f, :seqnum %>
|
||||
<%= error_tag f, :seqnum %>
|
||||
|
||||
<div>
|
||||
<%= submit "Tallenna" %>
|
||||
</div>
|
||||
<% end %>
|
||||
5
lib/runosaari_web/templates/workshop/new.html.eex
Normal file
5
lib/runosaari_web/templates/workshop/new.html.eex
Normal file
@@ -0,0 +1,5 @@
|
||||
<h1>Luo uusi työpaja</h1>
|
||||
|
||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_workshop_path(@conn, :create)) %>
|
||||
|
||||
<span><%= link "Takaisin", to: Routes.admin_workshop_path(@conn, :admin) %></span>
|
||||
23
lib/runosaari_web/templates/workshop/show.html.eex
Normal file
23
lib/runosaari_web/templates/workshop/show.html.eex
Normal file
@@ -0,0 +1,23 @@
|
||||
<h1>Työpajan tiedot</h1>
|
||||
|
||||
<ul>
|
||||
|
||||
<li>
|
||||
<strong>Nimi:</strong>
|
||||
<%= @workshop.name %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<strong>Teksti:</strong>
|
||||
<%= @workshop.text %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<strong>Prioriteetti:</strong>
|
||||
<%= @workshop.seqnum %>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<span><%= link "Muokkaa", to: Routes.admin_workshop_path(@conn, :edit, @workshop) %></span>
|
||||
<span><%= link "Takaisin", to: Routes.admin_workshop_path(@conn, :admin) %></span>
|
||||
3
lib/runosaari_web/views/workshop_view.ex
Normal file
3
lib/runosaari_web/views/workshop_view.ex
Normal file
@@ -0,0 +1,3 @@
|
||||
defmodule RunosaariWeb.WorkshopView do
|
||||
use RunosaariWeb, :view
|
||||
end
|
||||
Reference in New Issue
Block a user