mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 14:12:44 +01:00
Merge pull request #10154 from beganovich/1630-webhooks
Websockets: New notifications
This commit is contained in:
commit
d6d9d7d4c2
@ -11,17 +11,21 @@
|
||||
|
||||
namespace App\Events\Credit;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Utils\Traits\Invoice\Broadcasting\DefaultResourceBroadcast;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CreditWasCreated
|
||||
class CreditWasCreated implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
use DefaultResourceBroadcast;
|
||||
|
||||
public $credit;
|
||||
|
||||
@ -41,5 +45,12 @@ class CreditWasCreated
|
||||
$this->credit = $credit;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
|
||||
$this->dontBroadcastToCurrentUser();
|
||||
}
|
||||
|
||||
public function broadcastModel(): BaseModel
|
||||
{
|
||||
return $this->credit;
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,21 @@
|
||||
|
||||
namespace App\Events\Credit;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Utils\Traits\Invoice\Broadcasting\DefaultResourceBroadcast;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class CreditWasUpdated
|
||||
class CreditWasUpdated implements ShouldBroadcast
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
use DefaultResourceBroadcast;
|
||||
|
||||
public $credit;
|
||||
|
||||
@ -41,5 +45,12 @@ class CreditWasUpdated
|
||||
$this->credit = $credit;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
|
||||
$this->dontBroadcastToCurrentUser();
|
||||
}
|
||||
|
||||
public function broadcastModel(): BaseModel
|
||||
{
|
||||
return $this->credit;
|
||||
}
|
||||
}
|
||||
|
@ -12,10 +12,11 @@
|
||||
|
||||
namespace App\Events\Invoice;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Company;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Traits\Invoice\Broadcasting\DefaultInvoiceBroadcast;
|
||||
use App\Utils\Traits\Invoice\Broadcasting\DefaultResourceBroadcast;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
@ -25,7 +26,7 @@ use Illuminate\Queue\SerializesModels;
|
||||
*/
|
||||
class InvoiceWasPaid implements ShouldBroadcast
|
||||
{
|
||||
use SerializesModels, DefaultInvoiceBroadcast, InteractsWithSockets;
|
||||
use SerializesModels, DefaultResourceBroadcast, InteractsWithSockets;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
@ -39,4 +40,9 @@ class InvoiceWasPaid implements ShouldBroadcast
|
||||
{
|
||||
$this->dontBroadcastToCurrentUser();
|
||||
}
|
||||
|
||||
public function broadcastModel(): BaseModel
|
||||
{
|
||||
return $this->invoice;
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,23 @@
|
||||
|
||||
namespace App\Events\Invoice;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Company;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Utils\Traits\Invoice\Broadcasting\DefaultResourceBroadcast;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use League\Fractal\Manager;
|
||||
|
||||
/**
|
||||
* Class InvoiceWasViewed.
|
||||
*/
|
||||
class InvoiceWasViewed
|
||||
class InvoiceWasViewed implements ShouldBroadcast
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
use InteractsWithSockets;
|
||||
use DefaultResourceBroadcast;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
@ -32,5 +38,18 @@ class InvoiceWasViewed
|
||||
*/
|
||||
public function __construct(public InvoiceInvitation $invitation, public Company $company, public array $event_vars)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function broadcastModel(): BaseModel
|
||||
{
|
||||
return $this->invitation->invoice;
|
||||
}
|
||||
|
||||
public function broadcastManager(Manager $manager): Manager
|
||||
{
|
||||
$manager->parseIncludes('client');
|
||||
|
||||
return $manager;
|
||||
}
|
||||
}
|
||||
|
@ -11,16 +11,20 @@
|
||||
|
||||
namespace App\Events\Payment;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Models\Company;
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Traits\Invoice\Broadcasting\DefaultResourceBroadcast;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PaymentWasUpdated.
|
||||
*/
|
||||
class PaymentWasUpdated
|
||||
class PaymentWasUpdated implements ShouldBroadcast
|
||||
{
|
||||
use SerializesModels;
|
||||
use SerializesModels, InteractsWithSockets, DefaultResourceBroadcast;
|
||||
|
||||
/**
|
||||
* @var Payment
|
||||
@ -43,5 +47,12 @@ class PaymentWasUpdated
|
||||
$this->payment = $payment;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
|
||||
$this->dontBroadcastToCurrentUser();
|
||||
}
|
||||
|
||||
public function broadcastModel(): BaseModel
|
||||
{
|
||||
return $this->payment;
|
||||
}
|
||||
}
|
||||
|
@ -12,12 +12,13 @@
|
||||
|
||||
namespace App\Utils\Traits\Invoice\Broadcasting;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
use App\Transformers\ArraySerializer;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use League\Fractal\Manager;
|
||||
use League\Fractal\Resource\Item;
|
||||
|
||||
trait DefaultInvoiceBroadcast
|
||||
trait DefaultResourceBroadcast
|
||||
{
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
@ -26,17 +27,40 @@ trait DefaultInvoiceBroadcast
|
||||
];
|
||||
}
|
||||
|
||||
public function broadcastModel(): BaseModel
|
||||
{
|
||||
throw new \LogicException('Make sure to pass a model to the broadcastModel method.');
|
||||
}
|
||||
|
||||
public function broadcastManager(Manager $manager): Manager
|
||||
{
|
||||
return $manager;
|
||||
}
|
||||
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$entity = $this->broadcastModel();
|
||||
|
||||
$manager = new Manager();
|
||||
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->invoice));
|
||||
|
||||
$class = sprintf('App\\Transformers\\%sTransformer', class_basename($entity));
|
||||
|
||||
$transformer = new $class();
|
||||
|
||||
$resource = new Item($this->invoice, $transformer, $this->invoice->getEntityType());
|
||||
$resource = new Item($entity, $transformer, $entity->getEntityType());
|
||||
|
||||
$manager = $this->broadcastManager($manager);
|
||||
|
||||
$data = $manager->createData($resource)->toArray();
|
||||
|
||||
return [...$data, 'x-socket-id' => $this->socket];
|
||||
$data = [...$data];
|
||||
|
||||
if (\property_exists($this, 'socket')) {
|
||||
$data['x-socket-id'] = $this->socket;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -5361,6 +5361,10 @@ $lang = array(
|
||||
'small_company_info' => 'No disclosure of sales tax in accordance with § 19 UStG',
|
||||
'log_duration_words' => 'Time log duration in words',
|
||||
'log_duration' => 'Time log duration',
|
||||
'payment_status_changed' => 'Please note that the status of your payment has been updated. We recommend refreshing the page to view the most current version.',
|
||||
'credit_status_changed' => 'Please note that the status of your credit has been updated. We recommend refreshing the page to view the most current version.',
|
||||
'credit_updated' => 'Credit Updated',
|
||||
'payment_updated' => 'Payment Updated',
|
||||
'search_placeholder' => 'Find invoices, clients, and more',
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user