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.

127 lines
3.5 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. // If the new tweet is one that timed out, dismiss it
  46. if(this.show && this.tweet.tweet_id == e.tweet_id) {
  47. this.tweet = {};
  48. this.show = false;
  49. }
  50. }
  51. })
  52. .listen('TweetClaimedEvent', (e) => {
  53. this.removeTweetFromQueue(e.tweet_id);
  54. });
  55. }.bind(this));
  56. },
  57. dashboardPing() {
  58. setTimeout(function(){
  59. $.get('/dashboard/ping', function(){
  60. this.dashboardPing();
  61. }.bind(this));
  62. }.bind(this), 15000);
  63. },
  64. findTweetInQueue(tweet_id) {
  65. var queueIndex = false;
  66. for(var i in this.queue) {
  67. if(parseInt(this.queue[i].tweet_id) == parseInt(tweet_id)) {
  68. queueIndex = i;
  69. }
  70. }
  71. return queueIndex;
  72. },
  73. removeTweetFromQueue(tweet_id) {
  74. var queueIndex = this.findTweetInQueue(tweet_id);
  75. if(queueIndex !== false) {
  76. var removed = this.queue.splice(queueIndex, 1);
  77. return removed[0];
  78. }
  79. },
  80. clickedTweet(tweet_index) {
  81. // If another tweet was already open, dismiss that first
  82. if(this.show) {
  83. this.dismissTweet();
  84. }
  85. var tweet_data = this.queue[tweet_index];
  86. var tweet_id = tweet_data.tweet_id;
  87. if(tweet_data) {
  88. // Mark this as claimed
  89. $.post('/dashboard/claim-tweet', {
  90. tweet_id: tweet_id
  91. }, function(response) {
  92. });
  93. this.removeTweetFromQueue(tweet_id);
  94. // Load in the scorecard viewer
  95. this.tweet = tweet_data;
  96. this.show = true;
  97. } else {
  98. console.log("Tweet not found: "+tweet_id);
  99. }
  100. },
  101. dismissTweet() {
  102. this.queue.push(this.tweet);
  103. // Mark as un-claimed
  104. $.post('/dashboard/claim-tweet', {
  105. tweet_id: this.tweet.tweet_id,
  106. status: 'unclaimed'
  107. }, function(response){
  108. });
  109. this.tweet = {};
  110. this.show = false;
  111. }
  112. },
  113. created() {
  114. this.loadQueue();
  115. this.dashboardPing();
  116. }
  117. }
  118. </script>