Skip to content

Commit

Permalink
feat: UI for jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
64knl committed Jan 30, 2024
1 parent 61bc51f commit ff14e3e
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 35 deletions.
4 changes: 3 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Route;
use NotFound\Framework\Auth\Middleware\EnsureEmailIsVerified;
use NotFound\ListBoss\Http\Controllers\ListBossController;
use NotFound\ListBoss\Http\Controllers\RecipientController;

/*
|--------------------------------------------------------------------------
Expand All @@ -24,7 +25,8 @@
'middleware' => 'set-forget-locale',
], function () {
Route::get('', [ListBossController::class, 'index']);
Route::post('details', [ListBossController::class, 'status']);
Route::get('{list}', [ListBossController::class, 'status']);
Route::get('{list}/{recipient}', [RecipientController::class, 'show']);
}
);
});
Expand Down
5 changes: 5 additions & 0 deletions src/Helpers/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function start(array $list)
return $this->call(method: 'POST', endPoint: $this->id.'/start', params: $parameters, updateSelf: true);
}

public function result(): object
{
return $this->call(endPoint: $this->id.'/result', updateSelf: true);
}

public function status(): ?JobStatus
{
$status = $this->call(endPoint: $this->id.'/status', updateSelf: true);
Expand Down
5 changes: 5 additions & 0 deletions src/Helpers/ListBoss.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public function list(): array

return $jobs;
}

public function recipient(int $list, int $recipient): object
{
return $this->call(method: 'GET', endPoint: $list.'/recipient/'.$recipient);
}
}
72 changes: 38 additions & 34 deletions src/Http/Controllers/ListBossController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,61 @@

use NotFound\Framework\Http\Controllers\Controller;
use NotFound\Framework\Http\Requests\FormDataRequest;
use NotFound\Layout\Elements\LayoutButton;
use NotFound\Layout\Elements\LayoutForm;
use NotFound\Layout\Elements\LayoutText;
use NotFound\Layout\Elements\Table\LayoutTable;
use NotFound\Layout\Elements\Table\LayoutTableColumn;
use NotFound\Layout\Elements\Table\LayoutTableHeader;
use NotFound\Layout\Elements\Table\LayoutTableRow;
use NotFound\Layout\Helpers\LayoutWidgetHelper;
use NotFound\Layout\Inputs\LayoutInputDropdown;
use NotFound\ListBoss\Helpers\Job;
use NotFound\ListBoss\Helpers\ListBoss;

class ListBossController extends Controller
{
public function index()
{
if( !config('listboss.backend'))
{
if (! config('listboss.backend')) {
abort(404);
}

$widget = new LayoutWidgetHelper('Mailings', 'Resultaten van verzendingen inzien');
$widget->addBreadcrumb('Verzendingen');

$widget->widget->addForm($this->selectJob());
$widget = new LayoutWidgetHelper('E-mails', 'Verzendingen');
$widget->widget->addTable($this->selectJob());

return $widget->response();
}

public function status(FormDataRequest $request)
public function status(FormDataRequest $request, int $list)
{
if( !config('listboss.backend'))
{
if (! config('listboss.backend')) {
abort(404);
}

$request->validate([
'list' => 'required|integer',
]);
$job = new Job($request->get('list'));
$job = new Job($list);

$widget = new LayoutWidgetHelper('Verzending', $job->subject() ?? 'Verzending');
$widget->addBreadcrumb('Mailings', '/app/listboss/');
$widget->addBreadcrumb('Resultaten van verzendingen inzien', '/app/listboss/');
$widget = new LayoutWidgetHelper('E-mails', 'Status');
$widget->addBreadcrumb('Verzendingen', '/app/listboss/');
$widget->widget->addText(new LayoutText('Status: '.$job->status()->getReadableName()));

$widget->widget->addText($this->statusText($job->statusInfo()));
$widget->widget->addForm($this->selectJob());

$table = new LayoutTable(sort: false, delete: false, create: false);

$table->addHeader(new LayoutTableHeader('E-mailadres', 'email'));
$table->addHeader(new LayoutTableHeader('Ontvangen', 'received'));
$table->addHeader(new LayoutTableHeader('Geklikt', 'clicks'));
$table->addHeader(new LayoutTableHeader('Geopend', 'opens'));

$rowId = 1;
foreach ($job->result()->results as $result) {
$row = new LayoutTableRow($rowId++, '/app/listboss/'.$job->id().'/'.$result->id);
$row->addColumn(new LayoutTableColumn($result->email));
$row->addColumn(new LayoutTableColumn(\Sb::formatDate($result->delivered_at)));
$row->addColumn(new LayoutTableColumn($result->clicks));
$row->addColumn(new LayoutTableColumn($result->opens));
$table->addRow($row);
}

$widget->widget->addTable($table);

return $widget->response();
}
Expand All @@ -61,26 +72,19 @@ private function statusText(object $statusInfo): LayoutText
return new LayoutText($text);
}

private function selectJob(): LayoutForm
private function selectJob(): LayoutTable
{
$listBoss = new ListBoss();
$jobs = $listBoss->list();

$form = new LayoutForm('app/listboss/details');

$dropDown = new LayoutInputDropdown('list', 'Kies een mailing');
$dropDown->setRequired();

$table = new LayoutTable(delete: false, create: false, edit: true, sort: false);
$table->addHeader(new LayoutTableHeader('Onderwerp', 'email'));
foreach ($jobs as $job) {
if ($job->started()) {
$dropDown->addOption($job->id(), $job->subject());
}
$row = new LayoutTableRow($job->id(), '/app/listboss/'.$job->id().'/');
$row->addColumn(new LayoutTableColumn($job->subject()));
$table->addRow($row);
}

$form->addInput($dropDown);

$form->addButton(new LayoutButton('Bekijk resultaten', 'submit', 'primary'));

return $form;
return $table;
}
}
68 changes: 68 additions & 0 deletions src/Http/Controllers/RecipientController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace NotFound\ListBoss\Http\Controllers;

use NotFound\Framework\Http\Controllers\Controller;
use NotFound\Framework\Http\Requests\FormDataRequest;
use NotFound\Layout\Elements\Table\LayoutTable;
use NotFound\Layout\Elements\Table\LayoutTableColumn;
use NotFound\Layout\Elements\Table\LayoutTableHeader;
use NotFound\Layout\Elements\Table\LayoutTableRow;
use NotFound\Layout\Helpers\LayoutWidgetHelper;
use NotFound\ListBoss\Helpers\ListBoss;

class RecipientController extends Controller
{
public function show(FormDataRequest $request, int $list, int $recipient)
{
if (! config('listboss.backend')) {
abort(404);
}

$listBoss = new ListBoss();
$recipient = $listBoss->recipient($list, $recipient);

$table = new LayoutTable(sort: false, delete: false, create: false, edit: false);

$table->addHeader(new LayoutTableHeader('Eigenschap', 'key'));
$table->addHeader(new LayoutTableHeader('Waarde', 'value'));

$table->addRow($this->addRow(1, ['E-mailadres', $recipient->email]));
$table->addRow($this->addRow(2, ['Ontvangen', $recipient->delivered]));
$table->addRow($this->addRow(3, ['Aantal keer geklikt', $recipient->clicks]));
$table->addRow($this->addRow(4, ['Aantal keer geopend', $recipient->opens]));

$widget = new LayoutWidgetHelper('E-mails', 'Status');
$widget->addBreadcrumb('Verzendingen', '/app/listboss/');
$widget->widget->addTable($table);

$table = new LayoutTable(sort: false, delete: false, create: false, edit: false);

$table->addHeader(new LayoutTableHeader('Status', 'status'));
$table->addHeader(new LayoutTableHeader('Tijdstijd', 'timestamp'));
$table->addHeader(new LayoutTableHeader('Details', 'payload'));

$rowId = 1;
foreach ($recipient->events as $event) {
$row = new LayoutTableRow($rowId++);
$row->addColumn(new LayoutTableColumn($event->type));
$row->addColumn(new LayoutTableColumn(\Sb::formatDate($event->timestamp)));
$row->addColumn(new LayoutTableColumn($event->payload ?? ''));
$table->addRow($row);
}

$widget->widget->addTable($table);

return $widget->response();
}

private function addRow($id, array $values): LayoutTableRow
{
$row = new LayoutTableRow($id);
foreach ($values as $value) {
$row->addColumn(new LayoutTableColumn($value));
}

return $row;
}
}

0 comments on commit ff14e3e

Please sign in to comment.