Skip to content

Commit cd7fbc6

Browse files
committed
✨ Grouped buttons
1 parent cf1662a commit cd7fbc6

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ By 🐼 [Ramakant Gangwar](https://github.com/rxcod9).
2626
# 1. Require this Package in your fresh Laravel/Voyager project
2727
composer require joy/voyager-export
2828

29-
# 2. Publish
29+
# 2. Publish evrything
3030
php artisan vendor:publish --provider="Joy\VoyagerExport\VoyagerExportServiceProvider" --force
31+
# 3. OR Publish Voyager overrided actions blade [MANDATORY STEP FOR EXPORT BULK GROUP BUTTON TO WORK]
32+
php artisan vendor:publish --provider="Joy\VoyagerExport\VoyagerExportServiceProvider" --tag=voyager-actions-views --force
3133
```
3234

3335
---
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<div class="btn-group" role="group">
2+
<div class="btn-group" role="group">
3+
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
4+
<i class="{{ $action->getIcon() }}"></i> {{ $action->getTitle() }}
5+
<span class="caret"></span>
6+
</button>
7+
<ul class="dropdown-menu">
8+
<li><a class='export-by-writer' href="#" data-writer-type="Xls">Xls</a></li>
9+
<li><a class='export-by-writer' href="#" data-writer-type="Xlsx">Xlsx</a></li>
10+
<li><a class='export-by-writer' href="#" data-writer-type="Ods">Ods</a></li>
11+
<li><a class='export-by-writer' href="#" data-writer-type="Csv">Csv</a></li>
12+
<li><a class='export-by-writer' href="#" data-writer-type="Html">Html</a></li>
13+
@if(class_exists('TCPDF'))
14+
<li><a class='export-by-writer' href="#" data-writer-type="Tcpdf">Tcpdf</a></li>
15+
@endif
16+
@if(class_exists('Dompdf\Dompdf'))
17+
<li><a class='export-by-writer' href="#" data-writer-type="Dompdf">Dompdf</a></li>
18+
@endif
19+
@if(class_exists('Mpdf\Mpdf'))
20+
<li><a class='export-by-writer' href="#" data-writer-type="Mpdf">Mpdf</a></li>
21+
@endif
22+
</ul>
23+
</div>
24+
</div>
25+
<form id="bulk_export_form" method="post" action="{{ route('voyager.'.$dataType->slug.'.action') }}" style="display:none;">
26+
{{ csrf_field() }}
27+
<button type="submit"><i class="{{ $action->getIcon() }}"></i> {{ $action->getTitle() }}</button>
28+
<input type="hidden" name="action" value="{{ get_class($action) }}">
29+
<input type="hidden" name="ids" value="" class="selected_ids">
30+
</form>
31+
32+
@push('javascript')
33+
<script>
34+
$(function() {
35+
var exportAction = `{{ route('voyager.'.$dataType->slug.'.action') }}`;
36+
$('.export-by-writer').click(function() {
37+
var writerType = $(this).data('writer-type');
38+
$('#bulk_export_form').attr('action', exportAction + '?writerType=' + writerType);
39+
$('#bulk_export_form').submit();
40+
})
41+
});
42+
</script>
43+
@endpush
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@if($data)
2+
@php
3+
// need to recreate object because policy might depend on record data
4+
$class = get_class($action);
5+
$action = new $class($dataType, $data);
6+
@endphp
7+
@can ($action->getPolicy(), $data)
8+
@if ($action->shouldActionDisplayOnRow($data))
9+
@if (method_exists($action, 'view'))
10+
@include($action->view(), ['action' => $action, 'data' => $data, 'dataType' => $dataType])
11+
@else
12+
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
13+
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
14+
</a>
15+
@endif
16+
@endif
17+
@endcan
18+
@elseif (method_exists($action, 'massAction') && method_exists($action, 'view'))
19+
@include($action->view(), ['action' => $action, 'data' => null, 'dataType' => $dataType])
20+
@elseif (method_exists($action, 'massAction'))
21+
<form method="post" action="{{ route('voyager.'.$dataType->slug.'.action') }}" style="display:inline">
22+
{{ csrf_field() }}
23+
<button type="submit" {!! $action->convertAttributesToHtml() !!}><i class="{{ $action->getIcon() }}"></i> {{ $action->getTitle() }}</button>
24+
<input type="hidden" name="action" value="{{ get_class($action) }}">
25+
<input type="hidden" name="ids" value="" class="selected_ids">
26+
</form>
27+
@endif

src/Actions/ExportAction.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function massAction($ids, $comingFrom)
7474
// Check permission
7575
Gate::authorize('browse', app($dataType->model_name));
7676

77-
$writerType = $this->writerType ?? config('joy-voyager-export.writerType', Excel::XLSX);
77+
$writerType = request()->get('writerType', $this->writerType ?? config('joy-voyager-export.writerType', Excel::XLSX));
7878
$fileName = $this->fileName ?? ($dataType->slug . '.' . Str::lower($writerType));
7979

8080
$exportClass = 'joy-voyager-export.export';
@@ -95,6 +95,16 @@ public function massAction($ids, $comingFrom)
9595
);
9696
}
9797

98+
public function view()
99+
{
100+
$view = 'joy-voyager-export::bread.export';
101+
102+
if (view()->exists('joy-voyager-export::' . $this->dataType->slug . '.export')) {
103+
$view = 'joy-voyager-export::' . $this->dataType->slug . '.export';
104+
}
105+
return $view;
106+
}
107+
98108
protected function getSlug(Request $request)
99109
{
100110
if (isset($this->slug)) {

src/VoyagerExportServiceProvider.php

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ protected function registerPublishables(): void
9696
__DIR__ . '/../resources/views' => resource_path('views/vendor/joy-voyager-export'),
9797
], 'views');
9898

99+
$this->publishes([
100+
__DIR__ . '/../resources/views/bread/partials' => resource_path('views/vendor/voyager/bread/partials'),
101+
], 'voyager-actions-views');
102+
99103
$this->publishes([
100104
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/joy-voyager-export'),
101105
], 'translations');

0 commit comments

Comments
 (0)