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.

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