Skip to content

Commit 4608884

Browse files
committed
Web interface to refresh container list
1 parent d2641d5 commit 4608884

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

web/controllers/repository_controller.ex

+19-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ defmodule Beanie.RepositoryController do
33

44
alias Beanie.Repository
55

6-
def index(conn, _params) do
7-
repositories = Repo.all(Repository)
8-
render(conn, "index.html", repositories: repositories)
9-
end
10-
11-
def new(conn, _params) do
12-
changeset = Repository.changeset(%Repository{})
13-
render(conn, "new.html", changeset: changeset)
6+
def index(conn, params) do
7+
case repository_list(params["update"]) do
8+
{:ok, repositories} ->
9+
conn
10+
|> put_flash(:info, "Repository list updated")
11+
|> render("index.html", repositories: repositories)
12+
{:error, repositories} ->
13+
conn
14+
|> put_flash(:error, "Error fetching repositories")
15+
|> render("index.html", repositories: repositories)
16+
end
1417
end
1518

1619
def create(conn, %{"repository" => repository_params}) do
@@ -62,4 +65,12 @@ defmodule Beanie.RepositoryController do
6265
|> put_flash(:info, "Repository deleted successfully.")
6366
|> redirect(to: repository_path(conn, :index))
6467
end
68+
69+
defp repository_list("true") do
70+
# TODO refresh repository listing, then fetch from db
71+
{:ok, Repo.all(Repository)}
72+
end
73+
defp repository_list(_) do
74+
{:ok, Repo.all(Repository)}
75+
end
6576
end

web/templates/repository/index.html.eex

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<h2>Listing repositories</h2>
22

3+
<%= link "Update List", to: repository_path(@conn, :index, update: true) %>
4+
35
<table class="table">
46
<thead>
57
<tr>
@@ -22,5 +24,3 @@
2224
<% end %>
2325
</tbody>
2426
</table>
25-
26-
<%= link "New repository", to: repository_path(@conn, :new) %>

0 commit comments

Comments
 (0)