Skip to content

Commit

Permalink
Merge branch 'upgrade'
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Resources/EmailTemplateResource.php
  • Loading branch information
cannycookie committed Sep 4, 2023
2 parents 2019706 + b1785da commit 18fe797
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 366 deletions.
6 changes: 3 additions & 3 deletions resources/views/forms/components/iframe.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<iframe
src="{{ $src }}"
style="width: {{ $width }}; height: {{ $height }}"
name="{{ $name }}"
src="{{ $getRecord()->previewUrl }}"
style="width: {{ $width??'700' }}px; height: {{ $height??'500' }}px"
name="{{ $name??'' }}"
>
{{__('vb-email-templates::email-templates.general-labels.browser-not-compatible')}}
</iframe>
26 changes: 16 additions & 10 deletions src/Components/Iframe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ class Iframe extends Component
{
protected string $view = 'vb-email-templates::forms.components.iframe';

public $name;
public $src;
public $height;
public $width;
public string $name;
public string $src;
public string $height;
public string $width;

public function __construct($name, $label = null, $src = null, $height = '800px', $width = '100%')
public function __construct($name, $src = null, $height = '800px', $width = '100%')
{
$this->src = $src;
$this->height = $height;
Expand All @@ -24,13 +24,19 @@ public function __construct($name, $label = null, $src = null, $height = '800px'

protected function setUp(): void
{
$this->afterStateHydrated(function ($record) {
$this->src = route('email-template.preview', $record);
});
parent::setUp();

}

public static function make($name, $label = null, $src = null, $height = '800px', $width = '100%')
// protected function setUp(): void
// {
// $this->afterStateHydrated(function ($record) {
// $this->src = route('email-template.preview', $record);
// });
// }

public static function make($name, $src = null, $height = '800px', $width = '100%')
{
return new static($name, $label, $src, $height, $width);
return new static($name, $src, $height, $width);
}
}
12 changes: 12 additions & 0 deletions src/Contracts/FormHelperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Visualbuilder\EmailTemplates\Contracts;

interface FormHelperInterface
{
public function getLanguageOptions();

public function getTemplateViewOptions();

public function getRecipientOptions();
}
32 changes: 3 additions & 29 deletions src/EmailTemplatesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@
use Visualbuilder\EmailTemplates\Commands\InstallCommand;
use Visualbuilder\EmailTemplates\Commands\PublishEmailTemplateResource;
use Visualbuilder\EmailTemplates\Contracts\CreateMailableInterface;
use Visualbuilder\EmailTemplates\Contracts\FormHelperInterface;
use Visualbuilder\EmailTemplates\Contracts\TokenHelperInterface;
use Visualbuilder\EmailTemplates\Helpers\CreateMailableHelper;
use Visualbuilder\EmailTemplates\Helpers\FormHelper;
use Visualbuilder\EmailTemplates\Helpers\TokenHelper;
use Visualbuilder\EmailTemplates\Http\Controllers\EmailTemplateController;
use Visualbuilder\EmailTemplates\Resources\EmailTemplateResource;

class EmailTemplatesServiceProvider extends PackageServiceProvider
{
// protected array $resources = [
// EmailTemplateResource::class,
// ];

// protected array $styles = [
// 'vb-email-templates-styles' => 'https://cdn.jsdelivr.net/gh/lipis/flag-icons@6.6.6/css/flag-icons.min.css',
// ];

public function configurePackage(Package $package): void
{
$package->name("filament-email-templates")
Expand All @@ -40,35 +33,16 @@ public function configurePackage(Package $package): void
]);
}

// public function register()
// {
// parent::register();
// $this->app->singleton(TokenHelperInterface::class, TokenHelper::class);
// $this->app->singleton(CreateMailableInterface::class, CreateMailableHelper::class);
// $this->app->register(EmailTemplatesEventServiceProvider::class);
// }

public function packageRegistered(): void
{
parent::packageRegistered();

$this->app->singleton(TokenHelperInterface::class, TokenHelper::class);
$this->app->singleton(CreateMailableInterface::class, CreateMailableHelper::class);
$this->app->singleton(FormHelperInterface::class, FormHelper::class);
$this->app->register(EmailTemplatesEventServiceProvider::class);
}

// public function boot()
// {
// parent::boot();
// if($this->app->runningInConsole()) {
// $this->publishResources();
// }

// $this->registerRoutes();

// $this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'vb-email-templates');
// }

public function packageBooted(): void
{
parent::packageBooted();
Expand Down
93 changes: 93 additions & 0 deletions src/Helpers/FormHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Visualbuilder\EmailTemplates\Helpers;

use Visualbuilder\EmailTemplates\Contracts\FormHelperInterface;

class FormHelper implements FormHelperInterface
{
public function getLanguageOptions()
{
return collect(config('email-templates.languages'))->mapWithKeys(function ($langVal, $langKey) {
return [
$langKey => '<span class="flag-icon flag-icon-'.$langVal["flag-icon"].'"></span> '.$langVal["display"],
];
})->toArray();
}

public function getTemplateViewOptions()
{
$overrideDirectory = resource_path('views/vendor/vb-email-templates/email');
$packageDirectory = dirname(view(config('email-templates.template_view_path').'.default')->getPath());

$directories = [$overrideDirectory, $packageDirectory];

$filenamesArray = collect($directories)
->filter(function ($directory) {
return file_exists($directory);
})
->flatMap(function ($directory) {
return self::getFiles($directory, $directory);
})
->unique()
->values()
->toArray();

return array_combine($filenamesArray, $filenamesArray);
}

/**
* Recursively get all files in a directory and children
*/
private static function getFiles($dir, $basepath)
{
$files = $subdirs = $subFiles = [];

if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry == "." || $entry == "..") {
continue;
}
if (substr($entry, 0, 1) == '_') {
continue;
}
$entryPath = $dir.'/'.$entry;
if (is_dir($entryPath)) {
$subdirs[] = $entryPath;
} else {
$subFiles[] = str_replace(
'/',
'.',
str_replace(
'.blade.php',
'',
str_replace(
$basepath.'/',
'',
$entryPath
)
)
);
}
}
closedir($handle);
sort($subFiles);
$files = array_merge($files, $subFiles);
foreach ($subdirs as $subdir) {
$files = array_merge($files, self::getFiles($subdir, $basepath));
}
}

return $files;
}

public function getRecipientOptions()
{
return collect(config('email-templates.recipients'))->mapWithKeys(function ($recipient) {
$splitNamespace = explode('\\', $recipient);
$className = end($splitNamespace); // Get the class name without namespace

return [$className => $recipient]; // Use class name as key and full class name as value
})->toArray();
}
}
4 changes: 2 additions & 2 deletions src/Listeners/PasswordResetListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Auth\Events\PasswordReset;

use Visualbuilder\EmailTemplates\Notifications\UserVerifiedNotification;
use Visualbuilder\EmailTemplates\Notifications\UserPasswordResetNotification;

class PasswordResetListener
{
Expand All @@ -27,7 +27,7 @@ public function __construct()
public function handle(PasswordReset $event)
{
$user = $event->user;
$user->notify(new UserVerifiedNotification());
$user->notify(new UserPasswordResetNotification());


}
Expand Down
3 changes: 2 additions & 1 deletion src/Listeners/UserLockoutListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Visualbuilder\EmailTemplates\Listeners;

use Illuminate\Auth\Events\Login;
use Visualbuilder\EmailTemplates\Notifications\UserLockoutNotification;

class UserLockoutListener
{
Expand All @@ -15,7 +16,7 @@ class UserLockoutListener
public function handle(Login $event)
{
$user = $event->user;
$user->notify(new UserLoNotification());
$user->notify(new UserLockoutNotification());

}
}
4 changes: 2 additions & 2 deletions src/Listeners/UserRegisteredListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Visualbuilder\EmailTemplates\Listeners;

use Illuminate\Auth\Events\Registered;
use Visualbuilder\EmailTemplates\Notifications\UserLoginNotification;
use Visualbuilder\EmailTemplates\Notifications\UserRegisteredNotification;

class UserRegisteredListener
{
Expand All @@ -17,7 +17,7 @@ public function handle(Registered $event)
{
if(config('email-templates.send_emails.new_user_registered')) {
$user = $event->user;
$user->notify(new UserLoginNotification());
$user->notify(new UserRegisteredNotification());
}


Expand Down
5 changes: 5 additions & 0 deletions src/Models/EmailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ public function viewPath(): Attribute
get: fn () => config('email-templates.template_view_path').'.'.$this->view
);
}

public function previewUrl()
{
return route('email-template.preview', $this);
}
}
2 changes: 1 addition & 1 deletion src/Notifications/UserVerifiedNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
*/
public function via($notifiable)
{
return array_merge($this->userVias($notifiable), ['telegram']);
return ['mail'];
}

/**
Expand Down
Loading

0 comments on commit 18fe797

Please sign in to comment.