Have backend also keep track of users who voted on a track to prevent duplicate voting. Add vote count next to vote button. Make sure these details are correct, event on refresh.
This commit is contained in:
@@ -251,6 +251,7 @@ void GroovePlayerMgr::grooveEventLoop()
|
|||||||
//Pick new batch of tracks to vote on and inform UI of update.
|
//Pick new batch of tracks to vote on and inform UI of update.
|
||||||
currentVoteBatch = getNextVoteBatch(&sqlSession);
|
currentVoteBatch = getNextVoteBatch(&sqlSession);
|
||||||
currentVoteStatus = std::list<std::pair<AudioTrack, int>>();
|
currentVoteStatus = std::list<std::pair<AudioTrack, int>>();
|
||||||
|
currentUsersVoted.clear();
|
||||||
for(auto track : currentVoteBatch)
|
for(auto track : currentVoteBatch)
|
||||||
{
|
{
|
||||||
currentVoteStatus.push_back(std::pair<AudioTrack, int>(track,0));
|
currentVoteStatus.push_back(std::pair<AudioTrack, int>(track,0));
|
||||||
@@ -381,6 +382,7 @@ void GroovePlayerMgr::grooveEventLoop()
|
|||||||
std::pair<AudioTrack,int> newItem = (*voteItem);
|
std::pair<AudioTrack,int> newItem = (*voteItem);
|
||||||
newItem.second = ++(newItem.second);
|
newItem.second = ++(newItem.second);
|
||||||
currentVoteStatus.insert(currentVoteStatus.erase(voteItem),newItem);
|
currentVoteStatus.insert(currentVoteStatus.erase(voteItem),newItem);
|
||||||
|
currentUsersVoted.push_back(event.userInvolved);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
AudioTrack currentTrack;
|
AudioTrack currentTrack;
|
||||||
std::list<AudioTrack> currentVoteBatch;
|
std::list<AudioTrack> currentVoteBatch;
|
||||||
std::list<std::pair<AudioTrack, int>> currentVoteStatus;
|
std::list<std::pair<AudioTrack, int>> currentVoteStatus;
|
||||||
|
std::list<User> currentUsersVoted;
|
||||||
bool voteEndedButNotNextTrackYet = false;
|
bool voteEndedButNotNextTrackYet = false;
|
||||||
std::list<User> currentSkipRequester;
|
std::list<User> currentSkipRequester;
|
||||||
std::chrono::steady_clock::time_point skipRequestedAt;
|
std::chrono::steady_clock::time_point skipRequestedAt;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ void WebInterface::loginCompleted()
|
|||||||
priv_int->playerUI->animateShow(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade, Wt::WAnimation::TimingFunction::EaseIn, 500));
|
priv_int->playerUI->animateShow(Wt::WAnimation(Wt::WAnimation::AnimationEffect::Fade, Wt::WAnimation::TimingFunction::EaseIn, 500));
|
||||||
priv_int->playerUI->updateDetailsFromServer(GroovePlayerMgr::getInstance()->currentTrack);
|
priv_int->playerUI->updateDetailsFromServer(GroovePlayerMgr::getInstance()->currentTrack);
|
||||||
priv_int->playerUI->updateVoteableTracksFromServer(GroovePlayerMgr::getInstance()->currentVoteBatch);
|
priv_int->playerUI->updateVoteableTracksFromServer(GroovePlayerMgr::getInstance()->currentVoteBatch);
|
||||||
|
priv_int->playerUI->updateVoteTrackState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebInterface::playPauseActionFromServer(User userPausing, bool pause)
|
void WebInterface::playPauseActionFromServer(User userPausing, bool pause)
|
||||||
@@ -94,7 +95,7 @@ void WebInterface::skipVoteUpdateFromServer(User userVoting, bool forSkip)
|
|||||||
|
|
||||||
void WebInterface::voteNextSongFromServer(User userVoting, AudioTrack trackVoted)
|
void WebInterface::voteNextSongFromServer(User userVoting, AudioTrack trackVoted)
|
||||||
{
|
{
|
||||||
//priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"nextvote");
|
priv_int->playerUI->updateVoteCount(trackVoted);
|
||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +108,7 @@ void WebInterface::voteNextPollClosedFromServer(AudioTrack winner)
|
|||||||
void WebInterface::voteTracksUpdatedFromServer(std::list<AudioTrack> voteableTracks)
|
void WebInterface::voteTracksUpdatedFromServer(std::list<AudioTrack> voteableTracks)
|
||||||
{
|
{
|
||||||
priv_int->playerUI->updateVoteableTracksFromServer(voteableTracks);
|
priv_int->playerUI->updateVoteableTracksFromServer(voteableTracks);
|
||||||
|
priv_int->playerUI->updateVoteTrackState();
|
||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,8 +83,10 @@ PlayerInterface::PlayerInterface(WebInterface* app)
|
|||||||
track1vote->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
track1vote->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
||||||
track1vote->setMaximumSize(Wt::WLength(50,Wt::WLength::Pixel),Wt::WLength(50,Wt::WLength::Pixel));
|
track1vote->setMaximumSize(Wt::WLength(50,Wt::WLength::Pixel),Wt::WLength(50,Wt::WLength::Pixel));
|
||||||
track1vote->setText("");
|
track1vote->setText("");
|
||||||
track1->addWidget(track1details,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
track1votecount = new Wt::WText("0");
|
||||||
|
track1->addWidget(track1details,1,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
||||||
track1->addWidget(track1vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
|
track1->addWidget(track1vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
|
||||||
|
track1->addWidget(track1votecount,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
||||||
track2 = new Wt::WHBoxLayout();
|
track2 = new Wt::WHBoxLayout();
|
||||||
track2details = new TrackDetails();
|
track2details = new TrackDetails();
|
||||||
track2details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
track2details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
||||||
@@ -93,8 +95,10 @@ PlayerInterface::PlayerInterface(WebInterface* app)
|
|||||||
track2vote->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
track2vote->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
||||||
track2vote->setMaximumSize(Wt::WLength(50,Wt::WLength::Pixel),Wt::WLength(50,Wt::WLength::Pixel));
|
track2vote->setMaximumSize(Wt::WLength(50,Wt::WLength::Pixel),Wt::WLength(50,Wt::WLength::Pixel));
|
||||||
track2vote->setText("");
|
track2vote->setText("");
|
||||||
track2->addWidget(track2details,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
track2votecount = new Wt::WText("0");
|
||||||
|
track2->addWidget(track2details,1,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
||||||
track2->addWidget(track2vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
|
track2->addWidget(track2vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
|
||||||
|
track2->addWidget(track2votecount,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
||||||
track3 = new Wt::WHBoxLayout();
|
track3 = new Wt::WHBoxLayout();
|
||||||
track3details = new TrackDetails();
|
track3details = new TrackDetails();
|
||||||
track3details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
track3details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
||||||
@@ -103,8 +107,10 @@ PlayerInterface::PlayerInterface(WebInterface* app)
|
|||||||
track3vote->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
track3vote->decorationStyle().font().setFamily(Wt::WFont::Default,"FontAwesome");
|
||||||
track3vote->setMaximumSize(Wt::WLength(50,Wt::WLength::Pixel),Wt::WLength(50,Wt::WLength::Pixel));
|
track3vote->setMaximumSize(Wt::WLength(50,Wt::WLength::Pixel),Wt::WLength(50,Wt::WLength::Pixel));
|
||||||
track3vote->setText("");
|
track3vote->setText("");
|
||||||
track3->addWidget(track3details,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
track3votecount = new Wt::WText("0");
|
||||||
|
track3->addWidget(track3details,1,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
||||||
track3->addWidget(track3vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
|
track3->addWidget(track3vote,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignRight);
|
||||||
|
track3->addWidget(track3votecount,0,Wt::AlignmentFlag::AlignMiddle | Wt::AlignmentFlag::AlignLeft);
|
||||||
track1vote->clicked().connect(this, &PlayerInterface::vote1clicked);
|
track1vote->clicked().connect(this, &PlayerInterface::vote1clicked);
|
||||||
track2vote->clicked().connect(this, &PlayerInterface::vote2clicked);
|
track2vote->clicked().connect(this, &PlayerInterface::vote2clicked);
|
||||||
track3vote->clicked().connect(this, &PlayerInterface::vote3clicked);
|
track3vote->clicked().connect(this, &PlayerInterface::vote3clicked);
|
||||||
@@ -205,6 +211,14 @@ void PlayerInterface::updateVotingEnded(AudioTrack winner)
|
|||||||
else if(track3details->trackMatches(winner)) track3details->changeBackgroundColor(Wt::WColor("gold"));
|
else if(track3details->trackMatches(winner)) track3details->changeBackgroundColor(Wt::WColor("gold"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerInterface::updateVoteCount(AudioTrack trackVoted)
|
||||||
|
{
|
||||||
|
//update track vote
|
||||||
|
if(track1details->trackMatches(trackVoted)) track1votecount->setText(std::to_string(std::stoi(track1votecount->text())+1));
|
||||||
|
else if(track2details->trackMatches(trackVoted)) track2votecount->setText(std::to_string(std::stoi(track2votecount->text())+1));
|
||||||
|
else if(track3details->trackMatches(trackVoted)) track3votecount->setText(std::to_string(std::stoi(track3votecount->text())+1));
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerInterface::playpauseUpdated()
|
void PlayerInterface::playpauseUpdated()
|
||||||
{
|
{
|
||||||
if(isPaused)
|
if(isPaused)
|
||||||
@@ -274,3 +288,24 @@ void PlayerInterface::updateVoteableTracksFromServer(std::list<AudioTrack> track
|
|||||||
track2details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
track2details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
||||||
track3details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
track3details->changeBackgroundColor(Wt::WColor("gainsboro"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerInterface::updateVoteTrackState()
|
||||||
|
{
|
||||||
|
//Update vote counts of tracks
|
||||||
|
auto trackIter = GroovePlayerMgr::getInstance()->currentVoteStatus.begin();
|
||||||
|
track1votecount->setText(std::to_string(trackIter->second));
|
||||||
|
++trackIter;
|
||||||
|
track2votecount->setText(std::to_string(trackIter->second));
|
||||||
|
++trackIter;
|
||||||
|
track3votecount->setText(std::to_string(trackIter->second));
|
||||||
|
//Make sure vote buttons are disabled if this user already voted
|
||||||
|
for(User user : GroovePlayerMgr::getInstance()->currentUsersVoted)
|
||||||
|
{
|
||||||
|
if(user.username == app->currentUser.username)
|
||||||
|
{
|
||||||
|
track1vote->setEnabled(false);
|
||||||
|
track2vote->setEnabled(false);
|
||||||
|
track3vote->setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -62,10 +62,13 @@ public:
|
|||||||
Wt::WHBoxLayout* track3;
|
Wt::WHBoxLayout* track3;
|
||||||
TrackDetails* track1details;
|
TrackDetails* track1details;
|
||||||
Wt::WPushButton* track1vote;
|
Wt::WPushButton* track1vote;
|
||||||
|
Wt::WText* track1votecount;
|
||||||
TrackDetails* track2details;
|
TrackDetails* track2details;
|
||||||
Wt::WPushButton* track2vote;
|
Wt::WPushButton* track2vote;
|
||||||
|
Wt::WText* track2votecount;
|
||||||
TrackDetails* track3details;
|
TrackDetails* track3details;
|
||||||
Wt::WPushButton* track3vote;
|
Wt::WPushButton* track3vote;
|
||||||
|
Wt::WText* track3votecount;
|
||||||
|
|
||||||
bool isPaused = false;
|
bool isPaused = false;
|
||||||
//TODO:put in controls for requesting/admin skip and adding users as admin.
|
//TODO:put in controls for requesting/admin skip and adding users as admin.
|
||||||
@@ -79,10 +82,12 @@ public:
|
|||||||
void vote3clicked();
|
void vote3clicked();
|
||||||
void updateDetailsFromServer(AudioTrack track);
|
void updateDetailsFromServer(AudioTrack track);
|
||||||
void updateVoteableTracksFromServer(std::list<AudioTrack> tracks);
|
void updateVoteableTracksFromServer(std::list<AudioTrack> tracks);
|
||||||
|
void updateVoteTrackState();
|
||||||
void updateProgressFromTimer();
|
void updateProgressFromTimer();
|
||||||
void updateSkipRequestedFromServer();
|
void updateSkipRequestedFromServer();
|
||||||
void updateSkipDeniedFromServer();
|
void updateSkipDeniedFromServer();
|
||||||
void updateVotingEnded(AudioTrack winner);
|
void updateVotingEnded(AudioTrack winner);
|
||||||
|
void updateVoteCount(AudioTrack trackVoted);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLAYERINTERFACE_H
|
#endif // PLAYERINTERFACE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user