Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #62 from pingthepeople/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Austin Lord authored Dec 30, 2017
2 parents f4c91e2 + ffbb6ed commit 5708fc6
Show file tree
Hide file tree
Showing 78 changed files with 2,572 additions and 1,563 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": [
["es2015", {
"modules": false
}]
],
"plugins": ["transform-object-rest-spread"]
}
14 changes: 2 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,7 @@ REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

# to support login via facebook
FACEBOOK_CLIENT_ID=
FACEBOOK_CLIENT_SECRET=
FACEBOOK_CALLBACK=
FACEBOOK_CALLBACK=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
/node_modules
/public/storage
/public/hot
Expand All @@ -11,4 +12,4 @@ Homestead.yaml
/public/css/*
/public/js/*
/public/mix-manifest.json
.vscode/settings.json
.vscode/settings.json
72 changes: 63 additions & 9 deletions app/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,55 @@ class Bill extends Model
public $timestamps = false;

/**
* properties that can be assigned via ->update(), etc.
* @var array
*/
protected $fillable = [
'Name','Link','Title', 'Description','Authors', 'Chamber', 'ActionType'
'Name',
'Link',
'Title',
'Description',
'Chamber',
'ActionType'
];

/**
* Properties appended to the serialized model
* @var array
*/
protected $appends = [
'id',
'Chamber',
'Name',
'IgaSiteLink'
'DisplayName',
'IgaSiteLink',
"authorIds",
"coauthorIds",
"sponsorIds",
"cosponsorIds"
];

/**
* The relations to eager load on every query.
* @var array
*/
protected $with = [
"subjects",
"committees"
"committees",
"session",
"authors",
"coauthors",
"sponsors",
"cosponsors"
];

/**
* hide some relations from serialization
*/
protected $hidden = [
"authors",
"coauthors",
"sponsors",
"cosponsors"
];

/**
Expand All @@ -57,8 +84,6 @@ class Bill extends Model
protected static function boot()
{
parent::boot();

//static::addGlobalScope(new CurrentSessionScope);
}

/**
Expand Down Expand Up @@ -86,7 +111,7 @@ public function subjects() {
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function session() {
return $this->belongsTo(Session::class);
return $this->belongsTo(Session::class, 'SessionId', 'Id');
}

/**
Expand Down Expand Up @@ -118,7 +143,7 @@ public function getChamberAttribute() {
return $types[$this->attributes['Chamber']];
}

public function getNameAttribute() {
public function getDisplayNameAttribute() {
// names are stored without a space after their SB/HB prefix, and with leading zeroes on bill numbers
// e.g. SB0025, HB0189

Expand All @@ -132,7 +157,7 @@ public function getNameAttribute() {

// wow this is complicated
public function getIgaSiteLinkAttribute() {
$year = $this->session()->first() ? $this->session()->first()->Name : date('Y');
$year = $this->session ? $this->session->Name : date('Y');
$legislationType = 'bills';
$chamber = 'lobby';
// use title to determine bill/resolution type
Expand Down Expand Up @@ -185,4 +210,33 @@ public function toRowArray() {
$subjects
];
}

/*
* Authors, Coauthors, etc.
*/
public function authors() {
return $this->belongsToMany(Legislator::class, 'LegislatorBill', 'BillId', 'LegislatorId')->wherePivot('Position', '=', 1);
}
public function coauthors() {
return $this->belongsToMany(Legislator::class, 'LegislatorBill', 'BillId', 'LegislatorId')->wherePivot('Position', '=', 2);
}
public function sponsors() {
return $this->belongsToMany(Legislator::class, 'LegislatorBill', 'BillId', 'LegislatorId')->wherePivot('Position', '=', 3);
}
public function cosponsors() {
return $this->belongsToMany(Legislator::class, 'LegislatorBill', 'BillId', 'LegislatorId')->wherePivot('Position', '=', 4);
}

public function getAuthorIdsAttribute() {
return $this->authors->map(function($x){ return $x->Id; });
}
public function getCoauthorIdsAttribute() {
return $this->coauthors->map(function($x){ return $x->Id; });
}
public function getSponsorIdsAttribute() {
return $this->sponsors->map(function($x){ return $x->Id; });
}
public function getCosponsorIdsAttribute() {
return $this->cosponsors->map(function($x){ return $x->Id; });
}
}
19 changes: 15 additions & 4 deletions app/Committee.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,26 @@ class Committee extends Model
* @var array
*/
protected $fillable = [
'Name','Link', 'Chamber'
'Name',
'Link',
'Chamber'
];

/**
* @var array
*/
protected $appends = ['id', 'Chamber', 'IgaSiteLink'];
protected $appends = [
'id',
'Chamber',
'IgaSiteLink',
];

/**
*
*/
protected static function boot()
{
parent::boot();

//static::addGlobalScope(new CurrentSessionScope);
}

/**
Expand All @@ -61,6 +65,13 @@ public function session() {
return $this->belongsTo(Session::class);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function members() {
return $this->belongsToMany(Legislator::class, 'LegislatorCommittee', 'CommitteeId', 'LegislatorId');
}

/**
* @return mixed
*/
Expand Down
16 changes: 10 additions & 6 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ public function __construct(Container $container)
{
parent::__construct($container);

$this->_telemetryClient = new \ApplicationInsights\Telemetry_Client();
// there's probably a better way to get the instrumentation key than calling out to the environment.'
$instrumentationKey = env('APPINSIGHTS_INSTRUMENTATIONKEY');
$this->_telemetryClient->getContext()->setInstrumentationKey($instrumentationKey);
if(env('DISABLE_APPINSIGHTS', false)!==true) {
$this->_telemetryClient = new \ApplicationInsights\Telemetry_Client();
// there's probably a better way to get the instrumentation key than calling out to the environment.'
$instrumentationKey = env('APPINSIGHTS_INSTRUMENTATIONKEY');
$this->_telemetryClient->getContext()->setInstrumentationKey($instrumentationKey);
}
}

/**
Expand All @@ -44,8 +46,10 @@ public function __construct(Container $container)
*/
public function report(Exception $exception)
{
$this->_telemetryClient->trackException($exception);
$this->_telemetryClient->flush();
if(env('DISABLE_APPINSIGHTS', false)!==true) {
$this->_telemetryClient->trackException($exception);
$this->_telemetryClient->flush();
}

parent::report($exception);
}
Expand Down
68 changes: 18 additions & 50 deletions app/Http/Controllers/BillApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Http\Controllers;

use App\Bill;
use App\Session;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Carbon\Carbon;

/**
* Class BillApiController
Expand All @@ -20,60 +22,26 @@ public function __construct()
}
}

/**
* @param Request $request
* @return \Illuminate\Database\Eloquent\Collection|static[]
*/
public function all(Request $request)
{
if(Cache::has('bills')) {
public function all(Request $request) {
if(Cache::has('bills') && Cache::has('bills__etag')) {
$bills = json_decode(Cache::get('bills'));
$etag = Cache::get('bills__etag');
} else {
$bills = Bill::all();
Cache::put('bills', $bills->toJson(), 600);
}

return response()->json([
'bills' => $bills,
'user' => Auth::user()
]);
}

public function initialChunk() {
if(Cache::has('bills--initial')) {
$bills = json_decode(Cache::get('bills--initial'));
} else {
$bills = Bill::take(10)->get();
Cache::put('bills--initial', $bills->toJson(), 600);
}

return response()->json([
'bills' => $bills,
'user' => Auth::user()
]);
}

public function remainingChunk() {
if(Cache::has('bills--remaining')) {
$bills = json_decode(Cache::get('bills--remaining'));
} else {
$bills = Bill::skip(10)->take(5000)->get();
Cache::put('bills--remaining', $bills->toJson(), 600);
if($request->method() == 'HEAD') {
$bills = [];
$etag = 'expired';
} else {
$session = Session::current();
$bills = $session->bills->sortBy('Name')->values()->all();
$billsJson = json_encode($bills);
$etag = md5($billsJson);
Cache::forever('bills', $billsJson);
Cache::forever('bills__etag', $etag);
}
}

return response()->json([
'bills' => $bills,
]);
}

/**
* @return mixed
*/
public function mine() {
$user = Auth::user();
return response()->json([
'bills' => $user->bills,
'user' => $user
]);
'bills' => $bills
])->setEtag($etag);
}
}
Loading

0 comments on commit 5708fc6

Please sign in to comment.