Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
fix cleaning flash message in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Apr 11, 2022
1 parent 1b19212 commit d6c05c7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions apps/mishka_content/lib/blog/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,9 @@ defmodule MishkaContent.Blog.Post do
end

def notify_subscribers(params, _), do: params

def delete_record(id) do
MishkaDatabase.Repo.get(Post, id)
|> MishkaDatabase.Repo.delete()
end
end
2 changes: 1 addition & 1 deletion apps/mishka_database/lib/schema/mishka_content/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule MishkaDatabase.Schema.MishkaContent.Blog.Post do
field :show_location, :boolean, null: true

belongs_to :blog_categories, MishkaDatabase.Schema.MishkaContent.Blog.Category, foreign_key: :category_id, type: :binary_id
has_many :blog_authors, MishkaDatabase.Schema.MishkaContent.BlogAuthor, foreign_key: :post_id
has_many :blog_authors, MishkaDatabase.Schema.MishkaContent.BlogAuthor, foreign_key: :post_id, on_delete: :nothing

has_many :blog_likes, MishkaDatabase.Schema.MishkaContent.BlogLike, foreign_key: :post_id
has_many :blog_tags_mappers, MishkaDatabase.Schema.MishkaContent.BlogTagMapper, foreign_key: :post_id, on_delete: :delete_all
Expand Down
9 changes: 9 additions & 0 deletions apps/mishka_html/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ Hooks.Editor = {
}
}

Hooks.DeleteFlashMessage = {
mounted() {
this.handleEvent("delete_flash_message", ({id}) => {
const element = document.getElementById(id);
element.remove();
});
}
}

let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_token: csrfToken}})

Expand Down
4 changes: 2 additions & 2 deletions apps/mishka_html/lib/mishka_html/helpers/live_crud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule MishkaHtml.Helpers.LiveCRUD do
def handle_event("delete", %{"id" => id} = _params, socket) do
module_selected = Keyword.get(@interface_module, :module)
skip_list = Keyword.get(@interface_module, :skip_list)
socket = MishkaHtml.Helpers.LiveCRUD.delete_item_of_list(socket, module_selected, unquote(function), id, unquote(user_id), unquote(component), skip_list, fn x -> x end)
socket = MishkaHtml.Helpers.LiveCRUD.delete_item_of_list(socket, module_selected, unquote(function), id, unquote(user_id), unquote(component), skip_list, nil)
{:noreply, socket}
end
end
Expand Down Expand Up @@ -562,7 +562,7 @@ defmodule MishkaHtml.Helpers.LiveCRUD do
}, %{user_action: "delete_item_of_list", title: Map.get(repo_data, :title), full_name: Map.get(repo_data, :full_name), user_id: Map.get(socket.assigns, :user_id)})

# It should pass conn or socket output
after_condition.(id, socket)
if !is_nil(after_condition), do: after_condition.(id, socket), else: socket
|> put_flash(:info, MishkaTranslator.Gettext.dgettext("macro_live", "رکورد مورد نظر با موفقیت حذف گردید"))
{:error, :delete, :forced_to_delete, _error_atom} ->
socket
Expand Down
4 changes: 2 additions & 2 deletions apps/mishka_html/lib/mishka_html_web/live/admin_notifs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ defmodule MishkaHtmlWeb.AdminBlogNotifsLive do
page_title: MishkaTranslator.Gettext.dgettext("html_live", "مدیریت اعلانات"),
notifs: Notif.notifs(conditions: {1, 10}, filters: %{})
)
{:ok, socket, temporary_assigns: [categories: []]}
{:ok, socket, temporary_assigns: [notifs: []]}
end

# Live CRUD and Paginate
paginate(:notifs, user_id: false)

list_search_and_action()

delete_list_item(:notifs, DeleteErrorComponent, false)
delete_list_item(:notifs, MishkaHtmlWeb.AdminBlogNotifsLive, false)

selected_menue("MishkaHtmlWeb.AdminBlogNotifsLive")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,43 @@ defmodule MishkaHtml.Helpers.FlashComponent do

def render(assigns) do
~H"""
<div class="col-sm-12 rtl" id="live-flash">
<div class="col-sm-12 rtl" id="live-flash" phx-hook="DeleteFlashMessage">
<%= if live_flash(@flash, :info) do %>
<div class="space20"></div>
<p id={Ecto.UUID.generate} class="col titile-of-blog-posts alert alert-info" role="alert" phx-click="lv:clear-flash" phx-value-key="info">
<p class="col titile-of-blog-posts alert alert-info" role="alert" id="flash_message_admin_alert" phx-click="delete_flash_message" phx-target={@myself}>
<%= live_flash(@flash, :info) %>
</p>
<% end %>
<%= if live_flash(@flash, :success) do %>
<div class="space20"></div>
<p id={Ecto.UUID.generate} class="col titile-of-blog-posts alert alert-success" role="alert" phx-click="lv:clear-flash" phx-value-key="success">
<p class="col titile-of-blog-posts alert alert-success" role="alert" id="flash_message_admin_alert" phx-click="delete_flash_message" phx-target={@myself}>
<%= live_flash(@flash, :success) %>
</p>
<% end %>
<%= if live_flash(@flash, :warning) do %>
<div class="space20"></div>
<p id={Ecto.UUID.generate} class="col titile-of-blog-posts alert alert-warning" role="alert" phx-click="lv:clear-flash" phx-value-key="warning">
<p class="col titile-of-blog-posts alert alert-warning" role="alert" id="flash_message_admin_alert" phx-click="delete_flash_message" phx-target={@myself}>
<%= live_flash(@flash, :warning) %>
</p>
<% end %>
<%= if live_flash(@flash, :error) do %>
<div class="space20"></div>
<p id={Ecto.UUID.generate} class="col titile-of-blog-posts alert alert-danger" role="alert" phx-click="lv:clear-flash" phx-value-key="error">
<p class="col titile-of-blog-posts alert alert-danger" role="alert" id="flash_message_admin_alert" phx-click="delete_flash_message" phx-target={@myself}>
<%= live_flash(@flash, :error) %>
</p>
<% end %>
</div>
"""
end

def handle_event("delete_flash_message", _params, socket) do
socket =
socket
|> push_event("delete_flash_message", %{id: "flash_message_admin_alert"})

{:noreply, socket}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule MishkaHtml.Helpers.ListItemComponent do
</thead>
<tbody>
<%= for {list_item, color} <- Enum.zip(@list, Stream.cycle(["wlist", "glist"])) do %>
<tr class={"list-component-item #{if(color == "glist", do: "odd-list-of-blog-posts align-middle", else: "align-middle")}"}>
<tr id={Map.get(list_item, :id) || Ecto.UUID.generate} class={"list-component-item #{if(color == "glist", do: "odd-list-of-blog-posts align-middle", else: "align-middle")}"}>
<%= for field_item <- get_list_headers(@fields) do %>
<td class="col list-item-value">
<%= if field_item.form == "custom" do %>
Expand Down

0 comments on commit d6c05c7

Please sign in to comment.