mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 14:17:59 +01:00
unfinished topic moving
This commit is contained in:
parent
375a5c6de1
commit
ffed45269b
4 changed files with 32 additions and 21 deletions
|
@ -209,7 +209,13 @@ defmodule Philomena.Topics do
|
|||
Topic.unlock_changeset(topic)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def move_topic(%Topic{} = topic, attrs) do
|
||||
Topic.move_changeset(topic, attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
def clear_notification(nil, _user), do: nil
|
||||
def clear_notification(_topic, nil), do: nil
|
||||
def clear_notification(topic, user) do
|
||||
Notifications.delete_unread_notification("Topic", topic.id, user)
|
||||
|
|
|
@ -91,6 +91,11 @@ defmodule Philomena.Topics.Topic do
|
|||
|> put_change(:lock_reason, "")
|
||||
end
|
||||
|
||||
def move_changeset(topic, attrs) do
|
||||
change(topic)
|
||||
|> put_change(:forum_id, attrs["target_forum_id"] |> String.to_integer())
|
||||
end
|
||||
|
||||
def put_slug(changeset) do
|
||||
slug =
|
||||
changeset
|
||||
|
|
|
@ -8,12 +8,24 @@ defmodule PhilomenaWeb.Topic.MoveController do
|
|||
import Ecto.Query
|
||||
|
||||
plug :load_topic
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :stick, delete: :stick
|
||||
plug PhilomenaWeb.CanaryMapPlug, create: :move
|
||||
plug :authorize_resource, model: Topic, id_name: "topic_id", persisted: true
|
||||
|
||||
# intentionally blank
|
||||
# todo: moving
|
||||
def create(conn, _opts) do
|
||||
def create(conn, %{"topic" => topic_params}) do
|
||||
topic = conn.assigns.topic
|
||||
|
||||
case Topics.move_topic(topic, topic_params) do
|
||||
{:ok, topic} ->
|
||||
conn
|
||||
|> put_flash(:info, "Topic successfully moved!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic_params["target_forum_id"] |> String.to_integer(), topic.id))
|
||||
{:error, _changeset} ->
|
||||
conn
|
||||
|> put_flash(:error, "Unable to move the topic!")
|
||||
|> redirect(to: Routes.forum_topic_path(conn, :show, topic.forum_id, topic.id))
|
||||
end
|
||||
end
|
||||
|
||||
defp load_topic(conn, _opts) do
|
||||
|
|
|
@ -103,6 +103,13 @@ h1 = @topic.title
|
|||
i.fas.fa-thumbtack>
|
||||
' Stick
|
||||
- true ->
|
||||
= if can?(@conn, :move, @topic) do
|
||||
= form_for :topic, Routes.forum_topic_move_path(@conn, :create, @topic.forum_id, @topic), [method: :post, class: "hform"], fn f ->
|
||||
.field
|
||||
= select f, :target_forum_id, @conn.assigns.forums |> Enum.map(fn forum -> {forum.name, forum.id} end), class: "input hform__text"
|
||||
= submit class: "hform__button button" do
|
||||
i.fas.fa-truck>
|
||||
' Move
|
||||
/ Mod tools
|
||||
/- if can? :assist, Topic
|
||||
/ .block__content
|
||||
|
@ -111,25 +118,6 @@ h1 = @topic.title
|
|||
/ .toggle-box-container
|
||||
/ .toggle-box-container__content
|
||||
/ p
|
||||
/ - if can?(:unlock, @topic) && !@topic.locked_at.nil?
|
||||
/ => button_to forum_topic_lock_path(@forum, @topic), method: :delete, class: 'button' do
|
||||
/ i.fa.fa-lock>
|
||||
/ | Unlock
|
||||
/ - if can?(:stick, @topic) && !@topic.sticky
|
||||
/ => button_to forum_topic_stick_path(@forum, @topic), method: :post, class: 'button' do
|
||||
/ i.fa.fa-thumbtack>
|
||||
/ | Stick
|
||||
/ - if can?(:stick, @topic) && @topic.sticky
|
||||
/ => button_to forum_topic_stick_path(@forum, @topic), method: :delete, class: 'button' do
|
||||
/ i.fa.fa-thumbtack>
|
||||
/ | Unstick
|
||||
/ - if can?(:lock, @topic) && @topic.locked_at.nil?
|
||||
/ = form_tag forum_topic_lock_path(@forum, @topic), method: :post, class: 'hform' do
|
||||
/ .field
|
||||
/ => text_field_tag :lock_reason, '', placeholder: 'Lock reason', class: 'input hform__text'
|
||||
/ => button_tag class: 'hform__button button' do
|
||||
/ i.fa.fa-unlock>
|
||||
/ | Lock
|
||||
/ - if can? :move, @topic
|
||||
/ = form_tag forum_topic_move_path(@forum, @topic), method: :post, class: 'hform' do
|
||||
/ .field
|
||||
|
|
Loading…
Reference in a new issue