Editable landing page.
This commit is contained in:
104
lib/runosaari/pages.ex
Normal file
104
lib/runosaari/pages.ex
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
defmodule Runosaari.Pages do
|
||||||
|
@moduledoc """
|
||||||
|
The Pages context.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import Ecto.Query, warn: false
|
||||||
|
alias Runosaari.Repo
|
||||||
|
|
||||||
|
alias Runosaari.Pages.Index
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns the list of index_paragraphs.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> list_index_paragraphs()
|
||||||
|
[%Index{}, ...]
|
||||||
|
|
||||||
|
"""
|
||||||
|
def list_index_paragraphs do
|
||||||
|
Repo.all(Index)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Gets a single index.
|
||||||
|
|
||||||
|
Raises `Ecto.NoResultsError` if the Index does not exist.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> get_index!(123)
|
||||||
|
%Index{}
|
||||||
|
|
||||||
|
iex> get_index!(456)
|
||||||
|
** (Ecto.NoResultsError)
|
||||||
|
|
||||||
|
"""
|
||||||
|
def get_index!(id), do: Repo.get!(Index, id)
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Creates a index.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> create_index(%{field: value})
|
||||||
|
{:ok, %Index{}}
|
||||||
|
|
||||||
|
iex> create_index(%{field: bad_value})
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def create_index(attrs \\ %{}) do
|
||||||
|
%Index{}
|
||||||
|
|> Index.changeset(attrs)
|
||||||
|
|> Repo.insert()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Updates a index.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> update_index(index, %{field: new_value})
|
||||||
|
{:ok, %Index{}}
|
||||||
|
|
||||||
|
iex> update_index(index, %{field: bad_value})
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def update_index(%Index{} = index, attrs) do
|
||||||
|
index
|
||||||
|
|> Index.changeset(attrs)
|
||||||
|
|> Repo.update()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Deletes a index.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> delete_index(index)
|
||||||
|
{:ok, %Index{}}
|
||||||
|
|
||||||
|
iex> delete_index(index)
|
||||||
|
{:error, %Ecto.Changeset{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def delete_index(%Index{} = index) do
|
||||||
|
Repo.delete(index)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Returns an `%Ecto.Changeset{}` for tracking index changes.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
iex> change_index(index)
|
||||||
|
%Ecto.Changeset{data: %Index{}}
|
||||||
|
|
||||||
|
"""
|
||||||
|
def change_index(%Index{} = index, attrs \\ %{}) do
|
||||||
|
Index.changeset(index, attrs)
|
||||||
|
end
|
||||||
|
end
|
||||||
18
lib/runosaari/pages/index.ex
Normal file
18
lib/runosaari/pages/index.ex
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
defmodule Runosaari.Pages.Index do
|
||||||
|
use Ecto.Schema
|
||||||
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
schema "index_paragraphs" do
|
||||||
|
field :content, :string
|
||||||
|
field :seqnum, :integer, default: 999
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
def changeset(index, attrs) do
|
||||||
|
index
|
||||||
|
|> cast(attrs, [:content, :seqnum])
|
||||||
|
|> validate_required([:content, :seqnum])
|
||||||
|
end
|
||||||
|
end
|
||||||
67
lib/runosaari_web/controllers/index_controller.ex
Normal file
67
lib/runosaari_web/controllers/index_controller.ex
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
defmodule RunosaariWeb.IndexController do
|
||||||
|
use RunosaariWeb, :controller
|
||||||
|
|
||||||
|
alias Runosaari.Pages
|
||||||
|
alias Runosaari.Pages.Index
|
||||||
|
|
||||||
|
def index(conn, _params) do
|
||||||
|
index_paragraphs = Pages.list_index_paragraphs()
|
||||||
|
render(conn, "index.html", index_paragraphs: index_paragraphs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def admin(conn, _params) do
|
||||||
|
index_paragraphs = Pages.list_index_paragraphs()
|
||||||
|
render(conn, "admin.html", index_paragraphs: index_paragraphs)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new(conn, _params) do
|
||||||
|
changeset = Pages.change_index(%Index{})
|
||||||
|
render(conn, "new.html", changeset: changeset)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create(conn, %{"index" => index_params}) do
|
||||||
|
case Pages.create_index(index_params) do
|
||||||
|
{:ok, index} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Index created successfully.")
|
||||||
|
|> redirect(to: Routes.admin_index_path(conn, :show, index))
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
render(conn, "new.html", changeset: changeset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def show(conn, %{"id" => id}) do
|
||||||
|
index = Pages.get_index!(id)
|
||||||
|
render(conn, "show.html", index: index)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit(conn, %{"id" => id}) do
|
||||||
|
index = Pages.get_index!(id)
|
||||||
|
changeset = Pages.change_index(index)
|
||||||
|
render(conn, "edit.html", index: index, changeset: changeset)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update(conn, %{"id" => id, "index" => index_params}) do
|
||||||
|
index = Pages.get_index!(id)
|
||||||
|
|
||||||
|
case Pages.update_index(index, index_params) do
|
||||||
|
{:ok, index} ->
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Index updated successfully.")
|
||||||
|
|> redirect(to: Routes.admin_index_path(conn, :show, index))
|
||||||
|
|
||||||
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
|
render(conn, "edit.html", index: index, changeset: changeset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete(conn, %{"id" => id}) do
|
||||||
|
index = Pages.get_index!(id)
|
||||||
|
{:ok, _index} = Pages.delete_index(index)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_flash(:info, "Index deleted successfully.")
|
||||||
|
|> redirect(to: Routes.index_path(conn, :index))
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,10 +1,6 @@
|
|||||||
defmodule RunosaariWeb.PageController do
|
defmodule RunosaariWeb.PageController do
|
||||||
use RunosaariWeb, :controller
|
use RunosaariWeb, :controller
|
||||||
|
|
||||||
def index(conn, _params) do
|
|
||||||
render(conn, "index.html")
|
|
||||||
end
|
|
||||||
|
|
||||||
def info(conn, _params) do
|
def info(conn, _params) do
|
||||||
render(conn, "info.html")
|
render(conn, "info.html")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ defmodule RunosaariWeb.Router do
|
|||||||
scope "/", RunosaariWeb do
|
scope "/", RunosaariWeb do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
get "/", PageController, :index
|
resources "/", IndexController, only: [:index]
|
||||||
get "/info", PageController, :info
|
get "/info", PageController, :info
|
||||||
get "/covid19", PageController, :covid19
|
get "/covid19", PageController, :covid19
|
||||||
get "/privacy", PageController, :privacy
|
get "/privacy", PageController, :privacy
|
||||||
@@ -29,6 +29,8 @@ defmodule RunosaariWeb.Router do
|
|||||||
scope "/admin", RunosaariWeb, as: :admin do
|
scope "/admin", RunosaariWeb, as: :admin do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
|
get "/index", IndexController, :admin
|
||||||
|
resources "/index", IndexController, except: [:index]
|
||||||
get "/performers", PerformerController, :admin
|
get "/performers", PerformerController, :admin
|
||||||
get "/performances", PerformanceController, :admin
|
get "/performances", PerformanceController, :admin
|
||||||
resources "/performers", PerformerController, except: [:index]
|
resources "/performers", PerformerController, except: [:index]
|
||||||
|
|||||||
30
lib/runosaari_web/templates/index/admin.html.eex
Normal file
30
lib/runosaari_web/templates/index/admin.html.eex
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<section class="main">
|
||||||
|
<h1>HALLINTA - Etusivu</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Sisältö</th>
|
||||||
|
<th>Prioriteetti</th>
|
||||||
|
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<%= for index <- @index_paragraphs do %>
|
||||||
|
<tr>
|
||||||
|
<td><%= index.content %></td>
|
||||||
|
<td><%= index.seqnum %></td>
|
||||||
|
|
||||||
|
<td class="actions">
|
||||||
|
<span><%= link "Lisätietoja", to: Routes.admin_index_path(@conn, :show, index) %></span>
|
||||||
|
<span><%= link "Muokkaa", to: Routes.admin_index_path(@conn, :edit, index) %></span>
|
||||||
|
<span><%= link "Poista", to: Routes.admin_index_path(@conn, :delete, index), method: :delete, data: [confirm: "Are you sure?"] %></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<span><%= link "Uusi Kappale", to: Routes.admin_index_path(@conn, :new) %></span>
|
||||||
|
</section>
|
||||||
5
lib/runosaari_web/templates/index/edit.html.eex
Normal file
5
lib/runosaari_web/templates/index/edit.html.eex
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<h1>Muokkaa kappaletta</h1>
|
||||||
|
|
||||||
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_index_path(@conn, :update, @index)) %>
|
||||||
|
|
||||||
|
<span><%= link "Takaisin", to: Routes.index_path(@conn, :index) %></span>
|
||||||
19
lib/runosaari_web/templates/index/form.html.eex
Normal file
19
lib/runosaari_web/templates/index/form.html.eex
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<%= form_for @changeset, @action, fn f -> %>
|
||||||
|
<%= if @changeset.action do %>
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<p>Jokin kentistä on tyhjä</p>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= label f, :content, "Sisältö" %>
|
||||||
|
<%= textarea f, :content %>
|
||||||
|
<%= error_tag f, :content %>
|
||||||
|
|
||||||
|
<%= label f, :seqnum, "Prioriteetti (1 on korkein)" %>
|
||||||
|
<%= number_input f, :seqnum %>
|
||||||
|
<%= error_tag f, :seqnum %>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<%= submit "Tallenna" %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
28
lib/runosaari_web/templates/index/index.html.eex
Normal file
28
lib/runosaari_web/templates/index/index.html.eex
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<section class="logo" id="logo-start">
|
||||||
|
<picture>
|
||||||
|
<source
|
||||||
|
srcset="<%= Routes.static_path(@conn, "/images/runosaari-logo_small.jpg") %>"
|
||||||
|
media="(max-width: 600px)"
|
||||||
|
alt="Runosaari logo"
|
||||||
|
/>
|
||||||
|
<source srcset="<%= Routes.static_path(@conn, "/images/runosaari-logo.jpg") %>" alt="Runosaari logo" />
|
||||||
|
<img src="<%= Routes.static_path(@conn, "/images/runosaari-logo.jpg") %>" alt="Runosaari logo" />
|
||||||
|
</picture>
|
||||||
|
<div id="logo-credits"><div>@Sanna Hukkanen</div></div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section class="main">
|
||||||
|
<h1 id="main-title">Runosaari 2021</h1>
|
||||||
|
<h2>
|
||||||
|
<span class="time-and-place"
|
||||||
|
>~ 22.-24.7. Livonsaari & Velkuanmaa ~</span
|
||||||
|
><br />
|
||||||
|
Eksymisretki omaan luontoosi, metsänpeiton suojaan!
|
||||||
|
</h2>
|
||||||
|
<%= for index <- @index_paragraphs do %>
|
||||||
|
<p><%= index.content %></p>
|
||||||
|
<% end %>
|
||||||
|
<p>
|
||||||
|
<i>[Ohjelmaa päivitetään muuttuvan tilanteen mukaan]</i>
|
||||||
|
</p>
|
||||||
|
</section>
|
||||||
7
lib/runosaari_web/templates/index/new.html.eex
Normal file
7
lib/runosaari_web/templates/index/new.html.eex
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<section class="main">
|
||||||
|
<h1>Luo kappale</h1>
|
||||||
|
|
||||||
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_index_path(@conn, :create)) %>
|
||||||
|
|
||||||
|
<span><%= link "Takaisin", to: Routes.index_path(@conn, :index) %></span>
|
||||||
|
</section>
|
||||||
20
lib/runosaari_web/templates/index/show.html.eex
Normal file
20
lib/runosaari_web/templates/index/show.html.eex
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<section class="main">
|
||||||
|
<h1>Kappaleen tiedot</h1>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<strong>Sisältö:</strong>
|
||||||
|
<%= @index.content %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<strong>Prioriteetti:</strong>
|
||||||
|
<%= @index.seqnum %>
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<span><%= link "Muokkaa", to: Routes.admin_index_path(@conn, :edit, @index) %></span>
|
||||||
|
<span><%= link "Takaisin", to: Routes.index_path(@conn, :index) %></span>
|
||||||
|
</section>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<header >
|
<header >
|
||||||
<nav class="main-nav-bar" role="navigation">
|
<nav class="main-nav-bar" role="navigation">
|
||||||
<%= link "Etusivu", to: Routes.page_path(@conn, :index) %>
|
<%= link "Etusivu", to: Routes.index_path(@conn, :index) %>
|
||||||
<%= link "Ohjelma", to: Routes.performance_path(@conn, :index) %>
|
<%= link "Ohjelma", to: Routes.performance_path(@conn, :index) %>
|
||||||
<%= link "Esiintyjät", to: Routes.performer_path(@conn, :index) %>
|
<%= link "Esiintyjät", to: Routes.performer_path(@conn, :index) %>
|
||||||
<%= link "Info", to: Routes.page_path(@conn, :info) %>
|
<%= link "Info", to: Routes.page_path(@conn, :info) %>
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
<a href="/#logo-container">Runosaari 2021</a>
|
<a href="/#logo-container">Runosaari 2021</a>
|
||||||
</h1>
|
</h1>
|
||||||
<nav class="mobile-main-nav-bar" id="nav-bar">
|
<nav class="mobile-main-nav-bar" id="nav-bar">
|
||||||
<%= link "Etusivu", to: "#{Routes.page_path(@conn, :index)}#logo-start" %>
|
<%= link "Etusivu", to: "#{Routes.index_path(@conn, :index)}#logo-start" %>
|
||||||
<%= link "Ohjelma", to: "#{Routes.performance_path(@conn, :index)}#calendar-start" %>
|
<%= link "Ohjelma", to: "#{Routes.performance_path(@conn, :index)}#calendar-start" %>
|
||||||
<%= link "Esiintyjät", to: "#{Routes.performer_path(@conn, :index)}#performers-start" %>
|
<%= link "Esiintyjät", to: "#{Routes.performer_path(@conn, :index)}#performers-start" %>
|
||||||
<%= link "Info", to: "#{Routes.page_path(@conn, :info)}#contact-start" %>
|
<%= link "Info", to: "#{Routes.page_path(@conn, :info)}#contact-start" %>
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
|
|
||||||
<section class="logo" id="logo-start">
|
|
||||||
<picture>
|
|
||||||
<source
|
|
||||||
srcset="<%= Routes.static_path(@conn, "/images/runosaari-logo_small.jpg") %>"
|
|
||||||
media="(max-width: 600px)"
|
|
||||||
alt="Runosaari logo"
|
|
||||||
/>
|
|
||||||
<source srcset="<%= Routes.static_path(@conn, "/images/runosaari-logo.jpg") %>" alt="Runosaari logo" />
|
|
||||||
<img src="<%= Routes.static_path(@conn, "/images/runosaari-logo.jpg") %>" alt="Runosaari logo" />
|
|
||||||
</picture>
|
|
||||||
<div id="logo-credits"><div>@Sanna Hukkanen</div></div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="main">
|
|
||||||
<h1 id="main-title">Runosaari 2021</h1>
|
|
||||||
<h2>
|
|
||||||
<span class="time-and-place"
|
|
||||||
>~ 22.-24.7. Livonsaari & Velkuanmaa ~</span
|
|
||||||
><br />
|
|
||||||
Eksymisretki omaan luontoosi, metsänpeiton suojaan!
|
|
||||||
</h2>
|
|
||||||
<p>
|
|
||||||
Lumi ja jää vähenee, vedenpinta nousee ja pandemian aallot viistävät
|
|
||||||
meidänkin rantojamme. Peurojen kurittaman monimuotoisuuden keskelle
|
|
||||||
nousee RUNOSAARI täynnä ihmetystä ja kysymyksiä: onko tulevaisuudella
|
|
||||||
tulevaisuutta? Kuinka luontoon lomittuminen voi olla mahdollista? Jos
|
|
||||||
eksymme metsänpeittoon, voimmeko löytää jonnekin?
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Järjestämme Livonsaaressa ja Velkuanmaassa uuden poikkitaiteellisen
|
|
||||||
runofestivaalin 22.-24.7.2021. Ohjelmassa runous yhdistyy elävään
|
|
||||||
musiikkiin ja erilaisiin taiteellisiin työpajoihin. Tapahtuma
|
|
||||||
järjestetään joustavasti vallitsevien koronarajoitusten mukaan,
|
|
||||||
ulkotiloja sekä erillisiä sisätiloja hyödyntäen. Livonsaaren
|
|
||||||
perinteinen Seurantalo piknik-nurmikkoineen ja lähimetsineen tarjoaa
|
|
||||||
puitteet lavaesiintyjille, työpajoille ja elävälle musiikille.
|
|
||||||
Velkuanmaan saaren pastoraali-idylli kahden lossin takana viettelee
|
|
||||||
saaristoluonnon syvyyksiin runolaulu-työpajan, kukkaseppelkruunujen ja
|
|
||||||
karjalaisen löylyriitin myötä.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
Runosaari-festivaaliin osallistuu toistakymmentä maamme eturivin
|
|
||||||
runoilijaa, muusikoita, työpajan vetäjiä ja muita esiintyjiä to 22.7.–
|
|
||||||
la 24.7.2021.
|
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
<i>[Ohjelmaa päivitetään muuttuvan tilanteen mukaan]</i>
|
|
||||||
</p>
|
|
||||||
</section>
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<%= error_tag form, :desc %>
|
<%= error_tag form, :desc %>
|
||||||
|
|
||||||
<%= label form, :seqnum, "Prioriteetti (1 on korkein)" %>
|
<%= label form, :seqnum, "Prioriteetti (1 on korkein)" %>
|
||||||
<%= textarea form, :seqnum %>
|
<%= number_input form, :seqnum %>
|
||||||
<%= error_tag form, :seqnum %>
|
<%= error_tag form, :seqnum %>
|
||||||
|
|
||||||
<%= label form, :photo, "Esiintyjän kuva" %>
|
<%= label form, :photo, "Esiintyjän kuva" %>
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
<section class="main">
|
<section class="main">
|
||||||
<h1 id="performers-start">Esiintyjät</h1>
|
<h1 id="performers-start">Esiintyjät</h1>
|
||||||
|
|
||||||
<%= if length(@performers) == 0 do %>
|
<%= if length(@performers) == 0 do %>
|
||||||
<i>Lisätietoja tulossa myöhemmin!</i>
|
<i>Lisätietoja tulossa myöhemmin!</i>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= for performer <- @performers do %>
|
<%= for performer <- @performers do %>
|
||||||
<h2><%= performer.name %></h2>
|
<h2><%= performer.name %></h2>
|
||||||
<p><%= performer.desc %></p>
|
<p><%= performer.desc %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<section class="main">
|
<section class="main">
|
||||||
<h1>Ilmoittaudu</h1>
|
<h1>Luo esiintyjä</h1>
|
||||||
|
|
||||||
<%= render "form.html", Map.put(assigns, :action, Routes.admin_performer_path(@conn, :create)) %>
|
<%= render "form.html", Map.put(assigns, :action, Routes.admin_performer_path(@conn, :create)) %>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
3
lib/runosaari_web/views/index_view.ex
Normal file
3
lib/runosaari_web/views/index_view.ex
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
defmodule RunosaariWeb.IndexView do
|
||||||
|
use RunosaariWeb, :view
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
defmodule Runosaari.Repo.Migrations.CreateIndexParagraphs do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:index_paragraphs) do
|
||||||
|
add :content, :string, size: 3000
|
||||||
|
add :seqnum, :integer, default: 999
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
66
test/runosaari/pages_test.exs
Normal file
66
test/runosaari/pages_test.exs
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
defmodule Runosaari.PagesTest do
|
||||||
|
use Runosaari.DataCase
|
||||||
|
|
||||||
|
alias Runosaari.Pages
|
||||||
|
|
||||||
|
describe "index_paragraphs" do
|
||||||
|
alias Runosaari.Pages.Index
|
||||||
|
|
||||||
|
@valid_attrs %{content: "some content", seqnum: 42}
|
||||||
|
@update_attrs %{content: "some updated content", seqnum: 43}
|
||||||
|
@invalid_attrs %{content: nil, seqnum: nil}
|
||||||
|
|
||||||
|
def index_fixture(attrs \\ %{}) do
|
||||||
|
{:ok, index} =
|
||||||
|
attrs
|
||||||
|
|> Enum.into(@valid_attrs)
|
||||||
|
|> Pages.create_index()
|
||||||
|
|
||||||
|
index
|
||||||
|
end
|
||||||
|
|
||||||
|
test "list_index_paragraphs/0 returns all index_paragraphs" do
|
||||||
|
index = index_fixture()
|
||||||
|
assert Pages.list_index_paragraphs() == [index]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "get_index!/1 returns the index with given id" do
|
||||||
|
index = index_fixture()
|
||||||
|
assert Pages.get_index!(index.id) == index
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_index/1 with valid data creates a index" do
|
||||||
|
assert {:ok, %Index{} = index} = Pages.create_index(@valid_attrs)
|
||||||
|
assert index.content == "some content"
|
||||||
|
assert index.seqnum == 42
|
||||||
|
end
|
||||||
|
|
||||||
|
test "create_index/1 with invalid data returns error changeset" do
|
||||||
|
assert {:error, %Ecto.Changeset{}} = Pages.create_index(@invalid_attrs)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update_index/2 with valid data updates the index" do
|
||||||
|
index = index_fixture()
|
||||||
|
assert {:ok, %Index{} = index} = Pages.update_index(index, @update_attrs)
|
||||||
|
assert index.content == "some updated content"
|
||||||
|
assert index.seqnum == 43
|
||||||
|
end
|
||||||
|
|
||||||
|
test "update_index/2 with invalid data returns error changeset" do
|
||||||
|
index = index_fixture()
|
||||||
|
assert {:error, %Ecto.Changeset{}} = Pages.update_index(index, @invalid_attrs)
|
||||||
|
assert index == Pages.get_index!(index.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "delete_index/1 deletes the index" do
|
||||||
|
index = index_fixture()
|
||||||
|
assert {:ok, %Index{}} = Pages.delete_index(index)
|
||||||
|
assert_raise Ecto.NoResultsError, fn -> Pages.get_index!(index.id) end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "change_index/1 returns a index changeset" do
|
||||||
|
index = index_fixture()
|
||||||
|
assert %Ecto.Changeset{} = Pages.change_index(index)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
89
test/runosaari_web/controllers/index_controller_test.exs
Normal file
89
test/runosaari_web/controllers/index_controller_test.exs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
defmodule RunosaariWeb.IndexControllerTest do
|
||||||
|
use RunosaariWeb.ConnCase
|
||||||
|
|
||||||
|
alias Runosaari.Pages
|
||||||
|
|
||||||
|
@create_attrs %{content: "some content", seqnum: 42}
|
||||||
|
@update_attrs %{content: "some updated content", seqnum: 43}
|
||||||
|
@invalid_attrs %{content: nil, seqnum: nil}
|
||||||
|
|
||||||
|
def fixture(:index) do
|
||||||
|
{:ok, index} = Pages.create_index(@create_attrs)
|
||||||
|
index
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "index" do
|
||||||
|
test "lists all index_paragraphs", %{conn: conn} do
|
||||||
|
conn = get(conn, Routes.index_path(conn, :index))
|
||||||
|
assert html_response(conn, 200) =~ "Listing Index paragraphs"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "new index" do
|
||||||
|
test "renders form", %{conn: conn} do
|
||||||
|
conn = get(conn, Routes.admin_index_path(conn, :new))
|
||||||
|
assert html_response(conn, 200) =~ "New Index"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "create index" do
|
||||||
|
test "redirects to show when data is valid", %{conn: conn} do
|
||||||
|
conn = post(conn, Routes.admin_index_path(conn, :create), index: @create_attrs)
|
||||||
|
|
||||||
|
assert %{id: id} = redirected_params(conn)
|
||||||
|
assert redirected_to(conn) == Routes.admin_index_path(conn, :show, id)
|
||||||
|
|
||||||
|
conn = get(conn, Routes.admin_index_path(conn, :show, id))
|
||||||
|
assert html_response(conn, 200) =~ "Show Index"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders errors when data is invalid", %{conn: conn} do
|
||||||
|
conn = post(conn, Routes.admin_index_path(conn, :create), index: @invalid_attrs)
|
||||||
|
assert html_response(conn, 200) =~ "New Index"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "edit index" do
|
||||||
|
setup [:create_index]
|
||||||
|
|
||||||
|
test "renders form for editing chosen index", %{conn: conn, index: index} do
|
||||||
|
conn = get(conn, Routes.admin_index_path(conn, :edit, index))
|
||||||
|
assert html_response(conn, 200) =~ "Edit Index"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "update index" do
|
||||||
|
setup [:create_index]
|
||||||
|
|
||||||
|
test "redirects when data is valid", %{conn: conn, index: index} do
|
||||||
|
conn = put(conn, Routes.admin_index_path(conn, :update, index), index: @update_attrs)
|
||||||
|
assert redirected_to(conn) == Routes.admin_index_path(conn, :show, index)
|
||||||
|
|
||||||
|
conn = get(conn, Routes.admin_index_path(conn, :show, index))
|
||||||
|
assert html_response(conn, 200) =~ "some updated content"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "renders errors when data is invalid", %{conn: conn, index: index} do
|
||||||
|
conn = put(conn, Routes.admin_index_path(conn, :update, index), index: @invalid_attrs)
|
||||||
|
assert html_response(conn, 200) =~ "Edit Index"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "delete index" do
|
||||||
|
setup [:create_index]
|
||||||
|
|
||||||
|
test "deletes chosen index", %{conn: conn, index: index} do
|
||||||
|
conn = delete(conn, Routes.admin_index_path(conn, :delete, index))
|
||||||
|
assert redirected_to(conn) == Routes.index_path(conn, :index)
|
||||||
|
|
||||||
|
assert_error_sent 404, fn ->
|
||||||
|
get(conn, Routes.admin_index_path(conn, :show, index))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp create_index(_) do
|
||||||
|
index = fixture(:index)
|
||||||
|
%{index: index}
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user