Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
leeovery committed Feb 8, 2020
1 parent cebf0b7 commit db01fc0
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 82 deletions.
78 changes: 0 additions & 78 deletions resources/views/app/webhooks/edit.blade.php

This file was deleted.

61 changes: 61 additions & 0 deletions resources/views/app/webhooks/events-log.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@extends('mailcoach-api::app.webhooks.layouts.edit', [
'webhook' => $webhook,
'titlePrefix' => 'Events Log'
])

@section('breadcrumbs')
<li>
<a href="{{ route('mailcoach-api.webhooks.event-log', $webhook) }}">
<span class="breadcrumb">{{ $webhook->name }}</span>
</a>
</li>
<li><span class="breadcrumb">Event Log</span></li>
@endsection

@section('webhook')
@if($totalEventLogsCount > 0)
{{-- <div class="table-actions">--}}
{{-- <div class="table-filters">--}}
{{-- <x-search placeholder="Filter opens" />--}}
{{-- </div>--}}
{{-- </div>--}}

<table class="table table-fixed">
<thead>
<tr>
<x-th sort-by="status" class="">On Event</x-th>
<x-th sort-by="email">Url</x-th>
<x-th sort-by="status" class="w-32 th-numeric">Status</x-th>
<x-th sort-by="attempts" class="w-32 th-numeric">Attempts</x-th>
<x-th sort-by="-created_at" sort-default class="w-48 th-numeric hidden | md:table-cell">Created At</x-th>
</tr>
</thead>
<tbody>
@foreach($eventLogs as $eventLog)
<tr>
<td>{{ $eventLog->payload['event'] }}</td>
<td class="markup-links">
<div class="break-words">
{{ $eventLog->url }}
</div>
</td>
<td class="td-numeric">{{ ucfirst($eventLog->status) }}</td>
<td class="td-numeric">{{ $eventLog->attempts }}</td>
<td class="td-numeric hidden | md:table-cell">{{ $eventLog->created_at->toMailcoachFormat() }}</td>
</tr>
@endforeach
</tbody>
</table>

<x-table-status
name="event"
:paginator="$eventLogs"
:total-count="$totalEventLogsCount"
:show-all-url="route('mailcoach-api.webhooks.event-log', $webhook)"
></x-table-status>
@else
<p class="alert alert-info">
No events for this webhook yet.
</p>
@endif
@endsection
13 changes: 12 additions & 1 deletion resources/views/app/webhooks/layouts/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@extends('mailcoach::app.layouts.app', [
'title' => $webhook->name
'title' => (isset($titlePrefix) ? $titlePrefix . ' | ' : '') . $webhook->name
])

@section('header')
Expand All @@ -16,6 +16,17 @@
@endsection

@section('content')
<nav class="tabs">
<ul>
<x-navigation-item :href="route('mailcoach-api.webhooks.edit', $webhook)">
<x-icon-label icon="fa-cog" text="Settings" />
</x-navigation-item>
<x-navigation-item :href="route('mailcoach-api.webhooks.event-log', $webhook)">
<x-icon-label icon="fa-chart-pie" text="Event Log" :count="$webhook->webhookEvents()->count() ?? 0" />
</x-navigation-item>
</ul>
</nav>

<section class="card">
@yield('webhook')
</section>
Expand Down
71 changes: 71 additions & 0 deletions resources/views/app/webhooks/settings.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@extends('mailcoach-api::app.webhooks.layouts.edit', [
'webhook' => $webhook,
'titlePrefix' => 'Settings'
])

@section('breadcrumbs')
<li><span class="breadcrumb">{{ $webhook->name }}</span></li>
<li><span class="breadcrumb">Settings</span></li>
@endsection

@section('webhook')
<form
class="form-grid"
action="{{ route('mailcoach-api.webhooks.edit', [$webhook]) }}"
method="POST"
>
@csrf
@method('PUT')

<x-text-field label="Name" name="name" :value="$webhook->name" type="name" required/>

<x-text-field label="Url" name="url" :value="$webhook->url" type="name" required/>

<hr class="border-t-2 border-gray-200 my-8">

<h2 class="markup-h2">Trigger webhook on these triggers:</h2>

<x-help>
The url you specify above will be hit when the checked event(s) occur.
</x-help>

@error('triggers')
<p class="form-error">{{ $message }}</p>
@enderror

<div class="flex w-full">

<div class="w-1/2 flex flex-col align-start form-row">
<label class="label mb-4">When a message is…</label>
<div class="checkbox-group">
@foreach ($messageTriggers as $trigger)
<x-checkbox-field
:label="$trigger->label"
:name="'triggers['.$trigger->key.']'"
:checked="$webhook->hasTrigger($trigger->key)"
/>
@endforeach
</div>
</div>

<div class="w-1/2 flex flex-col align-start form-row">
<label class="label mb-4">When a subscriber…</label>
<div class="checkbox-group">
@foreach ($subscriberTriggers as $trigger)
<x-checkbox-field
:label="$trigger->label"
:name="'triggers['.$trigger->key.']'"
:checked="$webhook->hasTrigger($trigger->key)"
/>
@endforeach
</div>
</div>
</div>

<div class="form-buttons">
<button type="submit" class="button">
<x-icon-label icon="fas fa-play" text="Save & Activate"/>
</button>
</div>
</form>
@endsection
5 changes: 4 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Leeovery\MailcoachApi\Http\App\Controllers\DestroyWebhookController;
use Leeovery\MailcoachApi\Http\App\Controllers\ActivateWebhookController;
use Leeovery\MailcoachApi\Http\App\Controllers\DeactivateWebhookController;
use Leeovery\MailcoachApi\Http\App\Controllers\Webhooks\WebhookEventLogController;

Route::prefix('api')->group(function () {

Expand All @@ -30,7 +31,9 @@

Route::get('details', ['\\'.EditWebhookController::class, 'edit'])->name('mailcoach-api.webhooks.edit');
Route::put('details', ['\\'.EditWebhookController::class, 'update']);
Route::put('deactivate', '\\'.DeactivateWebhookController::class)->name('mailcoach-api.webhooks.deactivate');
Route::get('event-log', '\\'.WebhookEventLogController::class)->name('mailcoach-api.webhooks.event-log');
Route::put('deactivate', '\\'.DeactivateWebhookController::class)
->name('mailcoach-api.webhooks.deactivate');
Route::put('activate', '\\'.ActivateWebhookController::class)->name('mailcoach-api.webhooks.activate');
Route::delete('/', '\\'.DestroyWebhookController::class)->name('mailcoach-api.webhooks.delete');

Expand Down
2 changes: 1 addition & 1 deletion src/Http/App/Controllers/EditWebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function edit(Webhook $webhook, Triggers $triggers)
{
$viewModel = new WebhookViewModel($webhook, $triggers);

return view('mailcoach-api::app.webhooks.edit', $viewModel);
return view('mailcoach-api::app.webhooks.settings', $viewModel);
}

public function update(Webhook $webhook, UpdateWebhookRequest $request)
Expand Down
20 changes: 20 additions & 0 deletions src/Http/App/Controllers/Webhooks/WebhookEventLogController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Leeovery\MailcoachApi\Http\App\Controllers\Webhooks;

use Leeovery\MailcoachApi\Models\Webhook;
use Leeovery\MailcoachApi\Http\App\Queries\WebhookEventLogQuery;

class WebhookEventLogController
{
public function __invoke(Webhook $webhook)
{
$webhookEventLogQuery = new WebhookEventLogQuery($webhook);

return view('mailcoach-api::app.webhooks.events-log', [
'webhook' => $webhook,
'eventLogs' => $webhookEventLogQuery->paginate(),
'totalEventLogsCount' => $webhook->webhookEvents()->count(),
]);
}
}
22 changes: 22 additions & 0 deletions src/Http/App/Queries/WebhookEventLogQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Leeovery\MailcoachApi\Http\App\Queries;

use Spatie\QueryBuilder\QueryBuilder;
use Leeovery\MailcoachApi\Models\Webhook;

class WebhookEventLogQuery extends QueryBuilder
{
public function __construct(Webhook $webhook)
{
$query = $webhook->webhookEvents()->getQuery();

parent::__construct($query);

$this
->defaultSort('-created_at');
// ->allowedFilters(
// AllowedFilter::custom('search', new FuzzyFilter('name'))
// );
}
}
2 changes: 1 addition & 1 deletion src/Models/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function webhookEvents(): HasMany

public function getTriggerListCountAttribute(): int
{
return count($this->triggers);
return count($this->triggers ?? []);
}

public function hasTrigger($trigger)
Expand Down

0 comments on commit db01fc0

Please sign in to comment.