Skip to content

Commit

Permalink
🎨 ✨ Grouped buttons
Browse files Browse the repository at this point in the history
Handling password
  • Loading branch information
rxcod9 committed Mar 14, 2022
1 parent 2e91061 commit 69fdfce
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ By 🐼 [Ramakant Gangwar](https://github.com/rxcod9).
# 1. Require this Package in your fresh Laravel/Voyager project
composer require joy/voyager-import

# 2. Publish
# 2. Publish everything
php artisan vendor:publish --provider="Joy\VoyagerImport\VoyagerImportServiceProvider" --force

# 3. Publish Voyager overrided actions blade [MANDATORY STEP FOR IMPORT BULK BUTTON TO WORK]
# 3. OR Publish Voyager overrided actions blade [MANDATORY STEP FOR IMPORT BULK BUTTON TO WORK]
php artisan vendor:publish --provider="Joy\VoyagerImport\VoyagerImportServiceProvider" --tag=voyager-actions-views --force
```

Expand Down
2 changes: 1 addition & 1 deletion config/voyager-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
/*
| The default import readerType.
|
| Supported: "Xlsx", "Csv", "Csv", "Ods", "Xls",
| Supported: "Xlsx", "Csv", "Ods", "Xls",
| "Slk", "Xml", "Gnumeric", "Html"
*/
'readerType' => env('VOYAGER_IMPORT_READER_TYPE', 'Xlsx'),
Expand Down
64 changes: 55 additions & 9 deletions resources/views/bread/import.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,61 @@
<input type="file" name="file">
</div>
<div class="modal-footer">
<a
class="btn btn-info pull-left"
id="bulk_import_template_btn"
href="{{ route('voyager.'.$dataType->slug.'.import-template') }}"
title="{{ __('joy-voyager-import::generic.bulk_import_template') }}"
target="_blank"
>
<i class="voyager-download"></i> <span>{{ __('joy-voyager-import::generic.bulk_import_template') }}</span>
</a>
<div class="btn-group pull-left" role="group">
<div class="btn-group" role="group">
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="voyager-download"></i> <span>{{ __('joy-voyager-import::generic.bulk_import_template') }}</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>
<a
class='export-template-by-writer'
data-writer-type="Xls"
href="{{ route('voyager.'.$dataType->slug.'.import-template') }}?writerType=Xls"
title="{{ __('joy-voyager-import::generic.bulk_import_template') }}"
target="_blank"
>Xls</a>
</li>
<li>
<a
class='export-template-by-writer'
data-writer-type="Xlsx"
href="{{ route('voyager.'.$dataType->slug.'.import-template') }}?writerType=Xlsx"
title="{{ __('joy-voyager-import::generic.bulk_import_template') }}"
target="_blank"
>Xlsx</a>
</li>
<li>
<a
class='export-template-by-writer'
data-writer-type="Ods"
href="{{ route('voyager.'.$dataType->slug.'.import-template') }}?writerType=Ods"
title="{{ __('joy-voyager-import::generic.bulk_import_template') }}"
target="_blank"
>Ods</a>
</li>
<li>
<a
class='export-template-by-writer'
data-writer-type="Csv"
href="{{ route('voyager.'.$dataType->slug.'.import-template') }}?writerType=Csv"
title="{{ __('joy-voyager-import::generic.bulk_import_template') }}"
target="_blank"
>Csv</a>
</li>
<li>
<a
class='export-template-by-writer'
data-writer-type="Html"
href="{{ route('voyager.'.$dataType->slug.'.import-template') }}?writerType=Html"
title="{{ __('joy-voyager-import::generic.bulk_import_template') }}"
target="_blank"
>Html</a>
</li>
</ul>
</div>
</div>
<!-- <button type="submit" {!! $action->convertAttributesToHtml() !!}><i class="{{ $action->getIcon() }}"></i> {{ $action->getTitle() }}</button> -->
<input type="hidden" name="action" value="{{ get_class($action) }}">
<!-- <input type="hidden" name="ids" value="" class="selected_ids"> -->
Expand Down
14 changes: 9 additions & 5 deletions resources/views/bread/partials/actions.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
@endphp
@can ($action->getPolicy(), $data)
@if ($action->shouldActionDisplayOnRow($data))
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
</a>
@if (method_exists($action, 'view'))
@include($action->view(), ['action' => $action, 'data' => $data, 'dataType' => $dataType])
@else
<a href="{{ $action->getRoute($dataType->name) }}" title="{{ $action->getTitle() }}" {!! $action->convertAttributesToHtml() !!}>
<i class="{{ $action->getIcon() }}"></i> <span class="hidden-xs hidden-sm">{{ $action->getTitle() }}</span>
</a>
@endif
@endif
@endcan
@elseif (method_exists($action, 'massAction') && method_exists($action, 'massView'))
@include($action->massView(), ['action' => $action, 'data' => null])
@elseif (method_exists($action, 'massAction') && method_exists($action, 'view'))
@include($action->view(), ['action' => $action, 'data' => null, 'dataType' => $dataType])
@elseif (method_exists($action, 'massAction'))
<form method="post" action="{{ route('voyager.'.$dataType->slug.'.action') }}" style="display:inline">
{{ csrf_field() }}
Expand Down
5 changes: 3 additions & 2 deletions src/Actions/ImportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public function massAction($ids, $comingFrom)
}

$disk = $this->disk ?? config('joy-voyager-import.disk');
$readerType = $this->readerType ?? config('joy-voyager-import.readerType', Excel::XLSX);
// @FIXME let me auto detect OR NOT??
$readerType = null; //$this->readerType ?? config('joy-voyager-import.readerType', Excel::XLSX);

$importClass = 'joy-voyager-import.import';

Expand All @@ -122,7 +123,7 @@ public function massAction($ids, $comingFrom)
]);
}

public function massView()
public function view()
{
$view = 'joy-voyager-import::bread.import';

Expand Down
1 change: 1 addition & 0 deletions src/Exports/DataTypeTemplateExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function map($data): array

$columns = [];
// $columns[] = $data->id;

foreach ($this->dataType->rows as $row) {
$column = null;
if ($data->{$row->field . '_export'}) {
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Traits/ImportTemplateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function importTemplate(Request $request)
// Check permission
$this->authorize('browse', app($dataType->model_name));

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

$exportClass = 'joy-voyager-import.import-template';
Expand All @@ -42,9 +42,10 @@ public function importTemplate(Request $request)
}

$export = app($exportClass);

return $export->set(
$dataType,
[],
$request->all(),
)->download(
$fileName,
Expand Down
17 changes: 12 additions & 5 deletions src/Imports/DataTypeImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

// use App\Models\User;

use TCG\Voyager\Http\Controllers\Traits\BreadRelationshipParser;
use TCG\Voyager\Models\DataType;
use Maatwebsite\Excel\Concerns\Importable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Hash;
use Joy\VoyagerImport\Events\BreadDataImported;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithProgressBar;
use Maatwebsite\Excel\Concerns\WithUpserts;
use Maatwebsite\Excel\Concerns\WithValidation;
use Maatwebsite\Excel\Events\AfterImport;
use TCG\Voyager\Http\Controllers\Traits\BreadRelationshipParser;
use TCG\Voyager\Models\DataType;

class DataTypeImport implements
ToModel,
Expand Down Expand Up @@ -264,7 +265,7 @@ public function model(array $item)
// If a column has a relationship associated with it, we do not want to show that field
// $this->removeRelationshipField($this->dataType, 'browse');

$data->id = $item['id'];
$data->id = $item['id'] ?? $item[''] ?? null;

foreach ($this->dataType->rows as $row) {
if ($data->hasSetMutator($row->field . '_import')) {
Expand Down Expand Up @@ -342,7 +343,13 @@ public function model(array $item)
// @TODO check if not hash then use bcrypt
// Ignore if password is not set
if (($item[$row->field] ?? null)) {
$data->{$row->field} = ($item[$row->field] ?? null);
$password = $item[$row->field] ?? null;
$passwordInfo = password_get_info($password);
if ($passwordInfo['algo']) {
$data->{$row->field} = ($item[$row->field] ?? null);
} else {
$data->{$row->field} = Hash::make($item[$row->field] ?? null);
}
}
} elseif ($row->type == 'text_area') {
// view('voyager::multilingual.input-hidden-bread-browse');
Expand Down

0 comments on commit 69fdfce

Please sign in to comment.