mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
tag page
This commit is contained in:
parent
1349f41f99
commit
86ffbfdb5b
9 changed files with 41 additions and 20 deletions
|
@ -25,6 +25,9 @@ config :bcrypt_elixir,
|
||||||
config :elastix,
|
config :elastix,
|
||||||
json_codec: Jason
|
json_codec: Jason
|
||||||
|
|
||||||
|
config :canary,
|
||||||
|
repo: Philomena.Repo
|
||||||
|
|
||||||
# Configures the endpoint
|
# Configures the endpoint
|
||||||
config :philomena, PhilomenaWeb.Endpoint,
|
config :philomena, PhilomenaWeb.Endpoint,
|
||||||
url: [host: "localhost"],
|
url: [host: "localhost"],
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule Philomena.Images.Elasticsearch do
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mappings: %{
|
mappings: %{
|
||||||
_doc: %{
|
image: %{
|
||||||
_all: %{enabled: false},
|
_all: %{enabled: false},
|
||||||
dynamic: false,
|
dynamic: false,
|
||||||
properties: %{
|
properties: %{
|
||||||
|
@ -76,6 +76,10 @@ defmodule Philomena.Images.Elasticsearch do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# preload([
|
||||||
|
# :user, :deleter, :gallery_interactions, :upvoters, :downvoters, :favers,
|
||||||
|
# :hiders, tags: [:aliases, :aliased_tag]
|
||||||
|
# ])
|
||||||
def as_json(image) do
|
def as_json(image) do
|
||||||
%{
|
%{
|
||||||
id: image.id,
|
id: image.id,
|
||||||
|
|
|
@ -35,7 +35,7 @@ defmodule Philomena.Tags do
|
||||||
** (Ecto.NoResultsError)
|
** (Ecto.NoResultsError)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def get_tag!(id), do: Repo.get!(Tag, id)
|
def get_tag!(slug), do: Repo.get_by!(Tag, slug: slug)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Creates a tag.
|
Creates a tag.
|
||||||
|
|
|
@ -12,8 +12,8 @@ defimpl Canada.Can, for: [Atom, Philomena.Users.User] do
|
||||||
when action in [:new, :create, :index],
|
when action in [:new, :create, :index],
|
||||||
do: true
|
do: true
|
||||||
|
|
||||||
def can?(_user, :read, %Image{hidden_from_users: true}), do: false
|
def can?(_user, :show, %Image{hidden_from_users: true}), do: false
|
||||||
def can?(_user, :read, %Image{hidden_from_users: false}), do: true
|
def can?(_user, :show, %Image{hidden_from_users: false}), do: true
|
||||||
|
|
||||||
# Otherwise...
|
# Otherwise...
|
||||||
def can?(_user, _action, _model), do: false
|
def can?(_user, _action, _model), do: false
|
||||||
|
|
|
@ -23,6 +23,7 @@ defmodule PhilomenaWeb do
|
||||||
|
|
||||||
import Plug.Conn
|
import Plug.Conn
|
||||||
import PhilomenaWeb.Gettext
|
import PhilomenaWeb.Gettext
|
||||||
|
import Canary.Plugs
|
||||||
alias PhilomenaWeb.Router.Helpers, as: Routes
|
alias PhilomenaWeb.Router.Helpers, as: Routes
|
||||||
alias PhilomenaWeb.Plugs.ImageFilter
|
alias PhilomenaWeb.Plugs.ImageFilter
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
defmodule PhilomenaWeb.ImageController do
|
defmodule PhilomenaWeb.ImageController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias Philomena.{Images, Images.Image}
|
alias Philomena.{Images.Image}
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug ImageFilter
|
plug ImageFilter
|
||||||
|
plug :load_and_authorize_resource, model: Image, only: :show, preload: :tags
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
query = conn.assigns.compiled_filter
|
query = conn.assigns.compiled_filter
|
||||||
|
@ -21,8 +22,7 @@ defmodule PhilomenaWeb.ImageController do
|
||||||
render(conn, "index.html", images: images)
|
render(conn, "index.html", images: images)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(conn, %{"id" => id}) do
|
def show(conn, %{"id" => _id}) do
|
||||||
image = Images.get_image!(id)
|
render(conn, "show.html", image: conn.assigns.image)
|
||||||
render(conn, "show.html", image: image)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,35 @@
|
||||||
defmodule PhilomenaWeb.TagController do
|
defmodule PhilomenaWeb.TagController do
|
||||||
use PhilomenaWeb, :controller
|
use PhilomenaWeb, :controller
|
||||||
|
|
||||||
alias Philomena.Tags
|
alias Philomena.{Images.Image, Tags}
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
plug ImageFilter
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
tags = Tags.list_tags()
|
tags = Tags.list_tags()
|
||||||
render(conn, "index.html", tags: tags)
|
render(conn, "index.html", tags: tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show(conn, %{"id" => id}) do
|
def show(conn, %{"id" => slug}) do
|
||||||
tag = Tags.get_tag!(id)
|
tag = Tags.get_tag!(slug)
|
||||||
render(conn, "show.html", tag: tag)
|
|
||||||
|
query = conn.assigns.compiled_filter
|
||||||
|
|
||||||
|
images =
|
||||||
|
Image.search_records(
|
||||||
|
%{
|
||||||
|
query: %{
|
||||||
|
bool: %{
|
||||||
|
must_not: query,
|
||||||
|
must: %{term: %{"namespaced_tags.name": tag.name}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
sort: %{created_at: :desc}
|
||||||
|
},
|
||||||
|
Image |> preload(:tags)
|
||||||
|
)
|
||||||
|
|
||||||
|
render(conn, "show.html", tag: tag, images: images)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
<h1>Show Tag</h1>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<span><%= link "Edit", to: Routes.tag_path(@conn, :edit, @tag) %></span>
|
|
||||||
<span><%= link "Back", to: Routes.tag_path(@conn, :index) %></span>
|
|
1
lib/philomena_web/templates/tag/show.html.slime
Normal file
1
lib/philomena_web/templates/tag/show.html.slime
Normal file
|
@ -0,0 +1 @@
|
||||||
|
= render PhilomenaWeb.ImageView, "index.html", images: @images
|
Loading…
Reference in a new issue