barebones activity page

This commit is contained in:
byte[] 2019-10-04 12:48:00 -04:00
parent 6e5d81191d
commit 7508456919
6 changed files with 172 additions and 25 deletions

View file

@ -104,7 +104,7 @@ defmodule Philomena.Images do
Image.changeset(image, %{})
end
alias Philomena.Images.Features
alias Philomena.Images.Feature
@doc """
Returns the list of image_features.
@ -112,28 +112,28 @@ defmodule Philomena.Images do
## Examples
iex> list_image_features()
[%Features{}, ...]
[%Feature{}, ...]
"""
def list_image_features do
Repo.all(Features)
Repo.all(Feature)
end
@doc """
Gets a single features.
Raises `Ecto.NoResultsError` if the Features does not exist.
Raises `Ecto.NoResultsError` if the Feature does not exist.
## Examples
iex> get_features!(123)
%Features{}
%Feature{}
iex> get_features!(456)
** (Ecto.NoResultsError)
"""
def get_features!(id), do: Repo.get!(Features, id)
def get_features!(id), do: Repo.get!(Feature, id)
@doc """
Creates a features.
@ -141,15 +141,15 @@ defmodule Philomena.Images do
## Examples
iex> create_features(%{field: value})
{:ok, %Features{}}
{:ok, %Feature{}}
iex> create_features(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_features(attrs \\ %{}) do
%Features{}
|> Features.changeset(attrs)
%Feature{}
|> Feature.changeset(attrs)
|> Repo.insert()
end
@ -159,31 +159,31 @@ defmodule Philomena.Images do
## Examples
iex> update_features(features, %{field: new_value})
{:ok, %Features{}}
{:ok, %Feature{}}
iex> update_features(features, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_features(%Features{} = features, attrs) do
def update_features(%Feature{} = features, attrs) do
features
|> Features.changeset(attrs)
|> Feature.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a Features.
Deletes a Feature.
## Examples
iex> delete_features(features)
{:ok, %Features{}}
{:ok, %Feature{}}
iex> delete_features(features)
{:error, %Ecto.Changeset{}}
"""
def delete_features(%Features{} = features) do
def delete_features(%Feature{} = features) do
Repo.delete(features)
end
@ -193,11 +193,11 @@ defmodule Philomena.Images do
## Examples
iex> change_features(features)
%Ecto.Changeset{source: %Features{}}
%Ecto.Changeset{source: %Feature{}}
"""
def change_features(%Features{} = features) do
Features.changeset(features, %{})
def change_features(%Feature{} = features) do
Feature.changeset(features, %{})
end
alias Philomena.Images.Intensities

View file

@ -1,4 +1,4 @@
defmodule Philomena.Images.Features do
defmodule Philomena.Images.Feature do
use Ecto.Schema
import Ecto.Changeset

View file

@ -0,0 +1,98 @@
defmodule PhilomenaWeb.ActivityController do
use PhilomenaWeb, :controller
alias Philomena.{Images, Images.Image, Images.Feature, Channels.Channel, Topics.Topic, Forums.Forum}
alias Philomena.Repo
import Ecto.Query
plug ImageFilter
def index(conn, _params) do
user = conn.assigns.current_user
filter = conn.assigns.compiled_filter
{:ok, image_query} = Images.Query.compile(user, "created_at.lte:3 minutes ago")
images =
Image.search_records(
%{
query: %{
bool: %{
must_not: filter,
must: image_query
}
},
sort: %{created_at: :desc}
},
Image |> preload([:tags])
)
top_scoring =
Image.search_records(
%{
query: %{
bool: %{
must_not: filter,
must: %{range: %{first_seen_at: %{gt: "now-3d"}}}
}
},
size: 4,
from: :rand.uniform(26) - 1,
sort: [%{score: :desc}, %{first_seen_at: :desc}]
},
Image |> preload([:tags])
)
watched = if user do
{:ok, watched_query} = if !!user, do: Images.Query.compile(user, "my:watched")
Image.search_records(
%{
query: %{
bool: %{
must_not: filter,
must: watched_query
}
},
sort: %{created_at: :desc}
},
Image |> preload([:tags])
)
end
featured_image =
Image
|> join(:inner, [i], f in Feature, on: [id: f.image_id])
|> order_by([i, f], desc: f.created_at)
|> limit(1)
|> Repo.one()
#streams =
# Channel
# |> where([c], c.nsfw == false)
# |> where([c], not is_nil(c.last_fetched_at))
# |> order_by(desc: :is_live, asc: :title)
# |> limit(6)
# |> Repo.all()
topics =
Topic
|> join(:inner, [t], f in Forum, on: [forum_id: f.id])
|> where([t, _f], t.hidden_from_users == false)
|> where([t, _f], not ilike(t.title, "NSFW"))
|> where([_t, f], f.access_level == "normal")
|> order_by(desc: :last_replied_to_at)
|> preload([:forum, last_post: :user])
|> limit(6)
render(
conn,
"index.html",
images: images,
top_scoring: top_scoring,
watched: watched,
featured_image: featured_image,
#streams: streams,
topics: topics
)
end
end

View file

@ -14,16 +14,16 @@ defmodule PhilomenaWeb.Router do
plug :accepts, ["json"]
end
scope "/" do
pipe_through :browser
pow_routes()
end
#scope "/" do
# pipe_through :browser
#
# pow_routes()
#end
scope "/", PhilomenaWeb do
pipe_through :browser
get "/", PageController, :index
get "/", ActivityController, :index
resources "/images", ImageController, only: [:index, :show]
resources "/tags", TagController, only: [:index, :show]

View file

@ -0,0 +1,46 @@
.column-layout
aside.column-layout__left#activity-side
= if @featured_image do
.center
h4.remove-top-margin Featured Image
= render PhilomenaWeb.ImageView, "index.html", images: [@featured_image]
.block.block--fixed.block--fixed--sub.block--success.center.hide-mobile
' Enjoy the site?
a href="/pages/donations"
' Become a patron or donate!
.block.block--fixed.block--fixed--sub.center.hide-mobile
| Issues? Want to chat?
a< href="/pages/contact" Contact us!
.block.hide-mobile
.block__content.flex.flex--centered.flex--wrap.image-flex-grid
= render PhilomenaWeb.ImageView, "index.html", images: @top_scoring
/a.block__header--single-item.center href=search_path(q: '*', sf: 'score', sd: 'desc') All Time Top Scoring
/a.block__header--single-item.center href='/lists' More Lists
.block.hide-mobile
a.block__header--single-item.center href="/channels"
' Streams
/= render partial: 'channels/channel_strip', collection: @streams
.block.hide-mobile
a.block__header--single-item.center href="/forums"
' Forum Activity
/= render partial: 'topics/topic_slim', collection: @topics
.block.hide-mobile
a.block__header--single-item.center href="/lists/recent_comments"
' Recent Comments
/= render partial: 'comments/comment_activitypage', collection: @comments
/a.block__header--single-item.center href=search_path(q: 'first_seen_at.gt:3 days ago', sf: 'comments', sd: 'desc') Most Commented-on Images
.column-layout__main
/- @pagination_params = { params: { controller: :images, action: :index } }
= render PhilomenaWeb.ImageView, "index.html", images: @images
= if !!@watched and @watched != [] do
.block
.block__header
span.block__header__title
' Watched Images
a href="/search?q=my:watched" title="Browse Watched Images"
i.fa.fa-eye>
span.hide-mobile
' Browse Watched Images
.block__content.js-resizable-media-container
= render PhilomenaWeb.ImageView, "index.html", images: @watched

View file

@ -0,0 +1,3 @@
defmodule PhilomenaWeb.ActivityView do
use PhilomenaWeb, :view
end