related tags: build html server-side instead of client-side.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
class ArtistUrlsController < ApplicationController
|
class ArtistUrlsController < ApplicationController
|
||||||
respond_to :json, :xml, :html
|
respond_to :js, :json, :xml, :html
|
||||||
before_action :member_only, except: [:index]
|
before_action :member_only, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
class RelatedTagsController < ApplicationController
|
class RelatedTagsController < ApplicationController
|
||||||
respond_to :json
|
respond_to :json, :xml, :js, :html, except: [:update]
|
||||||
respond_to :html, :only=>[:show]
|
|
||||||
before_action :require_reportbooru_key, only: [:update]
|
before_action :require_reportbooru_key, only: [:update]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@query = RelatedTagQuery.new(params[:query].to_s.downcase, params[:category])
|
@query = RelatedTagQuery.new(params[:query], category: params[:category], translated_tags: params[:translated_tags], artists: params[:artists])
|
||||||
respond_with(@query) do |format|
|
respond_with(@query) do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render :json => @query.to_json
|
render :json => @query.to_json
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import Utility from './utility'
|
import Utility from './utility'
|
||||||
import Hammer from 'hammerjs'
|
import Hammer from 'hammerjs'
|
||||||
import RelatedTag from './related_tag.js.erb'
|
|
||||||
import Cookie from './cookie'
|
import Cookie from './cookie'
|
||||||
import Note from './notes'
|
import Note from './notes'
|
||||||
import SavedSearch from './saved_searches'
|
import SavedSearch from './saved_searches'
|
||||||
@@ -85,11 +84,6 @@ Post.initialize_edit_dialog = function() {
|
|||||||
Post.open_edit_dialog();
|
Post.open_edit_dialog();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#toggle-related-tags-link").on("click.danbooru", function(e) {
|
|
||||||
RelatedTag.toggle();
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Post.open_edit_dialog = function() {
|
Post.open_edit_dialog = function() {
|
||||||
@@ -102,14 +96,11 @@ Post.open_edit_dialog = function() {
|
|||||||
$("#share").hide();
|
$("#share").hide();
|
||||||
$("#post-sections li").removeClass("active");
|
$("#post-sections li").removeClass("active");
|
||||||
$("#post-edit-link").parent("li").addClass("active");
|
$("#post-edit-link").parent("li").addClass("active");
|
||||||
$("#related-tags-container").show();
|
|
||||||
|
|
||||||
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
||||||
$("div.input").has($tag_string).prevAll().hide();
|
$("div.input").has($tag_string).prevAll().hide();
|
||||||
$("#open-edit-dialog").hide();
|
$("#open-edit-dialog").hide();
|
||||||
|
|
||||||
$("#toggle-related-tags-link").show().click();
|
|
||||||
|
|
||||||
var dialog = $("<div/>").attr("id", "edit-dialog");
|
var dialog = $("<div/>").attr("id", "edit-dialog");
|
||||||
$("#form").appendTo(dialog);
|
$("#form").appendTo(dialog);
|
||||||
dialog.dialog({
|
dialog.dialog({
|
||||||
@@ -161,17 +152,19 @@ Post.open_edit_dialog = function() {
|
|||||||
|
|
||||||
$tag_string.css({"resize": "none", "width": "100%"});
|
$tag_string.css({"resize": "none", "width": "100%"});
|
||||||
$tag_string.focus().selectEnd().height($tag_string[0].scrollHeight);
|
$tag_string.focus().selectEnd().height($tag_string[0].scrollHeight);
|
||||||
|
|
||||||
|
$(document).trigger("danbooru:show-post-edit-form");
|
||||||
|
$(document).trigger("danbooru:open-post-edit-dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
Post.close_edit_dialog = function(e, ui) {
|
Post.close_edit_dialog = function(e, ui) {
|
||||||
$("#form").appendTo($("#c-posts #edit,#c-uploads #a-new"));
|
$("#form").appendTo($("#c-posts #edit,#c-uploads #a-new"));
|
||||||
$("#edit-dialog").remove();
|
$("#edit-dialog").remove();
|
||||||
RelatedTag.show();
|
|
||||||
$("#toggle-related-tags-link").hide();
|
|
||||||
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
var $tag_string = $("#post_tag_string,#upload_tag_string");
|
||||||
$("div.input").has($tag_string).prevAll().show();
|
$("div.input").has($tag_string).prevAll().show();
|
||||||
$("#open-edit-dialog").show();
|
$("#open-edit-dialog").show();
|
||||||
$tag_string.css({"resize": "", "width": ""});
|
$tag_string.css({"resize": "", "width": ""});
|
||||||
|
$(document).trigger("danbooru:close-post-edit-dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
Post.initialize_similar = function() {
|
Post.initialize_similar = function() {
|
||||||
@@ -439,9 +432,8 @@ Post.initialize_post_sections = function() {
|
|||||||
$("#comments").hide();
|
$("#comments").hide();
|
||||||
$("#share").hide();
|
$("#share").hide();
|
||||||
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
|
||||||
$("#related-tags-button").trigger("click");
|
|
||||||
$("#fetch-data-manual").trigger("click");
|
|
||||||
$("#recommended").hide();
|
$("#recommended").hide();
|
||||||
|
$(document).trigger("danbooru:show-post-edit-form");
|
||||||
} else if (e.target.hash === "#recommended") {
|
} else if (e.target.hash === "#recommended") {
|
||||||
$("#comments").hide();
|
$("#comments").hide();
|
||||||
$("#edit").hide();
|
$("#edit").hide();
|
||||||
|
|||||||
@@ -1,22 +1,18 @@
|
|||||||
import Upload from './uploads';
|
|
||||||
import Utility from './utility';
|
import Utility from './utility';
|
||||||
import Cookie from './cookie';
|
|
||||||
|
|
||||||
let RelatedTag = {};
|
let RelatedTag = {};
|
||||||
|
|
||||||
RelatedTag.initialize_all = function() {
|
RelatedTag.initialize_all = function() {
|
||||||
if ($("#c-posts #a-show").length || $("#c-uploads #a-new").length) {
|
RelatedTag.artists = [];
|
||||||
this.initialize_buttons();
|
RelatedTag.translated_tags = [];
|
||||||
$("#upload_tag_string,#post_tag_string").on("keyup.danbooru.relatedTags", RelatedTag.update_selected);
|
$(document).on("click.danbooru", ".related-tags-button", RelatedTag.on_click_related_tags_button);
|
||||||
$("#related-tags-container").on("click.danbooru", "#artist-related-tags-column a.del", RelatedTag.disable_artist_url)
|
$(document).on("click.danbooru", ".related-tags a.search-tag", RelatedTag.toggle_tag);
|
||||||
}
|
$(document).on("click.danbooru", "#show-related-tags-link, #hide-related-tags-link", RelatedTag.toggle);
|
||||||
}
|
$(document).on("keyup.danbooru.relatedTags", "#upload_tag_string, #post_tag_string", RelatedTag.update_selected);
|
||||||
|
$(document).on("danbooru:update-source-data", RelatedTag.on_update_source_data);
|
||||||
RelatedTag.initialize_buttons = function() {
|
$(document).on("danbooru:show-post-edit-form", RelatedTag.on_show_post_edit_form);
|
||||||
this.common_bind("#related-tags-button", "");
|
$(document).on("danbooru:open-post-edit-dialog", RelatedTag.on_open_post_edit_dialog);
|
||||||
<% TagCategory.related_button_list.each do |category| %>
|
$(document).on("danbooru:close-post-edit-dialog", RelatedTag.on_close_post_edit_dialog);
|
||||||
RelatedTag.common_bind("#related-<%= category %>-button", "<%= category %>"); // eslint-disable-line indent
|
|
||||||
<% end %>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.tags_include = function(name) {
|
RelatedTag.tags_include = function(name) {
|
||||||
@@ -24,20 +20,40 @@ RelatedTag.tags_include = function(name) {
|
|||||||
return $.inArray(name.toLowerCase(), current) > -1;
|
return $.inArray(name.toLowerCase(), current) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.common_bind = function(button_name, category) {
|
RelatedTag.update_related_tags = function (category = "") {
|
||||||
$(button_name).on("click.danbooru", function(e) {
|
$.get("/related_tag.js", {
|
||||||
var $dest = $("#related-tags");
|
"query": RelatedTag.current_tag(),
|
||||||
$dest.empty();
|
"category": category,
|
||||||
RelatedTag.build_recent_and_frequent($dest);
|
"translated_tags": RelatedTag.translated_tags.join(" "),
|
||||||
$dest.append("<em>Loading...</em>");
|
"artists": RelatedTag.artists.join(" "),
|
||||||
$.get("/related_tag.json", {
|
|
||||||
"query": RelatedTag.current_tag(),
|
|
||||||
"category": category
|
|
||||||
}, RelatedTag.process_response);
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RelatedTag.on_open_post_edit_dialog = function(event) {
|
||||||
|
$("#related-tags-container").removeClass("visible").addClass("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.on_close_post_edit_dialog = function(event) {
|
||||||
|
$("#related-tags-container").removeClass("hidden").addClass("visible");
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.on_show_post_edit_form = function(event) {
|
||||||
|
RelatedTag.update_related_tags();
|
||||||
|
$("#fetch-data-manual").click();
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.on_click_related_tags_button = function (event) {
|
||||||
|
const category = $(event.target).data("category");
|
||||||
|
RelatedTag.update_related_tags(category);
|
||||||
|
$("#related-tags-container").removeClass("hidden").addClass("visible");
|
||||||
|
}
|
||||||
|
|
||||||
|
RelatedTag.on_update_source_data = function (event, source) {
|
||||||
|
Danbooru.RelatedTag.artists = source.artists.map(artist => artist.name);
|
||||||
|
Danbooru.RelatedTag.translated_tags = source.translated_tags.map(tag => tag[0]);
|
||||||
|
RelatedTag.update_related_tags();
|
||||||
|
}
|
||||||
|
|
||||||
RelatedTag.current_tag = function() {
|
RelatedTag.current_tag = function() {
|
||||||
// 1. abc def | -> def
|
// 1. abc def | -> def
|
||||||
// 2. abc def| -> def
|
// 2. abc def| -> def
|
||||||
@@ -86,11 +102,6 @@ RelatedTag.current_tag = function() {
|
|||||||
return string.slice(a, b);
|
return string.slice(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.process_response = function(data) {
|
|
||||||
RelatedTag.recent_search = data;
|
|
||||||
RelatedTag.build_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.update_selected = function(e) {
|
RelatedTag.update_selected = function(e) {
|
||||||
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
var current_tags = $("#upload_tag_string,#post_tag_string").val().toLowerCase().match(/\S+/g) || [];
|
||||||
var $all_tags = $("#related-tags a");
|
var $all_tags = $("#related-tags a");
|
||||||
@@ -103,165 +114,6 @@ RelatedTag.update_selected = function(e) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.build_all = function() {
|
|
||||||
if (RelatedTag.recent_search === null || RelatedTag.recent_search === undefined) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.show();
|
|
||||||
|
|
||||||
var query = RelatedTag.recent_search.query;
|
|
||||||
var related_tags = RelatedTag.recent_search.tags;
|
|
||||||
var wiki_page_tags = RelatedTag.recent_search.wiki_page_tags;
|
|
||||||
var other_wikis = RelatedTag.recent_search.other_wikis;
|
|
||||||
var $dest = $("#related-tags");
|
|
||||||
$dest.empty();
|
|
||||||
|
|
||||||
this.build_recent_and_frequent($dest);
|
|
||||||
|
|
||||||
$dest.append(this.build_html(query, related_tags, "general"));
|
|
||||||
this.build_translated($dest);
|
|
||||||
if (wiki_page_tags.length) {
|
|
||||||
$dest.append(RelatedTag.build_html("wiki:" + query, wiki_page_tags, "wiki"));
|
|
||||||
}
|
|
||||||
$.each(other_wikis, function(i, wiki) {
|
|
||||||
$dest.append(RelatedTag.build_html("wiki:" + wiki.title, wiki.wiki_page_tags, "otherwiki" + i.toString()));
|
|
||||||
});
|
|
||||||
if (RelatedTag.recent_artists) {
|
|
||||||
var tags = [];
|
|
||||||
if (RelatedTag.recent_artists.length === 0) {
|
|
||||||
tags.push([" none", 0]);
|
|
||||||
} else if (RelatedTag.recent_artists.length === 1) {
|
|
||||||
tags.push([RelatedTag.recent_artists[0].name, 1]);
|
|
||||||
if (RelatedTag.recent_artists[0].is_banned === true) {
|
|
||||||
tags.push(["BANNED_ARTIST", "banned"]);
|
|
||||||
}
|
|
||||||
$.each(RelatedTag.recent_artists[0].sorted_urls, function(i, url) {
|
|
||||||
var x = url.url;
|
|
||||||
if (!url.is_active) {
|
|
||||||
x = "-" + x;
|
|
||||||
}
|
|
||||||
tags.push([" " + x, 0]);
|
|
||||||
});
|
|
||||||
} else if (RelatedTag.recent_artists.length >= 10) {
|
|
||||||
tags.push([" none", 0]);
|
|
||||||
} else {
|
|
||||||
$.each(RelatedTag.recent_artists, function(i, artist) {
|
|
||||||
tags.push([artist.name, 1]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
$dest.append(RelatedTag.build_html("artist", tags, "artist", true));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.build_recent_and_frequent = function($dest) {
|
|
||||||
var recent_tags = Cookie.get("recent_tags_with_categories");
|
|
||||||
var favorite_tags = Cookie.get("favorite_tags_with_categories");
|
|
||||||
if (recent_tags.length) {
|
|
||||||
$dest.append(this.build_html("recent", this.other_tags(recent_tags), "recent"));
|
|
||||||
}
|
|
||||||
if (favorite_tags.length) {
|
|
||||||
$dest.append(this.build_html("frequent", this.other_tags(favorite_tags), "frequent"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.other_tags = function(string) {
|
|
||||||
if (string && string.length) {
|
|
||||||
return $.map(string.match(/\S+ \d+/g), function(x, i) {
|
|
||||||
var submatch = x.match(/(\S+) (\d+)/);
|
|
||||||
return [[submatch[1], submatch[2]]];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.build_translated = function($dest) {
|
|
||||||
if (RelatedTag.translated_tags && RelatedTag.translated_tags.length) {
|
|
||||||
$dest.append(this.build_html("Translated Tags", RelatedTag.translated_tags, "translated"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.build_html = function(query, related_tags, name, is_wide_column) {
|
|
||||||
if (query === null || query === "") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
query = query.replace(/_/g, " ");
|
|
||||||
var header = $("<em/>");
|
|
||||||
|
|
||||||
var match = query.match(/^wiki:(.+)/);
|
|
||||||
if (match) {
|
|
||||||
header.html($("<a/>").attr("href", "/wiki_pages?title=" + encodeURIComponent(match[1])).attr("target", "_blank").text(query));
|
|
||||||
} else {
|
|
||||||
header.text(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
var $div = $("<div/>");
|
|
||||||
$div.attr("id", name + "-related-tags-column");
|
|
||||||
$div.addClass("tag-column");
|
|
||||||
if (is_wide_column) {
|
|
||||||
$div.addClass("wide-column");
|
|
||||||
}
|
|
||||||
var $ul = $("<ul/>");
|
|
||||||
$ul.append(
|
|
||||||
$("<li/>").append(
|
|
||||||
header
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$.each(related_tags, function(i, tag) {
|
|
||||||
if (tag[0][0] !== " ") {
|
|
||||||
var $link = $("<a/>");
|
|
||||||
$link.text(tag[0].replace(/_/g, " "));
|
|
||||||
$link.addClass("tag-type-" + tag[1]);
|
|
||||||
$link.attr("href", "/posts?tags=" + encodeURIComponent(tag[0]));
|
|
||||||
$link.on("click.danbooru", RelatedTag.toggle_tag);
|
|
||||||
if (RelatedTag.tags_include(tag[0])) {
|
|
||||||
$link.addClass("selected");
|
|
||||||
}
|
|
||||||
$ul.append(
|
|
||||||
$("<li/>").append($link)
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
var text = tag[0];
|
|
||||||
var desc = "";
|
|
||||||
if (text.match(/^ -http/)) {
|
|
||||||
text = text.substring(1, 1000);
|
|
||||||
desc = text.replace(/^-https?:\/\//, "");
|
|
||||||
if (desc.length > 30) {
|
|
||||||
desc = desc.substring(0, 30) + "...";
|
|
||||||
}
|
|
||||||
$ul.append(
|
|
||||||
$("<li>").append(
|
|
||||||
$("<del>").text(desc)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
} else if (text.match(/^ http/)) {
|
|
||||||
text = text.substring(1, 1000);
|
|
||||||
desc = text.replace(/^https?:\/\//, "");
|
|
||||||
if (desc.length > 30) {
|
|
||||||
desc = desc.substring(0, 30) + "...";
|
|
||||||
}
|
|
||||||
$ul.append(
|
|
||||||
$("<li>").append([
|
|
||||||
$("<a>").text(desc).attr("href", text).attr("target", "_blank"),
|
|
||||||
" ",
|
|
||||||
$("<a>").attr("href", text).addClass("del").append(
|
|
||||||
$("<i>").addClass("fas fa-minus-circle")
|
|
||||||
)
|
|
||||||
])
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
$ul.append($("<li/>").text(text));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$div.append($ul);
|
|
||||||
return $div;
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.toggle_tag = function(e) {
|
RelatedTag.toggle_tag = function(e) {
|
||||||
var $field = $("#upload_tag_string,#post_tag_string");
|
var $field = $("#upload_tag_string,#post_tag_string");
|
||||||
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
var tag = $(e.target).html().replace(/ /g, "_").replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
||||||
@@ -281,46 +133,9 @@ RelatedTag.toggle_tag = function(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
RelatedTag.toggle = function() {
|
RelatedTag.toggle = function(e) {
|
||||||
if ($("#related-tags").is(":visible")) {
|
$("#related-tags-container").toggleClass("visible hidden");
|
||||||
RelatedTag.hide();
|
e.preventDefault();
|
||||||
} else {
|
|
||||||
RelatedTag.show();
|
|
||||||
$("#related-tags-button").trigger("click");
|
|
||||||
$("#find-artist-button").trigger("click");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.show = function() {
|
|
||||||
$("#related-tags").show()
|
|
||||||
$("#toggle-related-tags-link").text("«");
|
|
||||||
$("#edit-dialog").height("auto");
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.hide = function() {
|
|
||||||
$("#related-tags").hide();
|
|
||||||
$("#toggle-related-tags-link").text("»");
|
|
||||||
}
|
|
||||||
|
|
||||||
RelatedTag.disable_artist_url = function(e) {
|
|
||||||
var url = e.currentTarget.href;
|
|
||||||
$.each(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(Upload.fetch_data_manual);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|||||||
@@ -3,8 +3,10 @@
|
|||||||
div#related-tags-container {
|
div#related-tags-container {
|
||||||
padding-right: 2em;
|
padding-right: 2em;
|
||||||
|
|
||||||
h1 {
|
&.visible a#show-related-tags-link,
|
||||||
font-size: $h3_size;
|
&.hidden a#hide-related-tags-link,
|
||||||
|
&.hidden div.related-tags {
|
||||||
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
class RelatedTagQuery
|
class RelatedTagQuery
|
||||||
attr_reader :query, :category
|
attr_reader :query, :category, :translated_tags, :artists
|
||||||
|
|
||||||
def initialize(query, category = nil)
|
def initialize(query, category: nil, translated_tags: nil, artists: nil);
|
||||||
@query = TagAlias.to_aliased(query.strip).join(" ")
|
@query = TagAlias.to_aliased(query.to_s.downcase.strip).join(" ")
|
||||||
@category = category
|
@category = category
|
||||||
|
@translated_tags = translated_tags.to_s.split
|
||||||
|
@artists = Artist.where(name: artists.to_s.split)
|
||||||
|
@artists = [Artist.find_by(name: "banned_artist")] + @artists if @artists.any?(&:is_banned?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pretty_name
|
||||||
|
query.tr("_", " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
@@ -27,17 +34,12 @@ class RelatedTagQuery
|
|||||||
end
|
end
|
||||||
|
|
||||||
def other_wiki_category_tags
|
def other_wiki_category_tags
|
||||||
if Tag.category_for(query) != Tag.categories.copyright
|
return [] unless Tag.category_for(query) == Tag.categories.copyright
|
||||||
return []
|
|
||||||
end
|
other_wikis = wiki_page&.tags.to_a.grep(/^list_of_/i)
|
||||||
listtags = (wiki_page.try(:tags) || []).select {|name| name =~ /^list_of_/i }
|
other_wikis = other_wikis.map { |name| WikiPage.titled(name).first }
|
||||||
results = listtags.map do |name|
|
other_wikis = other_wikis.select { |wiki| wiki.tags.present? }
|
||||||
listlinks = WikiPage.titled(name).first.try(:tags) || []
|
other_wikis
|
||||||
if listlinks.length > 0
|
|
||||||
{"title" => name, "wiki_page_tags" => map_with_category_data(listlinks)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
results.reject {|list| list.nil?}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags_for_html
|
def tags_for_html
|
||||||
|
|||||||
1
app/views/artist_urls/update.js.erb
Normal file
1
app/views/artist_urls/update.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Danbooru.Upload.fetch_data_manual();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<%= button_tag "Related tags", :id => "related-tags-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
<%= button_tag "Related tags", type: :button, id: "related-tags-button", class: "related-tags-button ui-button ui-widget ui-corner-all sub gradient" %>
|
||||||
|
|
||||||
<% TagCategory.related_button_list.each do |category| %>
|
<% TagCategory.related_button_list.each do |category| %>
|
||||||
<%= button_tag "#{TagCategory.related_button_mapping[category]}", :id => "related-#{category}-button", :type => "button", :class => "ui-button ui-widget ui-corner-all sub gradient" %>
|
<%= button_tag TagCategory.related_button_mapping[category], type: :button, "data-category": category, class: "related-tags-button ui-button ui-widget ui-corner-all sub gradient" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<div id="related-tags-container">
|
<div id="related-tags-container" class="visible">
|
||||||
<h1>Related Tags <a href="#" id="toggle-related-tags-link" style="display: none;">«</a></h1>
|
<h3>
|
||||||
<div id="related-tags" class="related-tags">
|
Related Tags
|
||||||
</div>
|
<a href="#" id="show-related-tags-link">»</a>
|
||||||
|
<a href="#" id="hide-related-tags-link">«</a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<%= render "related_tags/related_tags" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
40
app/views/related_tags/_related_tags.html.erb
Normal file
40
app/views/related_tags/_related_tags.html.erb
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<%# related_tags %>
|
||||||
|
|
||||||
|
<div id="related-tags" class="related-tags">
|
||||||
|
<% if local_assigns[:related_tags] %>
|
||||||
|
<%= render "tag_column", tags: cookies[:recent_tags].to_s.split, title: "Recent" %>
|
||||||
|
<%= render "tag_column", tags: cookies[:favorite_tags].to_s.split, title: "Frequent" %>
|
||||||
|
<%= render "tag_column", tags: related_tags.tags, class: "general-related-tags-column", title: related_tags.pretty_name %>
|
||||||
|
<%= render "tag_column", tags: related_tags.translated_tags, title: "Translated Tags" %>
|
||||||
|
<%= render "tag_column", tags: related_tags.wiki_page_tags, class: "wiki-related-tags-column", title: link_to("wiki:#{related_tags.pretty_name}", show_or_new_wiki_pages_path(title: related_tags.query)) %>
|
||||||
|
|
||||||
|
<% related_tags.other_wiki_category_tags.each do |wiki| %>
|
||||||
|
<%= render "tag_column", tags: wiki.tags, class: "other-wiki-related-tags-column", title: link_to("wiki:#{wiki.pretty_title}", show_or_new_wiki_pages_path(title: wiki.title)) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="tag-column wide-column artist-related-tags-column">
|
||||||
|
<h6>Artist</h6>
|
||||||
|
|
||||||
|
<% if related_tags.artists.size == 0 %>
|
||||||
|
none
|
||||||
|
<% else %>
|
||||||
|
<% related_tags.artists.each do |artist| %>
|
||||||
|
<%= TagSetPresenter.new([artist.name]).tag_list_html(name_only: true) %>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<% artist.sorted_urls.each do |url| %>
|
||||||
|
<li>
|
||||||
|
<% if url.is_active %>
|
||||||
|
<%= external_link_to url.url, truncate: 30 %>
|
||||||
|
<%= link_to tag.i(class: "fas fa-minus-circle"), artist_url_path(id: url.id, artist_url: { is_active: false }), remote: true, method: :put, "data-confirm": "This will mark the URL as inactive. Continue?" %>
|
||||||
|
<% else %>
|
||||||
|
<del><%= truncate(url.url, length: 30) %></del>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
8
app/views/related_tags/_tag_column.html.erb
Normal file
8
app/views/related_tags/_tag_column.html.erb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<%# tags, title, class (optional) %>
|
||||||
|
|
||||||
|
<% if tags.present? %>
|
||||||
|
<div class="tag-column <%= local_assigns[:class] || "#{title.parameterize}-related-tags-column" %>">
|
||||||
|
<h6><%= title %></h6>
|
||||||
|
<%= TagSetPresenter.new(tags).tag_list_html(name_only: true) %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
2
app/views/related_tags/show.js.erb
Normal file
2
app/views/related_tags/show.js.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
$("div#related-tags").replaceWith("<%= j render "related_tags", related_tags: @query %>");
|
||||||
|
Danbooru.RelatedTag.update_selected();
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
$("#source-info").replaceWith("<%= j render "info", source: @source %>");
|
$("#source-info").replaceWith("<%= j render "info", source: @source %>");
|
||||||
|
|
||||||
Danbooru.RelatedTag.recent_artists = <%= raw @source.artists.to_json(include: :sorted_urls) %>;
|
$(document).trigger("danbooru:update-source-data", <%= raw @source.to_json %>);
|
||||||
Danbooru.RelatedTag.translated_tags = <%= raw @source.translated_tags.to_json %>;
|
|
||||||
Danbooru.RelatedTag.build_all();
|
|
||||||
|
|
||||||
if ($("#c-uploads #a-new").length) {
|
if ($("#c-uploads #a-new").length) {
|
||||||
$("#upload_artist_commentary_title").val(<%= raw @source.dtext_artist_commentary_title.to_json %>);
|
$("#upload_artist_commentary_title").val(<%= raw @source.dtext_artist_commentary_title.to_json %>);
|
||||||
|
|||||||
Reference in New Issue
Block a user