diff --git a/lib/kmxgit/organisation_manager.ex b/lib/kmxgit/organisation_manager.ex
index e9fed40..dde5de1 100644
--- a/lib/kmxgit/organisation_manager.ex
+++ b/lib/kmxgit/organisation_manager.ex
@@ -13,9 +13,17 @@ defmodule Kmxgit.OrganisationManager do
from(org in Organisation)
|> join(:inner, [org], s in Slug, on: s.organisation_id == org.id)
|> preload([:owned_repositories, :slug])
+ |> search(params)
|> index_order_by(params)
|> Repo.all()
end
+
+ def search(query, %IndexParams{search: search}) do
+ expr = "%#{search}%"
+ query
+ |> where([org, s], ilike(org.name, ^expr) or ilike(s.slug, ^expr))
+ end
+
def index_order_by(query, %{column: "id", reverse: true}) do
order_by(query, [desc: :id])
end
diff --git a/lib/kmxgit_web/controllers/admin/organisation_controller.ex b/lib/kmxgit_web/controllers/admin/organisation_controller.ex
index 38100c1..04124ff 100644
--- a/lib/kmxgit_web/controllers/admin/organisation_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/organisation_controller.ex
@@ -10,10 +10,13 @@ defmodule KmxgitWeb.Admin.OrganisationController do
def index(conn, params) do
index_params = %IndexParams{}
|> KmxgitWeb.Admin.sort_param(params["sort"])
+ |> KmxgitWeb.Admin.search_param(params["search"])
orgs = OrganisationManager.list_organisations(index_params)
conn
|> assign(:index, index_params)
|> assign(:orgs, orgs)
+ |> assign(:search, params["search"])
+ |> assign(:search_action, Routes.admin_organisation_path(conn, :index, sort: params["sort"], search: params["search"]))
|> render("index.html")
end
diff --git a/lib/kmxgit_web/templates/admin/organisation/index.html.heex b/lib/kmxgit_web/templates/admin/organisation/index.html.heex
index 0d161bd..4368936 100644
--- a/lib/kmxgit_web/templates/admin/organisation/index.html.heex
+++ b/lib/kmxgit_web/templates/admin/organisation/index.html.heex
@@ -7,13 +7,14 @@
<%= link gettext("Create"), to: Routes.admin_organisation_path(@conn, :new), class: "btn btn-primary" %>
</div>
</div>
+ <%= render(KmxgitWeb.LayoutView, "search.html", assigns) %>
<table class="table admin-index">
<thead>
<tr>
- <th><%= link gettext("Id"), to: Routes.admin_organisation_path(@conn, :index, sort: "id#{if @index.column == "id" && !@index.reverse, do: "-"}") %><%= if @index.column == "id" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
- <th><%= link gettext("Name"), to: Routes.admin_organisation_path(@conn, :index, sort: "name#{if @index.column == "name" && !@index.reverse, do: "-"}") %><%= if @index.column == "name" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
- <th><%= link gettext("Slug"), to: Routes.admin_organisation_path(@conn, :index, sort: "slug#{if @index.column == "slug" && !@index.reverse, do: "-"}") %><%= if @index.column == "slug" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
- <th><%= link gettext("Disk usage"), to: Routes.admin_organisation_path(@conn, :index, sort: "du#{if @index.column != "du" || (@index.column == "du" && !@index.reverse), do: "-"}") %><%= if @index.column == "du" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
+ <th><%= link gettext("Id"), to: Routes.admin_organisation_path(@conn, :index, search: @search, sort: "id#{if @index.column == "id" && !@index.reverse, do: "-"}") %><%= if @index.column == "id" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
+ <th><%= link gettext("Name"), to: Routes.admin_organisation_path(@conn, :index, search: @search, sort: "name#{if @index.column == "name" && !@index.reverse, do: "-"}") %><%= if @index.column == "name" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
+ <th><%= link gettext("Slug"), to: Routes.admin_organisation_path(@conn, :index, search: @search, sort: "slug#{if @index.column == "slug" && !@index.reverse, do: "-"}") %><%= if @index.column == "slug" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
+ <th><%= link gettext("Disk usage"), to: Routes.admin_organisation_path(@conn, :index, search: @search, sort: "du#{if @index.column != "du" || (@index.column == "du" && !@index.reverse), do: "-"}") %><%= if @index.column == "du" do %><%= if @index.reverse do %> <i class="fa fa-angle-down"></i><% else %> <i class="fa fa-angle-up"></i><% end %><% end %></th>
<th><%= gettext("Actions") %></th>
</tr>
</thead>
diff --git a/lib/kmxgit_web/templates/admin/repository/index.html.heex b/lib/kmxgit_web/templates/admin/repository/index.html.heex
index c5fd04a..9782fa8 100644
--- a/lib/kmxgit_web/templates/admin/repository/index.html.heex
+++ b/lib/kmxgit_web/templates/admin/repository/index.html.heex
@@ -1,8 +1,6 @@
<div class="container-fluid">
<h1>Repositories</h1>
-
<%= render(KmxgitWeb.LayoutView, "search.html", assigns) %>
-
<table class="table admin-index">
<thead>
<tr>