Added a play history view

This commit is contained in:
emeric
2018-08-03 15:30:38 +02:00
parent ea9ff83355
commit 500fa104c3
9 changed files with 187 additions and 10 deletions
+1
View File
@@ -31,6 +31,7 @@ lms_approot_DATA = \
approot/login.xml \
approot/mediaplayer.xml \
approot/messages.xml \
approot/playhistory.xml \
approot/playqueue.xml \
approot/release.xml \
approot/releases.xml \
+6 -2
View File
@@ -64,8 +64,8 @@
<!--Explore-->
<message id="Lms.Explore.add-filter">Add filter</message>
<message id="Lms.Explore.artists">Artists</message>
<message id="Lms.Explore.most-played-artists">Most played artists</message>
<message id="Lms.Explore.most-played-releases">Most played albums</message>
<message id="Lms.Explore.most-played-artists">Top artists</message>
<message id="Lms.Explore.most-played-releases">Top albums</message>
<message id="Lms.Explore.recently-added-artists">Recently added artists</message>
<message id="Lms.Explore.recently-added-releases">Recently added albums</message>
<message id="Lms.Explore.recently-played-artists">Recently played artists</message>
@@ -85,6 +85,10 @@
<message id="Lms.PlayQueue.playqueue">Play Queue</message>
<message id="Lms.PlayQueue.radio-mode">Radio mode</message>
<!--PlayHistory-->
<message id="Lms.PlayHistory.playhistory">Play History</message>
<!--Settings-->
<message id="Lms.Settings.account">Account</message>
<message id="Lms.Settings.audio">Audio</message>
+1
View File
@@ -23,6 +23,7 @@ lms_SOURCES = \
$(srcdir)/ui/LmsApplicationGroup.cpp \
$(srcdir)/ui/MediaPlayer.cpp \
$(srcdir)/ui/PlayQueueView.cpp \
$(srcdir)/ui/PlayHistoryView.cpp \
$(srcdir)/ui/SettingsView.cpp \
$(srcdir)/ui/admin/DatabaseSettingsView.cpp \
$(srcdir)/ui/admin/InitWizardView.cpp \
+16
View File
@@ -102,6 +102,22 @@ TrackList::getEntries(int offset, int size) const
return std::vector<Wt::Dbo::ptr<TrackListEntry>>(entries.begin(), entries.end());
}
std::vector<Wt::Dbo::ptr<TrackListEntry>>
TrackList::getEntriesReverse(int offset, int size) const
{
assert(session());
assert(IdIsValid(self()->id()));
Wt::Dbo::collection<Wt::Dbo::ptr<TrackListEntry>> entries =
session()->find<TrackListEntry>()
.where("tracklist_id = ?").bind(self().id())
.orderBy("id DESC")
.limit(size)
.offset(offset);
return std::vector<Wt::Dbo::ptr<TrackListEntry>>(entries.begin(), entries.end());
}
Wt::Dbo::ptr<TrackListEntry>
TrackList::getEntry(std::size_t pos) const
{
+1
View File
@@ -67,6 +67,7 @@ class TrackList : public Wt::Dbo::Dbo<TrackList>
std::size_t getCount() const;
Wt::Dbo::ptr<TrackListEntry> getEntry(std::size_t pos) const;
std::vector<Wt::Dbo::ptr<TrackListEntry>> getEntries(int offset = -1, int size = -1) const;
std::vector<Wt::Dbo::ptr<TrackListEntry>> getEntriesReverse(int offset = -1, int size = -1) const;
std::vector<IdType> getTrackIds() const;
+11 -6
View File
@@ -36,6 +36,7 @@
#include "explore/Explore.hpp"
#include "MediaPlayer.hpp"
#include "PlayHistoryView.hpp"
#include "PlayQueueView.hpp"
#include "SettingsView.hpp"
@@ -99,6 +100,7 @@ LmsApplication::LmsApplication(const Wt::WEnvironment& env, Wt::Dbo::SqlConnecti
messageResourceBundle().use(appRoot() + "mediaplayer");
messageResourceBundle().use(appRoot() + "messages");
messageResourceBundle().use(appRoot() + "playqueue");
messageResourceBundle().use(appRoot() + "playhistory");
messageResourceBundle().use(appRoot() + "release");
messageResourceBundle().use(appRoot() + "releases");
messageResourceBundle().use(appRoot() + "settings");
@@ -209,6 +211,7 @@ enum IdxRoot
{
IdxExplore = 0,
IdxPlayQueue,
IdxPlayHistory,
IdxSettings,
IdxAdminDatabase,
IdxAdminUsers,
@@ -231,6 +234,7 @@ handlePathChange(Wt::WStackedWidget* stack, bool isAdmin)
{ "/release", IdxExplore, false },
{ "/tracks", IdxExplore, false },
{ "/playqueue", IdxPlayQueue, false },
{ "/playhistory", IdxPlayHistory, false },
{ "/settings", IdxSettings, false },
{ "/admin/database", IdxAdminDatabase, true },
{ "/admin/users", IdxAdminUsers, true },
@@ -339,6 +343,11 @@ LmsApplication::createHome()
menuItem->setLink(Wt::WLink(Wt::LinkType::InternalPath, "/playqueue"));
menuItem->setSelectable(false);
}
{
auto menuItem = menu->insertItem(4, Wt::WString::tr("Lms.PlayHistory.playhistory"));
menuItem->setLink(Wt::WLink(Wt::LinkType::InternalPath, "/playhistory"));
menuItem->setSelectable(false);
}
Wt::WMenu* rightMenu = navbar->addMenu(std::make_unique<Wt::WMenu>(), Wt::AlignmentFlag::Right);
std::size_t itemCounter = 0;
@@ -380,6 +389,7 @@ LmsApplication::createHome()
Explore* explore = mainStack->addNew<Explore>();
PlayQueue* playqueue = mainStack->addNew<PlayQueue>();
PlayHistory* playhistory = mainStack->addNew<PlayHistory>();
mainStack->addNew<SettingsView>();
// Admin stuff
@@ -419,12 +429,7 @@ LmsApplication::createHome()
});
// Events from the PlayQueue
playqueue->playTrack.connect([=](Database::IdType trackId)
{
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
LmsApp->getUser()->getPlayedTrackList().modify()->add(trackId);
});
playqueue->playTrack.connect(playhistory, &PlayHistory::addTrack);
playqueue->playTrack.connect(explore, &Explore::handleTrackPlayed);
playqueue->playTrack.connect(player, &MediaPlayer::playTrack);
+106
View File
@@ -0,0 +1,106 @@
/*
* 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 "PlayHistoryView.hpp"
#include <Wt/WAnchor.h>
#include <Wt/WText.h>
#include "utils/Logger.hpp"
#include "database/Track.hpp"
#include "database/TrackList.hpp"
#include "LmsApplication.hpp"
namespace {
using namespace UserInterface;
std::unique_ptr<Wt::WTemplate> createEntry(Database::Track::pointer track)
{
auto entry = std::make_unique<Wt::WTemplate>(Wt::WString::tr("Lms.PlayHistory.template.entry"));
entry->bindString("name", Wt::WString::fromUTF8(track->getName()), Wt::TextFormat::Plain);
auto artist = track->getArtist();
if (artist)
{
entry->setCondition("if-has-artist", true);
entry->bindWidget("artist-name", LmsApplication::createArtistAnchor(track->getArtist()));
}
auto release = track->getRelease();
if (release)
{
entry->setCondition("if-has-release", true);
entry->bindWidget("release-name", LmsApplication::createReleaseAnchor(track->getRelease()));
}
return entry;
}
}
namespace UserInterface {
PlayHistory::PlayHistory()
: Wt::WTemplate(Wt::WString::tr("Lms.PlayHistory.template"))
{
addFunction("tr", &Wt::WTemplate::Functions::tr);
_entriesContainer = bindNew<Wt::WContainerWidget>("entries");
// TODO move "Lms.Explore.show-more"
_showMore = bindNew<Wt::WTemplate>("show-more", Wt::WString::tr("Lms.Explore.show-more"));
_showMore->addFunction("tr", &Wt::WTemplate::Functions::tr);
_showMore->setHidden(true);
_showMore->clicked().connect([=]
{
addSome();
});
addSome();
}
void
PlayHistory::addTrack(Database::IdType trackId)
{
Wt::Dbo::Transaction transaction (LmsApp->getDboSession());
auto trackEntry = LmsApp->getUser()->getPlayedTrackList().modify()->add(trackId);
_entriesContainer->insertWidget(0, createEntry(trackEntry->getTrack()));
}
void
PlayHistory::addSome()
{
Wt::Dbo::Transaction transaction (LmsApp->getDboSession());
auto trackList = LmsApp->getUser()->getPlayedTrackList();
auto trackEntries = trackList->getEntriesReverse(_entriesContainer->count(), 50);
for (auto trackEntry : trackEntries)
_entriesContainer->addWidget(createEntry(trackEntry->getTrack()));
_showMore->setHidden(static_cast<std::size_t>(_entriesContainer->count()) >= trackList->getCount());
}
} // namespace UserInterface
+45
View File
@@ -0,0 +1,45 @@
/*
* 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>
#include "database/Types.hpp"
namespace UserInterface {
class PlayHistory : public Wt::WTemplate
{
public:
PlayHistory();
void addTrack(Database::IdType trackId);
private:
void addSome();
Wt::WContainerWidget* _entriesContainer;
Wt::WTemplate* _showMore;
};
} // namespace UserInterface
-2
View File
@@ -22,8 +22,6 @@
#include <random>
#include <Wt/WAnchor.h>
#include <Wt/WImage.h>
#include <Wt/WLocalDateTime.h>
#include <Wt/WText.h>
#include "utils/Logger.hpp"