Display what subscriptions (if any) a subscriber has

This commit is contained in:
James Brooks
2016-02-09 19:09:30 +00:00
committed by Graham Campbell
parent c9f08a3e6e
commit 0b78332a20
4 changed files with 53 additions and 27 deletions

View File

@@ -48,6 +48,13 @@ class Subscriber extends Model implements HasPresenter
'email' => 'required|email',
];
/**
* The relations to eager load on every query.
*
* @var string[]
*/
protected $with = ['subscriptions'];
/**
* Overrides the models boot method.
*/

View File

@@ -14,6 +14,7 @@ namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Dates\DateFactory;
use CachetHQ\Cachet\Presenters\Traits\TimestampsTrait;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\Config;
use McCool\LaravelAutoPresenter\BasePresenter;
class SubscriberPresenter extends BasePresenter implements Arrayable
@@ -30,6 +31,16 @@ class SubscriberPresenter extends BasePresenter implements Arrayable
return app(DateFactory::class)->make($this->wrappedObject->verified_at)->toDateTimeString();
}
/**
* Present formatted subscribed date.
*
* @return string
*/
public function subscribed_at()
{
return ucfirst(app(DateFactory::class)->make($this->wrappedObject->subscribed_at)->format(Config::get('setting.incident_date_format', 'l jS F Y H:i:s')));
}
/**
* Convert the presenter instance to an array.
*

View File

@@ -140,11 +140,13 @@ return [
],
// Subscribers
'subscribers' => [
'subscribers' => 'Subscribers',
'description' => 'Subscribers will receive email updates when incidents are created.',
'verified' => 'Verified',
'not_verified' => 'Not verified',
'add' => [
'subscribers' => 'Subscribers',
'description' => 'Subscribers will receive email updates when incidents are created.',
'verified' => 'Verified',
'not_verified' => 'Not verified',
'subscriber' => ':email, subscribed :date',
'no_subscriptions' => 'Subscribed to all updates',
'add' => [
'title' => 'Add a new subscriber',
'success' => 'Subscriber has been added!',
'failure' => 'Something went wrong with the component.',

View File

@@ -18,30 +18,36 @@
<div class="content-wrapper header-fixed">
<div class="row">
<div class="col-sm-12">
<p class="lead">{{ trans('dashboard.subscribers.description') }}</p>
<p class="lead">{{ trans('dashboard.subscribers.description') }}</p>
<div class="striped-list">
@foreach($subscribers as $subscriber)
<div class="row striped-list-item">
<div class="col-xs-3">
<p>{{ $subscriber->email }}</p>
<div class="striped-list">
@foreach($subscribers as $subscriber)
<div class="row striped-list-item">
<div class="col-xs-3">
<p>{{ trans('dashboard.subscribers.subscriber', ['email' => $subscriber->email, 'date' => $subscriber->subscribed_at]) }}</p>
</div>
<div class="col-xs-3">
@if(is_null($subscriber->getOriginal('verified_at')))
<b class="text-danger">{{ trans('dashboard.subscribers.not_verified') }}</b>
@else
<b class="text-success">{{ trans('dashboard.subscribers.verified') }}</b>
@endif
</div>
<div class="col-xs-3">
@if($subscriber->subscriptions->count() > 0)
{!! $subscriber->subscriptions->map(function ($subscription) {
return '<span class="label label-primary">'.$subscription->component->name.'</span>';
})->implode(' ') !!}
@else
<p>{{ trans('dashboard.subscribers.no_subscriptions') }}</p>
@endif
</div>
<div class="col-xs-3 text-right">
<a href="/dashboard/subscribers/{{ $subscriber->id }}/delete" class="btn btn-danger confirm-action" data-method='DELETE'>{{ trans('forms.delete') }}</a>
</div>
</div>
@endforeach
</div>
<div class="col-xs-3">
<p>{{ $subscriber->created_at }}</p>
</div>
<div class="col-xs-3">
@if(is_null($subscriber->getOriginal('verified_at')))
<b class="text-danger">{{ trans('dashboard.subscribers.not_verified') }}</b>
@else
<b class="text-success">{{ trans('dashboard.subscribers.verified') }}</b>
@endif
</div>
<div class="col-xs-3 text-right">
<a href="/dashboard/subscribers/{{ $subscriber->id }}/delete" class="btn btn-danger confirm-action" data-method='DELETE'>{{ trans('forms.delete') }}</a>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>