diff --git a/approot/artist.xml b/approot/artist.xml index 434e056b..070c46c7 100644 --- a/approot/artist.xml +++ b/approot/artist.xml @@ -13,11 +13,16 @@ ${releases class="list-group"} + + ${name} + +
diff --git a/src/database/DbArtist.cpp b/src/database/DbArtist.cpp index 32654f5e..bd871e7f 100644 --- a/src/database/DbArtist.cpp +++ b/src/database/DbArtist.cpp @@ -137,7 +137,7 @@ Artist::getByFilter(Wt::Dbo::Session& session, return res; } -std::vector > +std::vector> Artist::getReleases(const std::set& clusterIds) const { assert(self()); @@ -183,6 +183,25 @@ Artist::getReleases(const std::set& clusterIds) const return std::vector< Wt::Dbo::ptr > (res.begin(), res.end()); } +std::vector> +Artist::getClusters(int size) const +{ + assert(self()); + assert(self()->id() != Wt::Dbo::dbo_traits::invalidId() ); + assert(session()); + + Wt::Dbo::Query query = session()->query + ("select c from cluster c INNER JOIN track t ON c.id = t_c.cluster_id INNER JOIN track_cluster t_c ON t_c.track_id = t.id INNER JOIN artist a ON t.artist_id = a.id") + .where("a.id = ?").bind(self()->id()) + .groupBy("c.id") + .orderBy("COUNT(c.id) DESC") + .limit(size); + + Wt::Dbo::collection res = query; + + return std::vector(res.begin(), res.end()); +} + } // namespace Database diff --git a/src/database/DbArtist.hpp b/src/database/DbArtist.hpp index a22360dc..6ee5b283 100644 --- a/src/database/DbArtist.hpp +++ b/src/database/DbArtist.hpp @@ -63,9 +63,12 @@ class Artist : public Wt::Dbo::Dbo std::string getName(void) const { return _name; } std::string getMBID(void) const { return _MBID; } - // Get the releases that have at least one track for this artist + belongs to optonal cluster filters + // Get the releases that have at least one track for this artist that belongs to optional cluster filters std::vector> getReleases(const std::set& clusterIds = std::set()) const; + // Get the cluster of the tracks made by this artist + std::vector> getClusters(int size) const; + void setMBID(std::string mbid) { _MBID = mbid; } // Create diff --git a/src/ui/ArtistView.cpp b/src/ui/ArtistView.cpp index fc529a4f..6b770af0 100644 --- a/src/ui/ArtistView.cpp +++ b/src/ui/ArtistView.cpp @@ -74,6 +74,20 @@ Artist::refresh() auto t = new Wt::WTemplate(Wt::WString::tr("template-artist"), this); t->addFunction("tr", &Wt::WTemplate::Functions::tr); + auto clusterContainers = new Wt::WContainerWidget(); + t->bindWidget("tags", clusterContainers); + + { + auto clusters = artist->getClusters(3); + + for (auto cluster : clusters) + { + auto entry = new Wt::WTemplate(Wt::WString::tr("template-artist-tag-entry"), clusterContainers); + + entry->bindString("name", Wt::WString::fromUTF8(cluster->getName()), Wt::PlainText); + } + } + t->bindString("name", Wt::WString::fromUTF8(artist->getName()), Wt::PlainText); { auto playBtn = new Wt::WText(Wt::WString::tr("btn-artist-play-btn"), Wt::XHTMLText);