Commit 161e408a authored by Kevin Whitaker's avatar Kevin Whitaker

Implement vote sending to backend. Have trackdetails spit out a msotly...

Implement vote sending to backend. Have trackdetails spit out a msotly complete audiotrack for voting. Fix voting to actually modify list. Fix js code to not break on songs with apostrophes.
parent 1b82d58c
......@@ -374,11 +374,14 @@ void GroovePlayerMgr::grooveEventLoop()
voteTransaction.commit();
//Add vote to vote status
for(std::pair<AudioTrack, int> voteItem: currentVoteStatus)
for(auto voteItem = currentVoteStatus.begin(); voteItem != currentVoteStatus.end(); voteItem++)
{
if(voteItem.first.trackFingerprint == event.tracksInvolved.front().trackFingerprint)
if(voteItem->first.trackFingerprint == event.tracksInvolved.front().trackFingerprint)
{
++(voteItem.second);
std::pair<AudioTrack,int> newItem = (*voteItem);
newItem.second = ++(newItem.second);
currentVoteStatus.insert(currentVoteStatus.erase(voteItem),newItem);
break;
}
}
......
......@@ -112,5 +112,5 @@ void WebInterface::voteTracksUpdatedFromServer(std::list<AudioTrack> voteableTra
std::string WebInterface::getNotificationJs(std::string notificationText)
{
return std::string("function notifyMe(a,b){var c='")+notificationText+std::string("';if('Notification'in window)if('granted'===Notification.permission){new Notification(c)}else'denied'!==Notification.permission&&Notification.requestPermission(function(a){if('granted'===a){new Notification(c)}});else;}");
return std::string("function notifyMe(a,b){var c=\"")+notificationText+std::string("\";if('Notification'in window)if('granted'===Notification.permission){new Notification(c)}else'denied'!==Notification.permission&&Notification.requestPermission(function(a){if('granted'===a){new Notification(c)}});else;}");
}
......@@ -105,7 +105,9 @@ PlayerInterface::PlayerInterface(WebInterface* app)
track3vote->setText("&#61770;");
track3->addWidget(track3details,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
track3->addWidget(track3vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
//TODO: implement voting actions
track1vote->clicked().connect(this, &PlayerInterface::vote1clicked);
track2vote->clicked().connect(this, &PlayerInterface::vote2clicked);
track3vote->clicked().connect(this, &PlayerInterface::vote3clicked);
interfaceLayout->addWidget(playControlWidget);
interfaceLayout->addWidget(currentTrackProgress);
......@@ -155,6 +157,30 @@ void PlayerInterface::skipDenyClicked()
}
}
void PlayerInterface::vote1clicked()
{
track1vote->setEnabled(false);
track2vote->setEnabled(false);
track3vote->setEnabled(false);
GroovePlayerMgr::getInstance()->lastInternalEvents.push_back(GroovePlayerMgr::PlayerEvent() = {GroovePlayerMgr::PlayerEventType::VOTE_CAST, app->currentUser, std::list<AudioTrack>{track1details->extractTrackFromDetails()}});
}
void PlayerInterface::vote2clicked()
{
track1vote->setEnabled(false);
track2vote->setEnabled(false);
track3vote->setEnabled(false);
GroovePlayerMgr::getInstance()->lastInternalEvents.push_back(GroovePlayerMgr::PlayerEvent() = {GroovePlayerMgr::PlayerEventType::VOTE_CAST, app->currentUser, std::list<AudioTrack>{track2details->extractTrackFromDetails()}});
}
void PlayerInterface::vote3clicked()
{
track1vote->setEnabled(false);
track2vote->setEnabled(false);
track3vote->setEnabled(false);
GroovePlayerMgr::getInstance()->lastInternalEvents.push_back(GroovePlayerMgr::PlayerEvent() = {GroovePlayerMgr::PlayerEventType::VOTE_CAST, app->currentUser, std::list<AudioTrack>{track3details->extractTrackFromDetails()}});
}
void PlayerInterface::updateSkipRequestedFromServer()
{
skipRequest->setHidden(true);
......
......@@ -74,6 +74,9 @@ public:
void playpauseUpdated();
void skipRequestClicked();
void skipDenyClicked();
void vote1clicked();
void vote2clicked();
void vote3clicked();
void updateDetailsFromServer(AudioTrack track);
void updateVoteableTracksFromServer(std::list<AudioTrack> tracks);
void updateProgressFromTimer();
......
......@@ -59,6 +59,8 @@ void TrackDetails::updateWithTrackDetails(AudioTrack track)
trackTitle->setText(track.trackName);
trackArtist->setText(track.trackArtistName);
trackAlbum->setText(track.trackAlbumName);
trackFingerprint = track.trackFingerprint;
trackGenre = track.trackGenre;
//Set image to data from track obj.
coverData = new Wt::WMemoryResource(track.coverMimeType);
......@@ -80,3 +82,14 @@ bool TrackDetails::trackMatches(AudioTrack track)
}
return false;
}
AudioTrack TrackDetails::extractTrackFromDetails()
{
AudioTrack track;
track.trackName = trackTitle->text().toUTF8();
track.trackArtistName = trackArtist->text().toUTF8();
track.trackAlbumName = trackAlbum->text().toUTF8();
track.trackGenre = trackGenre;
track.trackFingerprint = trackFingerprint;
return track;
}
......@@ -41,9 +41,13 @@ public:
Wt::WText* trackArtist;
Wt::WText* trackAlbum;
std::string trackFingerprint;
std::string trackGenre;
void updateWithTrackDetails(AudioTrack track);
void changeBackgroundColor(Wt::WColor color);
bool trackMatches(AudioTrack track);
AudioTrack extractTrackFromDetails();
};
#endif // TRACKDETAILS_H
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