Skip to content

Commit 0e1bfe2

Browse files
committed
add advanced params and factory option in the config and small fixes
1 parent f0ed5a9 commit 0e1bfe2

File tree

6 files changed

+137
-16
lines changed

6 files changed

+137
-16
lines changed

config/maileclipse.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222

2323
'mail_dir' => app_path('Mail/'),
2424

25+
26+
/*
27+
|--------------------------------------------------------------------------
28+
| If you want the package to look for the equivalent factory if the
29+
| dependency is an eloquent model.
30+
|--------------------------------------------------------------------------
31+
|
32+
*/
33+
34+
'factory' => true,
35+
2536
/*
2637
|--------------------------------------------------------------------------
2738
| Environment
@@ -46,7 +57,7 @@
4657
*/
4758

4859
'middleware' => [
49-
'web',
60+
5061
],
5162

5263
/*

public/css/maileclipse-app.css

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/css/maileclipse-app.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/maileclipse-app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const el = document.querySelector('img');
1414

1515
$(function () {
1616
$('[data-toggle="popover"]').popover();
17+
$('[maileclipse-data-toggle="tooltip"]').tooltip();
1718
})
1819

1920
$(document).on('click', function (e) {

resources/views/sections/edit-mailable-template.blade.php

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,55 @@
9191

9292

9393
<div class="tab-pane fade show active" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">
94-
<div class="p-2" style="border-top: 1px solid #ccc;">
94+
<div class="p-3" style="border-top: 1px solid #ccc;">
9595
@foreach($templateData['view_data'] as $param)
96-
<span class="badge badge-secondary view_data_param mr-1" style="font-size: .84em;"><i class="fa fa-anchor mr-1" aria-hidden="true"></i>{{ $param }}</span>
97-
@endforeach
96+
97+
{{-- {{ dd($param) }} --}}
98+
@if ( $param['data']['type'] === 'model' )
99+
<div class="btn-group dropright">
100+
<button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" maileclipse-data-toggle="tooltip" data-placement="top" title="Elequent Model">
101+
<i class="fas fa-database mr-1"></i>{{ $param['key'] }}
102+
</button>
103+
<div class="dropdown-menu">
104+
105+
<!-- Dropdown menu links -->
106+
@if ( !$param['data']['attributes']->isEmpty() )
107+
<a class="dropdown-item view_data_param" param-key="{{ $param['key'] }}" href="#">{{ $param['key'] }}</a>
108+
<div class="dropdown-divider"></div>
109+
@foreach( $param['data']['attributes'] as $key => $val )
110+
<a class="dropdown-item is-attribute view_data_param" param-parent-key="{{ $param['key'] }}" param-key="{{ $key }}" href="#">{{ $key }}</a>
111+
@endforeach
112+
113+
@else
114+
115+
<span class="dropdown-item">No attributes found</span>
116+
117+
@endif
118+
119+
</div>
120+
</div>
121+
122+
@elseif( $param['data']['type'] === 'elequent-collection' )
123+
124+
<button type="button" class="btn btn-info btn-sm view_data_param" maileclipse-data-toggle="tooltip" data-placement="top" title="Elequent Collection" param-key="{{ $param['key'] }}">
125+
<i class="fa fa-table mr-1" aria-hidden="true"></i>{{ $param['key'] }}
126+
</button>
127+
128+
@elseif( $param['data']['type'] === 'collection' )
129+
130+
<button type="button" class="btn btn-success btn-sm view_data_param" maileclipse-data-toggle="tooltip" data-placement="top" title="Collection" param-key="{{ $param['key'] }}">
131+
<i class="fa fa-table mr-1" aria-hidden="true"></i>{{ $param['key'] }}
132+
</button>
133+
134+
@else
135+
136+
<button type="button" class="btn btn-secondary btn-sm view_data_param" maileclipse-data-toggle="tooltip" data-placement="top" title="Simple Variable" param-key="{{ $param['key'] }}">
137+
<i class="fa fa-anchor mr-1" aria-hidden="true"></i>{{ $param['key'] }}
138+
</button>
139+
140+
@endif
141+
142+
@endforeach
98143
</div>
99144
<textarea id="template_editor" cols="30" rows="10">{{ $templateData['template'] }}</textarea>
100145
</div>
@@ -436,10 +481,15 @@ function viewMarkdownParser(plainText){
436481
var cm = simplemde.codemirror;
437482
var output = '';
438483
var selectedText = cm.getSelection();
439-
var param = $(this).text();
484+
var param = $(this).attr('param-key');
440485
441486
output = `\{\{ $` + param + ` \}\}`;
442487
488+
if ( $(this).hasClass('is-attribute') ){
489+
490+
var output = `\{\{ $` + $(this).attr('param-parent-key') + '->' + param + ` \}\}`;
491+
}
492+
443493
cm.replaceSelection(output);
444494
});
445495
@@ -483,8 +533,14 @@ function viewMarkdownParser(plainText){
483533
484534
485535
$('.view_data_param').click(function(){
486-
var param = $(this).text();
487-
var output = `\{\{ $` + param + ` \}\}`;
536+
var param = $(this).attr('param-key');
537+
output = `\{\{ $` + param + ` \}\}`;
538+
539+
if ( $(this).hasClass('is-attribute') ){
540+
541+
var output = `\{\{ $` + $(this).attr('param-parent-key') + '->' + param + ` \}\}`;
542+
}
543+
488544
tinymce.activeEditor.selection.setContent(output);
489545
});
490546

src/mailEclipse.php

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,16 @@ static protected function mailablesList()
548548
continue;
549549
}
550550

551+
$mailable_data = self::buildMailable($mailableClass);
552+
551553
if (!is_null(self::handleMailableViewDataArgs($mailableClass))) {
552-
$mailable_view_data = self::getMailableViewData(self::handleMailableViewDataArgs($mailableClass));
554+
$mailable_view_data = self::getMailableViewData(self::handleMailableViewDataArgs($mailableClass), $mailable_data);
555+
556+
// dd($mailable_view_data);
553557
} else {
554-
$mailable_view_data = self::getMailableViewData(new $mailableClass);
558+
$mailable_view_data = self::getMailableViewData(new $mailableClass, $mailable_data);
555559
}
556560

557-
558561
$mailable_data = self::buildMailable($mailableClass);
559562

560563
$fqcns[$i]['data'] = $mailable_data;
@@ -673,7 +676,7 @@ static public function handleMailableViewDataArgs($mailable)
673676

674677
if (isset($arg['is_instance'])) {
675678

676-
if (isset($eloquentFactory[$arg['instance']])) {
679+
if (isset($eloquentFactory[$arg['instance']]) && config('maileclipse.factory')) {
677680

678681
$filteredparams[] = factory($arg['instance'])->states($factoryStates)->create();
679682

@@ -716,7 +719,7 @@ static public function handleMailableViewDataArgs($mailable)
716719
}
717720

718721

719-
static private function getMailableViewData($mailable)
722+
static private function getMailableViewData($mailable, $mailable_data)
720723
{
721724

722725
$traitProperties = [];
@@ -748,10 +751,52 @@ static private function getMailableViewData($mailable)
748751

749752
$classProps = array_diff($allProps, $traitProperties);
750753

751-
$mailableData = collect($classProps)->merge(collect($obj->viewData)->keys());
754+
$withFuncData = collect($obj->viewData)->keys();
755+
756+
$mailableData = collect($classProps)->merge($withFuncData);
757+
758+
// dd($mailableData);
759+
760+
$data = $mailableData->map(function($parameter) use ($mailable_data){
761+
762+
return [
763+
'key' => $parameter,
764+
'value' => $mailable_data->$parameter,
765+
'data' => self::viewDataInspect($mailable_data->$parameter),
766+
];
767+
768+
});
769+
770+
return $data->all();
771+
772+
}
773+
752774

753-
return $mailableData->all();
775+
static protected function viewDataInspect($param){
754776

777+
// dd($param);
778+
779+
if ( $param instanceof \Illuminate\Database\Eloquent\Model ){
780+
781+
return [
782+
'type' => 'model',
783+
'attributes' => collect($param->getAttributes()),
784+
];
785+
786+
} elseif ( $param instanceof \Illuminate\Database\Eloquent\Collection) {
787+
788+
return [
789+
'type' => 'elequent-collection',
790+
'attributes' => $param->all(),
791+
];
792+
}
793+
794+
elseif ( $param instanceof \Illuminate\Support\Collection ) {
795+
return [
796+
'type' => 'collection',
797+
'attributes' => $param->all(),
798+
];
799+
}
755800
}
756801

757802
/**

0 commit comments

Comments
 (0)