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.

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