From a2ecaa71f5c0c55b62fb65cc5de0efa66f40db01 Mon Sep 17 00:00:00 2001 From: emeric Date: Mon, 14 May 2018 13:14:16 +0200 Subject: [PATCH] Adding tags ni the artits view --- approot/artists.xml | 1 + docroot/css/lms.css | 3 ++ src/ui/LmsApplication.cpp | 2 ++ src/ui/explore/ArtistView.cpp | 2 +- src/ui/explore/ArtistsView.cpp | 55 ++++++++++++++++++++++++++++++++-- 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/approot/artists.xml b/approot/artists.xml index 368eb13f..43dcc37c 100644 --- a/approot/artists.xml +++ b/approot/artists.xml @@ -20,6 +20,7 @@
${nb-release} ${name} + ${clusters}
diff --git a/docroot/css/lms.css b/docroot/css/lms.css index 03d32c2b..35ec32de 100644 --- a/docroot/css/lms.css +++ b/docroot/css/lms.css @@ -1,4 +1,7 @@ +.Lms-cluster { +} + .Lms-cluster-type-0 { background-color: darkslategrey; } diff --git a/src/ui/LmsApplication.cpp b/src/ui/LmsApplication.cpp index 1dedd55f..702f23b2 100644 --- a/src/ui/LmsApplication.cpp +++ b/src/ui/LmsApplication.cpp @@ -183,6 +183,8 @@ LmsApplication::createCluster(Database::Cluster::pointer cluster, bool canDelete res->bindString("name", Wt::WString::fromUTF8(cluster->getName()), Wt::TextFormat::Plain); res->setCondition("if-can-delete", canDelete); + res->setStyleClass("Lms-cluster"); + return res; } diff --git a/src/ui/explore/ArtistView.cpp b/src/ui/explore/ArtistView.cpp index 3bae5b00..025bc6f7 100644 --- a/src/ui/explore/ArtistView.cpp +++ b/src/ui/explore/ArtistView.cpp @@ -22,8 +22,8 @@ #include #include -#include "database/Types.hpp" #include "database/Setting.hpp" +#include "database/Types.hpp" #include "utils/Logger.hpp" #include "utils/Utils.hpp" diff --git a/src/ui/explore/ArtistsView.cpp b/src/ui/explore/ArtistsView.cpp index 45ccfce1..8cd3ec77 100644 --- a/src/ui/explore/ArtistsView.cpp +++ b/src/ui/explore/ArtistsView.cpp @@ -21,6 +21,7 @@ #include #include +#include "database/Setting.hpp" #include "database/Types.hpp" #include "utils/Logger.hpp" @@ -30,14 +31,44 @@ #include "Filters.hpp" #include "ArtistsView.hpp" -namespace UserInterface { - using namespace Database; +namespace { + +const std::string artistsClusterTypesSetting = "artists_cluster_types"; +const std::vector defaultArtistsClusterTypes = +{ + "ALBUMGROUPING", + "GENRE", + "ALBUMMOOD", +}; + +std::vector getArtistsClusterTypes(Wt::Dbo::Session& session) +{ + Wt::Dbo::Transaction transaction(session); + + std::vector res; + for (auto clusterTypeName : splitString(Setting::getString(session, artistsClusterTypesSetting), " ")) + { + auto clusterType = ClusterType::getByName(session, clusterTypeName); + if (clusterType) + res.push_back(clusterType); + } + + return res; +} + +} + +namespace UserInterface { + Artists::Artists(Filters* filters) : Wt::WTemplate(Wt::WString::tr("Lms.Explore.Artists.template")), _filters(filters) { + if (!Setting::exists(LmsApp->getDboSession(), artistsClusterTypesSetting)) + Setting::setString(LmsApp->getDboSession(), artistsClusterTypesSetting, joinStrings(defaultArtistsClusterTypes, " ")); + addFunction("tr", &Wt::WTemplate::Functions::tr); _search = bindNew("search"); @@ -87,6 +118,26 @@ Artists::addSome() entry->bindInt("nb-release", artist->getReleases(clusterIds).size()); entry->bindWidget("name", LmsApplication::createArtistAnchor(artist)); + + + Wt::WContainerWidget* clusterContainers = entry->bindNew("clusters"); + { + auto clusterTypes = getArtistsClusterTypes(LmsApp->getDboSession()); + auto clusterGroups = artist->getClusterGroups(clusterTypes, 1); + + for (auto clusters : clusterGroups) + { + for (auto cluster : clusters) + { + auto clusterId = cluster.id(); + auto entry = clusterContainers->addWidget(LmsApp->createCluster(cluster)); + entry->clicked().connect([=] + { + _filters->add(clusterId); + }); + } + } + } } _showMore->setHidden(!moreResults);