Commit e5b86cc4 authored by Kevin Whitaker's avatar Kevin Whitaker

Make sure admin can remove tracks from the collection.

parent 4f2a0c5d
......@@ -662,6 +662,23 @@ void GroovePlayerMgr::removeOrphanedTracks(Wt::Dbo::Session* session)
transaction.commit();
}
void GroovePlayerMgr::removeTrack(Wt::Dbo::Session* session, AudioTrack track)
{
Wt::Dbo::Transaction transaction(*session);
Wt::Dbo::ptr<AudioTrack> DBtrack = session->find<AudioTrack>().where("fingerprint = ?").bind(track.trackFingerprint);
Wt::log("info") << (*DBtrack).trackPath + " being removed.";
if(std::filesystem::exists(std::filesystem::path((*DBtrack).trackPath)))
{
remove((*DBtrack).trackPath.c_str());
}
DBtrack.remove();
transaction.commit();
}
void GroovePlayerMgr::getPictureFromTrack(AudioTrack* trackToFill)
{
if(trackToFill->trackPath != "")
......
......@@ -71,6 +71,7 @@ public:
Wt::Dbo::FixedSqlConnectionPool* connectionPool;
void getPictureFromTrack(AudioTrack* trackToFill);
void removeTrack(Wt::Dbo::Session* session, AudioTrack track);
private:
GroovePlayerMgr (std::string dbFile);
~GroovePlayerMgr();
......
......@@ -62,6 +62,20 @@ void RequestInterface::trackRequestClicked(AudioTrack track)
}
}
void RequestInterface::trackRemoveClicked(RequestItem* item, AudioTrack track)
{
if(GroovePlayerMgr::getInstance()->currentTrack.trackFingerprint != track.trackFingerprint)
{
Wt::Dbo::Session sqlSession;
sqlSession.setConnectionPool(*GroovePlayerMgr::getInstance()->connectionPool);
sqlSession.mapClass<User>("user");
sqlSession.mapClass<AudioTrack>("tracks");
sqlSession.mapClass<UserAction>("actions");
GroovePlayerMgr::getInstance()->removeTrack(&sqlSession,track);
delete item;
}
}
void RequestInterface::updateRequestButtonState()
{
if(getRequestCountForUser(app->currentUser) < 3)
......
......@@ -41,25 +41,39 @@ public:
TrackDetails* track;
Wt::WHBoxLayout* layout;
Wt::WPushButton* voteBtn;
Wt::WPushButton* removeBtn;
RequestInterface* parent;
void requestClicked() {
this->parent->trackRequestClicked(track->extractTrackFromDetails());
};
void removeClicked() {
this->parent->trackRemoveClicked(this, track->extractTrackFromDetails());
};
RequestItem(RequestInterface* parent, AudioTrack track) {
this->track = new TrackDetails();
this->track->updateWithTrackDetails(track);
this->track->changeBackgroundColor(Wt::WColor("gainsboro"));
layout = new Wt::WHBoxLayout();
voteBtn = new Wt::WPushButton();
removeBtn = new Wt::WPushButton();
this->parent = parent;
this->setLayout(layout);
voteBtn->setTextFormat(Wt::XHTMLText);
voteBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
voteBtn->setText("&#61525;");
removeBtn->setTextFormat(Wt::XHTMLText);
removeBtn->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
removeBtn->setText("&#61527;");
if(!parent->app->currentUser.isAdmin)
{
removeBtn->setHidden(true);
}
layout->addWidget(this->track,1,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
layout->addWidget(voteBtn,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
layout->addWidget(removeBtn,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
voteBtn->clicked().connect(this, &RequestItem::requestClicked);
removeBtn->clicked().connect(this, &RequestItem::removeClicked);
};
~RequestItem(){
this->clear();
......@@ -76,6 +90,7 @@ public:
std::list<RequestItem*> foundItems;
void trackRequestClicked(AudioTrack track);
void trackRemoveClicked(RequestItem* item,AudioTrack track);
void searchClicked();
int getRequestCountForUser(User user);
void updateRequestButtonState();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment