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.

79 lines
2.0 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 load_dropdowns() {
  59. $documents = DB::table('m7_documents')->orderBy('id')->get();
  60. $transit_centers = DB::table('transit_centers')->orderBy('name')->get();
  61. $transit_lines = DB::table('transit_lines')->orderBy('sort')->get();
  62. return response()->json([
  63. 'documents' => $documents,
  64. 'transit_centers' => $transit_centers,
  65. 'transit_lines' => $transit_lines
  66. ]);
  67. }
  68. }