From 95f206a2093b4243b299b2ce34a57d565a18a5bd Mon Sep 17 00:00:00 2001 From: emeric Date: Tue, 28 Aug 2018 15:23:16 +0200 Subject: [PATCH] Move the top/recently added parts into a dedicated panel on the left --- Makefile.am | 2 + approot/artists.xml | 14 ---- approot/artistsinfo.xml | 25 ++++++ approot/explore.xml | 16 +++- approot/messages.xml | 17 ++-- approot/playhistory.xml | 17 ++++ approot/releases.xml | 16 ---- approot/releasesinfo.xml | 27 +++++++ src/Makefile.am | 2 + src/ui/LmsApplication.cpp | 2 + src/ui/explore/ArtistsInfoView.cpp | 87 +++++++++++++++++++++ src/ui/explore/ArtistsInfoView.hpp | 41 ++++++++++ src/ui/explore/ArtistsView.cpp | 44 ----------- src/ui/explore/ArtistsView.hpp | 6 -- src/ui/explore/Explore.cpp | 116 ++++++++++++++++++++-------- src/ui/explore/Filters.cpp | 2 + src/ui/explore/ReleasesInfoView.cpp | 108 ++++++++++++++++++++++++++ src/ui/explore/ReleasesInfoView.hpp | 41 ++++++++++ src/ui/explore/ReleasesView.cpp | 66 +--------------- src/ui/explore/ReleasesView.hpp | 7 -- 20 files changed, 462 insertions(+), 194 deletions(-) create mode 100644 approot/artistsinfo.xml create mode 100644 approot/playhistory.xml create mode 100644 approot/releasesinfo.xml create mode 100644 src/ui/explore/ArtistsInfoView.cpp create mode 100644 src/ui/explore/ArtistsInfoView.hpp create mode 100644 src/ui/explore/ReleasesInfoView.cpp create mode 100644 src/ui/explore/ReleasesInfoView.hpp diff --git a/Makefile.am b/Makefile.am index bbc921d5..b62cf797 100644 --- a/Makefile.am +++ b/Makefile.am @@ -27,6 +27,7 @@ lms_approot_DATA = \ approot/admin-initwizard.xml \ approot/artist.xml \ approot/artists.xml \ + approot/artistsinfo.xml \ approot/explore.xml \ approot/login.xml \ approot/mediaplayer.xml \ @@ -35,6 +36,7 @@ lms_approot_DATA = \ approot/playqueue.xml \ approot/release.xml \ approot/releases.xml \ + approot/releasesinfo.xml \ approot/settings.xml \ approot/templates.xml \ approot/tracks.xml diff --git a/approot/artists.xml b/approot/artists.xml index 23425af9..43dcc37c 100644 --- a/approot/artists.xml +++ b/approot/artists.xml @@ -3,16 +3,6 @@ - - ${most-played-artists} - - - ${recently-added-artists} - @@ -26,10 +16,6 @@ ${show-more} - - ${name} - -
${nb-release} diff --git a/approot/artistsinfo.xml b/approot/artistsinfo.xml new file mode 100644 index 00000000..56e5c6bb --- /dev/null +++ b/approot/artistsinfo.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + ${name} + + + diff --git a/approot/explore.xml b/approot/explore.xml index 446a3893..2cc7a377 100644 --- a/approot/explore.xml +++ b/approot/explore.xml @@ -2,8 +2,15 @@ - ${filters} - ${contents} +
+
+ ${filters} + ${info} +
+
+ ${contents} +
+
@@ -12,7 +19,10 @@
- ${add-filter}${clusters} + + ${clusters}
diff --git a/approot/messages.xml b/approot/messages.xml index 5419428a..5e020a35 100644 --- a/approot/messages.xml +++ b/approot/messages.xml @@ -62,14 +62,9 @@ Welcome! -Add filter +Add Artists -Top artists -Top albums -Recently added artists -Recently added albums -Recently played artists -Recently played albums +Filters Albums Search... Show more @@ -78,6 +73,14 @@ Value Various artists + +Recently added +Top artists + + +Recently added +Top releases + {1} tracks Added {1} tracks diff --git a/approot/playhistory.xml b/approot/playhistory.xml new file mode 100644 index 00000000..d674445e --- /dev/null +++ b/approot/playhistory.xml @@ -0,0 +1,17 @@ + + + + + + + ${entries} + ${show-more} + + + + ${name} ${}${release-name}${} ${}${artist-name}${} + + + diff --git a/approot/releases.xml b/approot/releases.xml index 92cf00ce..69f6864f 100644 --- a/approot/releases.xml +++ b/approot/releases.xml @@ -3,16 +3,6 @@ - - ${most-played-releases} - - - ${recently-added-releases} - @@ -34,12 +24,6 @@ - - ${cover} - ${release-name} - ${}${artist-name}${} - -
diff --git a/approot/releasesinfo.xml b/approot/releasesinfo.xml new file mode 100644 index 00000000..f6f44d65 --- /dev/null +++ b/approot/releasesinfo.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + ${cover} + ${release-name} + ${}${artist-name}${} + + + diff --git a/src/Makefile.am b/src/Makefile.am index 468d413d..bf097b57 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -32,9 +32,11 @@ lms_SOURCES = \ $(srcdir)/ui/common/Validators.cpp \ $(srcdir)/ui/explore/ArtistView.cpp \ $(srcdir)/ui/explore/ArtistsView.cpp \ + $(srcdir)/ui/explore/ArtistsInfoView.cpp \ $(srcdir)/ui/explore/Explore.cpp \ $(srcdir)/ui/explore/Filters.cpp \ $(srcdir)/ui/explore/ReleasesView.cpp \ + $(srcdir)/ui/explore/ReleasesInfoView.cpp \ $(srcdir)/ui/explore/ReleaseView.cpp \ $(srcdir)/ui/explore/TracksView.cpp \ $(srcdir)/ui/resource/ImageResource.cpp \ diff --git a/src/ui/LmsApplication.cpp b/src/ui/LmsApplication.cpp index 8488339a..80f3433d 100644 --- a/src/ui/LmsApplication.cpp +++ b/src/ui/LmsApplication.cpp @@ -95,6 +95,7 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti messageResourceBundle().use(appRoot() + "admin-initwizard"); messageResourceBundle().use(appRoot() + "artist"); messageResourceBundle().use(appRoot() + "artists"); + messageResourceBundle().use(appRoot() + "artistsinfo"); messageResourceBundle().use(appRoot() + "explore"); messageResourceBundle().use(appRoot() + "login"); messageResourceBundle().use(appRoot() + "mediaplayer"); @@ -103,6 +104,7 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti messageResourceBundle().use(appRoot() + "playhistory"); messageResourceBundle().use(appRoot() + "release"); messageResourceBundle().use(appRoot() + "releases"); + messageResourceBundle().use(appRoot() + "releasesinfo"); messageResourceBundle().use(appRoot() + "settings"); messageResourceBundle().use(appRoot() + "tracks"); messageResourceBundle().use(appRoot() + "templates"); diff --git a/src/ui/explore/ArtistsInfoView.cpp b/src/ui/explore/ArtistsInfoView.cpp new file mode 100644 index 00000000..ec389a3b --- /dev/null +++ b/src/ui/explore/ArtistsInfoView.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2018 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include "ArtistsInfoView.hpp" + +#include +#include + +#include "database/Artist.hpp" +#include "database/TrackList.hpp" + +#include "utils/Utils.hpp" + +#include "LmsApplication.hpp" + +using namespace Database; + +namespace { + +using namespace UserInterface; + +void addEntries(Wt::WContainerWidget *container, const std::vector& artists) +{ + for (auto artist : artists) + { + Wt::WTemplate* entry = container->addNew(Wt::WString::tr("Lms.Explore.ArtistsInfo.template.entry")); + + entry->bindWidget("name", LmsApplication::createArtistAnchor(artist)); + } +} + +} + +namespace UserInterface { + +ArtistsInfo::ArtistsInfo() +: Wt::WTemplate(Wt::WString::tr("Lms.Explore.ArtistsInfo.template")) +{ + addFunction("tr", &Wt::WTemplate::Functions::tr); + + _mostPlayedContainer = bindNew("most-played"); + _recentlyAddedContainer = bindNew("recently-added"); + + refreshMostPlayed(); + refreshRecentlyAdded(); +} + +void +ArtistsInfo::refreshRecentlyAdded() +{ + auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1); + + Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); + auto artists = Artist::getLastAdded(LmsApp->getDboSession(), after, 5); + + _recentlyAddedContainer->clear(); + addEntries(_recentlyAddedContainer, artists); +} + +void +ArtistsInfo::refreshMostPlayed() +{ + Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); + auto artists = LmsApp->getUser()->getPlayedTrackList()->getTopArtists(5); + + _mostPlayedContainer->clear(); + addEntries(_mostPlayedContainer, artists); +} + +} // namespace UserInterface + diff --git a/src/ui/explore/ArtistsInfoView.hpp b/src/ui/explore/ArtistsInfoView.hpp new file mode 100644 index 00000000..dc9d83c1 --- /dev/null +++ b/src/ui/explore/ArtistsInfoView.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#pragma once + +#include +#include + +namespace UserInterface { + +class ArtistsInfo : public Wt::WTemplate +{ + public: + ArtistsInfo(); + + void refreshRecentlyAdded(); + void refreshMostPlayed(); + + private: + Wt::WContainerWidget* _mostPlayedContainer; + Wt::WContainerWidget* _recentlyAddedContainer; +}; + +} // namespace UserInterface + diff --git a/src/ui/explore/ArtistsView.cpp b/src/ui/explore/ArtistsView.cpp index b2b73e4a..78d202aa 100644 --- a/src/ui/explore/ArtistsView.cpp +++ b/src/ui/explore/ArtistsView.cpp @@ -25,7 +25,6 @@ #include #include "database/Artist.hpp" -#include "database/TrackList.hpp" #include "utils/Logger.hpp" #include "utils/Utils.hpp" @@ -35,22 +34,6 @@ using namespace Database; -namespace { - -using namespace UserInterface; - -void addCompactEntries(Wt::WContainerWidget *container, const std::vector& artists) -{ - for (auto artist : artists) - { - Wt::WTemplate* entry = container->addNew(Wt::WString::tr("Lms.Explore.Artists.template.compact-entry")); - - entry->bindWidget("name", LmsApplication::createArtistAnchor(artist)); - } -} - -} - namespace UserInterface { Artists::Artists(Filters* filters) @@ -64,9 +47,6 @@ Artists::Artists(Filters* filters) _search->textInput().connect(this, &Artists::refresh); _container = bindNew("artists"); - _mostPlayedContainer = bindNew("most-played-artists"); - _recentlyAddedContainer = bindNew("recently-added-artists"); - _recentlyPlayedContainer = bindNew("recently-played-artists"); _showMore = bindNew("show-more", Wt::WString::tr("Lms.Explore.template.show-more")); _showMore->addFunction("tr", &Wt::WTemplate::Functions::tr); @@ -77,34 +57,10 @@ Artists::Artists(Filters* filters) })); refresh(); - refreshMostPlayed(); - refreshRecentlyAdded(); filters->updated().connect(this, &Artists::refresh); } -void -Artists::refreshRecentlyAdded() -{ - auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1); - - Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); - auto artists = Artist::getLastAdded(LmsApp->getDboSession(), after, 5); - - _recentlyAddedContainer->clear(); - addCompactEntries(_recentlyAddedContainer, artists); -} - -void -Artists::refreshMostPlayed() -{ - Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); - auto artists = LmsApp->getUser()->getPlayedTrackList()->getTopArtists(5); - - _mostPlayedContainer->clear(); - addCompactEntries(_mostPlayedContainer, artists); -} - void Artists::refresh() { diff --git a/src/ui/explore/ArtistsView.hpp b/src/ui/explore/ArtistsView.hpp index e6da4276..6a54e934 100644 --- a/src/ui/explore/ArtistsView.hpp +++ b/src/ui/explore/ArtistsView.hpp @@ -38,9 +38,6 @@ class Artists : public Wt::WTemplate Wt::Signal artistAdd; Wt::Signal artistPlay; - void refreshRecentlyAdded(); - void refreshMostPlayed(); - private: void refresh(); void addSome(); @@ -49,9 +46,6 @@ class Artists : public Wt::WTemplate Wt::WTemplate* _showMore; Wt::WLineEdit* _search; Wt::WContainerWidget* _container; - Wt::WContainerWidget* _mostPlayedContainer; - Wt::WContainerWidget* _recentlyAddedContainer; - Wt::WContainerWidget* _recentlyPlayedContainer; }; } // namespace UserInterface diff --git a/src/ui/explore/Explore.cpp b/src/ui/explore/Explore.cpp index d19a9a2c..1b9f8ce9 100644 --- a/src/ui/explore/Explore.cpp +++ b/src/ui/explore/Explore.cpp @@ -29,26 +29,29 @@ #include "Filters.hpp" #include "ArtistsView.hpp" +#include "ArtistsInfoView.hpp" #include "ArtistView.hpp" #include "ReleasesView.hpp" +#include "ReleasesInfoView.hpp" #include "ReleaseView.hpp" #include "TracksView.hpp" namespace UserInterface { +namespace { -enum IdxRoot +void +handleContentsPathChange(Wt::WStackedWidget* stack) { - IdxArtists = 0, - IdxArtist, - IdxReleases, - IdxRelease, - IdxTracks, -}; + enum Idx + { + IdxArtists = 0, + IdxArtist, + IdxReleases, + IdxRelease, + IdxTracks, + }; -static void -handlePathChange(Wt::WStackedWidget* stack) -{ static const std::map indexes = { { "/artists", IdxArtists }, @@ -70,65 +73,114 @@ handlePathChange(Wt::WStackedWidget* stack) } } +void +handleInfoPathChange(Wt::WStackedWidget* stack) +{ + enum Idx + { + IdxArtists = 0, + IdxReleases, + IdxEmpty, + }; + + static const std::map indexes = + { + { "/artists", IdxArtists }, + { "/artist", IdxArtists }, + { "/releases", IdxReleases }, + { "/release", IdxReleases }, + { "/tracks", IdxEmpty }, + }; + + LMS_LOG(UI, DEBUG) << "Internal path changed to '" << wApp->internalPath() << "'"; + + for (auto index : indexes) + { + if (wApp->internalPathMatches(index.first)) + { + stack->setCurrentIndex(index.second); + return; + } + } +} + +} // namespace + Explore::Explore() : Wt::WTemplate(Wt::WString::tr("Lms.Explore.template")) { + addFunction("tr", &Functions::tr); + _filters = bindNew("filters"); // Contents - Wt::WStackedWidget* stack = bindNew("contents"); + Wt::WStackedWidget* contentsStack = bindNew("contents"); auto artists = std::make_unique(_filters); - auto artists_raw = artists.get(); artists->artistAdd.connect(this, &Explore::handleArtistAdd); artists->artistPlay.connect(this, &Explore::handleArtistPlay); - stack->addWidget(std::move(artists)); + contentsStack->addWidget(std::move(artists)); auto artist = std::make_unique(_filters); artist->artistAdd.connect(this, &Explore::handleArtistAdd); artist->artistPlay.connect(this, &Explore::handleArtistPlay); artist->releaseAdd.connect(this, &Explore::handleReleaseAdd); artist->releasePlay.connect(this, &Explore::handleReleasePlay); - stack->addWidget(std::move(artist)); + contentsStack->addWidget(std::move(artist)); auto releases = std::make_unique(_filters); - auto releases_raw = releases.get(); releases->releaseAdd.connect(this, &Explore::handleReleaseAdd); releases->releasePlay.connect(this, &Explore::handleReleasePlay); - stack->addWidget(std::move(releases)); + contentsStack->addWidget(std::move(releases)); auto release = std::make_unique(_filters); release->releaseAdd.connect(this, &Explore::handleReleaseAdd); release->releasePlay.connect(this, &Explore::handleReleasePlay); release->trackAdd.connect(this, &Explore::handleTrackAdd); release->trackPlay.connect(this, &Explore::handleTrackPlay); - stack->addWidget(std::move(release)); - - _dbChanged.connect([=] - { - artists_raw->refreshRecentlyAdded(); - releases_raw->refreshRecentlyAdded(); - }); - - _trackPlayed.connect([=] - { - artists_raw->refreshMostPlayed(); - releases_raw->refreshMostPlayed(); - }); + contentsStack->addWidget(std::move(release)); auto tracks = std::make_unique(_filters); tracks->trackAdd.connect(this, &Explore::handleTrackAdd); tracks->trackPlay.connect(this, &Explore::handleTrackPlay); tracks->tracksAdd.connect(this, &Explore::handleTracksAdd); tracks->tracksPlay.connect(this, &Explore::handleTracksPlay); - stack->addWidget(std::move(tracks)); + contentsStack->addWidget(std::move(tracks)); + + // Info + Wt::WStackedWidget* infoStack = bindNew("info"); + + auto artistsInfo = std::make_unique(); + auto artistsInfoRaw = artistsInfo.get(); + infoStack->addWidget(std::move(artistsInfo)); + + auto releasesInfo = std::make_unique(); + auto releasesInfoRaw = releasesInfo.get(); + infoStack->addWidget(std::move(releasesInfo)); + + infoStack->addWidget(std::make_unique()); + + _dbChanged.connect([=] + { + artistsInfoRaw->refreshRecentlyAdded(); + releasesInfoRaw->refreshRecentlyAdded(); + }); + + _trackPlayed.connect([=] + { + artistsInfoRaw->refreshMostPlayed(); + releasesInfoRaw->refreshMostPlayed(); + }); + wApp->internalPathChanged().connect(std::bind([=] { - handlePathChange(stack); + handleContentsPathChange(contentsStack); + handleInfoPathChange(infoStack); })); - handlePathChange(stack); + handleContentsPathChange(contentsStack); + handleInfoPathChange(infoStack); } // TODO SQL this? diff --git a/src/ui/explore/Filters.cpp b/src/ui/explore/Filters.cpp index a460c3e9..abbf6626 100644 --- a/src/ui/explore/Filters.cpp +++ b/src/ui/explore/Filters.cpp @@ -142,6 +142,8 @@ Filters::add(Database::IdType clusterId) Filters::Filters() : Wt::WTemplate(Wt::WString::tr("Lms.Explore.template.filters")) { + addFunction("tr", &Functions::tr); + // Filters Wt::WPushButton *addFilterBtn = bindNew("add-filter", Wt::WText::tr("Lms.Explore.add-filter")); addFilterBtn->clicked().connect(this, &Filters::showDialog); diff --git a/src/ui/explore/ReleasesInfoView.cpp b/src/ui/explore/ReleasesInfoView.cpp new file mode 100644 index 00000000..99e85331 --- /dev/null +++ b/src/ui/explore/ReleasesInfoView.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2018 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include "ReleasesInfoView.hpp" + +#include +#include +#include +#include + +#include "database/Release.hpp" +#include "database/TrackList.hpp" + +#include "resource/ImageResource.hpp" + +#include "LmsApplication.hpp" + +using namespace Database; + +namespace { + +using namespace UserInterface; + +void addEntries(Wt::WContainerWidget* container, const std::vector& releases) +{ + for (auto release : releases) + { + Wt::WTemplate* entry = container->addNew(Wt::WString::tr("Lms.Explore.ReleasesInfo.template.entry")); + + entry->bindWidget("release-name", LmsApplication::createReleaseAnchor(release)); + + Wt::WAnchor* anchor = entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false)); + auto cover = std::make_unique(); + cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 128)); + anchor->setImage(std::move(cover)); + + auto artists = release->getArtists(); + if (artists.size() > 1) + { + entry->setCondition("if-has-artist", true); + entry->bindString("artist-name", Wt::WString::tr("Lms.Explore.various-artists")); + } + else if (artists.size() == 1) + { + entry->setCondition("if-has-artist", true); + entry->bindWidget("artist-name", LmsApplication::createArtistAnchor(artists.front())); + } + } +} + +} // namespace + +namespace UserInterface { + +ReleasesInfo::ReleasesInfo() +: Wt::WTemplate(Wt::WString::tr("Lms.Explore.ReleasesInfo.template")) +{ + addFunction("tr", &Wt::WTemplate::Functions::tr); + + _mostPlayedContainer = bindNew("most-played"); + _recentlyAddedContainer = bindNew("recently-added"); + + refreshRecentlyAdded(); + refreshMostPlayed(); +} + +void +ReleasesInfo::refreshRecentlyAdded() +{ + auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1); + + Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); + + auto releases = Release::getLastAdded(LmsApp->getDboSession(), after, 5); + + _recentlyAddedContainer->clear(); + addEntries(_recentlyAddedContainer, releases); +} + +void +ReleasesInfo::refreshMostPlayed() +{ + Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); + + auto releases = LmsApp->getUser()->getPlayedTrackList()->getTopReleases(5); + + _mostPlayedContainer->clear(); + addEntries(_mostPlayedContainer, releases); +} + +} // namespace UserInterface + diff --git a/src/ui/explore/ReleasesInfoView.hpp b/src/ui/explore/ReleasesInfoView.hpp new file mode 100644 index 00000000..fe402421 --- /dev/null +++ b/src/ui/explore/ReleasesInfoView.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#pragma once + +#include +#include + +namespace UserInterface { + +class ReleasesInfo : public Wt::WTemplate +{ + public: + ReleasesInfo(); + + void refreshRecentlyAdded(); + void refreshMostPlayed(); + + private: + Wt::WContainerWidget* _mostPlayedContainer; + Wt::WContainerWidget* _recentlyAddedContainer; +}; + +} // namespace UserInterface + diff --git a/src/ui/explore/ReleasesView.cpp b/src/ui/explore/ReleasesView.cpp index 1dc79f8d..26137186 100644 --- a/src/ui/explore/ReleasesView.cpp +++ b/src/ui/explore/ReleasesView.cpp @@ -18,15 +18,13 @@ */ #include "ReleasesView.hpp" -#include + #include #include -#include #include #include #include "database/Release.hpp" -#include "database/TrackList.hpp" #include "utils/Logger.hpp" #include "utils/Utils.hpp" @@ -38,39 +36,6 @@ using namespace Database; -namespace { - -using namespace UserInterface; - -void addCompactEntries(Wt::WContainerWidget* container, const std::vector& releases) -{ - for (auto release : releases) - { - Wt::WTemplate* entry = container->addNew(Wt::WString::tr("Lms.Explore.Releases.template.compact-entry")); - - entry->bindWidget("release-name", LmsApplication::createReleaseAnchor(release)); - - Wt::WAnchor* anchor = entry->bindWidget("cover", LmsApplication::createReleaseAnchor(release, false)); - auto cover = std::make_unique(); - cover->setImageLink(LmsApp->getImageResource()->getReleaseUrl(release.id(), 128)); - anchor->setImage(std::move(cover)); - - auto artists = release->getArtists(); - if (artists.size() > 1) - { - entry->setCondition("if-has-artist", true); - entry->bindString("artist-name", Wt::WString::tr("Lms.Explore.various-artists")); - } - else if (artists.size() == 1) - { - entry->setCondition("if-has-artist", true); - entry->bindWidget("artist-name", LmsApplication::createArtistAnchor(artists.front())); - } - } -} - -} // namespace - namespace UserInterface { Releases::Releases(Filters* filters) @@ -84,9 +49,6 @@ _filters(filters) _search->textInput().connect(this, &Releases::refresh); _container = bindNew("releases"); - _mostPlayedContainer = bindNew("most-played-releases"); - _recentlyAddedContainer = bindNew("recently-added-releases"); - _recentlyPlayedContainer = bindNew("recently-played-releases"); _showMore = bindNew("show-more", Wt::WString::tr("Lms.Explore.show-more")); _showMore->addFunction("tr", &Wt::WTemplate::Functions::tr); @@ -95,37 +57,11 @@ _filters(filters) addSome(); })); - refreshRecentlyAdded(); - refreshMostPlayed(); refresh(); filters->updated().connect(this, &Releases::refresh); } -void -Releases::refreshRecentlyAdded() -{ - auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1); - - Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); - - auto releases = Release::getLastAdded(LmsApp->getDboSession(), after, 5); - - _recentlyAddedContainer->clear(); - addCompactEntries(_recentlyAddedContainer, releases); -} - -void -Releases::refreshMostPlayed() -{ - Wt::Dbo::Transaction transaction(LmsApp->getDboSession()); - - auto releases = LmsApp->getUser()->getPlayedTrackList()->getTopReleases(5); - - _mostPlayedContainer->clear(); - addCompactEntries(_mostPlayedContainer, releases); -} - void Releases::refresh() { diff --git a/src/ui/explore/ReleasesView.hpp b/src/ui/explore/ReleasesView.hpp index bbf45960..da4cd227 100644 --- a/src/ui/explore/ReleasesView.hpp +++ b/src/ui/explore/ReleasesView.hpp @@ -21,7 +21,6 @@ #include #include -#include #include #include "database/Types.hpp" @@ -38,9 +37,6 @@ class Releases : public Wt::WTemplate Wt::Signal releaseAdd; Wt::Signal releasePlay; - void refreshRecentlyAdded(); - void refreshMostPlayed(); - private: void refresh(); void addSome(); @@ -49,9 +45,6 @@ class Releases : public Wt::WTemplate Wt::WTemplate* _showMore; Wt::WLineEdit* _search; Wt::WContainerWidget* _container; - Wt::WContainerWidget* _mostPlayedContainer; - Wt::WContainerWidget* _recentlyAddedContainer; - Wt::WContainerWidget* _recentlyPlayedContainer; }; } // namespace UserInterface