Added Tracks information panel

This commit is contained in:
emeric
2018-09-11 13:09:47 +02:00
parent ff9a5ebec2
commit dcf8e3df42
13 changed files with 209 additions and 11 deletions
+2 -1
View File
@@ -106,8 +106,9 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
messageResourceBundle().use(appRoot() + "releases");
messageResourceBundle().use(appRoot() + "releasesinfo");
messageResourceBundle().use(appRoot() + "settings");
messageResourceBundle().use(appRoot() + "tracks");
messageResourceBundle().use(appRoot() + "templates");
messageResourceBundle().use(appRoot() + "tracks");
messageResourceBundle().use(appRoot() + "tracksinfo");
// Require js here to avoid async problems
requireJQuery("/js/jquery-1.10.2.min.js");
+11 -6
View File
@@ -27,13 +27,14 @@
#include "LmsApplication.hpp"
#include "Filters.hpp"
#include "ArtistsView.hpp"
#include "ArtistsInfoView.hpp"
#include "ArtistsView.hpp"
#include "ArtistView.hpp"
#include "ReleasesView.hpp"
#include "Filters.hpp"
#include "ReleasesInfoView.hpp"
#include "ReleasesView.hpp"
#include "ReleaseView.hpp"
#include "TracksInfoView.hpp"
#include "TracksView.hpp"
namespace UserInterface {
@@ -80,7 +81,7 @@ handleInfoPathChange(Wt::WStackedWidget* stack)
{
IdxArtists = 0,
IdxReleases,
IdxEmpty,
IdxTracks,
};
static const std::map<std::string, int> indexes =
@@ -89,7 +90,7 @@ handleInfoPathChange(Wt::WStackedWidget* stack)
{ "/artist", IdxArtists },
{ "/releases", IdxReleases },
{ "/release", IdxReleases },
{ "/tracks", IdxEmpty },
{ "/tracks", IdxTracks },
};
LMS_LOG(UI, DEBUG) << "Internal path changed to '" << wApp->internalPath() << "'";
@@ -158,18 +159,22 @@ Explore::Explore()
auto releasesInfoRaw = releasesInfo.get();
infoStack->addWidget(std::move(releasesInfo));
infoStack->addWidget(std::make_unique<Wt::WContainerWidget>());
auto tracksInfo = std::make_unique<TracksInfo>();
auto tracksInfoRaw = tracksInfo.get();
infoStack->addWidget(std::move(tracksInfo));
_dbChanged.connect([=]
{
artistsInfoRaw->refreshRecentlyAdded();
releasesInfoRaw->refreshRecentlyAdded();
tracksInfoRaw->refreshRecentlyAdded();
});
_trackPlayed.connect([=]
{
artistsInfoRaw->refreshMostPlayed();
releasesInfoRaw->refreshMostPlayed();
tracksInfoRaw->refreshMostPlayed();
});
+87
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#include "TracksInfoView.hpp"
#include <Wt/WAnchor.h>
#include <Wt/WLocalDateTime.h>
#include "database/Track.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<Track::pointer>& tracks)
{
for (auto track : tracks)
{
Wt::WTemplate* entry = container->addNew<Wt::WTemplate>(Wt::WString::tr("Lms.Explore.TracksInfo.template.entry"));
entry->bindString("name", Wt::WString::fromUTF8(track->getName()), Wt::TextFormat::Plain);
}
}
}
namespace UserInterface {
TracksInfo::TracksInfo()
: Wt::WTemplate(Wt::WString::tr("Lms.Explore.TracksInfo.template"))
{
addFunction("tr", &Wt::WTemplate::Functions::tr);
_mostPlayedContainer = bindNew<Wt::WContainerWidget>("most-played");
_recentlyAddedContainer = bindNew<Wt::WContainerWidget>("recently-added");
refreshMostPlayed();
refreshRecentlyAdded();
}
void
TracksInfo::refreshRecentlyAdded()
{
auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1);
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
auto tracks = Track::getLastAdded(LmsApp->getDboSession(), after, 5);
_recentlyAddedContainer->clear();
addEntries(_recentlyAddedContainer, tracks);
}
void
TracksInfo::refreshMostPlayed()
{
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
auto tracks = LmsApp->getUser()->getPlayedTrackList()->getTopTracks(5);
_mostPlayedContainer->clear();
addEntries(_mostPlayedContainer, tracks);
}
} // namespace UserInterface
+41
View File
@@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Wt/WContainerWidget.h>
#include <Wt/WTemplate.h>
namespace UserInterface {
class TracksInfo : public Wt::WTemplate
{
public:
TracksInfo();
void refreshRecentlyAdded();
void refreshMostPlayed();
private:
Wt::WContainerWidget* _mostPlayedContainer;
Wt::WContainerWidget* _recentlyAddedContainer;
};
} // namespace UserInterface