Merge branch 'content-refactors' into 'master'

feat: Add comments to admin

See merge request mythic-insight/legendary!10
This commit is contained in:
Robert Prehn 2020-07-29 13:53:44 +00:00
commit 8683083ce0
61 changed files with 461 additions and 1298 deletions

View file

@ -23,6 +23,7 @@
</div>
<%= error_tag f, :password, class: "ui error message" %>
</div>
<%= hidden_input f, :persistent_session, value: "true" %>
<%= submit "Login", class: "ui fluid large teal submit button" %>
</div>
<% end %>

View file

@ -11,7 +11,7 @@ defmodule Content.Attachment do
|> Post.metas_map
deserialization_results =
meta["_wp_attachment_metadata"]
meta["attachment_metadata"]
|> PhpSerializer.unserialize
case deserialization_results do

View file

@ -1,178 +0,0 @@
defmodule Content.UpdateMenu do
alias Content.{Menu, Post, Postmeta, Repo, TermRelationship}
alias Ecto.Multi
import Ecto.Query
def run(id, new_menu_params) do
current_posts = Menu.nav_menu_items_for_id(id)
post_ids_in_new_menu = recursive_post_ids(new_menu_params)
deleted_post_ids =
current_posts
|> Enum.reject(& &1.id in post_ids_in_new_menu)
|> Enum.map(& &1.id)
Multi.new()
|> process_nodes(id, 0, new_menu_params |> add_order())
|> Multi.delete_all(:stale_nodes, from(p in Post, where: p.id in ^deleted_post_ids))
|> Repo.transaction()
end
def add_order(tree) do
{_next_order, nodes} = add_order_starting_at(tree, 1)
nodes
end
def add_order_starting_at(tree, starting_at) do
tree
|> Enum.reduce({starting_at, []}, fn node, {order, new_nodes} ->
{next_order, new_child_nodes} = add_order_starting_at(node["children"], order + 1)
new_node =
node
|> Map.merge(%{
"order" => order,
"children" => new_child_nodes,
})
{next_order, new_nodes ++ [new_node]}
end)
end
defp process_nodes(multi, menu_id, parent_id, nodes) do
nodes
|> Enum.reduce(multi, fn node, m ->
case node["post_id"] do
nil ->
create_node(m, menu_id, parent_id, node)
_id ->
update_node(m, menu_id, parent_id, node)
end
end)
end
defp create_node(multi, menu_id, parent_id, node) do
post =
Post.changeset(
%Post{},
%{
post_author: 1,
post_title: node["title"],
post_status: "publish",
comment_status: "closed",
ping_status: "closed",
menu_order: node["order"],
post_type: "nav_menu_item",
comment_count: 0,
}
)
step_name = "#{parent_id}.create_node.#{node["order"]}"
multi
|> Multi.insert(step_name, post)
|> Multi.run("#{step_name}.term_relationship", fn _repo, %{^step_name => post} ->
tr =
TermRelationship.changeset(
%TermRelationship{},
%{
object_id: post.id,
term_taxonomy_id: menu_id,
term_order: 0,
}
)
Repo.insert(tr)
end)
|> Multi.merge(fn %{^step_name => post} ->
Multi.new()
|> insert_metas(type_of_node(node), post, parent_id, node)
end)
|> Multi.merge(fn %{^step_name => post} ->
Multi.new()
|> process_nodes(menu_id, post.id, node["children"])
end)
end
defp insert_metas(multi, "post", post, parent_id, node) do
multi
|> update_meta(post.id, "_menu_item_type", "post_type")
|> update_meta(post.id, "_menu_item_object", "page")
|> update_meta(post.id, "_menu_item_object_id", node["target_id"])
|> update_meta(post.id, "_menu_item_menu_item_parent", parent_id)
end
defp insert_metas(multi, "category", post, parent_id, node) do
multi
|> update_meta(post.id, "_menu_item_type", "taxonomy")
|> update_meta(post.id, "_menu_item_object", "category")
|> update_meta(post.id, "_menu_item_object_id", node["target_id"])
|> update_meta(post.id, "_menu_item_menu_item_parent", parent_id)
end
defp insert_metas(multi, "link", post, parent_id, node) do
multi
|> update_meta(post.id, "_menu_item_type", "custom")
|> update_meta(post.id, "_menu_item_object", "custom")
|> update_meta(post.id, "_menu_item_object_id", post.id)
|> update_meta(post.id, "_menu_item_url", node["url"])
|> update_meta(post.id, "_menu_item_menu_item_parent", parent_id)
end
defp type_of_node(%{"url" => url}) when url != nil, do: "link"
defp type_of_node(%{"related_item" => %{"resource" => "posts"}}), do: "post"
defp type_of_node(%{"related_item" => %{"resource" => "category"}}), do: "category"
defp update_node(multi, menu_id, parent_id, node) do
multi
|> update_meta(node["post_id"], "_menu_item_menu_item_parent", parent_id)
|> update_order(node["post_id"], node["order"])
|> process_nodes(menu_id, node["post_id"], node["children"])
end
defp update_meta(multi, post_id, meta_key, new_value) when is_integer(new_value),
do: update_meta(multi, post_id, meta_key, new_value |> Integer.to_string())
defp update_meta(multi, post_id, meta_key, new_value) do
step_name = "#{post_id}.update_meta.#{meta_key}"
type = Postmeta.__schema__(:type, :meta_value)
cast_value = Ecto.Type.cast(type, new_value)
Postmeta
|> where([pm], pm.meta_key == ^meta_key)
|> where([pm], pm.post_id == ^post_id)
|> Repo.one()
|> case do
nil ->
multi
|> Multi.insert(
step_name,
Postmeta.changeset(
%Postmeta{},
%{
post_id: post_id,
meta_key: meta_key,
meta_value: new_value
}
)
)
%{meta_value: ^cast_value} ->
# No change needed
multi
meta ->
multi
|> Multi.update(step_name, Postmeta.changeset(meta, %{meta_value: new_value}))
end
end
defp update_order(multi, post_id, new_order) do
step_name = "#{post_id}.update_order"
multi
|> Multi.update_all(step_name, from(p in Post, where: p.id == ^post_id), [set: [menu_order: new_order]])
end
defp recursive_post_ids(params) do
params
|> Enum.flat_map(& [&1["post_id"]|recursive_post_ids(&1["children"])])
end
end

View file

@ -6,49 +6,47 @@ defmodule Content.Comment do
import Ecto.Changeset
alias Content.{Post}
@primary_key {:comment_id, :id, autogenerate: true}
@derive {Phoenix.Param, key: :comment_id}
schema "wp_comments" do
belongs_to :post, Post, foreign_key: :comment_post_id, references: :id
field :comment_author, :string
field :comment_author_email, :string
field :comment_author_url, :string
field :comment_author_IP, :string
field :comment_date, :naive_datetime
field :comment_date_gmt, :naive_datetime
field :comment_content, :string
field :comment_karma, :integer
field :comment_approved, :string
field :comment_agent, :string
field :comment_type, :string
field :comment_parent, :integer, default: 0
schema "comments" do
belongs_to :post, Post
field :author, :string
field :author_email, :string
field :author_url, :string
field :author_IP, :string
field :date, :naive_datetime
field :date_gmt, :naive_datetime
field :content, :string
field :karma, :integer
field :approved, :string
field :agent, :string
field :type, :string
field :parent, :integer, default: 0
field :user_id, :integer
end
def changeset(struct, params \\ %{}) do
struct
|> Map.merge(%{
comment_date: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second),
comment_date_gmt: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second),
comment_approved: "1"
date: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second),
date_gmt: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second),
approved: "1"
})
|> cast(params, [
:comment_id,
:comment_post_id,
:comment_author,
:comment_author_email,
:comment_author_url,
:comment_author_IP,
:comment_date,
:comment_date_gmt,
:comment_content,
:comment_karma,
:comment_approved,
:comment_agent,
:comment_type,
:comment_parent,
:id,
:post_id,
:author,
:author_email,
:author_url,
:author_IP,
:date,
:date_gmt,
:content,
:karma,
:approved,
:agent,
:type,
:parent,
:user_id
])
|> validate_required([:comment_content])
|> validate_required([:content])
end
end

View file

@ -0,0 +1,26 @@
defmodule Content.CommentAdmin do
def index(_) do
[
id: nil,
author: nil,
author_email: nil,
author_url: nil,
content: nil,
approved: nil,
date: nil,
date_gmt: nil,
]
end
def form_fields(_) do
[
author: nil,
author_email: nil,
author_url: nil,
content: %{type: :textarea, rows: 8},
date: nil,
date_gmt: nil,
approved: nil,
]
end
end

View file

@ -5,15 +5,14 @@ defmodule Content.Commentmeta do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:meta_id, :id, autogenerate: true}
schema "wp_commentmeta" do
schema "commentmeta" do
field :comment_id, :integer
field :meta_key, :string
field :meta_value, :string
field :key, :string
field :value, :string
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:meta_id, :comment_id, :meta_key, :meta_value])
|> cast(params, [:id, :comment_id, :key, :value])
end
end

View file

@ -6,9 +6,9 @@ defmodule Content.Comments do
alias Content.Comment
alias Content.Repo
def children(parent_comment_id, array_of_comments) do
def children(parent_id, array_of_comments) do
array_of_comments
|> Enum.filter(&(&1.comment_parent == parent_comment_id))
|> Enum.filter(&(&1.parent == parent_id))
end
@doc """

View file

@ -5,38 +5,37 @@ defmodule Content.Link do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:link_id, :id, autogenerate: true}
schema "wp_links" do
field :link_url, :string
field :link_name, :string
field :link_image, :string
field :link_target, :string
field :link_description, :string
field :link_visible, :string
field :link_owner, :integer
field :link_rating, :integer
field :link_updated, :naive_datetime
field :link_rel, :string
field :link_notes, :string
field :link_rss, :string
schema "links" do
field :url, :string
field :name, :string
field :image, :string
field :target, :string
field :description, :string
field :visible, :string
field :owner, :integer
field :rating, :integer
field :updated, :naive_datetime
field :rel, :string
field :notes, :string
field :rss, :string
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [
:link_id,
:link_url,
:link_name,
:link_image,
:link_target,
:link_description,
:link_visible,
:link_owner,
:link_rating,
:link_updated,
:link_rel,
:link_notes,
:link_rss
:id,
:url,
:name,
:image,
:target,
:description,
:visible,
:owner,
:rating,
:updated,
:rel,
:notes,
:rss
])
end
end

View file

@ -1,167 +0,0 @@
defmodule Content.Menu do
@moduledoc """
Module for retrieving, manipulating, and processing navigation menus.
"""
alias Content.{Option, Post, Repo, Term, TermRelationship}
import Ecto.Query
def put_menu_option(option_name, location_name, menu_id) do
option =
Option
|> where(option_name: ^option_name)
|> Repo.one()
|> Kernel.||(%Option{option_name: option_name, option_value: "a:0:{}"})
value =
option
|> Option.parse_option_value
nav_menu_locations =
value
|> Enum.find(fn {key, _value} -> key == "nav_menu_locations" end)
|> Kernel.||({"nav_menu_locations", []})
|> elem(1)
new_nav_menu_locations =
nav_menu_locations
|> Enum.filter(fn {key, _value} -> key != location_name end)
|> Kernel.++([{location_name, menu_id}])
new_value =
value
|> Enum.filter(fn {key, _value} -> key != "nav_menu_locations" end)
|> Kernel.++([{"nav_menu_locations", new_nav_menu_locations}])
option
|> Option.put_new_value(new_value)
end
def get_menu_from_option_and_location(option_name, location_name) do
option =
Option
|> where(option_name: ^option_name)
|> Repo.one()
|> Kernel.||(%Option{option_name: option_name, option_value: "a:0:{}"})
value =
option
|> Option.parse_option_value
menu_pair =
value
|> Enum.find(fn {key, _value} -> key == "nav_menu_locations" end)
|> Kernel.||({"nav_menu_locations", []})
|> elem(1)
|> Enum.find(fn {key, _value} -> key == location_name end)
case menu_pair do
{^location_name, menu_id} ->
menu_id |> get_menu_from_id()
nil ->
nil
end
end
def get_menu_from_id(menu_id) do
menu_id
|> nav_menu_items_for_id()
|> arrange_menu_item_posts()
end
def nav_menu_items_for_id(menu_id) do
Post
|> join(
:inner,
[p],
tr in TermRelationship,
on: p.id == tr.object_id
)
|> order_by(:menu_order)
|> preload(:metas)
|> where([p, tr], tr.term_taxonomy_id == ^menu_id)
|> Repo.all()
end
defp arrange_menu_item_posts(nav_posts, parent_id \\ "0", nav_to_post_map \\ nil) do
nav_to_post_map = nav_to_post_map || make_nav_to_post_map(nav_posts)
nav_posts
|> Enum.filter(fn post ->
meta_map = post |> Post.metas_map
meta_map["_menu_item_menu_item_parent"] == parent_id
end)
|> Enum.map(fn post ->
meta_map = post |> Post.metas_map
related_item =
if meta_map["_menu_item_object"] == "category" do
item = nav_to_post_map["category/#{meta_map["_menu_item_object_id"]}"] || %Term{}
%{
title: item.name,
slug: item.slug,
resource: "category",
}
else
item = nav_to_post_map["post/#{meta_map["_menu_item_object_id"]}"] || %Post{}
%{
title: item.post_title,
slug: item.post_name,
resource: "posts",
}
end
%{
post_id: post.id,
type: meta_map["_menu_item_object"],
target_id: meta_map["_menu_item_object_id"],
parent_id: meta_map["_menu_item_menu_item_parent"],
url: meta_map["_menu_item_url"],
related_item: related_item,
children: arrange_menu_item_posts(nav_posts, Integer.to_string(post.id), nav_to_post_map),
}
end)
end
defp make_nav_to_post_map(nav_posts) do
nav_post_meta_map = nav_posts |> Post.metas_map()
linked_post_ids =
nav_post_meta_map
|> Enum.filter(fn {_key, value} ->
value["_menu_item_object"] != "category"
end)
|> Enum.map(fn {_key, value} ->
value["_menu_item_object_id"]
end)
nav_to_post_map =
Post
|> where([p], p.id in ^linked_post_ids)
|> Repo.all()
|> Enum.map(fn post ->
{"post/#{post.id}", post}
end)
|> Map.new
linked_category_ids =
nav_post_meta_map
|> Enum.filter(fn {_key, value} ->
value["_menu_item_object"] == "category"
end)
|> Enum.map(fn {_key, value} ->
value["_menu_item_object_id"]
end)
nav_to_category_map =
Term
|> where([t], t.term_id in ^linked_category_ids)
|> Repo.all()
|> Enum.map(fn category ->
{"category/#{category.term_id}", category}
end)
|> Map.new
nav_to_post_map |> Map.merge(nav_to_category_map)
end
end

View file

@ -5,20 +5,19 @@ defmodule Content.Option do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:option_id, :id, autogenerate: true}
schema "wp_options" do
field :option_name, :string
schema "options" do
field :name, :string
field :autoload, :string
field :option_value, :string
field :value, :string
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:option_id, :option_name, :option_value, :autoload])
|> cast(params, [:id, :name, :value, :autoload])
end
def parse_option_value(struct) do
case PhpSerializer.unserialize(struct.option_value) do
def parse_value(struct) do
case PhpSerializer.unserialize(struct.value) do
{:ok, values} ->
values
end
@ -26,6 +25,6 @@ defmodule Content.Option do
def put_new_value(struct, value) do
struct
|> change(%{option_value: PhpSerializer.serialize(value)})
|> change(%{value: PhpSerializer.serialize(value)})
end
end

View file

@ -8,13 +8,13 @@ defmodule Content.Options do
def put(key, value) do
%Option{}
|> Option.changeset(%{
option_name: key,
option_value: value,
name: key,
value: value,
})
|> Repo.insert()
end
def get(key), do: Option |> Repo.get_by(option_name: key)
def get(key), do: Option |> Repo.get_by(name: key)
def get_value(key) do
case get(key) do
@ -22,7 +22,7 @@ defmodule Content.Options do
nil
opt ->
opt
|> (&(&1.option_value)).()
|> (&(&1.value)).()
end
end

View file

@ -6,38 +6,37 @@ defmodule Content.Post do
import Ecto.Changeset
alias Content.Slugs
@primary_key {:id, :id, autogenerate: true}
@derive {Phoenix.Param, key: :post_name}
schema "wp_posts" do
field :post_date, :naive_datetime
field :post_date_gmt, :naive_datetime
field :post_content, :string, default: ""
field :post_title, :string
field :post_excerpt, :string
field :post_status, :string
@derive {Phoenix.Param, key: :name}
schema "posts" do
field :date, :naive_datetime
field :date_gmt, :naive_datetime
field :content, :string, default: ""
field :title, :string
field :excerpt, :string
field :status, :string
field :comment_status, :string
field :ping_status, :string
field :post_password, :string, default: ""
field :post_name, :string
field :password, :string, default: ""
field :name, :string
field :to_ping, :string, default: ""
field :pinged, :string, default: ""
field :post_modified, :naive_datetime
field :post_modified_gmt, :naive_datetime
field :post_content_filtered, :string, default: ""
field :post_parent, :integer
field :modified, :naive_datetime
field :modified_gmt, :naive_datetime
field :content_filtered, :string, default: ""
field :parent, :integer
field :guid, :string
field :menu_order, :integer
field :post_type, :string
field :post_mime_type, :string
field :type, :string
field :mime_type, :string
field :comment_count, :integer
field :sticky, :boolean, [virtual: true, default: false]
has_many :metas, Content.Postmeta, foreign_key: :post_id
has_many :comments, Content.Comment, foreign_key: :comment_post_id
has_many :metas, Content.Postmeta
has_many :comments, Content.Comment
has_many :term_relationships, Content.TermRelationship, foreign_key: :object_id
has_many :categories, through: [:term_relationships, :category, :term]
has_many :tags, through: [:term_relationships, :tag, :term]
has_one :post_format, through: [:term_relationships, :post_format, :term]
belongs_to :author, Auth.User, foreign_key: :post_author
has_one :format, through: [:term_relationships, :format, :term]
belongs_to :author, Auth.User
end
def changeset(struct, params \\ %{}) do
@ -46,35 +45,35 @@ defmodule Content.Post do
params,
[
:id,
:post_author,
:post_date,
:post_date_gmt,
:post_content,
:post_title,
:post_excerpt,
:post_status,
:author_id,
:date,
:date_gmt,
:content,
:title,
:excerpt,
:status,
:comment_status,
:ping_status,
:post_password,
:post_name,
:password,
:name,
:to_ping,
:pinged,
:post_content_filtered,
:post_parent,
:content_filtered,
:parent,
:menu_order,
:post_type,
:post_mime_type,
:type,
:mime_type,
:comment_count,
:sticky,
])
|> put_default(:post_date, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_default(:post_date_gmt, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_change(:post_modified, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_change(:post_modified_gmt, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_default(:date, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_default(:date_gmt, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_change(:modified, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> put_change(:modified_gmt, NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> Slugs.ensure_post_has_slug()
|> maybe_put_guid()
|> validate_required([:post_name, :post_status])
|> validate_inclusion(:post_status, ["publish", "future", "draft", "pending", "private", "trash", "auto-draft", "inherit"])
|> validate_required([:name, :status])
|> validate_inclusion(:status, ["publish", "future", "draft", "pending", "private", "trash", "auto-draft", "inherit"])
end
def put_default(changeset, key, value) do
@ -93,14 +92,14 @@ defmodule Content.Post do
end
def content_page(struct, page) do
(struct.post_content || "")
(struct.content || "")
|> String.split("<!--nextpage-->")
|> Enum.at(page - 1)
|> Kernel.||("")
end
def content_page_count(struct) do
(struct.post_content || "")
(struct.content || "")
|> String.split("<!--nextpage-->")
|> Enum.count
end
@ -118,13 +117,13 @@ defmodule Content.Post do
end
def metas_map(%Content.Post{} = struct) do
struct.metas
|> Enum.map(&({&1.meta_key, &1.meta_value}))
|> Enum.map(&({&1.key, &1.value}))
|> Map.new
end
def maybe_put_guid(changeset) do
import Content.Router.Helpers, only: [posts_url: 3]
slug = changeset |> get_field(:post_name)
slug = changeset |> get_field(:name)
case slug do
nil -> changeset

View file

@ -20,12 +20,12 @@ defmodule Content.PostAdmin do
def index(_) do
[
id: nil,
post_type: nil,
post_name: nil,
post_title: nil,
post_status: nil,
post_date_gmt: nil,
post_modified_gmt: nil,
type: nil,
name: nil,
title: nil,
status: nil,
date_gmt: nil,
modified_gmt: nil,
]
end
@ -43,17 +43,17 @@ defmodule Content.PostAdmin do
end)
[
post_type: %{choices: [{"Blog Post", :post}, {"Page", :page}]},
post_name: %{label: "Slug"},
post_title: nil,
post_content: %{type: :textarea, rows: 32},
post_status: %{choices: [{"Publish", :publish}, {"Draft", :draft}]},
post_author: %{choices: authors},
post_excerpt: %{type: :textarea, rows: 4},
type: %{choices: [{"Blog Post", :post}, {"Page", :page}]},
name: %{label: "Slug"},
title: nil,
content: %{type: :textarea, rows: 32},
status: %{choices: [{"Publish", :publish}, {"Draft", :draft}]},
author_id: %{choices: authors},
excerpt: %{type: :textarea, rows: 4},
sticky: nil,
comment_status: %{choices: [{"open", :open}, {"closed", :closed}]},
ping_status: %{choices: [{"open", :open}, {"closed", :closed}]},
post_password: nil,
password: nil,
menu_order: nil,
]
end

View file

@ -5,15 +5,14 @@ defmodule Content.Postmeta do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:meta_id, :id, autogenerate: true}
schema "wp_postmeta" do
schema "postmeta" do
belongs_to :post, Content.Post
field :meta_key, :string
field :meta_value, :string
field :key, :string
field :value, :string
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:meta_id, :post_id, :meta_key, :meta_value])
|> cast(params, [:id, :post_id, :key, :value])
end
end

View file

@ -12,7 +12,7 @@ defmodule Content.Posts do
alias Content.Post
alias Ecto.Changeset
@preloads [:metas, :author, :categories, :tags, :comments, :post_format]
@preloads [:metas, :author, :categories, :tags, :comments, :format]
@doc """
Returns the lisdpt of posts for admin interface.
@ -23,14 +23,14 @@ defmodule Content.Posts do
[%Post{}, ...]
"""
def list_admin_posts(page, post_type \\ "post") do
post_type = post_type || "post"
def list_admin_posts(page, type \\ "post") do
type = type || "post"
Repo.all(
from p in Post,
where: p.post_type == ^post_type,
where: p.post_status in ["publish", "future", "draft", "pending", "private", "inherit"],
where: p.type == ^type,
where: p.status in ["publish", "future", "draft", "pending", "private", "inherit"],
preload: ^@preloads,
order_by: [desc: p.post_date],
order_by: [desc: p.date],
limit: @page_size,
offset: ^(@page_size * (String.to_integer(page) - 1))
)
@ -59,12 +59,12 @@ defmodule Content.Posts do
end
def post_scope_for_params(params) do
post_type = params |> Map.get("post_type", "post")
type = params |> Map.get("type", "post")
category = params |> Map.get("category")
query =
post_scope()
|> where([p], p.post_type == ^post_type)
|> where([p], p.type == ^type)
if category do
query |> join(:inner, [p], term in assoc(p, :categories), on: term.slug == ^category)
@ -75,15 +75,15 @@ defmodule Content.Posts do
def post_scope do
from p in Post,
where: p.post_status == "publish",
where: p.status == "publish",
preload: ^@preloads,
order_by: [desc: p.post_date]
order_by: [desc: p.date]
end
def post_scope_with_drafts do
from p in Post,
preload: ^@preloads,
order_by: [desc: p.post_date]
order_by: [desc: p.date]
end
def sticky_posts_for_page(%{"page" => "1"} = params) do
@ -103,12 +103,12 @@ defmodule Content.Posts do
def sticky_posts_for_page(_), do: []
defp sticky_ids do
case Repo.one(from opt in Option, where: opt.option_name == "sticky_posts") do
case Repo.one(from opt in Option, where: opt.name == "sticky_posts") do
nil ->
[]
option ->
option
|> Option.parse_option_value
|> Option.parse_value
|> Enum.map(&(elem(&1, 1)))
end
end
@ -175,14 +175,14 @@ defmodule Content.Posts do
case Integer.parse(id, 10) do
:error ->
scope |> where([p], p.post_name == ^id)
scope |> where([p], p.name == ^id)
{int_id, _} ->
scope |> where([p], p.id == ^int_id)
end
end
post_scope()
|> where([p], p.post_type != "nav_menu_item")
|> where([p], p.type != "nav_menu_item")
|> id_filter.(slug)
end
@ -205,16 +205,16 @@ defmodule Content.Posts do
case Integer.parse(id, 10) do
:error ->
scope |> where([p], p.post_name == ^id)
scope |> where([p], p.name == ^id)
{int_id, ""} ->
scope |> where([p], p.id == ^int_id)
{_int_id, _} ->
scope |> where([p], p.post_name == ^id)
scope |> where([p], p.name == ^id)
end
end
post_scope_with_drafts()
|> where([p], p.post_type != "nav_menu_item")
|> where([p], p.type != "nav_menu_item")
|> id_filter.(slug)
|> Repo.one!()
end
@ -244,7 +244,7 @@ defmodule Content.Posts do
%Post{}
|> Repo.preload(@preloads)
|> Post.changeset(attrs)
|> Changeset.put_change(:post_name, "preview")
|> Changeset.put_change(:name, "preview")
|> Changeset.apply_changes()
end

View file

@ -7,14 +7,14 @@ defmodule Content.Slugs do
def ensure_post_has_slug(changeset) do
cond do
!is_nil(changeset |> get_field(:post_name)) ->
!is_nil(changeset |> get_field(:name)) ->
changeset
is_nil(changeset |> get_field(:post_title)) ->
is_nil(changeset |> get_field(:title)) ->
changeset
|> put_change(
:post_name,
:name,
changeset
|> get_field(:post_date)
|> get_field(:date)
|> Kernel.||(NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second))
|> Timex.format!("%F", :strftime)
|> Slugger.slugify_downcase()
@ -23,16 +23,16 @@ defmodule Content.Slugs do
true ->
changeset
|> put_change(
:post_name,
:name,
changeset
|> get_field(:post_title)
|> get_field(:title)
|> Slugger.slugify_downcase()
|> unique_slug(changeset |> get_field(:id))
)
end
end
defp unique_slug(proposed_slug, post_id, postfix_number \\ 0) do
defp unique_slug(proposed_slug, id, postfix_number \\ 0) do
proposed_slug_with_postfix =
if postfix_number == 0 do
proposed_slug
@ -44,8 +44,8 @@ defmodule Content.Slugs do
Repo.aggregate(
(
Post
|> where([post], post.post_name == ^proposed_slug_with_postfix)
|> post_id_match(post_id)
|> where([post], post.name == ^proposed_slug_with_postfix)
|> post_id_match(id)
),
:count,
:id
@ -54,7 +54,7 @@ defmodule Content.Slugs do
if competition_count == 0 do
proposed_slug_with_postfix
else
unique_slug(proposed_slug, post_id, postfix_number + 1)
unique_slug(proposed_slug, id, postfix_number + 1)
end
end

View file

@ -5,8 +5,7 @@ defmodule Content.Term do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:term_id, :id, autogenerate: true}
schema "wp_terms" do
schema "terms" do
field :name, :string
field :slug, :string
field :term_group, :integer
@ -14,6 +13,6 @@ defmodule Content.Term do
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:term_id, :name, :slug, :term_group])
|> cast(params, [:id, :name, :slug, :term_group])
end
end

View file

@ -8,30 +8,26 @@ defmodule Content.TermRelationship do
@primary_key {:object_id, :integer, []}
@primary_key {:term_taxonomy_id, :integer, []}
schema "wp_term_relationships" do
schema "term_relationships" do
field :term_order, :integer
belongs_to :post, Post, foreign_key: :object_id, references: :id
belongs_to :term_taxonomy,
Content.TermTaxonomy,
foreign_key: :term_taxonomy_id,
references: :term_taxonomy_id,
define_field: false
belongs_to :category,
Content.TermTaxonomy,
foreign_key: :term_taxonomy_id,
references: :term_taxonomy_id,
define_field: false,
where: [taxonomy: "category"]
belongs_to :tag,
Content.TermTaxonomy,
foreign_key: :term_taxonomy_id,
references: :term_taxonomy_id,
define_field: false,
where: [taxonomy: "post_tag"]
belongs_to :post_format,
belongs_to :format,
Content.TermTaxonomy,
foreign_key: :term_taxonomy_id,
references: :term_taxonomy_id,
define_field: false,
where: [taxonomy: "post_format"]
end

View file

@ -5,17 +5,16 @@ defmodule Content.TermTaxonomy do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:term_taxonomy_id, :id, autogenerate: true}
schema "wp_term_taxonomy" do
schema "term_taxonomy" do
field :taxonomy, :string
field :description, :string
field :parent, :integer
field :count, :integer
belongs_to :term, Content.Term, foreign_key: :term_id, references: :term_id
belongs_to :term, Content.Term
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:term_taxonomy_id, :term_id, :taxonomy, :description, :parent, :count])
|> cast(params, [:id, :term_id, :taxonomy, :description, :parent, :count])
end
end

View file

@ -5,15 +5,14 @@ defmodule Content.Termmeta do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:meta_id, :id, autogenerate: true}
schema "wp_termmeta" do
schema "termmeta" do
field :term_id, :integer
field :meta_key, :string
field :meta_value, :string
field :key, :string
field :value, :string
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:meta_id, :term_id, :meta_key, :meta_value])
|> cast(params, [:id, :term_id, :key, :value])
end
end

View file

@ -9,7 +9,7 @@ defmodule Content.Terms do
def categories do
from t in Content.Term,
join: tt in Content.TermTaxonomy,
on: t.term_id == tt.term_id,
on: t.id == tt.term_id,
where: tt.taxonomy == "category"
end
end

View file

@ -15,7 +15,7 @@ defmodule Content.CommentController do
{:ok, comment} ->
post =
Post
|> where([p], p.id == ^comment.comment_post_id)
|> where([p], p.id == ^comment.post_id)
|> Repo.one()
conn
@ -24,7 +24,7 @@ defmodule Content.CommentController do
{:error, _} ->
post =
Post
|> where([p], p.id == ^comment_params["comment_post_id"])
|> where([p], p.id == ^comment_params["post_id"])
|> Repo.one()
conn
@ -39,7 +39,7 @@ defmodule Content.CommentController do
{:ok, comment} ->
post =
Post
|> where([p], p.id == ^comment.comment_post_id)
|> where([p], p.id == ^comment.post_id)
|> Repo.one()
conn
@ -48,7 +48,7 @@ defmodule Content.CommentController do
{:error, _} ->
post =
Post
|> where([p], p.id == ^comment_params["comment_post_id"])
|> where([p], p.id == ^comment_params["post_id"])
|> Repo.one()
conn
@ -61,7 +61,7 @@ defmodule Content.CommentController do
{:ok, comment} = Comments.delete_comment(comment)
post =
Post
|> where([p], p.id == ^comment.comment_post_id)
|> where([p], p.id == ^comment.post_id)
|> Repo.one()
conn

View file

@ -1,39 +0,0 @@
defmodule Content.MenusController do
use Content, :controller
alias Content.Repo
def edit(conn, %{"id" => id}) do
menu = id |> Content.Menu.get_menu_from_id()
posts =
Content.Posts.post_scope
|> Repo.all()
|> Enum.map(fn post ->
post |> Map.take([:id, :post_title, :post_name])
end)
categories =
Content.Terms.categories
|> Repo.all()
|> Enum.map(fn cat ->
cat |> Map.take([:name, :slug, :term_group, :term_id])
end)
conn
|> render(
"edit.html",
[
id: id,
menu: menu,
posts: posts,
categories: categories,
]
)
end
def update(conn, %{"id" => id, "menu" => menu}) do
Content.UpdateMenu.run(id, menu |> Phoenix.json_library().decode!())
conn
|> redirect(to: Routes.menus_path(conn, :edit, id))
end
end

View file

@ -1,8 +1,7 @@
defmodule Content.PostsController do
use Content, :controller
alias Auth.User
alias Content.{Options, Post, Posts, Repo}
alias Content.{Options, Posts}
plug :put_layout, false when action in [:preview]
@ -44,34 +43,6 @@ defmodule Content.PostsController do
show(conn, %{"id" => page_id})
end
def new(conn, params) do
changeset = Posts.change_posts(%Post{})
render(
conn,
"new.html",
changeset: changeset,
post_type: params["post_type"] || "post",
author_options: User |> Repo.all()
)
end
def create(conn, %{"post" => post_params}) do
case Posts.create_posts(post_params) do
{:ok, post} ->
conn
|> put_flash(:info, "Posts created successfully.")
|> redirect(to: Routes.posts_path(conn, :show, post))
{:error, %Ecto.Changeset{} = changeset} ->
render(
conn,
"new.html",
changeset: changeset,
post_type: post_params["post_type"] || "post",
author_options: User |> Repo.all()
)
end
end
def preview(conn, %{"post" => post_params}) do
post = Posts.preview_post(post_params)
@ -84,8 +55,6 @@ defmodule Content.PostsController do
end
def show(conn, %{"id" => id, "page" => page_string}) do
{page_id_for_posts, _} = Options.get_value_as_int("page_for_posts")
post = Posts.get_post(id)
if is_nil(post) do
@ -126,57 +95,15 @@ defmodule Content.PostsController do
page = String.to_integer(page_string)
thumbs = [post] |> Posts.thumbs_for_posts()
case post.post_type do
case post.type do
"attachment" ->
{:ok, decoded} = post.post_content |> Base.decode64
{:ok, decoded} = post.content |> Base.decode64
conn
|> put_resp_content_type(post.post_mime_type, "binary")
|> put_resp_content_type(post.mime_type, "binary")
|> send_resp(conn.status || 200, decoded)
_ ->
render(conn, template, post: post, page: page, thumbs: thumbs)
end
end
def edit(conn, %{"id" => id}) do
posts = Posts.get_post_with_drafts!(id)
changeset = Posts.change_posts(posts)
render(
conn,
"edit.html",
posts: posts,
changeset: changeset,
post_type: posts.post_type || "post",
author_options: User |> Repo.all()
)
end
def update(conn, %{"id" => id, "post" => posts_params}) do
posts = Posts.get_post_with_drafts!(id)
case Posts.update_posts(posts, posts_params) do
{:ok, posts} ->
conn
|> put_flash(:info, "Posts updated successfully.")
|> redirect(to: Routes.posts_path(conn, :edit, posts))
{:error, %Ecto.Changeset{} = changeset} ->
render(
conn,
"edit.html",
posts: posts,
changeset: changeset,
post_type: posts.post_type || "post",
author_options: User |> Repo.all()
)
end
end
def delete(conn, %{"id" => id}) do
posts = Posts.get_post_with_drafts!(id)
{:ok, _posts} = Posts.delete_posts(posts)
conn
|> put_flash(:info, "Posts deleted successfully.")
|> redirect(to: Routes.admin_posts_path(conn, :index))
end
end

View file

@ -8,7 +8,7 @@ defmodule Content.SitemapController do
def index(conn, _params) do
posts =
Posts.post_scope
|> where([p], p.post_type not in ["nav_menu_item", "attachment"])
|> where([p], p.type not in ["nav_menu_item", "attachment"])
|> Repo.all()
categories =

View file

@ -1 +0,0 @@
<h1>Dashboard</h1>

View file

@ -1,93 +0,0 @@
<div class="grid">
<div class="column">
<h1>
<%= humanize(@post_type) %>s
</h1>
</div>
<div class="column admin-actions">
<%= link "New " <> humanize(@post_type), to: Routes.posts_path(@conn, :new, post_type: @post_type), class: "button" %>
</div>
</div>
<table class="admin-table small">
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Categories</th>
<th>Tags</th>
<th>Comments</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<%= for post <- @posts do %>
<tr>
<td>
<%= link post.post_title, to: Routes.posts_path(@conn, :edit, post) %>
</td>
<td>
<%= if !is_nil(post.author) do %>
<%= post.author.display_name %>
<% end %>
</td>
<td>
<%= post.categories |> Enum.map(&(&1.name)) |> Enum.join(", ") %>
</td>
<td>
<%= post.tags |> Enum.map(&(&1.name)) |> Enum.join(", ") %>
</td>
<td>
<%= post.comments |> Enum.count() %>
</td>
<td>
<%= case post.post_status do %>
<% "publish" -> %>
<%= "Published" %>
<% "future" -> %>
<%= "Scheduled" %>
<% "draft" -> %>
<%= "Last Modified" %>
<% "pending" -> %>
<%= "Scheduled" %>
<% "private" -> %>
<%= "Published Privately" %>
<% "inherit" -> %>
<%= "Inherit" %>
<% end %>
<div>
<%= post.post_date |> Timex.format!("%F", :strftime) %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<hr />
<%= if @page > 1 do %>
<%= link 1, to: Routes.admin_posts_path(@conn, :index, page: 1) %>
<% end %>
<%= if @page > 3 do %>
...
<% end %>
<%= if @page > 2 do %>
<%= link @page - 1, to: Routes.admin_posts_path(@conn, :index, page: @page - 1) %>
<% end %>
<%= @page %>
<%= if @page + 1 < @last_page do %>
<%= link @page + 1, to: Routes.admin_posts_path(@conn, :index, page: @page + 1) %>
<% end %>
<%= if @page + 2 < @last_page do %>
...
<% end %>
<%= if @page < @last_page do %>
<%= link @last_page, to: Routes.admin_posts_path(@conn, :index, page: @last_page) %>
<% end %>

View file

@ -8,12 +8,12 @@
<%= for post <- @posts do %>
<item>
<title><%= post.post_title |> HtmlSanitizeEx.strip_tags() %></title>
<title><%= post.title |> HtmlSanitizeEx.strip_tags() %></title>
<description>
<%= post.post_content |> process_content |> html_escape |> safe_to_string %>
<%= post.content |> process_content |> html_escape |> safe_to_string %>
</description>
<pubDate><%=
post.post_date
post.date
|> DateTime.from_naive!("Etc/UTC")
|> Timex.format!("{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} {Z}")
%></pubDate>

View file

@ -10,12 +10,6 @@
</head>
<body>
<main role="main" class="container">
<%= for level <- [:info, :danger] do %>
<%= if get_flash(@conn, level) do %>
<p class="alert alert-<%= level %>" role="alert"><%= get_flash(@conn, level) %></p>
<% end %>
<% end %>
<%= render "_side_menu.html", assigns %>
<!-- Page Contents -->
@ -25,6 +19,8 @@
</div>
</div>
<%= flash_block(@conn) %>
<%= @inner_content %>
</main>
</body>

View file

@ -2,19 +2,19 @@
<%= Enum.map(Content.Comments.children(@parent_id, @post.comments), fn comment -> %>
<div class="event">
<div class="label">
<img src="<%= comment.comment_author_email |> gravatar_url_for_email %>" />
<img src="<%= comment.author_email |> gravatar_url_for_email %>" />
</div>
<div class="content">
<div class="summary">
<span class="user">
<%= comment.comment_author || "Anonymous" %>
<%= comment.author || "Anonymous" %>
</span>
<div class="date">
<%= comment.comment_date |> Timex.format!("%F", :strftime) %>
<%= comment.date |> Timex.format!("%F", :strftime) %>
</div>
</div>
<div class="extra text">
<%= sanitize comment.comment_content |> auto_paragraph_tags |> elem(1) |> IO.iodata_to_binary() %>
<%= sanitize comment.content |> auto_paragraph_tags |> elem(1) |> IO.iodata_to_binary() %>
</div>
</div>
</div>

View file

@ -1 +0,0 @@
<%= render "form.html", Map.put(assigns, :action, Routes.posts_path(@conn, :update, @posts)) %>

View file

@ -1,82 +0,0 @@
<%= form_for @changeset, @action, fn f -> %>
<div class="grid">
<div class="column three">
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<ul>
<%= for {error_key, error} <- @changeset.errors |> Keyword.drop([:post_title, :post_content]) do %>
<%= if error do %>
<li><%= error_key %>: <%= error_tag f, error_key %></li>
<% end %>
<% end %>
</ul>
<% end %>
<%= label f, :post_title do %>
Title
<%= text_input f, :post_title %>
<% end %>
<%= label f, :post_content, "data-react-class": "Editor" do %>
Content
<%= textarea f, :post_content, "data-simplemde": true %>
<% end %>
<div class="grid">
<div class="form-group input-group column uLeft">
<%= submit "Delete", class: "btn btn-warning", form: "deleteForm" %>
</div>
<div class="form-group input-group column">
<%= submit "Save", class: "btn btn-primary" %>
</div>
</div>
</div>
<div class="column post-admin-sidebar">
<%= label f, :post_status, class: "column input-group" do %>
<div>Status</div>
<%= select f, :post_status, [{"Publish", :publish}, {"Draft", :draft}] %>
<% end %>
<%= label f, :post_author, class: "input-group" do %>
<div>Author</div>
<%= select f, :post_author, @author_options |> Enum.map(&({&1.display_name, &1.id})) %>
<% end %>
<%= label f, :post_excerpt, class: "input-group" do %>
<div>Excerpt</div>
<%= textarea f, :post_excerpt %>
<% end %>
<%= label f, :sticky, class: "input-group" do %>
<div>Sticky?</div>
<%= checkbox f, :sticky %>
<% end %>
<%= label f, :comment_status, class: "input-group" do %>
<div>Comment Status</div>
<%= select f, :comment_status, ["open", "closed"] %>
<% end %>
<%= label f, :ping_status, class: "input-group" do %>
<div>Ping Status</div>
<%= select f, :ping_status, ["open", "closed"] %>
<% end %>
<%= label f, :post_password, class: "input-group" do %>
<div>Post Password</div>
<%= text_input f, :post_password %>
<% end %>
<%= label f, :post_name, class: "input-group" do %>
<div>Slug</div>
<%= text_input f, :post_name %>
<% end %>
<%= label f, :post_order, class: "input-group" do %>
<div>Post Order</div>
<%= number_input f, :post_order %>
<% end %>
</div>
</div>
<%= hidden_input f, :post_type, value: @post_type %>
<% end %>
<%= if assigns[:posts] do %>
<%= form_for @changeset, Routes.posts_path(@conn, :delete, @posts), [method: :delete, id: "deleteForm"], fn _f -> %>
<% end %>
<% end %>

View file

@ -2,12 +2,12 @@
<div class="uHidden">
<h1 class="p-name">
<%= link to: Routes.posts_path(@conn, :show, @post), class: "u-url" do %>
<%= raw @post.post_title %>
<%= raw @post.title %>
<% end %>
</h1>
<%= post_topmatter(@conn, @post) %>
</div>
<div class="Article-content <%= if @post.post_format, do: @post.post_format.slug %> e-content">
<div class="Article-content <%= if @post.format, do: @post.format.slug %> e-content">
<%= render "thumb.html", post: @post, thumbs: @thumbs %>
<%= @post |> Content.Post.content_page(@page) |> process_content |> raw %>
</div>

View file

@ -3,17 +3,17 @@
<div class="ui main padded text container">
<h1 class="ui header p-name">
<%= link to: Routes.posts_path(@conn, :show, post), class: "u-url" do %>
<%= raw post.post_title %>
<%= raw post.title %>
<% end %>
</h1>
<%= post_topmatter(@conn, post) %>
</div>
<div class="Article-content <%= if post.post_format, do: post.post_format.slug %> e-content">
<div class="Article-content <%= if post.format, do: post.format.slug %> e-content">
<%= if authenticated_for_post?(@conn, post) do %>
<%= render "thumb.html", post: post, thumbs: @thumbs %>
<div class="Article-content-words" style="padding-bottom: 4em; padding-top: 4em;">
<%= raw post |> Content.Post.content_page(1) |> Content.Post.before_more |> process_content |> raw %>
<%= if post.post_content =~ "<!--more-->" do %>
<%= if post.content =~ "<!--more-->" do %>
<p>
<%= link "Keep Reading", to: Routes.posts_path(@conn, :show, post) %>
</p>

View file

@ -1 +0,0 @@
<%= render "form.html", Map.put(assigns, :action, Routes.posts_path(@conn, :create)) %>

View file

@ -8,23 +8,23 @@
<%= changeset_error_block(@comment_changeset) %>
<div class="ui stacked left aligned segment">
<%= form_for @comment_changeset, Routes.comment_path(@conn, :create), [class: "ui form"], fn f -> %>
<%= hidden_input f, :comment_parent %>
<%= hidden_input f, :comment_post_id %>
<%= label f, :comment_author do %>
<%= hidden_input f, :parent %>
<%= hidden_input f, :post_id %>
<%= label f, :author do %>
Your Name
<%= text_input f, :comment_author %>
<%= text_input f, :author %>
<% end %>
<%= label f, :comment_author_email do %>
<%= label f, :author_email do %>
Your Email
<%= email_input f, :comment_author_email %>
<%= email_input f, :author_email %>
<% end %>
<%= label f, :comment_author_url do %>
<%= label f, :author_url do %>
Your Website
<%= text_input f, :comment_author_url %>
<%= text_input f, :author_url %>
<% end %>
<%= label f, :comment_content do %>
<%= label f, :content do %>
Comment
<%= textarea f, :comment_content %>
<%= textarea f, :content %>
<% end %>
<div class="form-group">
<%= submit "Leave My Comment", class: "ui fluid large teal submit button" %>

View file

@ -2,12 +2,12 @@
<div class="ui main padded text container">
<h1 class="ui header p-name">
<%= link to: Routes.posts_path(@conn, :show, @post), class: "u-url" do %>
<%= raw @post.post_title %>
<%= raw @post.title %>
<% end %>
</h1>
<%= post_topmatter(@conn, @post) %>
</div>
<div class="ui text container <%= if @post.post_format, do: @post.post_format.slug %> e-content" style="padding-bottom: 4em; padding-top: 4em;">
<div class="ui text container <%= if @post.format, do: @post.format.slug %> e-content" style="padding-bottom: 4em; padding-top: 4em;">
<%= render "thumb.html", post: @post, thumbs: @thumbs %>
<%= @post |> Content.Post.content_page(@page) |> process_content |> raw %>
<div class="ui grid">

View file

@ -4,7 +4,7 @@
<%= for post <- @posts do %>
<li>
<%= link to: Routes.posts_path(@conn, :show, post) do %>
<%= raw post.post_title %>
<%= raw post.title %>
<% end %>
</li>
<% end %>

View file

@ -55,8 +55,8 @@ defmodule Content.FeedsView do
</h4>
<h5>
<%= link to: Routes.posts_path(conn, :show, post) do %>
<time class="dt-published" datetime="<%= post.post_date %>">
<%= post.post_date |> Timex.format!("%F", :strftime) %>
<time class="dt-published" datetime="<%= post.post %>">
<%= post.post |> Timex.format!("%F", :strftime) %>
</time>
<% end %>
</h5>
@ -65,6 +65,6 @@ defmodule Content.FeedsView do
end
def unauthenticated_post?(_conn, post) do
post.post_password == nil || String.length(post.post_password) == 0
post.password == nil || String.length(post.password) == 0
end
end

View file

@ -12,20 +12,20 @@ defmodule Content.LayoutView do
end
def title(Content.PostsView, "show.html", assigns) do
(assigns.post.post_title |> HtmlSanitizeEx.strip_tags()) <> " | " <> title(nil, nil, nil)
(assigns.post.title |> HtmlSanitizeEx.strip_tags()) <> " | " <> title(nil, nil, nil)
end
def title(_, _, _) do
case Options.get("blogname") do
opt = %Option{} ->
opt.option_value
opt.value
_ ->
I18n.t! "en", "site.title"
end
end
def excerpt(Content.PostsView, "show.html", assigns) do
assigns.post.post_excerpt
assigns.post.excerpt
|> HtmlSanitizeEx.strip_tags()
end
@ -36,7 +36,7 @@ defmodule Content.LayoutView do
def excerpt(_, _, _) do
case Options.get("blogdescription") do
opt = %Option{} ->
opt.option_value
opt.value
_ ->
I18n.t! "en", "site.excerpt"
end

View file

@ -17,7 +17,7 @@ defmodule Content.PostsView do
end
def authenticated_for_post?(conn, post) do
post.post_password == nil || String.length(post.post_password) == 0 || get_session(conn, :post_password) == post.post_password
post.password == nil || String.length(post.password) == 0 || get_session(conn, :post_password) == post.password
end
def gravatar_url_for_email(email) do
@ -33,15 +33,15 @@ defmodule Content.PostsView do
def comment_changeset_for_post(%Post{} = post) do
%Comment{
comment_post_id: post.id
post_id: post.id
}
|> Comment.changeset()
end
def comment_changeset_for_parent(%Comment{} = comment) do
%Comment{
comment_parent: comment.comment_id,
comment_post_id: comment.comment_post_id
parent: comment.id,
post_id: comment.post_id
}
|> Comment.changeset()
end
@ -83,8 +83,8 @@ defmodule Content.PostsView do
<span><%= author.display_name %></span>
&#8226;
<%= link to: Routes.posts_path(conn, :show, post) do %>
<time class="dt-published" datetime="<%= post.post_date %>">
<%= post.post_date |> Timex.format!("%F", :strftime) %>
<time class="dt-published" datetime="<%= post.date %>">
<%= post.date |> Timex.format!("%F", :strftime) %>
</time>
<% end %>
<% end %>

View file

@ -0,0 +1,108 @@
defmodule Content.Repo.Migrations.CreateSchema do
use Ecto.Migration
def change do
create table("commentmeta") do
add :comment_id, :integer
add :key, :string
add :value, :text
end
create table("comments") do
add :post_id, :integer
add :author, :text
add :author_email, :text
add :author_url, :text
add :author_IP, :text
add :date, :naive_datetime
add :date_gmt, :naive_datetime
add :content, :text
add :karma, :integer
add :approved, :text
add :agent, :text
add :type, :text
add :parent, :integer
add :user_id, :integer
end
create table("links") do
add :url, :text
add :name, :text
add :image, :text
add :target, :text
add :description, :text
add :visible, :text
add :owner, :integer
add :rating, :integer
add :updated, :naive_datetime
add :rel, :text
add :rss, :text
add :notes, :text
end
create table("options") do
add :name, :text
add :autoload, :text
add :value, :text
end
create table("postmeta") do
add :post_id, :integer
add :key, :string
add :value, :text
end
create table("posts") do
add :author_id, :integer
add :date, :naive_datetime
add :date_gmt, :naive_datetime
add :content, :text
add :title, :string
add :excerpt, :string
add :status, :text
add :comment_status, :text
add :ping_status, :text
add :password, :text
add :name, :text
add :to_ping, :string
add :pinged, :string
add :modified, :naive_datetime
add :modified_gmt, :naive_datetime
add :content_filtered, :text
add :parent, :integer
add :guid, :text
add :menu_order, :integer
add :type, :text
add :mime_type, :text
add :comment_count, :integer, default: 0
end
create unique_index(:posts, ["name"])
create table("term_relationships", primary_key: false) do
add :object_id, :serial, primary_key: true
add :term_taxonomy_id, :integer, [:primary_key]
add :term_order, :integer
end
create table("term_taxonomy") do
add :term_id, :integer
add :taxonomy, :text
add :description, :text
add :parent, :integer
add :count, :integer
end
create table("termmeta") do
add :term_id, :integer
add :key, :string
add :value, :text
end
create table("terms") do
add :name, :text
add :slug, :text
add :term_group, :integer
end
end
end

View file

@ -1,120 +0,0 @@
defmodule Content.Repo.Migrations.CreateWpSchema do
use Ecto.Migration
def change do
create table("wp_commentmeta", primary_key: false) do
add :meta_id, :serial, primary_key: true
add :comment_id, :integer
add :meta_key, :text
end
create table("wp_comments", primary_key: false) do
add :comment_id, :serial, primary_key: true
add :comment_post_id, :integer
add :comment_author, :text
add :comment_author_email, :text
add :comment_author_url, :text
add :comment_author_IP, :text
add :comment_date, :naive_datetime
add :comment_date_gmt, :naive_datetime
add :comment_content, :string
add :comment_karma, :integer
add :comment_approved, :text
add :comment_agent, :text
add :comment_type, :text
add :comment_parent, :integer
add :user_id, :integer
end
create table("wp_links", primary_key: false) do
add :link_id, :serial, primary_key: true
add :link_url, :text
add :link_name, :text
add :link_image, :text
add :link_target, :text
add :link_description, :text
add :link_visible, :text
add :link_owner, :integer
add :link_rating, :integer
add :link_updated, :naive_datetime
add :link_rel, :text
add :link_rss, :text
end
create table("wp_options", primary_key: false) do
add :option_id, :serial, primary_key: true
add :option_name, :text
add :autoload, :text
add :option_value, :text
end
create table("wp_postmeta", primary_key: false) do
add :meta_id, :serial, primary_key: true
add :post_id, :integer
add :meta_key, :text
add :meta_value, :text
end
create table("wp_posts", primary_key: false) do
add :id, :serial, primary_key: true
add :post_author, :integer
add :post_date, :naive_datetime
add :post_date_gmt, :naive_datetime
add :post_content, :text
add :post_title, :string
add :post_excerpt, :string
add :post_status, :text
add :comment_status, :text
add :ping_status, :text
add :post_password, :text
add :post_name, :text
add :to_ping, :string
add :pinged, :string
add :post_modified, :naive_datetime
add :post_modified_gmt, :naive_datetime
add :post_content_filtered, :text
add :post_parent, :integer
add :guid, :text
add :menu_order, :integer
add :post_type, :text
add :post_mime_type, :text
add :comment_count, :integer
end
create table("wp_term_relationships", primary_key: false) do
add :object_id, :serial, primary_key: true
add :term_taxonomy_id, :integer, [:primary_key]
add :term_order, :integer
end
create table("wp_term_taxonomy", primary_key: false) do
add :term_taxonomy_id, :serial, primary_key: true
add :term_id, :integer
add :taxonomy, :text
add :description, :text
add :parent, :integer
add :count, :integer
end
create table("wp_termmeta", primary_key: false) do
add :meta_id, :serial, primary_key: true
add :term_id, :integer
add :meta_key, :text
add :meta_value, :text
end
create table("wp_terms", primary_key: false) do
add :term_id, :serial, primary_key: true
add :name, :text
add :slug, :text
add :term_group, :integer
end
create table("wp_usermeta", primary_key: false) do
add :umeta_id, :serial, primary_key: true
add :user_id, :integer
add :meta_key, :text
add :meta_value, :text
end
end
end

View file

@ -1,9 +0,0 @@
defmodule Content.Repo.Migrations.ChangeCommentContentToText do
use Ecto.Migration
def change do
alter table("wp_comments") do
modify :comment_content, :text
end
end
end

View file

@ -1,9 +0,0 @@
defmodule Content.Repo.Migrations.AddDefaultToCommentCount do
use Ecto.Migration
def change do
alter table("wp_posts") do
modify :comment_count, :integer, default: 0
end
end
end

View file

@ -1,9 +0,0 @@
defmodule Content.Repo.Migrations.AddMetaValueToWpCommentmetas do
use Ecto.Migration
def change do
alter table("wp_commentmeta") do
add :meta_value, :string
end
end
end

View file

@ -1,9 +0,0 @@
defmodule Content.Repo.Migrations.AddLinkNotesToWpLinks do
use Ecto.Migration
def change do
alter table("wp_links") do
add :link_notes, :string
end
end
end

View file

@ -1,7 +0,0 @@
defmodule Content.Repo.Migrations.AddUniqueIndexToPostName do
use Ecto.Migration
def change do
create unique_index(:wp_posts, ["post_name"])
end
end

View file

@ -5,12 +5,12 @@ defmodule Content.AttachmentTest do
@create_attrs %{
id: 123,
post_name: "my-attachment",
post_title: "My Attachment",
post_content: "",
post_status: "publish",
post_type: "attachment",
post_date: "2018-01-01T00:00:00Z"
name: "my-attachment",
title: "My Attachment",
content: "",
status: "publish",
type: "attachment",
date: "2018-01-01T00:00:00Z"
}
def fixture(:wide_attachment) do
@ -18,8 +18,8 @@ defmodule Content.AttachmentTest do
{:ok, _meta} =
%Postmeta{
post_id: attachment.id,
meta_key: "_wp_attachment_metadata",
meta_value: "a:2:{s:5:\"width\";i:640;s:6:\"height\";i:480;}"
key: "attachment_metadata",
value: "a:2:{s:5:\"width\";i:640;s:6:\"height\";i:480;}"
} |> Repo.insert()
Content.Post
@ -32,8 +32,8 @@ defmodule Content.AttachmentTest do
{:ok, _meta} =
%Postmeta{
post_id: attachment.id,
meta_key: "_wp_attachment_metadata",
meta_value: "a:2:{s:5:\"width\";i:480;s:6:\"height\";i:640;}"
key: "attachment_metadata",
value: "a:2:{s:5:\"width\";i:480;s:6:\"height\";i:640;}"
} |> Repo.insert()
Content.Post
|> preload([:metas])

View file

@ -7,8 +7,8 @@ defmodule Content.CommentmetaTest do
%Commentmeta{}
|> Commentmeta.changeset(%{
comment_id: 123,
meta_key: "testcommentmeta",
meta_value: "some value",
key: "testcommentmeta",
value: "some value",
})
|> Repo.insert!()
end

View file

@ -6,19 +6,19 @@ defmodule Content.CommentsTest do
def fixture(:parent_comment) do
%Comment{
comment_id: 123,
comment_content: "Hello world",
comment_post_id: 456,
id: 123,
content: "Hello world",
post_id: 456,
}
|> Repo.insert!()
end
def fixture(:child_comment) do
%Comment{
comment_id: 456,
comment_parent: 123,
comment_content: "Hello back",
comment_post_id: 456,
id: 456,
parent: 123,
content: "Hello back",
post_id: 456,
}
|> Repo.insert!()
end
@ -28,14 +28,14 @@ defmodule Content.CommentsTest do
parent = fixture(:parent_comment)
kid = fixture(:child_comment)
kids = Comments.children(parent.comment_id, Comments.list_comments)
kids = Comments.children(parent.id, Comments.list_comments)
assert kids == [kid]
end
test "returns an empty list if the comment has no children " do
parent = fixture(:parent_comment)
kids = Comments.children(parent.comment_id, Comments.list_comments)
kids = Comments.children(parent.id, Comments.list_comments)
assert kids == []
end
end
@ -45,8 +45,8 @@ defmodule Content.CommentsTest do
changeset = fixture(:parent_comment) |> Comments.change_comment
changed_value =
changeset
|> Changeset.put_change(:comment_content, "woops")
|> Changeset.get_change(:comment_content)
|> Changeset.put_change(:content, "woops")
|> Changeset.get_change(:content)
assert changed_value == "woops"
end
end

View file

@ -1,141 +0,0 @@
defmodule Content.MenuTest do
use Content.DataCase
alias Content.{Menu, Option, Post, Postmeta, Repo, Term, TermRelationship}
@theme_option %Option{
option_name: "test_theme",
option_value: "a:1:{s:18:\"nav_menu_locations\";a:1:{s:3:\"top\";i:13;}}"
}
@term_relationship %TermRelationship{
term_taxonomy_id: 13,
object_id: 123,
}
@top_nav_item %Post{
id: 123,
post_name: "home",
post_title: "Home",
post_content: "",
post_status: "publish",
post_type: "nav_item",
post_date: ~N"2018-01-01T00:00:00",
comment_status: "open",
}
@top_nav_metas [
%{
post_id: 123,
meta_key: "_menu_item_object_id",
meta_value: "456",
},
%{
post_id: 123,
meta_key: "_menu_item_object",
meta_value: "post",
},
%{
post_id: 123,
meta_key: "_menu_item_menu_item_parent",
meta_value: "0",
},
]
@category_nav_metas [
%{
post_id: 123,
meta_key: "_menu_item_object_id",
meta_value: "42",
},
%{
post_id: 123,
meta_key: "_menu_item_object",
meta_value: "category",
},
%{
post_id: 123,
meta_key: "_menu_item_menu_item_parent",
meta_value: "0",
},
]
@related_page %Post {
id: 456,
post_title: "Test Nav Home",
}
@related_category %Term{
term_id: 42,
name: "Test Category",
slug: "test-category",
}
def fixture(:option) do
@theme_option |> Repo.insert()
end
def fixture(:menu) do
{:ok, option} = fixture(:option)
{:ok, _term_relationship} = @term_relationship |> Repo.insert()
{:ok, _nav_item} = @top_nav_item |> Repo.insert()
{3, nil} = Repo.insert_all(Postmeta, @top_nav_metas)
{:ok, _post} = @related_page |> Repo.insert()
option
end
def fixture(:category_menu) do
{:ok, option} = fixture(:option)
{:ok, _term_relationship} = @term_relationship |> Repo.insert()
{:ok, _nav_item} = @top_nav_item |> Repo.insert()
{3, nil} = Repo.insert_all(Postmeta, @category_nav_metas)
{:ok, _category} = @related_category |> Repo.insert()
option
end
describe "get_menu_from_option_and_location" do
test "returns an empty if the menu is not present" do
fixture(:option)
assert Menu.get_menu_from_option_and_location("test_theme", "top") == []
end
test "returns items if the menu is present" do
fixture(:menu)
menu = Menu.get_menu_from_option_and_location("test_theme", "top")
refute menu == []
assert (menu |> Enum.at(0)) == %{
children: [],
parent_id: "0",
post_id: 123,
related_item: %{resource: "posts", slug: nil, title: "Test Nav Home"},
target_id: "456",
type: "post",
url: nil,
}
end
test "returns items if the menu has a category" do
fixture(:category_menu)
menu = Menu.get_menu_from_option_and_location("test_theme", "top")
refute menu == []
assert (menu |> Enum.at(0)) == %{
children: [],
parent_id: "0",
post_id: 123,
related_item: %{resource: "category", slug: "test-category", title: "Test Category"},
target_id: "42",
type: "category",
url: nil,
}
end
end
describe "put_menu_option" do
test "it can change the active menu in a position" do
fixture(:menu)
{:ok, _option} = Menu.put_menu_option("test_theme", "top", 7) |> Repo.update()
assert Menu.get_menu_from_option_and_location("test_theme", "top") == []
end
end
end

View file

@ -6,8 +6,8 @@ defmodule Content.OptionTest do
test "can save a new link" do
%Option{}
|> Option.changeset(%{
option_name: "test_up",
option_value: "1",
name: "test_up",
value: "1",
})
|> Repo.insert!()
end

View file

@ -6,8 +6,8 @@ defmodule Content.OptionsTest do
def fixture(:option) do
%Option{}
|> Option.changeset(%{
option_name: "test_up",
option_value: "1",
name: "test_up",
value: "1",
})
|> Repo.insert!()
end

View file

@ -7,8 +7,8 @@ defmodule Content.PostmetaTest do
%Postmeta{}
|> Postmeta.changeset(%{
post_id: 123,
meta_key: "testpostmeta",
meta_value: "some value",
key: "testpostmeta",
value: "some value",
})
|> Repo.insert!()
end

View file

@ -6,34 +6,34 @@ defmodule Content.SlugsTest do
@create_attrs %{
id: 123,
post_name: "my-post",
post_title: "My Post",
post_content: "",
post_status: "publish",
post_type: "post",
post_date: "2018-01-01T00:00:00Z"
name: "my-post",
title: "My Post",
content: "",
status: "publish",
type: "post",
date: "2018-01-01T00:00:00Z"
}
@dupe_title_attrs %{
id: 456,
post_title: "My Post",
post_content: "",
post_status: "publish",
post_type: "post",
post_date: "2018-01-01T00:00:00Z"
title: "My Post",
content: "",
status: "publish",
type: "post",
date: "2018-01-01T00:00:00Z"
}
describe "ensure_post_has_slug" do
test "doesn't overwrite a set slug" do
new_post =
%Post{
post_name: "a-set-slug"
name: "a-set-slug"
}
|> Post.changeset()
|> Slugs.ensure_post_has_slug()
|> Changeset.apply_changes()
assert new_post.post_name == "a-set-slug"
assert new_post.name == "a-set-slug"
end
test "works even if the title is nil" do
@ -43,19 +43,19 @@ defmodule Content.SlugsTest do
|> Slugs.ensure_post_has_slug()
|> Changeset.apply_changes()
assert new_post.post_name |> String.length() > 0
assert new_post.name |> String.length() > 0
end
test "sets a slug if the title is there" do
new_post =
%Post{
post_title: "My NEW Post"
title: "My NEW Post"
}
|> Changeset.change(%{})
|> Slugs.ensure_post_has_slug()
|> Changeset.apply_changes()
assert new_post.post_name == "my-new-post"
assert new_post.name == "my-new-post"
end
test "ensures uniqueness of the slug" do
@ -64,14 +64,14 @@ defmodule Content.SlugsTest do
new_post =
%Post{
post_title: "MY POST"
title: "MY POST"
}
|> Changeset.change(%{})
|> Slugs.ensure_post_has_slug()
|> Changeset.apply_changes()
assert new_post.post_name != og_post.post_name
assert new_post.post_name == "my-post-1"
assert new_post.name != og_post.name
assert new_post.name == "my-post-1"
end
test "ensures uniqueness of the slug on update" do
@ -84,8 +84,8 @@ defmodule Content.SlugsTest do
|> Slugs.ensure_post_has_slug()
|> Changeset.apply_changes()
assert new_post.post_name != og_post.post_name
assert new_post.post_name == "my-post-1"
assert new_post.name != og_post.name
assert new_post.name == "my-post-1"
end
end
end

View file

@ -7,8 +7,8 @@ defmodule Content.TermmetaTest do
%Termmeta{}
|> Termmeta.changeset(%{
term_id: 123,
meta_key: "testtermmeta",
meta_value: "some value",
key: "testtermmeta",
value: "some value",
})
|> Repo.insert!()
end

View file

@ -4,10 +4,10 @@ defmodule Content.CommentControllerTest do
alias Content.Comments
alias Content.Posts
@post_attrs %{id: 456, post_name: "blergh", post_status: "publish"}
@create_attrs %{comment_id: 123, comment_content: "Hello world", comment_post_id: 456}
@update_attrs %{comment_id: 123, comment_content: "Goodbye", comment_post_id: 456}
@invalid_attrs %{comment_id: 123, comment_content: "", comment_post_id: 456}
@post_attrs %{id: 456, name: "blergh", status: "publish"}
@create_attrs %{id: 123, content: "Hello world", post_id: 456}
@update_attrs %{id: 123, content: "Goodbye", post_id: 456}
@invalid_attrs %{id: 123, content: "", post_id: 456}
def fixture(:post) do
{:ok, post} = Posts.create_posts(@post_attrs)

View file

@ -6,64 +6,52 @@ defmodule Content.PostsControllerTest do
@create_attrs %{
id: 123,
post_name: "my-post",
post_title: "My Post",
post_content: "Page One <!--nextpage--> Page Two",
post_status: "publish",
post_type: "post",
post_date: "2018-01-01T00:00:00Z",
comment_status: "open",
}
@blog_post_attrs %{
id: 456,
post_name: "my-blog-post",
post_title: "My Blog Post",
post_content: "Page One <!--nextpage--> Page Two",
post_status: "publish",
post_type: "post",
post_date: "2018-01-01T00:00:00Z",
name: "my-post",
title: "My Post",
content: "Page One <!--nextpage--> Page Two",
status: "publish",
type: "post",
date: "2018-01-01T00:00:00Z",
comment_status: "open",
}
@preview_attrs %{
post_name: "my-post",
post_title: "My Post",
post_content: "",
post_status: "publish",
post_type: "post",
post_date: "2018-01-01T00:00:00Z"
name: "my-post",
title: "My Post",
content: "",
status: "publish",
type: "post",
date: "2018-01-01T00:00:00Z"
}
@thumb_attrs %{
id: 124,
post_name: "my-thumb",
post_title: "My Thumb",
post_content: "",
post_status: "publish",
post_type: "attachment",
post_date: "2018-01-01T00:00:00Z",
name: "my-thumb",
title: "My Thumb",
content: "",
status: "publish",
type: "attachment",
date: "2018-01-01T00:00:00Z",
guid: "http://placekitten.com/200/300"
}
@attachment_attrs %{
id: 123,
post_name: "attachment.txt",
post_title: "",
post_content: "my text attachment" |> Base.encode64,
post_status: "publish",
post_type: "attachment",
post_mime_type: "text/plain",
post_date: "2018-01-01T00:00:00Z",
name: "attachment.txt",
title: "",
content: "my text attachment" |> Base.encode64,
status: "publish",
type: "attachment",
mime_type: "text/plain",
date: "2018-01-01T00:00:00Z",
comment_status: "open",
}
@update_attrs %{post_name: "my-post"}
@invalid_attrs %{post_status: "", post_type: "post"}
@post_category %Term{
term_id: 42,
id: 42,
name: "Test Category",
slug: "test-category",
}
@post_category_taxonomy %TermTaxonomy{
term_taxonomy_id: 64,
id: 64,
term_id: 42,
taxonomy: "category",
description: "A test category",
@ -78,15 +66,15 @@ defmodule Content.PostsControllerTest do
def fixture(:posts) do
{:ok, post} = Posts.create_posts(@create_attrs)
{:ok, thumb} = Posts.create_posts(@thumb_attrs)
{:ok, _meta} = %Content.Postmeta{post_id: post.id, meta_key: "_thumbnail_id", meta_value: Integer.to_string(thumb.id)} |> Repo.insert()
{:ok, _option} = %Content.Option{option_name: "sticky_posts", option_value: "a:1:{i:0;i:123;}"} |> Repo.insert()
{:ok, _meta} = %Content.Postmeta{post_id: post.id, key: "_thumbnail_id", value: Integer.to_string(thumb.id)} |> Repo.insert()
{:ok, _option} = %Content.Option{name: "sticky_posts", value: "a:1:{i:0;i:123;}"} |> Repo.insert()
post
end
def fixture(:single_post) do
{:ok, post} = Posts.create_posts(@create_attrs)
{:ok, _comment} = %Comment{comment_post_id: post.id, comment_parent: 0, comment_date: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)} |> Repo.insert()
{:ok, _comment} = %Comment{post_id: post.id, parent: 0, date: NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)} |> Repo.insert()
post
end
@ -99,8 +87,8 @@ defmodule Content.PostsControllerTest do
def fixture(:front_post) do
{:ok, post} = Posts.create_posts(@create_attrs)
{:ok, _option} = %Content.Option{option_name: "show_on_front", option_value: "page"} |> Repo.insert()
{:ok, _option} = %Content.Option{option_name: "page_on_front", option_value: post.id |> Integer.to_string(10)} |> Repo.insert()
{:ok, _option} = %Content.Option{name: "show_on_front", value: "page"} |> Repo.insert()
{:ok, _option} = %Content.Option{name: "page_on_front", value: post.id |> Integer.to_string(10)} |> Repo.insert()
post
end
@ -149,19 +137,19 @@ defmodule Content.PostsControllerTest do
test "shows the post", %{conn: conn, posts: posts} do
conn = get conn, Routes.posts_path(conn, :show, posts)
assert html_response(conn, 200) =~ posts.post_title
assert html_response(conn, 200) =~ posts.title
end
test "shows the post by id", %{conn: conn, posts: posts} do
conn = get conn, Routes.posts_path(conn, :show, posts.id)
assert html_response(conn, 200) =~ posts.post_title
assert html_response(conn, 200) =~ posts.title
end
test "shows the post with pagination", %{conn: conn, posts: posts} do
conn = get conn, Routes.paged_post_path(conn, :show, posts, "2")
assert html_response(conn, 200) =~ posts.post_title
assert html_response(conn, 200) =~ posts.title
end
end
@ -179,7 +167,7 @@ defmodule Content.PostsControllerTest do
post = fixture(:single_post)
conn = get conn, Routes.posts_path(conn, :show, "blog")
assert html_response(conn, 200) =~ post.post_title
assert html_response(conn, 200) =~ post.title
end
end
@ -199,7 +187,7 @@ defmodule Content.PostsControllerTest do
post conn, Routes.posts_path(conn, :preview, %{"post" => @preview_attrs})
end
assert html_response(conn, 200) =~ @preview_attrs[:post_title]
assert html_response(conn, 200) =~ @preview_attrs[:title]
end
test "shows the post (put method)", %{conn: conn} do
@ -208,7 +196,7 @@ defmodule Content.PostsControllerTest do
put conn, Routes.posts_path(conn, :preview, %{"post" => @preview_attrs})
end
assert html_response(conn, 200) =~ @preview_attrs[:post_title]
assert html_response(conn, 200) =~ @preview_attrs[:title]
end
end
@ -216,9 +204,4 @@ defmodule Content.PostsControllerTest do
post = fixture(:single_post)
{:ok, posts: post}
end
defp create_posts(_) do
posts = fixture(:posts)
{:ok, posts: posts}
end
end

View file

@ -17,7 +17,8 @@ config :admin, Admin,
content: [
name: "Content",
resources: [
post: [schema: Content.Post, admin: Content.PostAdmin, label: "Posts and Pages", id_column: :post_name]
post: [schema: Content.Post, admin: Content.PostAdmin, label: "Posts and Pages", id_column: :name],
comment: [schema: Content.Comment, admin: Content.CommentAdmin],
]
]
]

View file

@ -10,4 +10,5 @@ $DIR_PATH/bootstrap
mix deps.get
mix npm.install
mix ecto.migrate
mix ecto.create
mix ecto.migrate