You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.0 KiB

  1. <template>
  2. <div class="container">
  3. <div class="row">
  4. <div class="col-xs-4 col-md-4">
  5. <div class="panel panel-default">
  6. <div class="panel-heading">Queue</div>
  7. <div class="panel-body tweet-queue">
  8. <div v-for="(tweet, index) in queue" v-on:click="clickedTweet(index)" class="tweet">
  9. <div class="mission">{{ tweet.mission }}</div>
  10. <div class="profile">
  11. <img :src="tweet.player_photo" :style="'border-color: #'+tweet.team_color">
  12. <span>@{{ tweet.player_username }}</span>
  13. </div>
  14. <div class="text">{{ tweet.text }}</div>
  15. </div>
  16. </div>
  17. </div>
  18. </div>
  19. <div class="col-xs-8 col-md-8">
  20. <scorecard :show.sync="show" :tweet="tweet" v-on:dismiss="dismissTweet"></scorecard>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. module.exports = {
  27. data () {
  28. return {
  29. queue: [],
  30. tweet: {},
  31. show: false
  32. }
  33. },
  34. methods: {
  35. loadQueue () {
  36. $.get('/dashboard/queue', function(tweets){
  37. for(var i in tweets.queue) {
  38. this.queue.push(tweets.queue[i]);
  39. }
  40. // Listen for new items on the queue
  41. Echo.channel('tweet-queue')
  42. .listen('NewTweetEvent', (e) => {
  43. if(this.findTweetInQueue(e.tweet_id) === false) {
  44. this.queue.push(e);
  45. }
  46. })
  47. .listen('TweetClaimedEvent', (e) => {
  48. this.removeTweetFromQueue(e.tweet_id);
  49. });
  50. }.bind(this));
  51. },
  52. findTweetInQueue(tweet_id) {
  53. var queueIndex = false;
  54. for(var i in this.queue) {
  55. if(parseInt(this.queue[i].tweet_id) == parseInt(tweet_id)) {
  56. queueIndex = i;
  57. }
  58. }
  59. return queueIndex;
  60. },
  61. removeTweetFromQueue(tweet_id) {
  62. var queueIndex = this.findTweetInQueue(tweet_id);
  63. if(queueIndex !== false) {
  64. var removed = this.queue.splice(queueIndex, 1);
  65. return removed[0];
  66. }
  67. },
  68. clickedTweet(tweet_index) {
  69. // var tweet_data = this.removeTweetFromQueue(tweet_id);
  70. var tweet_data = this.queue[tweet_index];
  71. var tweet_id = tweet_data.tweet_id;
  72. if(tweet_data) {
  73. // Mark this as claimed
  74. $.post('/dashboard/claim-tweet', {
  75. tweet_id: tweet_id
  76. }, function(response) {
  77. });
  78. this.removeTweetFromQueue(tweet_id);
  79. // Load in the scorecard viewer
  80. this.tweet = tweet_data;
  81. this.show = true;
  82. } else {
  83. console.log("Tweet not found: "+tweet_id);
  84. }
  85. },
  86. dismissTweet() {
  87. this.queue.push(this.tweet);
  88. // Mark as un-claimed
  89. $.post('/dashboard/claim-tweet', {
  90. tweet_id: this.tweet.tweet_id,
  91. status: 'unclaimed'
  92. }, function(response){
  93. });
  94. this.tweet = {};
  95. this.show = false;
  96. }
  97. },
  98. created() {
  99. this.loadQueue();
  100. }
  101. }
  102. </script>