mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
unfinished topic moving
This commit is contained in:
parent
375a5c6de1
commit
ffed45269b
4 changed files with 32 additions and 21 deletions
|
@ -210,6 +210,12 @@ defmodule Philomena.Topics do
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
end
|
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, nil), do: nil
|
||||||
def clear_notification(topic, user) do
|
def clear_notification(topic, user) do
|
||||||
Notifications.delete_unread_notification("Topic", topic.id, user)
|
Notifications.delete_unread_notification("Topic", topic.id, user)
|
||||||
|
|
|
@ -91,6 +91,11 @@ defmodule Philomena.Topics.Topic do
|
||||||
|> put_change(:lock_reason, "")
|
|> put_change(:lock_reason, "")
|
||||||
end
|
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
|
def put_slug(changeset) do
|
||||||
slug =
|
slug =
|
||||||
changeset
|
changeset
|
||||||
|
|
|
@ -8,12 +8,24 @@ defmodule PhilomenaWeb.Topic.MoveController do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
plug :load_topic
|
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
|
plug :authorize_resource, model: Topic, id_name: "topic_id", persisted: true
|
||||||
|
|
||||||
# intentionally blank
|
# intentionally blank
|
||||||
# todo: moving
|
# 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
|
end
|
||||||
|
|
||||||
defp load_topic(conn, _opts) do
|
defp load_topic(conn, _opts) do
|
||||||
|
|
|
@ -103,6 +103,13 @@ h1 = @topic.title
|
||||||
i.fas.fa-thumbtack>
|
i.fas.fa-thumbtack>
|
||||||
' Stick
|
' Stick
|
||||||
- true ->
|
- 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
|
/ Mod tools
|
||||||
/- if can? :assist, Topic
|
/- if can? :assist, Topic
|
||||||
/ .block__content
|
/ .block__content
|
||||||
|
@ -111,25 +118,6 @@ h1 = @topic.title
|
||||||
/ .toggle-box-container
|
/ .toggle-box-container
|
||||||
/ .toggle-box-container__content
|
/ .toggle-box-container__content
|
||||||
/ p
|
/ 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
|
/ - if can? :move, @topic
|
||||||
/ = form_tag forum_topic_move_path(@forum, @topic), method: :post, class: 'hform' do
|
/ = form_tag forum_topic_move_path(@forum, @topic), method: :post, class: 'hform' do
|
||||||
/ .field
|
/ .field
|
||||||
|
|
Loading…
Reference in a new issue