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.

120 lines
3.5 KiB

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Twitter;
  5. use App\Tweet;
  6. use App\Events\NewTweetEvent, App\Events\TweetClaimedEvent;
  7. use DB;
  8. class DashboardController extends Controller
  9. {
  10. /**
  11. * Create a new controller instance.
  12. *
  13. * @return void
  14. */
  15. public function __construct()
  16. {
  17. $this->middleware('auth');
  18. }
  19. /**
  20. * Show the application dashboard.
  21. *
  22. * @return \Illuminate\Http\Response
  23. */
  24. public function index()
  25. {
  26. return view('dashboard', [
  27. ]);
  28. }
  29. public function queue() {
  30. Tweet::claimed_timeout();
  31. $tweets = Tweet::queued()->get();
  32. $queue = [];
  33. foreach($tweets as $tweet) {
  34. $queue[] = new NewTweetEvent($tweet);
  35. }
  36. return response()->json(['queue'=>$queue]);
  37. }
  38. public function ping() {
  39. Tweet::claimed_timeout();
  40. return response()->json(['result'=>'ok']);
  41. }
  42. public function claim_tweet(Request $request) {
  43. $tweet = Tweet::where('id', $request->input('tweet_id'))->first();
  44. if($tweet) {
  45. if($request->input('status') == 'unclaimed') {
  46. $tweet->claimed_at = null;
  47. $tweet->save();
  48. event(new NewTweetEvent($tweet));
  49. } else {
  50. $tweet->claimed_at = date('Y-m-d H:i:s');
  51. $tweet->save();
  52. // Broadcast that this tweet was claimed
  53. event(new TweetClaimedEvent($tweet));
  54. }
  55. }
  56. return response()->json(['result'=>'ok']);
  57. }
  58. public function reject_tweet(Request $request) {
  59. $tweet = Tweet::where('id', $request->input('tweet_id'))->first();
  60. if($tweet) {
  61. $tweet->processed = 1;
  62. $tweet->m1_transit_line_id = null;
  63. $tweet->m1_non_trimet = null;
  64. $tweet->m2_transit_center_id = null;
  65. $tweet->m2_with_other_team = 0;
  66. $tweet->m3_complete = null;
  67. $tweet->m4_complete = null;
  68. $tweet->m5_complete = null;
  69. $tweet->m5_tip = null;
  70. $tweet->m6_complete = null;
  71. $tweet->m7_document_id = null;
  72. $tweet->save();
  73. }
  74. return response()->json(['result'=>'ok']);
  75. }
  76. public function score_tweet(Request $request) {
  77. $tweet = Tweet::where('id', $request->input('tweet_id'))->first();
  78. if($tweet) {
  79. $tweet->m1_transit_line_id = null;
  80. $tweet->m1_non_trimet = null;
  81. $tweet->m2_transit_center_id = null;
  82. $tweet->m2_with_other_team = 0;
  83. $tweet->m3_complete = null;
  84. $tweet->m4_complete = null;
  85. $tweet->m5_complete = null;
  86. $tweet->m5_tip = null;
  87. $tweet->m6_complete = null;
  88. $tweet->m7_document_id = null;
  89. foreach($request->input('score_data') as $k=>$v) {
  90. $tweet->{$k} = $v;
  91. }
  92. $tweet->processed = 1;
  93. $tweet->save();
  94. }
  95. return response()->json(['result'=>'ok']);
  96. }
  97. public function load_dropdowns() {
  98. $documents = DB::table('m7_documents')->orderBy('id')->get();
  99. $transit_centers = DB::table('transit_centers')->orderBy('name')->get();
  100. $transit_lines = DB::table('transit_lines')->orderBy('sort')->get();
  101. return response()->json([
  102. 'documents' => $documents,
  103. 'transit_centers' => $transit_centers,
  104. 'transit_lines' => $transit_lines
  105. ]);
  106. }
  107. }