mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-31 20:24:27 -04:00
* Added a reoccuring task to cleanup db entries that might be abandoned. On library page, the Library in question will be prepoulated. * Laid out the foundation for customized sorting. Added all series page to the UI when clicking on Libraries section header on home page so user can apply any filtering they like. * When filtering, the current library filter will now automatically filter out the options for people and genres. * Implemented Sorting controls * Clear now clears sorting and read progress. Sorting is disabled on deck and recently added. * Fixed an issue where all-series page couldn't click to open series * Don't let the user unselect the last read progress. Added new comicinfo v2.1 draft tags. * Hooked in Translator tag into backend and UI. * Fixed an issue where you could open multiple typeaheads at the same time * Integrated Translator and Tags ComicInfo extension fields. Started work on a badge expander. * Reworked a bit more on badge expander. Added the UI code for Age Rating and Tags * Integrated backend for Tags, Translator, and Age Rating * Metadata tags now collapse if more than 4 present * Some code cleanup * Made the not read badge slightly smaller
94 lines
3.2 KiB
C#
94 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using API.Data;
|
|
using API.Entities;
|
|
|
|
namespace API.Helpers;
|
|
|
|
public static class TagHelper
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="allTags"></param>
|
|
/// <param name="names"></param>
|
|
/// <param name="isExternal"></param>
|
|
/// <param name="action">Callback for every item. Will give said item back and a bool if item was added</param>
|
|
public static void UpdateTag(ICollection<Tag> allTags, IEnumerable<string> names, bool isExternal, Action<Tag, bool> action)
|
|
{
|
|
foreach (var name in names)
|
|
{
|
|
if (string.IsNullOrEmpty(name.Trim())) continue;
|
|
|
|
var added = false;
|
|
var normalizedName = Parser.Parser.Normalize(name);
|
|
|
|
// var tag = DbFactory.Tag(name, isExternal);
|
|
// TagHelper.AddTagIfNotExists(allTags, tag);
|
|
|
|
var genre = allTags.FirstOrDefault(p =>
|
|
p.NormalizedTitle.Equals(normalizedName) && p.ExternalTag == isExternal);
|
|
if (genre == null)
|
|
{
|
|
added = true;
|
|
genre = DbFactory.Tag(name, false);
|
|
allTags.Add(genre);
|
|
}
|
|
|
|
action(genre, added);
|
|
}
|
|
}
|
|
|
|
public static void KeepOnlySameTagBetweenLists(ICollection<Tag> existingTags, ICollection<Tag> removeAllExcept, Action<Tag> action = null)
|
|
{
|
|
var existing = existingTags.ToList();
|
|
foreach (var genre in existing)
|
|
{
|
|
var existingPerson = removeAllExcept.FirstOrDefault(g => g.ExternalTag == genre.ExternalTag && genre.NormalizedTitle.Equals(g.NormalizedTitle));
|
|
if (existingPerson != null) continue;
|
|
existingTags.Remove(genre);
|
|
action?.Invoke(genre);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds the tag to the list if it's not already in there. This will ignore the ExternalTag.
|
|
/// </summary>
|
|
/// <param name="metadataTags"></param>
|
|
/// <param name="tag"></param>
|
|
public static void AddTagIfNotExists(ICollection<Tag> metadataTags, Tag tag)
|
|
{
|
|
var existingGenre = metadataTags.FirstOrDefault(p =>
|
|
p.NormalizedTitle == Parser.Parser.Normalize(tag.Title));
|
|
if (existingGenre == null)
|
|
{
|
|
metadataTags.Add(tag);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove tags on a list
|
|
/// </summary>
|
|
/// <remarks>Used to remove before we update/add new tags</remarks>
|
|
/// <param name="existingTags">Existing tags on Entity</param>
|
|
/// <param name="tags">Tags from metadata</param>
|
|
/// <param name="isExternal">Remove external tags?</param>
|
|
/// <param name="action">Callback which will be executed for each tag removed</param>
|
|
public static void RemoveTags(ICollection<Tag> existingTags, IEnumerable<string> tags, bool isExternal, Action<Tag> action = null)
|
|
{
|
|
var normalizedTags = tags.Select(Parser.Parser.Normalize).ToList();
|
|
foreach (var person in normalizedTags)
|
|
{
|
|
var existingTag = existingTags.FirstOrDefault(p => p.ExternalTag == isExternal && person.Equals(p.NormalizedTitle));
|
|
if (existingTag == null) continue;
|
|
|
|
existingTags.Remove(existingTag);
|
|
action?.Invoke(existingTag);
|
|
}
|
|
|
|
}
|
|
}
|
|
|