From: Louis Jeckel Date: Tue, 17 Nov 2020 13:57:39 +0000 (+0100) Subject: unlayer X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=71e09e2f7a07cee11ee8f6ea71f25d2cfa0686ca;p=psq.git unlayer --- diff --git a/.idea/lettre-pharma.iml b/.idea/lettre-pharma.iml index d832340..372f6f2 100644 --- a/.idea/lettre-pharma.iml +++ b/.idea/lettre-pharma.iml @@ -20,6 +20,7 @@ + diff --git a/.idea/php.xml b/.idea/php.xml index 8922dea..f577850 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -212,6 +212,7 @@ + diff --git a/app/EmailTemplate.php b/app/EmailTemplate.php index 6fb79a5..8155b95 100644 --- a/app/EmailTemplate.php +++ b/app/EmailTemplate.php @@ -3,8 +3,10 @@ namespace App; use App\Mail\TemplateMail; +use App\Mail\TemplateMailOld; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Mail\Mailable; use Illuminate\Support\Str; /** @@ -21,9 +23,12 @@ class EmailTemplate extends Model public $timestamps = false; protected $casts = [ - 'show_in_actions' => 'boolean' + 'show_in_actions' => 'boolean', + 'design' => 'array', ]; + protected $guarded = []; + /** * @param $slug * @return EmailTemplate @@ -48,7 +53,7 @@ class EmailTemplate extends Model $match = Str::before(Str::after($matches[0], '%'), '%'); - return $user->templateAttribute($match); + return $user->templateAttribute($match, null) ?? $matches[0]; }, $content); @@ -103,7 +108,18 @@ class EmailTemplate extends Model public function render() { $user = User::query()->offset(1)->first(); - return (new TemplateMail($this->fillFor($user), $this->fillSubjectFor($user)))->render(); + return $this->getMailFor($user)->render(); + } + + /** + * @param User $user + * @return Mailable + */ + public function getMailableFor(User $user) + { + return $this->html ? + (new TemplateMail($this->fillFor($user), $this->fillSubjectFor($user))) : + (new TemplateMailOld($this->fillFor($user), $this->fillSubjectFor($user))); } /** @@ -114,4 +130,11 @@ class EmailTemplate extends Model { return $this->render(); } + + public function getContentAttribute() + { + return $this->html ?? $this->getAttributes()['content']; + } + + } diff --git a/app/Mail/TemplateMail.php b/app/Mail/TemplateMail.php index a574f1a..882ab60 100644 --- a/app/Mail/TemplateMail.php +++ b/app/Mail/TemplateMail.php @@ -38,6 +38,8 @@ class TemplateMail extends Mailable implements ShouldQueue */ public function build() { - return $this->markdown('emails.template'); + return $this->html($this->content); } + + } diff --git a/app/Mail/TemplateMailOld.php b/app/Mail/TemplateMailOld.php new file mode 100644 index 0000000..91be9a8 --- /dev/null +++ b/app/Mail/TemplateMailOld.php @@ -0,0 +1,51 @@ +content = $content; + $this->subject = $subject; + $this->replyTo(config('app.emails.olivier')); + } + + /** + * Build the message. + * + * @return $this + */ + public function build() + { + return $this->markdown('emails.template'); + } + + +} diff --git a/app/Nova/Actions/SendCustomNotification.php b/app/Nova/Actions/SendCustomNotification.php index a03a3ee..921bf30 100644 --- a/app/Nova/Actions/SendCustomNotification.php +++ b/app/Nova/Actions/SendCustomNotification.php @@ -73,9 +73,11 @@ class SendCustomNotification extends Action /** * @return array + * @todo */ public static function getActions() { + return []; return \App\EmailTemplate::inActionsMenu()->get()->mapInto(self::class)->toArray(); } } diff --git a/app/Nova/EmailTemplate.php b/app/Nova/EmailTemplate.php index e0cee3b..daf9d56 100644 --- a/app/Nova/EmailTemplate.php +++ b/app/Nova/EmailTemplate.php @@ -2,6 +2,7 @@ namespace App\Nova; +use IDF\NovaUnlayerField\Unlayer; use Illuminate\Http\Request; use Laravel\Nova\Fields\Boolean; use Laravel\Nova\Fields\ID; @@ -59,9 +60,30 @@ class EmailTemplate extends Resource Text::make('Nom code', 'slug')->hideFromIndex(), Text::make('Nom', 'name')->required(), Text::make('Sujet', 'subject'), - Trix::make('Contenu', 'content')->alwaysShow()->required(), Boolean::make('Dans menu action ?', 'show_in_actions'), Iframe::make('Aperçu', 'renderedHtml'), + Unlayer::make('Email', 'design')->config([ + 'projectId' => config('services.unlayer.projectId'), + 'templateId' => $this->design === null ? 20390 : null, + 'locale' => app()->getLocale(), + 'specialLinks' => [ + [ + 'name' => 'Home', + 'href' => route('home'), + ], + [ + 'name' => 'Contact', + 'href' => route('contact.index') + ], + + ], + ])->savingCallback(function ($request, $attribute, $model, $html) + { + $model->update([ + 'design' => $request->get('design'), + 'html' => $request->get('design_html') + ]); + })->hideFromDetail(), ]; } diff --git a/app/TemplateVariables.php b/app/TemplateVariables.php index d3f7710..ba7e74f 100644 --- a/app/TemplateVariables.php +++ b/app/TemplateVariables.php @@ -25,15 +25,14 @@ trait TemplateVariables $template = EmailTemplate::findSlug($template); } - \Mail::to($this)->send(new TemplateMail( - $template->fillFor($this), - $template->fillSubjectFor($this) - )); + + \Mail::to($this)->send($template->getMailableFor($this)); } /** * @param $subject * @param $content + * @todo Broken * Fills subject and content, then sends mail */ public function sendTemplateEmail($subject, $content) diff --git a/composer.json b/composer.json index 1054697..df47b1e 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "fruitcake/laravel-cors": "^1.0", "guzzlehttp/guzzle": "^6.3", "html2text/html2text": "^4.3", + "idf/nova-unlayer-field": "^0.2.1", "itsgoingd/clockwork": "^4.1", "judev/php-htmltruncator": "^1.2", "kriswallsmith/buzz": "^1.1", diff --git a/composer.lock b/composer.lock index 5873fbf..c721f28 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "170a4b87161eb1a26074692e0e8292bd", + "content-hash": "28f3513135fec03d3b77372b1e83ad1f", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -2161,6 +2161,47 @@ ], "time": "2018-07-31T19:32:56+00:00" }, + { + "name": "idf/nova-unlayer-field", + "version": "0.2.1", + "source": { + "type": "git", + "url": "https://github.com/InteractionDesignFoundation/nova-unlayer-field.git", + "reference": "10fb6a76a075c699f38ae8d16786d161f408d0b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/InteractionDesignFoundation/nova-unlayer-field/zipball/10fb6a76a075c699f38ae8d16786d161f408d0b8", + "reference": "10fb6a76a075c699f38ae8d16786d161f408d0b8", + "shasum": "" + }, + "require": { + "php": ">=7.1.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "IDF\\NovaUnlayerField\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "IDF\\NovaUnlayerField\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A Laravel Nova field for Unlayer to compose emails and landing pages", + "keywords": [ + "laravel", + "nova" + ], + "time": "2020-04-23T11:09:48+00:00" + }, { "name": "imgix/imgix-php", "version": "3.3.0", diff --git a/config/app.php b/config/app.php index 430ce7d..a7dec26 100644 --- a/config/app.php +++ b/config/app.php @@ -133,6 +133,7 @@ return [ ], + /* |-------------------------------------------------------------------------- | Autoloaded Service Providers diff --git a/config/services.php b/config/services.php index fc4fe19..5f90194 100644 --- a/config/services.php +++ b/config/services.php @@ -33,6 +33,10 @@ return [ 'stripe' => [ 'enable' => env('STRIPE_ENABLE', false), 'test_social_id' => env('STRIPE_TEST_SOCIAL_ID', null) + ], + + 'unlayer' => [ + 'projectId' => 7628, ] ]; diff --git a/database/migrations/2020_11_17_114315_add_design_to_email_templates.php b/database/migrations/2020_11_17_114315_add_design_to_email_templates.php new file mode 100644 index 0000000..ed19cb9 --- /dev/null +++ b/database/migrations/2020_11_17_114315_add_design_to_email_templates.php @@ -0,0 +1,34 @@ +json('design')->nullable(); + $table->longText('html')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('email_templates', function (Blueprint $table) { + $table->dropColumn('design'); + $table->dropColumn('html'); + }); + } +}