diff --git a/app/assets/javascripts/related_tag.js.erb b/app/assets/javascripts/related_tag.js.erb index 352eda78c..b7aa78f52 100644 --- a/app/assets/javascripts/related_tag.js.erb +++ b/app/assets/javascripts/related_tag.js.erb @@ -7,6 +7,7 @@ $("#related-tags-container").hide(); $("#artist-tags-container").hide(); $("#upload_tag_string,#post_tag_string").keyup(Danbooru.RelatedTag.update_selected); + $("body").on("click", "#artist-related-tags-column a.del", Danbooru.RelatedTag.disable_artist_url) } } @@ -236,19 +237,26 @@ if (desc.length > 30) { desc = desc.substring(0, 30) + "..."; } - var $del = $("").text(desc); - $ul.append($("
  • ").html($del)); + $ul.append( + $("
  • ").append( + $("").text(desc) + ) + ); } else if (text.match(/^ http/)) { text = text.substring(1, 1000); - var $url = $(""); var desc = text.replace(/^https?:\/\//, ""); if (desc.length > 30) { desc = desc.substring(0, 30) + "..."; } - $url.text(desc); - $url.attr("href", text); - $url.attr("target", "_blank"); - $ul.append($("
  • ").html($url)); + $ul.append( + $("
  • ").append([ + $("").text(desc).attr("href", text).attr("target", "_blank"), + " ", + $("").attr("href", text).addClass("del").append( + $("").addClass("fas fa-minus-circle") + ) + ]) + ); } else { $ul.append($("
  • ").text(text)); } @@ -286,7 +294,9 @@ var url = $("#upload_source,#post_source"); var referer_url = $("#upload_referer_url"); $.get("/artists/finder.json", {"url": url.val(), "referer_url": referer_url.val()}, Danbooru.RelatedTag.process_artist); - e.preventDefault(); + if (e) { + e.preventDefault(); + } } Danbooru.RelatedTag.process_artist = function(data) { @@ -314,6 +324,28 @@ $("#related-tags").hide(); $("#toggle-related-tags-link").text("ยป"); } + + Danbooru.RelatedTag.disable_artist_url = function(e) { + var url = e.currentTarget.href; + console.log("clicked %o", url); + $.each(Danbooru.RelatedTag.recent_artists[0].sorted_urls, function(k, v) { + if (v["normalized_url"] === url || v["url"] === url) { + if (!confirm("This will mark the URL as inactive. Continue?")) { + return; + } + + $.ajax("/artist_urls/" + v["id"], { + method: "PUT", + data: { + artist_url: { + is_active: false + } + } + }).done(Danbooru.RelatedTag.find_artist); + } + }); + return false; + } })(); $(function() { diff --git a/app/assets/stylesheets/specific/related_tags.scss b/app/assets/stylesheets/specific/related_tags.scss index 141995254..ff5fe72ee 100644 --- a/app/assets/stylesheets/specific/related_tags.scss +++ b/app/assets/stylesheets/specific/related_tags.scss @@ -28,6 +28,11 @@ div.related-tags { font-weight: bold; } + svg { + margin-top: 2px; + cursor: pointer; + } + a { min-width: 3em; } diff --git a/app/controllers/artist_urls_controller.rb b/app/controllers/artist_urls_controller.rb new file mode 100644 index 000000000..1c75ece3b --- /dev/null +++ b/app/controllers/artist_urls_controller.rb @@ -0,0 +1,18 @@ +class ArtistUrlsController < ApplicationController + respond_to :json + before_action :member_only + + def update + @artist_url = ArtistUrl.find(params[:id]) + @artist_url.update(artist_url_params) + respond_with(@artist_url) + end + +private + + def artist_url_params + permitted_params = %i[is_active] + + params.fetch(:artist_url, {}).permit(permitted_params) + end +end diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index 102e941f1..1c83352fd 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -1,5 +1,5 @@ class ArtistsController < ApplicationController - respond_to :html, :xml, :json + respond_to :html, :xml, :json, :js before_action :member_only, :except => [:index, :show, :show_or_new, :banned] before_action :builder_only, :only => [:destroy] before_action :admin_only, :only => [:ban, :unban] diff --git a/app/views/artists/_secondary_links.html.erb b/app/views/artists/_secondary_links.html.erb index 2d8c20c39..496fb339d 100644 --- a/app/views/artists/_secondary_links.html.erb +++ b/app/views/artists/_secondary_links.html.erb @@ -17,7 +17,7 @@ <% if @artist.is_active? %>
  • <%= link_to "Delete", artist_path(@artist), method: :delete, data: {confirm: "Are you sure you want to delete this artist?"} %>
  • <% else %> -
  • <%= link_to "Undelete", artist_path(@artist), method: :put, data: {confirm: "Are you sure you want to undelete this artist?", params: {"artist[is_active]" => true}} %>
  • +
  • <%= link_to "Undelete", artist_path(@artist, format: "js"), method: :put, data: {confirm: "Are you sure you want to undelete this artist?", params: "artist[is_active]=true"}, remote: true %>
  • <% end %> <% end %> <% if CurrentUser.is_admin? %> diff --git a/app/views/artists/update.js.erb b/app/views/artists/update.js.erb new file mode 100644 index 000000000..bcebe9d37 --- /dev/null +++ b/app/views/artists/update.js.erb @@ -0,0 +1 @@ +location.reload(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3fca106f3..b6d9c5584 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -81,6 +81,7 @@ Rails.application.routes.draw do get :finder end end + resources :artist_urls, only: [:update] resources :artist_versions, :only => [:index] do collection do get :search