Browse Source

simple tweet viewer for teams and missions

master
Aaron Parecki 7 years ago
parent
commit
dbcab8ffe3
No known key found for this signature in database GPG Key ID: 276C2817346D6056
16 changed files with 246 additions and 5 deletions
  1. +2
    -0
      app/Http/Controllers/DashboardController.php
  2. +35
    -0
      app/Http/Controllers/ShowTweetsController.php
  3. +1
    -0
      app/Http/Controllers/TeamController.php
  4. +4
    -0
      app/Mission.php
  5. +5
    -1
      app/Team.php
  6. +20
    -1
      app/Tweet.php
  7. +32
    -0
      database/migrations/2017_07_04_200516_team_slug.php
  8. +32
    -0
      database/migrations/2017_07_04_201225_mission_slug.php
  9. +32
    -0
      database/migrations/2017_07_04_201516_explicit_mark_accepted.php
  10. +1
    -1
      database/seeds/MissionSeeder.php
  11. +13
    -0
      public/css/app.css
  12. +14
    -0
      resources/assets/sass/app.scss
  13. +23
    -0
      resources/views/components/tweet.blade.php
  14. +15
    -0
      resources/views/mission-tweets.blade.php
  15. +2
    -2
      resources/views/scoreboard.blade.php
  16. +15
    -0
      resources/views/team-tweets.blade.php

+ 2
- 0
app/Http/Controllers/DashboardController.php View File

@ -69,6 +69,7 @@ class DashboardController extends Controller
$tweet = Tweet::where('id', $request->input('tweet_id'))->first();
if($tweet) {
$tweet->processed = 1;
$tweet->accepted = 0;
$tweet->m1_transit_line_id = null;
$tweet->m1_non_trimet = null;
$tweet->m2_transit_center_id = null;
@ -104,6 +105,7 @@ class DashboardController extends Controller
$tweet->{$k} = $v;
}
$tweet->processed = 1;
$tweet->accepted = 1;
$tweet->save();
event(new TweetAcceptedEvent($tweet, $previousMissionStatus));
}

+ 35
- 0
app/Http/Controllers/ShowTweetsController.php View File

@ -0,0 +1,35 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Tweet, App\Team, App\Mission;
class ShowTweetsController extends Controller
{
public function mission(Mission $mission) {
$tweets = Tweet::where('mission_id', $mission->id)
->where('processed', 1)
->where('accepted', 1)
->orderBy('tweet_date', 'desc')->get();
return view('mission-tweets', [
'mission' => $mission,
'tweets' => $tweets
]);
}
public function team(Team $team) {
$tweets = Tweet::where('team_id', $team->id)
->where('processed', 1)
->where('accepted', 1)
->orderBy('tweet_date', 'desc')->get();
return view('team-tweets', [
'team' => $team,
'tweets' => $tweets
]);
}
}

+ 1
- 0
app/Http/Controllers/TeamController.php View File

@ -75,6 +75,7 @@ class TeamController extends Controller
$team = new \App\Team;
$team->name = $next;
$team->slug = strtolower($next);
$team->color = $colors[$next];
$team->save();

+ 4
- 0
app/Mission.php View File

@ -10,6 +10,10 @@ class Mission extends Model
'hashtag',
];
public function getRouteKeyName() {
return 'slug';
}
public function tweets() {
return $this->hasMany('App\Tweet');
}

+ 5
- 1
app/Team.php View File

@ -7,9 +7,13 @@ use Illuminate\Database\Eloquent\Model;
class Team extends Model
{
protected $fillable = [
'name', 'color'
'name', 'slug', 'color'
];
public function getRouteKeyName() {
return 'slug';
}
public function players() {
return $this->hasMany('App\Player');
}

+ 20
- 1
app/Tweet.php View File

@ -4,6 +4,7 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Events\NewTweetEvent;
use DB;
use DateTime, DateTimeZone;
class Tweet extends Model
{
@ -39,9 +40,27 @@ class Tweet extends Model
return $this->belongsTo('\App\Document', 'm7_document_id');
}
public function photos() {
if($this->photo) {
return json_decode($this->photo);
} else {
return [];
}
}
public function localtime() {
$date = new DateTime($this->tweet_date);
$date->setTimeZone(new DateTimeZone('US/Pacific')); // TODO: put in config or somewhere
return $date;
}
public function twitter_permalink() {
return 'https://twitter.com/'.$this->player->twitter.'/status/'.$this->tweet_id;
}
public static function claimed_timeout() {
// time out tweets if they aren't processed after the specified time
$timeout = 520;
$timeout = 300;
$tweets = Tweet::where('claimed_at', '<', date('Y-m-d H:i:s', time()-$timeout))->where('processed', 0)->get();
foreach($tweets as $tweet) {
$tweet->claimed_at = null;

+ 32
- 0
database/migrations/2017_07_04_200516_team_slug.php View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class TeamSlug extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('teams', function (Blueprint $table) {
$table->string('slug', 255);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('teams', function (Blueprint $table) {
$table->dropColumn('slug');
});
}
}

+ 32
- 0
database/migrations/2017_07_04_201225_mission_slug.php View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class MissionSlug extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('missions', function (Blueprint $table) {
$table->string('slug', 255);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('missions', function (Blueprint $table) {
$table->dropColumn('slug');
});
}
}

+ 32
- 0
database/migrations/2017_07_04_201516_explicit_mark_accepted.php View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ExplicitMarkAccepted extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('tweets', function (Blueprint $table) {
$table->boolean('accepted')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tweets', function (Blueprint $table) {
$table->dropColumn('accepted');
});
}
}

+ 1
- 1
database/seeds/MissionSeeder.php View File

@ -21,6 +21,6 @@ class MissionSeeder extends Seeder
'#document',
];
foreach($missions as $i=>$m)
DB::table('missions')->insert(['id' => $i+1, 'hashtag' => $m]);
DB::table('missions')->insert(['id' => $i+1, 'hashtag' => $m, 'slug' => trim($m, '#')]);
}
}

+ 13
- 0
public/css/app.css View File

@ -8753,3 +8753,16 @@ button.close {
display: inline-block;
}
.tweet {
border: 1px #d3e0e9 solid;
border-radius: 4px;
padding: 6px;
margin-bottom: 6px;
}
.tweet .text {
white-space: pre-wrap;
font-size: 1.5em;
margin: 8px 0;
}

+ 14
- 0
resources/assets/sass/app.scss View File

@ -252,3 +252,17 @@
}
.tweet {
border: 1px $laravel-border-color solid;
border-radius: 4px;
padding: 6px;
margin-bottom: 6px;
.text {
white-space: pre-wrap;
font-size: 1.5em;
margin: 8px 0;
}
}

+ 23
- 0
resources/views/components/tweet.blade.php View File

@ -0,0 +1,23 @@
<div class="tweet">
<div class="profile">
<img src="{{ $tweet->player->photo }}" style="border-color: {{ '#'.$tweet->team->color }}">
<span><a href="'https://twitter.com/'+tweet.player_username">{{ '@'.$tweet->player->twitter }}</a></span>
</div>
<div class="text">{!! Twitter::linkify($tweet->text) !!}</div>
@if($tweet->photos())
<div class="multi-photo photos-{{ count($tweet->photos()) }}">
@foreach($tweet->photos() as $photo)
<div class="photo" style="background-image:url({{ $photo }})" data-featherlight="{{ $photo }}">
<img src="{{ $photo }}">
</div>
@endforeach
</div>
<div class="multi-photo-clear"></div>
@endif
<a href="{{ $tweet->twitter_permalink() }}">{{ $tweet->localtime()->format('F j, g:ia') }}</a>
</div>

+ 15
- 0
resources/views/mission-tweets.blade.php View File

@ -0,0 +1,15 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h2>{{ $mission->hashtag }}</h2>
@each('components.tweet', $tweets, 'tweet')
</div>
</div>
</div>
@endsection

+ 2
- 2
resources/views/scoreboard.blade.php View File

@ -12,7 +12,7 @@
@foreach($missions as $mission)
<th class="score">
<h3>{{ $mission->id }}</h3>
{{ $mission->hashtag }}
<a href="{{ route('mission', $mission) }}">{{ $mission->hashtag }}</a>
</th>
@endforeach
<th class="score">Score</th>
@ -24,7 +24,7 @@
<td>
<div class="team">
<span class="team-icon" style="background-color: #{{ $team->color }};"></span>
<span class="team-name">{{ $team->name }}</span>
<span class="team-name"><a href="{{ route('team', $team) }}">{{ $team->name }}</a></span>
</div>
<div class="players">
@foreach($team->players as $player)

+ 15
- 0
resources/views/team-tweets.blade.php View File

@ -0,0 +1,15 @@
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h2>Team {{ $team->name }}</h2>
@each('components.tweet', $tweets, 'tweet')
</div>
</div>
</div>
@endsection

Loading…
Cancel
Save